From: Timo Sirainen Date: Tue, 20 Dec 2022 12:46:02 +0000 (+0200) Subject: config: Generate unique index numbers for unnamed sections X-Git-Tag: 2.4.0~3090 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=294c90648f518ee2bca6e1940fde0e5a070c49be;p=thirdparty%2Fdovecot%2Fcore.git config: Generate unique index numbers for unnamed sections This will be required by the following changes to allow incrementally parsing filtered settings. --- diff --git a/src/config/config-connection.c b/src/config/config-connection.c index 26c3e4eb57..321a798ced 100644 --- a/src/config/config-connection.c +++ b/src/config/config-connection.c @@ -70,6 +70,7 @@ static int config_connection_request(struct config_connection *conn, struct config_export_context *ctx; struct master_service_settings_output output; struct config_filter filter; + unsigned int section_idx = 0; const char *path, *value, *error, *module, *const *wanted_modules; ARRAY(const char *) modules; ARRAY(const char *) exclude_settings; @@ -148,7 +149,7 @@ static int config_connection_request(struct config_connection *conn, o_stream_nsend_str(conn->output, "used-remote\t"); o_stream_nsend_str(conn->output, "\n"); - if (config_export_finish(&ctx) < 0) { + if (config_export_finish(&ctx, §ion_idx) < 0) { config_connection_destroy(conn); return -1; } diff --git a/src/config/config-request.c b/src/config/config-request.c index 9924a46c8a..28ffacd6be 100644 --- a/src/config/config-request.c +++ b/src/config/config-request.c @@ -28,6 +28,7 @@ struct config_export_context { const struct config_module_parser *parsers; struct config_module_parser *dup_parsers; struct master_service_settings_output output; + unsigned int section_idx; bool failed; }; @@ -301,7 +302,8 @@ settings_export(struct config_export_context *ctx, for (i = 0; i < count; i++) { if (i > 0) str_append_c(ctx->value, ' '); - setting_export_section_name(ctx->value, def, children[i], i); + setting_export_section_name(ctx->value, def, children[i], + ctx->section_idx + i); } change_children = array_get(change_val, &count2); i_assert(count == count2); @@ -363,10 +365,13 @@ settings_export(struct config_export_context *ctx, i_assert(count == 0 || children != NULL); prefix_len = str_len(ctx->prefix); + unsigned int section_start_idx = ctx->section_idx; + ctx->section_idx += count; for (i = 0; i < count; i++) { str_append(ctx->prefix, def->key); str_append_c(ctx->prefix, SETTINGS_SEPARATOR); - setting_export_section_name(ctx->prefix, def, children[i], i); + setting_export_section_name(ctx->prefix, def, children[i], + section_start_idx + i); str_append_c(ctx->prefix, SETTINGS_SEPARATOR); settings_export(ctx, def->list_info, def->type == SET_DEFLIST_UNIQUE, @@ -457,7 +462,8 @@ static void config_export_free(struct config_export_context *ctx) pool_unref(&ctx->pool); } -int config_export_finish(struct config_export_context **_ctx) +int config_export_finish(struct config_export_context **_ctx, + unsigned int *section_idx) { struct config_export_context *ctx = *_ctx; const struct config_module_parser *parser; @@ -472,6 +478,7 @@ int config_export_finish(struct config_export_context **_ctx) return -1; } + ctx->section_idx = *section_idx; for (i = 0; ctx->parsers[i].root != NULL; i++) { parser = &ctx->parsers[i]; if (!config_module_want_parser(config_module_parsers, @@ -499,6 +506,7 @@ int config_export_finish(struct config_export_context **_ctx) } } } + *section_idx = ctx->section_idx; config_export_free(ctx); return ret; } diff --git a/src/config/config-request.h b/src/config/config-request.h index 29cff2fb21..f0fb8f6b6d 100644 --- a/src/config/config-request.h +++ b/src/config/config-request.h @@ -54,6 +54,7 @@ void config_export_get_output(struct config_export_context *ctx, struct master_service_settings_output *output_r); const char * config_export_get_import_environment(struct config_export_context *ctx); -int config_export_finish(struct config_export_context **ctx); +int config_export_finish(struct config_export_context **ctx, + unsigned int *section_idx); #endif diff --git a/src/config/doveconf.c b/src/config/doveconf.c index 246c572dff..1e294a5402 100644 --- a/src/config/doveconf.c +++ b/src/config/doveconf.c @@ -333,12 +333,13 @@ config_dump_human_output(struct config_dump_human_context *ctx, unsigned int i, j, count, prefix_count; unsigned int prefix_idx = UINT_MAX; size_t len, skip_len, setting_name_filter_len; + unsigned int section_idx = 0; bool unique_key; int ret = 0; setting_name_filter_len = setting_name_filter == NULL ? 0 : strlen(setting_name_filter); - if (config_export_finish(&ctx->export_ctx) < 0) + if (config_export_finish(&ctx->export_ctx, §ion_idx) < 0) return -1; array_sort(&ctx->strings, config_string_cmp); @@ -615,11 +616,12 @@ config_dump_one(const struct config_filter *filter, bool hide_key, static struct config_dump_human_context *ctx; const char *str; size_t len; + unsigned int section_idx = 0; bool dump_section = FALSE; ctx = config_dump_human_init(NULL, scope, FALSE); config_export_by_filter(ctx->export_ctx, filter); - if (config_export_finish(&ctx->export_ctx) < 0) + if (config_export_finish(&ctx->export_ctx, §ion_idx) < 0) return -1; len = strlen(setting_name_filter); @@ -995,13 +997,14 @@ int main(int argc, char *argv[]) if (simple_output) { struct config_export_context *ctx; + unsigned int section_idx = 0; ctx = config_export_init(wanted_modules, NULL, scope, CONFIG_DUMP_FLAG_CHECK_SETTINGS, config_request_simple_stdout, setting_name_filters); config_export_by_filter(ctx, &filter); - ret2 = config_export_finish(&ctx); + ret2 = config_export_finish(&ctx, §ion_idx); } else if (setting_name_filters != NULL) { ret2 = 0; /* ignore settings-check failures in configuration. this allows @@ -1029,6 +1032,7 @@ int main(int argc, char *argv[]) ret2 = config_dump_human(&filter, wanted_modules, scope, NULL, hide_passwords); } else { struct config_export_context *ctx; + unsigned int section_idx = 0; ctx = config_export_init(wanted_modules, NULL, CONFIG_DUMP_SCOPE_SET, CONFIG_DUMP_FLAG_CHECK_SETTINGS, @@ -1048,7 +1052,7 @@ int main(int argc, char *argv[]) } env_put("DOVECONF_ENV", "1"); - if (config_export_finish(&ctx) < 0) + if (config_export_finish(&ctx, §ion_idx) < 0) i_fatal("Invalid configuration"); execvp(exec_args[0], exec_args); i_fatal("execvp(%s) failed: %m", exec_args[0]);