]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Add config_parsed_get_all_keys()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 7 Apr 2025 10:11:41 +0000 (13:11 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 12 May 2025 15:51:47 +0000 (15:51 +0000)
src/config/config-parser-private.h
src/config/config-parser.c
src/config/config-parser.h

index ed78e6f71fbe31ce133bd24ba811a09ae072cce8..b93323921b7489c25e030c281a5dc627881586a9 100644 (file)
@@ -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;
index 0f89ae8ca0aac3fabd295e81300a49e9762c75c8..eb75f39dda2ce3f7d0c525c87277f99cb151f70d 100644 (file)
 #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);
 }
index 231edeeed567ed6b943113e57a8c54391e9ae52d..d48c2b4a53edf4a0bbdf7e503b67ef0e23098d9b 100644 (file)
@@ -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 *