From: Timo Sirainen Date: Sun, 2 Mar 2025 10:13:17 +0000 (+0200) Subject: config: Support tracking setting changes for named filter paths X-Git-Tag: 2.4.1~111 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c1f0e0b44b201e992c1bd592a016ea1efdbe3b7;p=thirdparty%2Fdovecot%2Fcore.git config: Support tracking setting changes for named filter paths --- diff --git a/src/config/config-dump-full.c b/src/config/config-dump-full.c index 2032fa2415..e6784b9921 100644 --- a/src/config/config-dump-full.c +++ b/src/config/config-dump-full.c @@ -538,11 +538,13 @@ config_dump_full_sections(struct config_dump_full_context *ctx, export_ctx = config_export_init( CONFIG_DUMP_SCOPE_SET_AND_DEFAULT_OVERRIDES, 0, ctx->dovecot_config_version, + config_filter_get_path_prefix(&filter->filter), config_dump_full_stdout_callback, &dump_ctx); } else { export_ctx = config_export_init( CONFIG_DUMP_SCOPE_SET_AND_DEFAULT_OVERRIDES, 0, ctx->dovecot_config_version, + config_filter_get_path_prefix(&filter->filter), config_dump_full_callback, &dump_ctx); } config_export_set_module_parsers(export_ctx, @@ -620,12 +622,12 @@ int config_dump_full(struct config_parsed *config, if (dest == CONFIG_DUMP_FULL_DEST_STDOUT) { export_ctx = config_export_init( CONFIG_DUMP_SCOPE_SET_AND_DEFAULT_OVERRIDES, - flags, dovecot_config_version, + flags, dovecot_config_version, "", config_dump_full_stdout_callback, &dump_ctx); } else { export_ctx = config_export_init( CONFIG_DUMP_SCOPE_SET_AND_DEFAULT_OVERRIDES, - flags, dovecot_config_version, + flags, dovecot_config_version, "", config_dump_full_callback, &dump_ctx); } struct config_filter_parser *filter_parser = diff --git a/src/config/config-filter.c b/src/config/config-filter.c index 717b739ffc..48f2cd4c74 100644 --- a/src/config/config-filter.c +++ b/src/config/config-filter.c @@ -2,6 +2,7 @@ #include "lib.h" #include "array.h" +#include "str.h" #include "crc32.h" #include "settings-parser.h" #include "master-service-settings.h" @@ -206,3 +207,23 @@ bool config_filter_is_empty_defaults(const struct config_filter *filter) { return config_filters_equal(filter, &empty_defaults_filter); } + +static void +config_filter_get_path_str(string_t **path, const struct config_filter *filter) +{ + if (filter->parent != NULL) + config_filter_get_path_str(path, filter->parent); + if (filter->filter_name != NULL) { + if (*path == NULL) + *path = t_str_new(128); + str_append(*path, filter->filter_name); + str_append_c(*path, '/'); + } +} + +const char *config_filter_get_path_prefix(const struct config_filter *filter) +{ + string_t *path = NULL; + config_filter_get_path_str(&path, filter); + return path == NULL ? "" : str_c(path); +} diff --git a/src/config/config-filter.h b/src/config/config-filter.h index 4d6186b697..40eb404d73 100644 --- a/src/config/config-filter.h +++ b/src/config/config-filter.h @@ -93,4 +93,7 @@ bool config_filter_is_empty(const struct config_filter *filter); default_settings=TRUE. */ bool config_filter_is_empty_defaults(const struct config_filter *filter); +/* Return path prefix of named [list] filters. */ +const char *config_filter_get_path_prefix(const struct config_filter *filter); + #endif diff --git a/src/config/config-request.c b/src/config/config-request.c index bb2ff067f3..1c79e37039 100644 --- a/src/config/config-request.c +++ b/src/config/config-request.c @@ -19,6 +19,7 @@ struct config_export_context { HASH_TABLE(const char *, const char *) keys; enum config_dump_scope scope; const char *dovecot_config_version; + const char *path_prefix; config_request_callback_t *callback; void *context; @@ -230,8 +231,14 @@ settings_export(struct config_export_context *ctx, if (module_parser->change_counters[define_idx] <= CONFIG_PARSER_CHANGE_DEFAULTS) { /* Setting isn't explicitly set. We need to see if its default has changed. */ + const char *key_with_path = def->key; + if (ctx->path_prefix[0] != '\0') { + key_with_path = t_strconcat( + ctx->path_prefix, def->key, NULL); + } if (old_settings_default(ctx->dovecot_config_version, - def->key, &old_default)) { + def->key, key_with_path, + &old_default)) { default_str = t_str_new(strlen(old_default)); str_append(default_str, old_default); default_changed = TRUE; @@ -384,7 +391,7 @@ settings_export(struct config_export_context *ctx, struct config_export_context * config_export_init(enum config_dump_scope scope, enum config_dump_flags flags, - const char *dovecot_config_version, + const char *dovecot_config_version, const char *path_prefix, config_request_callback_t *callback, void *context) { struct config_export_context *ctx; @@ -399,6 +406,7 @@ config_export_init(enum config_dump_scope scope, ctx->context = context; ctx->scope = scope; ctx->dovecot_config_version = p_strdup(pool, dovecot_config_version); + ctx->path_prefix = p_strdup(pool, path_prefix); ctx->value = str_new(pool, 256); if ((ctx->flags & CONFIG_DUMP_FLAG_DEDUPLICATE_KEYS) != 0) hash_table_create(&ctx->keys, ctx->pool, 0, str_hash, strcmp); diff --git a/src/config/config-request.h b/src/config/config-request.h index 72951a055b..1b5c83612b 100644 --- a/src/config/config-request.h +++ b/src/config/config-request.h @@ -53,11 +53,11 @@ bool config_export_type(string_t *str, const void *value, struct config_export_context * config_export_init(enum config_dump_scope scope, enum config_dump_flags flags, - const char *dovecot_config_version, + const char *dovecot_config_version, const char *path_prefix, config_request_callback_t *callback, void *context) ATTR_NULL(1, 5); -#define config_export_init(scope, flags, version, callback, context) \ - config_export_init(scope, flags, version, \ +#define config_export_init(scope, flags, version, path_prefix, callback, context) \ + config_export_init(scope, flags, version, path_prefix, \ (config_request_callback_t *)callback, \ TRUE ? context : CALLBACK_TYPECHECK(callback, \ void (*)(const struct config_export_setting *, typeof(context)))) diff --git a/src/config/doveconf.c b/src/config/doveconf.c index fd429bf546..6925cd2ec3 100644 --- a/src/config/doveconf.c +++ b/src/config/doveconf.c @@ -189,8 +189,9 @@ config_dump_human_init(enum config_dump_scope scope, flags = CONFIG_DUMP_FLAG_DEDUPLICATE_KEYS; ctx->export_ctx = config_export_init(scope, flags, - dovecot_config_version, - config_request_get_strings, ctx); + dovecot_config_version, + config_filter_get_path_prefix(&filter_parser->filter), + config_request_get_strings, ctx); config_export_set_module_parsers(ctx->export_ctx, filter_parser->module_parsers); return ctx; diff --git a/src/config/old-set-parser.c b/src/config/old-set-parser.c index 2515f2163c..0d2255d20a 100644 --- a/src/config/old-set-parser.c +++ b/src/config/old-set-parser.c @@ -73,7 +73,8 @@ void old_settings_handle(struct config_parser_context *ctx, } bool old_settings_default(const char *dovecot_config_version, - const char *key, const char **old_default_r) + const char *key, const char *key_with_path, + const char **old_default_r) { struct settings_history *history = settings_history_get(); const struct setting_history_default *def; @@ -84,7 +85,8 @@ bool old_settings_default(const char *dovecot_config_version, array_foreach(&history->defaults, def) { if (version_cmp(def->version, dovecot_config_version) <= 0) break; - if (strcmp(def->key, key) == 0) { + if (strcmp(def->key, key) == 0 || + strcmp(def->key, key_with_path) == 0) { *old_default_r = def->old_value; return TRUE; } diff --git a/src/config/old-set-parser.h b/src/config/old-set-parser.h index 000f9c9fa8..baeb80ef01 100644 --- a/src/config/old-set-parser.h +++ b/src/config/old-set-parser.h @@ -8,6 +8,7 @@ struct config_parser_context; void old_settings_handle(struct config_parser_context *ctx, struct config_line *line); bool old_settings_default(const char *dovecot_config_version, - const char *key, const char **old_default_r); + const char *key, const char *key_with_path, + const char **old_default_r); #endif