]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dict: dict_iterate() - Always return NULL if DICT_ITERATE_FLAG_NO_VALUE is used
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 17 Nov 2020 12:30:27 +0000 (14:30 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 23 Nov 2020 12:04:46 +0000 (12:04 +0000)
This way it behaves more consistently across backends.

src/lib-dict-backend/dict-sql.c
src/lib-dict-extra/dict-fs.c
src/lib-dict/dict-private.h
src/lib-dict/dict.c

index 143799b89da504d7e4b275f45338041018c9ecaf..97a70a9b0375ea2e006adad488aa2a4660ed7d65 100644 (file)
@@ -865,9 +865,7 @@ static bool sql_dict_iterate(struct dict_iterate_context *_ctx,
        }
 
        *key_r = str_c(ctx->key);
-       if ((ctx->flags & DICT_ITERATE_FLAG_NO_VALUE) != 0)
-               *value_r = "";
-       else {
+       if ((ctx->flags & DICT_ITERATE_FLAG_NO_VALUE) == 0) {
                *value_r = sql_dict_result_unescape_value(ctx->map,
                                        pool_datastack_create(), ctx->result);
        }
index d79b33c0f8f6a39bdecd92738199e016422a6fb6..446a902522f7b545d5fd3dff03aa112d6e43de6d 100644 (file)
@@ -171,7 +171,6 @@ static bool fs_dict_iterate(struct dict_iterate_context *ctx,
        path = t_strconcat(iter->paths[iter->path_idx], *key_r, NULL);
        if ((iter->flags & DICT_ITERATE_FLAG_NO_VALUE) != 0) {
                *key_r = path;
-               *value_r = NULL;
                return TRUE;
        }
        p_clear(iter->value_pool);
index 6aa96e61991699e3f8509b408e1cd4c48352ce5b..fc832ecef5648063156182cba9bf6e834aca9272 100644 (file)
@@ -65,6 +65,7 @@ struct dict {
 struct dict_iterate_context {
        struct dict *dict;
        struct event *event;
+       enum dict_iterate_flags flags;
 
        dict_iterate_callback_t *async_callback;
        void *async_context;
index 26c0e6dab83ff6fca6feb2538e5b01d160a806a6..997fe030b191676eea28db635af8669bbe8ecceb 100644 (file)
@@ -370,6 +370,7 @@ dict_iterate_init_multiple(struct dict *dict, const char *const *paths,
           passed as parameter, e.g. it can be dict-fail when
           iteration is not supported. */
        ctx->event = event_create(dict->event);
+       ctx->flags = flags;
 
        event_add_str(ctx->event, "key", paths[0]);
        event_set_name(ctx->event, "dict_iteration_started");
@@ -390,6 +391,11 @@ bool dict_iterate(struct dict_iterate_context *ctx,
        }
        if (!ctx->dict->v.iterate(ctx, key_r, value_r))
                return FALSE;
+       if ((ctx->flags & DICT_ITERATE_FLAG_NO_VALUE) != 0) {
+               /* always return value as NULL to be consistent across
+                  drivers */
+               *value_r = NULL;
+       }
        ctx->row_count++;
        return TRUE;
 }