From: Timo Sirainen Date: Tue, 17 Nov 2020 12:30:27 +0000 (+0200) Subject: lib-dict: dict_iterate() - Always return NULL if DICT_ITERATE_FLAG_NO_VALUE is used X-Git-Tag: 2.3.14.rc1~331 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=028f46875b2b15b01c5ff752c083ffdc1feab462;p=thirdparty%2Fdovecot%2Fcore.git lib-dict: dict_iterate() - Always return NULL if DICT_ITERATE_FLAG_NO_VALUE is used This way it behaves more consistently across backends. --- diff --git a/src/lib-dict-backend/dict-sql.c b/src/lib-dict-backend/dict-sql.c index 143799b89d..97a70a9b03 100644 --- a/src/lib-dict-backend/dict-sql.c +++ b/src/lib-dict-backend/dict-sql.c @@ -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); } diff --git a/src/lib-dict-extra/dict-fs.c b/src/lib-dict-extra/dict-fs.c index d79b33c0f8..446a902522 100644 --- a/src/lib-dict-extra/dict-fs.c +++ b/src/lib-dict-extra/dict-fs.c @@ -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); diff --git a/src/lib-dict/dict-private.h b/src/lib-dict/dict-private.h index 6aa96e6199..fc832ecef5 100644 --- a/src/lib-dict/dict-private.h +++ b/src/lib-dict/dict-private.h @@ -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; diff --git a/src/lib-dict/dict.c b/src/lib-dict/dict.c index 26c0e6dab8..997fe030b1 100644 --- a/src/lib-dict/dict.c +++ b/src/lib-dict/dict.c @@ -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; }