]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Use config_module_parsers_get_setting() where possible
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Sat, 20 May 2023 20:21:00 +0000 (23:21 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 20 Nov 2023 12:22:31 +0000 (14:22 +0200)
src/config/config-request.c
src/config/doveconf.c

index ba44e689f6d1ffbb6525a521642276c13a9fa8ee..56ef240174090fe606e51ad46142ada292f04550 100644 (file)
@@ -356,38 +356,14 @@ unsigned int config_export_get_parser_count(struct config_export_context *ctx)
 const char *
 config_export_get_import_environment(struct config_export_context *ctx)
 {
-       enum setting_type stype;
-       unsigned int i;
-
-       for (i = 0; ctx->module_parsers[i].info != NULL; i++) {
-               if (ctx->module_parsers[i].info == &master_service_setting_parser_info) {
-                       const char *key = "import_environment";
-                       const char *const *value =
-                               settings_parse_get_value(ctx->module_parsers[i].parser,
-                                                        &key, &stype);
-                       i_assert(value != NULL);
-                       return *value;
-               }
-       }
-       i_unreached();
+       return config_module_parsers_get_setting(ctx->module_parsers,
+               "master_service", "import_environment");
 }
 
 const char *config_export_get_base_dir(struct config_export_context *ctx)
 {
-       enum setting_type stype;
-       unsigned int i;
-
-       for (i = 0; ctx->module_parsers[i].info != NULL; i++) {
-               if (ctx->module_parsers[i].info == &master_service_setting_parser_info) {
-                       const char *key = "base_dir";
-                       const char *const *value =
-                               settings_parse_get_value(ctx->module_parsers[i].parser,
-                                                        &key, &stype);
-                       i_assert(value != NULL);
-                       return *value;
-               }
-       }
-       i_unreached();
+       return config_module_parsers_get_setting(ctx->module_parsers,
+                                                "master_service", "base_dir");
 }
 
 void config_export_free(struct config_export_context **_ctx)
index c0d3b8235071d44832077d84a90db5505c21ec84..f624b7448afffa6518689ee0e506550c4b5960bf 100644 (file)
@@ -700,28 +700,6 @@ config_dump_human(enum config_dump_scope scope,
        return ret;
 }
 
-static const char *get_setting(const char *info_name, const char *name)
-{
-       const struct config_module_parser *l;
-       const struct setting_define *def;
-       const char *const *value;
-       const void *set;
-
-       for (l = config_parsed_get_module_parsers(config); l->info != NULL; l++) {
-               if (strcmp(l->info->name, info_name) != 0)
-                       continue;
-
-               set = settings_parser_get_set(l->parser);
-               for (def = l->info->defines; def->key != NULL; def++) {
-                       if (strcmp(def->key, name) == 0) {
-                               value = CONST_PTR_OFFSET(set, def->offset);
-                               return *value;
-                       }
-               }
-       }
-       i_unreached();
-}
-
 struct hostname_format {
        const char *prefix, *suffix;
        unsigned int numcount;
@@ -830,7 +808,9 @@ static void check_wrong_config(const char *config_path)
 {
        const char *base_dir, *symlink_path, *prev_path, *error;
 
-       base_dir = get_setting("master_service", "base_dir");
+       base_dir = config_module_parsers_get_setting(
+                       config_parsed_get_module_parsers(config),
+                       "master_service", "base_dir");
        symlink_path = t_strconcat(base_dir, "/"PACKAGE".conf", NULL);
        if (t_readlink(symlink_path, &prev_path, &error) < 0) {
                if (errno != ENOENT)
@@ -1017,9 +997,12 @@ int main(int argc, char *argv[])
                                                hide_key, hide_passwords);
                }
        } else {
-               const char *info;
+               const char *info, *mail_location;
 
-               info = sysinfo_get(get_setting("mail_storage", "mail_location"));
+               mail_location = config_module_parsers_get_setting(
+                       config_parsed_get_module_parsers(config),
+                       "mail_storage", "mail_location");
+               info = sysinfo_get(mail_location);
                if (*info != '\0')
                        printf("# %s\n", info);
                printf("# Hostname: %s\n", my_hostdomain());