From: Timo Sirainen Date: Sat, 20 May 2023 20:21:00 +0000 (+0300) Subject: config: Use config_module_parsers_get_setting() where possible X-Git-Tag: 2.4.0~1983 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e67dee95b0a2cae403d08833f91f980836a88fc;p=thirdparty%2Fdovecot%2Fcore.git config: Use config_module_parsers_get_setting() where possible --- diff --git a/src/config/config-request.c b/src/config/config-request.c index ba44e689f6..56ef240174 100644 --- a/src/config/config-request.c +++ b/src/config/config-request.c @@ -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) diff --git a/src/config/doveconf.c b/src/config/doveconf.c index c0d3b82350..f624b7448a 100644 --- a/src/config/doveconf.c +++ b/src/config/doveconf.c @@ -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());