]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Remove config_parser_context.key_path and config_section_stack.pathlen
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 22 Nov 2023 21:42:50 +0000 (23:42 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:10 +0000 (12:34 +0200)
Now that all settings are global, the only time when key_path is non-empty
is with strlist { .. } and boollist { .. } settings, and they can't have
nested hierarchies. There's no need for tracking a nested path in sections.

src/config/config-parser-private.h
src/config/config-parser.c
src/config/old-set-parser.c

index aad101140ba95eff037c979a0bc7a7e66c9cb4b8..ebd125b8289d56f6b6fc900b5960205b1c9276fe 100644 (file)
@@ -24,12 +24,15 @@ struct config_line {
        bool value_quoted;
 };
 
+/* Returns TRUE if section is inside strlist { .. } or boollist { .. } */
+#define config_section_is_in_list(section) \
+       (!(section)->is_filter && (section)->key != NULL)
+
 struct config_section_stack {
        struct config_section_stack *prev;
        const char *key;
 
        struct config_filter_parser *filter_parser;
-       size_t pathlen;
 
        const char *open_path;
        unsigned int open_linenum;
@@ -57,7 +60,7 @@ struct config_parser_context {
        struct input_stack *cur_input;
        uint8_t change_counter;
 
-       string_t *key_path, *value;
+       string_t *value;
        const char *error;
 
        const char *dovecot_config_version;
index e7fbb96086e08a83996f42a7451a725570454048..e3b9729399fb34ce18735279d4a5dc3169f8471a 100644 (file)
@@ -1659,8 +1659,12 @@ static int config_write_value(struct config_parser_context *ctx,
                        str_append_c(ctx->value, '<');
                        str_append(ctx->value, line->value);
                } else {
-                       key_with_path = t_strconcat(str_c(ctx->key_path),
-                                                   line->key, NULL);
+                       key_with_path =
+                               config_section_is_in_list(ctx->cur_section) ?
+                               t_strdup_printf("%s"SETTINGS_SEPARATOR_S"%s",
+                                               ctx->cur_section->key,
+                                               line->key) :
+                               line->key;
                        path = fix_relative_path(line->value, ctx->cur_input);
                        if (str_append_file(ctx->value, key_with_path, path,
                                            &error) < 0) {
@@ -1819,8 +1823,13 @@ void config_parser_apply_line(struct config_parser_context *ctx,
                            config_apply_error(ctx, line->key) < 0)
                                break;
                } else {
-                       const char *key_with_path = t_strdup_printf("%s%s",
-                               str_c(ctx->key_path), line->key);
+                       /* Either a global key or list/key */
+                       const char *key_with_path =
+                               config_section_is_in_list(ctx->cur_section) ?
+                               t_strdup_printf("%s"SETTINGS_SEPARATOR_S"%s",
+                                               ctx->cur_section->key,
+                                               line->key) :
+                               line->key;
                        if (config_apply_line_full(ctx, line, key_with_path,
                                                   str_c(ctx->value),
                                                   &full_key) == 0)
@@ -1829,7 +1838,6 @@ void config_parser_apply_line(struct config_parser_context *ctx,
                break;
        case CONFIG_LINE_TYPE_SECTION_BEGIN:
                ctx->cur_section = config_add_new_section(ctx);
-               ctx->cur_section->pathlen = str_len(ctx->key_path);
                ctx->cur_section->key = p_strdup(ctx->pool, line->key);
 
                if (config_filter_add_new_filter(ctx, line)) {
@@ -1838,8 +1846,6 @@ void config_parser_apply_line(struct config_parser_context *ctx,
                }
 
                /* This is SET_STRLIST or SET_BOOLLIST */
-               str_append(ctx->key_path, line->key);
-               str_append_c(ctx->key_path, SETTINGS_SEPARATOR);
                break;
        case CONFIG_LINE_TYPE_SECTION_END:
                if (ctx->cur_section->prev == NULL)
@@ -1853,7 +1859,6 @@ void config_parser_apply_line(struct config_parser_context *ctx,
                                ctx->cur_section->filter_def->key,
                                ctx->cur_section->filter_def->required_setting);
                } else {
-                       str_truncate(ctx->key_path, ctx->cur_section->pathlen);
                        ctx->cur_section = ctx->cur_section->prev;
                }
                break;
@@ -1981,7 +1986,6 @@ int config_parse_file(const char *path, enum config_parse_flags flags,
        struct config_filter root_filter = { };
        config_add_new_parser(&ctx, &root_filter, ctx.cur_section, TRUE);
 
-       ctx.key_path = str_new(ctx.pool, 256);
        ctx.value = str_new(ctx.pool, 256);
        full_line = str_new(default_pool, 512);
        ctx.cur_input->input = fd != -1 ?
index ce2b90db18a5891a99d64e582d6459ebd24299ea..45bb50a9dde4a1e1d7b1616f3390c9f844d6854d 100644 (file)
@@ -634,7 +634,8 @@ static bool
 old_settings_handle_path(struct config_parser_context *ctx,
                         const char *key, const char *value)
 {
-       if (str_begins_with(str_c(ctx->key_path), "plugin/")) {
+       if (config_section_is_in_list(ctx->cur_section) &&
+           strcmp(ctx->cur_section->key, "plugin") == 0) {
                if (strcmp(key, "push_notification_backend") == 0) {
                        obsolete(ctx, "%s has been replaced by push_notification_driver", key);
                        config_apply_line(ctx,
@@ -678,7 +679,7 @@ bool old_settings_handle(struct config_parser_context *ctx,
                break;
        case CONFIG_LINE_TYPE_KEYFILE:
        case CONFIG_LINE_TYPE_KEYVALUE:
-               if (str_len(ctx->key_path) == 0) {
+               if (!config_section_is_in_list(ctx->cur_section)) {
                        struct config_section_stack *old_section =
                                ctx->cur_section;
                        bool ret;
@@ -694,23 +695,27 @@ bool old_settings_handle(struct config_parser_context *ctx,
        case CONFIG_LINE_TYPE_SECTION_BEGIN:
                if (ctx->old->auth_section > 0)
                        return old_auth_section(ctx, key, value);
-               else if (str_len(ctx->key_path) == 0 && strcmp(key, "auth") == 0) {
+               else if (!config_section_is_in_list(ctx->cur_section) &&
+                        strcmp(key, "auth") == 0) {
                        obsolete(ctx, "add auth_ prefix to all settings inside auth {} and remove the auth {} section completely");
                        ctx->old->auth_section = 1;
                        return TRUE;
-               } else if (str_len(ctx->key_path) == 0 && strcmp(key, "protocol") == 0 &&
+               } else if (!config_section_is_in_list(ctx->cur_section) &&
+                          strcmp(key, "protocol") == 0 &&
                         strcmp(value, "managesieve") == 0) {
                        obsolete(ctx, "protocol managesieve {} has been replaced by protocol sieve { }");
                        old_set_parser_apply(ctx, CONFIG_LINE_TYPE_SECTION_BEGIN,
                                             "protocol", "sieve");
                        return TRUE;
-               } else if (str_len(ctx->key_path) == 0 && strcmp(key, "service") == 0 &&
+               } else if (!config_section_is_in_list(ctx->cur_section) &&
+                          strcmp(key, "service") == 0 &&
                           strcmp(value, "dns_client") == 0) {
                        obsolete(ctx, "service dns_client {} has been replaced by service dns-client { }");
                        old_set_parser_apply(ctx, CONFIG_LINE_TYPE_SECTION_BEGIN,
                                             "service", "dns-client");
                        return TRUE;
-               } else if (str_len(ctx->key_path) == 0 && strcmp(key, "service") == 0 &&
+               } else if (!config_section_is_in_list(ctx->cur_section) &&
+                          strcmp(key, "service") == 0 &&
                           strcmp(value, "ipc") == 0) {
                        obsolete(ctx, "service ipc {} no longer exists");
                        /* continue anyway */