From: Timo Sirainen Date: Wed, 6 Nov 2024 13:44:28 +0000 (+0200) Subject: config: Replace config_module_parsers_get_setting() with config_parsed_get_setting() X-Git-Tag: 2.4.1~567 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b84b17efd29c49216923e73ebd916a263e6de154;p=thirdparty%2Fdovecot%2Fcore.git config: Replace config_module_parsers_get_setting() with config_parsed_get_setting() The new function looks up both explicitly changed settings and default settings. --- diff --git a/src/config/config-dump-full.c b/src/config/config-dump-full.c index b535196fa6..fd4d8ab035 100644 --- a/src/config/config-dump-full.c +++ b/src/config/config-dump-full.c @@ -619,8 +619,7 @@ int config_dump_full(struct config_parsed *config, switch (dest) { case CONFIG_DUMP_FULL_DEST_RUNDIR: { const char *base_dir = - config_module_parsers_get_setting( - filter_parser->module_parsers, + config_parsed_get_setting(config, "master_service", "base_dir"); final_path = t_strdup_printf("%s/dovecot.conf.binary", base_dir); str_append(path, final_path); @@ -657,8 +656,7 @@ int config_dump_full(struct config_parsed *config, if (import_environment_r != NULL) { const char *value = - config_module_parsers_get_setting( - filter_parser->module_parsers, + config_parsed_get_setting(config, "master_service", "import_environment"); *import_environment_r = t_strdup(value); } diff --git a/src/config/config-parser.c b/src/config/config-parser.c index 5576b9b40b..5f8aa2434c 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -2545,9 +2545,14 @@ prevfile: i_stream_destroy(&ctx.cur_input->input); ctx.cur_input = ctx.cur_input->prev; } + + old_settings_handle_post(&ctx); + if (ret == 0) + ret = config_parse_finish(&ctx, flags, config_r, error_r); + if (ret == 0 && !dump_defaults && (flags & CONFIG_PARSE_FLAG_NO_DEFAULTS) == 0) { - const char *version = config_module_parsers_get_setting(ctx.root_module_parsers, + const char *version = config_parsed_get_setting(*config_r, "master_service", "dovecot_storage_version"); if (version[0] == '\0') { *error_r = "dovecot_storage_version setting must be set"; @@ -2555,10 +2560,6 @@ prevfile: } } - old_settings_handle_post(&ctx); - if (ret == 0) - ret = config_parse_finish(&ctx, flags, config_r, error_r); - hash_table_destroy(&ctx.seen_settings); hash_table_destroy(&ctx.all_keys); str_free(&full_line); @@ -2585,55 +2586,98 @@ config_parsed_get_global_filter_parser(struct config_parsed *config) return config->filter_parsers[0]; } +struct config_filter_parser * +config_parsed_get_global_default_filter_parser(struct config_parsed *config) +{ + return config->filter_parsers[1]; +} + struct config_filter_parser *const * config_parsed_get_filter_parsers(struct config_parsed *config) { return config->filter_parsers; } +static void +config_parsed_strlist_append(string_t *keyvals, + const ARRAY_TYPE(const_string) *values, + const ARRAY_TYPE(const_string) *drop_values) +{ + if (values == NULL || !array_is_created(values)) + return; + + const char *const *strlist, *const *drop_strlist; + unsigned int i, j, len, drop_len; + if (drop_values != NULL && array_is_created(drop_values)) + drop_strlist = array_get(drop_values, &drop_len); + else { + drop_strlist = NULL; + drop_len = 0; + } + + strlist = array_get(values, &len); + for (i = 0; i < len; i += 2) { + if (str_len(keyvals) > 0) + str_append_c(keyvals, ' '); + for (j = 0; j < drop_len; j += 2) { + if (strcmp(strlist[i], drop_strlist[j]) == 0) + break; + } + if (j == drop_len) { + str_printfa(keyvals, "%s=%s", strlist[i], + strlist[i + 1]); + } + } +} + const char * -config_module_parsers_get_setting(const struct config_module_parser *module_parsers, - const char *info_name, const char *key) +config_parsed_get_setting(struct config_parsed *config, + const char *info_name, const char *key) { - const struct config_module_parser *l; - unsigned int key_idx; + struct config_filter_parser *filter_parser = + config_parsed_get_global_filter_parser(config); + struct config_filter_parser *default_filter_parser = + config_parsed_get_global_default_filter_parser(config); + const struct config_module_parser *l = filter_parser->module_parsers; + const struct config_module_parser *ldef = + default_filter_parser->module_parsers; + unsigned int info_idx, key_idx; - for (l = module_parsers; l->info != NULL; l++) { - if (strcmp(l->info->name, info_name) == 0) + for (info_idx = 0; l[info_idx].info != NULL; info_idx++) { + if (strcmp(l[info_idx].info->name, info_name) == 0) break; } - if (l->info == NULL || - !setting_parser_info_find_key(l->info, key, &key_idx)) { + if (l[info_idx].info == NULL || + !setting_parser_info_find_key(l[info_idx].info, key, &key_idx)) { i_panic("BUG: Couldn't find setting with info=%s key=%s", info_name, key); } - const struct setting_define *def = &l->info->defines[key_idx]; + const struct setting_define *def = &l[info_idx].info->defines[key_idx]; /* Custom handler for the import_environment strlist setting. The calling function expects a string of key=value pairs. See master_service_get_import_environment_keyvals() for the original implementation. */ if (strcmp(key, "import_environment") == 0) { - unsigned int len = array_count(l->settings[key_idx].array.values); string_t *keyvals = t_str_new(64); - for (unsigned int i = 0; i < len; i += 2) { - const char *const *key = array_idx(l->settings[key_idx].array.values, i); - const char *const *val = array_idx(l->settings[key_idx].array.values, i + 1); - str_append(keyvals, t_strdup_printf("%s=%s", *key, *val)); - - if (i + 2 < len) - str_append_c(keyvals, ' '); - } + const ARRAY_TYPE(const_string) *strlist_set = + l[info_idx].settings[key_idx].array.values; + const ARRAY_TYPE(const_string) *strlist_defaults = + ldef[info_idx].settings[key_idx].array.values; + config_parsed_strlist_append(keyvals, strlist_set, NULL); + config_parsed_strlist_append(keyvals, strlist_defaults, strlist_set); return str_c(keyvals); } i_assert(def->type != SET_STRLIST && def->type != SET_BOOLLIST && def->type != SET_FILTER_ARRAY); - if (l->change_counters[key_idx] != 0) - return l->settings[key_idx].str; + if (l[info_idx].change_counters[key_idx] != 0) + return l[info_idx].settings[key_idx].str; + if (ldef[info_idx].change_counters[key_idx] != 0) + return ldef[info_idx].settings[key_idx].str; - const void *value = CONST_PTR_OFFSET(l->info->defaults, def->offset); + const void *value = CONST_PTR_OFFSET(l[info_idx].info->defaults, def->offset); string_t *str = t_str_new(64); if (!config_export_type(str, value, def->type)) i_unreached(); diff --git a/src/config/config-parser.h b/src/config/config-parser.h index a7f16ff042..0b0bb15413 100644 --- a/src/config/config-parser.h +++ b/src/config/config-parser.h @@ -77,6 +77,9 @@ config_parsed_get_errors(struct config_parsed *config); /* Returns the global filter */ struct config_filter_parser * config_parsed_get_global_filter_parser(struct config_parsed *config); +/* Returns the global default filter */ +struct config_filter_parser * +config_parsed_get_global_default_filter_parser(struct config_parsed *config); /* Returns all filters */ struct config_filter_parser *const * config_parsed_get_filter_parsers(struct config_parsed *config); @@ -87,8 +90,8 @@ void config_fill_set_parser(struct setting_parser_context *parser, /* Returns the value for a specified setting. The setting must be found and it must be a string, or the function panics. */ const char * -config_module_parsers_get_setting(const struct config_module_parser *module_parsers, - const char *info_name, const char *key); +config_parsed_get_setting(struct config_parsed *config, + const char *info_name, const char *key); /* Lookup setting with the specified key. */ const struct setting_define * config_parsed_key_lookup(struct config_parsed *config, const char *key); diff --git a/src/config/doveconf.c b/src/config/doveconf.c index 433393258a..c486346145 100644 --- a/src/config/doveconf.c +++ b/src/config/doveconf.c @@ -987,12 +987,9 @@ static void hostname_verify_format(const char *arg) static void check_wrong_config(const char *config_path) { const char *base_dir, *symlink_path, *prev_path, *error; - struct config_filter_parser *global_filter = - config_parsed_get_global_filter_parser(config); - base_dir = config_module_parsers_get_setting( - global_filter->module_parsers, - "master_service", "base_dir"); + base_dir = config_parsed_get_setting(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) @@ -1195,12 +1192,9 @@ int main(int argc, char *argv[]) } } else { const char *info, *mail_path, *version; - struct config_filter_parser *global_filter = - config_parsed_get_global_filter_parser(config); - mail_path = config_module_parsers_get_setting( - global_filter->module_parsers, - "mail_storage", "mail_path"); + mail_path = config_parsed_get_setting(config, "mail_storage", + "mail_path"); info = sysinfo_get(mail_path); if (*info != '\0') printf("# %s\n", info);