]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-settings: Split off settings_key_part_find()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 7 Jun 2023 23:57:40 +0000 (02:57 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:09 +0000 (12:34 +0200)
src/lib-settings/settings.c

index ab213152c025b8adcc6576421296d35937de6d53..d4d44fad14d18c86eb01ca34764e2788f227a3de 100644 (file)
@@ -963,31 +963,44 @@ static int settings_override_cmp(const struct settings_override *set1,
        return set2->type - set1->type;
 }
 
-static int
-settings_override_get_value(struct settings_apply_ctx *ctx,
-                           const struct settings_override *set,
-                           const char **_key, unsigned int *key_idx_r,
-                           const char **value_r, const char **error_r)
-{
-       const char *key = *_key;
-       unsigned int key_idx = UINT_MAX;
 
-       if (set->last_filter_value != NULL) {
-               i_assert(set->last_filter_key != NULL);
+static bool
+settings_key_part_find(struct settings_apply_ctx *ctx, const char **key,
+                      const char *last_filter_key,
+                      const char *last_filter_value,
+                      unsigned int *key_idx_r)
+{
+       if (last_filter_value != NULL) {
+               i_assert(last_filter_key != NULL);
                /* Try filter/name/key -> filter_key. Do this before the
                   non-prefixed check, so e.g. inet_listener/imap/ssl won't
                   try to change the global ssl setting. */
-               const char *key_prefix = set->last_filter_key;
+               const char *key_prefix = last_filter_key;
                if (strcmp(key_prefix, SETTINGS_EVENT_MAILBOX_NAME_WITHOUT_PREFIX) == 0)
                        key_prefix = SETTINGS_EVENT_MAILBOX_NAME_WITH_PREFIX;
                const char *prefixed_key =
-                       t_strdup_printf("%s_%s", key_prefix, key);
+                       t_strdup_printf("%s_%s", key_prefix, *key);
                if (setting_parser_info_find_key(ctx->info, prefixed_key,
-                                                &key_idx))
-                       key = prefixed_key;
+                                                key_idx_r)) {
+                       *key = prefixed_key;
+                       return TRUE;
+               }
        }
-       if (key_idx == UINT_MAX)
-               (void)setting_parser_info_find_key(ctx->info, key, &key_idx);
+       return setting_parser_info_find_key(ctx->info, *key, key_idx_r);
+}
+
+static int
+settings_override_get_value(struct settings_apply_ctx *ctx,
+                           const struct settings_override *set,
+                           const char **_key, unsigned int *key_idx_r,
+                           const char **value_r, const char **error_r)
+{
+       const char *key = *_key;
+       unsigned int key_idx = UINT_MAX;
+
+       if (!settings_key_part_find(ctx, &key, set->last_filter_key,
+                                   set->last_filter_value, &key_idx))
+               key_idx = UINT_MAX;
 
        if (key_idx == UINT_MAX && strchr(key, '/') == NULL &&
            set->type == SETTINGS_OVERRIDE_TYPE_USERDB &&