]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-settings: Add settings_parser_get_root_set()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Sat, 26 Feb 2022 21:16:33 +0000 (22:16 +0100)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 30 Nov 2022 12:35:26 +0000 (14:35 +0200)
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.

src/lib-settings/settings-parser.c
src/lib-settings/settings-parser.h

index 034e00ba53c0fb3234921c7f05a25c9ecff1251e..d2726b108601ee428ccb1355292e52fd2b7fe8ee 100644 (file)
@@ -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 */
index 1ccbd73d4eaa5a1ed42e21dc02740edfea7e8876..4a3c002363962e3df659f2735944dce69f165ef4 100644 (file)
@@ -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()). */