From: Timo Sirainen Date: Mon, 7 Apr 2025 10:11:41 +0000 (+0300) Subject: config: Add config_parsed_get_all_keys() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=642f807215b25ff680bbcde9b52b9ae449a76a53;p=thirdparty%2Fdovecot%2Fcore.git config: Add config_parsed_get_all_keys() --- diff --git a/src/config/config-parser-private.h b/src/config/config-parser-private.h index ed78e6f71f..b93323921b 100644 --- a/src/config/config-parser-private.h +++ b/src/config/config-parser-private.h @@ -82,7 +82,7 @@ struct config_parser_context { const char *path; ARRAY_TYPE(config_path) seen_paths; - HASH_TABLE(const char *, struct config_parser_key *) all_keys; + HASH_TABLE_TYPE(config_key) all_keys; ARRAY(struct config_filter_parser *) all_filter_parsers; HASH_TABLE(struct config_filter *, struct config_filter_parser *) all_filter_parsers_hash; diff --git a/src/config/config-parser.c b/src/config/config-parser.c index 0f89ae8ca0..eb75f39dda 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -37,16 +37,6 @@ #define DNS_LOOKUP_TIMEOUT_SECS 30 #define DNS_LOOKUP_WARN_SECS 5 -struct config_parser_key { - struct config_parser_key *prev, *next; - - /* Index number to get setting_parser_info from all_infos[] or - module_parsers[] */ - unsigned int info_idx; - /* Index number inside setting_parser_info->defines[] */ - unsigned int define_idx; -}; - struct config_include_group_filters { const char *label; ARRAY(struct config_filter_parser *) filters; @@ -61,6 +51,7 @@ struct config_parsed { ARRAY_TYPE(const_string) errors; HASH_TABLE(const char *, const struct setting_define *) key_hash; HASH_TABLE_TYPE(include_group) include_groups; + HASH_TABLE_TYPE(config_key) all_keys; }; ARRAY_DEFINE_TYPE(setting_parser_info_p, const struct setting_parser_info *); @@ -2382,6 +2373,10 @@ config_parse_finish(struct config_parser_context *ctx, new_config->include_groups = ctx->all_include_groups; i_zero(&ctx->all_include_groups); + /* Copy the all_keys to new_config, which takes care of freeing it. + It's temporarily needed to exist in both ctx and new_config. */ + new_config->all_keys = ctx->all_keys; + /* Destroy it here, so config filter tree merging no longer attempts to update it. */ hash_table_destroy(&ctx->all_filter_parsers_hash); @@ -2396,6 +2391,8 @@ config_parse_finish(struct config_parser_context *ctx, ctx->path, error); } + i_zero(&ctx->all_keys); + /* Merge defaults into main settings after running settings checks. */ if (ret == 0 && (flags & CONFIG_PARSE_FLAG_MERGE_DEFAULT_FILTERS) != 0) config_parse_merge_default_filters(ctx, new_config); @@ -3205,6 +3202,12 @@ config_parsed_get_filter_parsers(struct config_parsed *config) return config->filter_parsers; } +const HASH_TABLE_TYPE(config_key) * +config_parsed_get_all_keys(struct config_parsed *config) +{ + return &config->all_keys; +} + static void config_parsed_strlist_append(string_t *keyvals, const ARRAY_TYPE(const_string) *values, @@ -3403,6 +3406,7 @@ void config_parsed_free(struct config_parsed **_config) *_config = NULL; hash_table_destroy(&config->include_groups); + hash_table_destroy(&config->all_keys); hash_table_destroy(&config->key_hash); pool_unref(&config->pool); } diff --git a/src/config/config-parser.h b/src/config/config-parser.h index 231edeeed5..d48c2b4a53 100644 --- a/src/config/config-parser.h +++ b/src/config/config-parser.h @@ -66,6 +66,17 @@ struct config_module_parser { }; ARRAY_DEFINE_TYPE(config_module_parsers, struct config_module_parser *); +struct config_parser_key { + struct config_parser_key *prev, *next; + + /* Index number to get setting_parser_info from all_infos[] or + module_parsers[] */ + unsigned int info_idx; + /* Index number inside setting_parser_info->defines[] */ + unsigned int define_idx; +}; +HASH_TABLE_DEFINE_TYPE(config_key, const char *, struct config_parser_key *); + struct config_path { const char *path; struct stat st; @@ -103,6 +114,8 @@ config_parsed_get_filter_parsers(struct config_parsed *config); void config_fill_set_parser(struct setting_parser_context *parser, const struct config_module_parser *p, bool expand_values); +const HASH_TABLE_TYPE(config_key) * +config_parsed_get_all_keys(struct config_parsed *config); /* Returns the value for a specified setting. The setting must be found and it must be a string, or the function panics. */ const char *