From: Timo Sirainen Date: Sat, 26 Feb 2022 21:16:33 +0000 (+0100) Subject: lib-settings: Add settings_parser_get_root_set() X-Git-Tag: 2.4.0~3368 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a6dc0057d043bf1ce5f6e722d99e92905c22fbe;p=thirdparty%2Fdovecot%2Fcore.git lib-settings: Add settings_parser_get_root_set() To make this work, for now we need to have a pointer to the original struct setting_parser_info before dynamic parsers reallocate it. After removing dynamic parsers this orig_info can be removed as well. --- diff --git a/src/lib-settings/settings-parser.c b/src/lib-settings/settings-parser.c index 034e00ba53..d2726b1086 100644 --- a/src/lib-settings/settings-parser.c +++ b/src/lib-settings/settings-parser.c @@ -263,6 +263,22 @@ void **settings_parser_get_list(const struct setting_parser_context *ctx) return sets; } +void *settings_parser_get_root_set(const struct setting_parser_context *ctx, + const struct setting_parser_info *root) +{ + for (unsigned int i = 0; i < ctx->root_count; i++) { + /* FIXME: after removing dynamic settings this should be + just comparing info == root. */ + const struct setting_parser_info *ctx_root = + ctx->roots[i].info->orig_info != NULL ? + ctx->roots[i].info->orig_info : + ctx->roots[i].info; + if (ctx_root == root) + return ctx->roots[i].set_struct; + } + i_panic("Couldn't find settings for root %s", root->module_name); +} + void *settings_parser_get_changes(struct setting_parser_context *ctx) { i_assert(ctx->root_count == 1); @@ -1595,6 +1611,8 @@ void settings_parser_dyn_update(pool_t pool, old_parent = dyn_parsers[0].info->parent; new_parent = p_new(pool, struct setting_parser_info, 1); *new_parent = *old_parent; + new_parent->orig_info = old_parent->orig_info != NULL ? + old_parent->orig_info : old_parent; settings_parser_update_children_parent(new_parent, pool); /* update root */ diff --git a/src/lib-settings/settings-parser.h b/src/lib-settings/settings-parser.h index 1ccbd73d4e..4a3c002363 100644 --- a/src/lib-settings/settings-parser.h +++ b/src/lib-settings/settings-parser.h @@ -101,6 +101,7 @@ struct setting_define { SETTING_DEFINE_STRUCT_TYPE(SET_ENUM, SET_FLAG_HIDDEN, const char *, key, name, struct_name) struct setting_parser_info { + const struct setting_parser_info *orig_info; /* FIXME: remove after getting rid of dynamic parsers */ const char *module_name; const struct setting_define *defines; const void *defaults; @@ -149,6 +150,11 @@ void *settings_parser_get(struct setting_parser_context *ctx); /* If there are multiple roots, return a NULL-terminated list to all of their settings. */ void **settings_parser_get_list(const struct setting_parser_context *ctx); +/* Returns settings for a specific root. The root is expected to exist, and it + must be the same pointer as given to settings_parser_init*(). If it doesn't, + the function panics. */ +void *settings_parser_get_root_set(const struct setting_parser_context *ctx, + const struct setting_parser_info *root); /* Like settings_parser_get(), but return change struct. */ void *settings_parser_get_changes(struct setting_parser_context *ctx); /* Returns the setting parser's roots (same as given to init()). */