From: Timo Sirainen Date: Tue, 17 Nov 2020 12:20:40 +0000 (+0200) Subject: lib-dict: Add dict_iterate_values() X-Git-Tag: 2.3.14.rc1~329 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cf0d196c2b373a37bc1ab4e10fde89fb61089f3c;p=thirdparty%2Fdovecot%2Fcore.git lib-dict: Add dict_iterate_values() --- diff --git a/src/lib-dict/dict.c b/src/lib-dict/dict.c index 936c747c4f..b6eff42228 100644 --- a/src/lib-dict/dict.c +++ b/src/lib-dict/dict.c @@ -384,6 +384,16 @@ bool dict_iterate(struct dict_iterate_context *ctx, { const char *const *values; + if (!dict_iterate_values(ctx, key_r, &values)) + return FALSE; + *value_r = values[0]; + return TRUE; +} + +bool dict_iterate_values(struct dict_iterate_context *ctx, + const char **key_r, const char *const **values_r) +{ + if (ctx->max_rows > 0 && ctx->row_count >= ctx->max_rows) { e_debug(ctx->event, "Maximum row count (%"PRIu64") reached", ctx->max_rows); @@ -391,15 +401,14 @@ bool dict_iterate(struct dict_iterate_context *ctx, ctx->has_more = FALSE; return FALSE; } - if (!ctx->dict->v.iterate(ctx, key_r, &values)) + if (!ctx->dict->v.iterate(ctx, key_r, values_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; + *values_r = NULL; } else { - i_assert(values[0] != NULL); - *value_r = values[0]; + i_assert(values_r[0] != NULL); } ctx->row_count++; return TRUE; diff --git a/src/lib-dict/dict.h b/src/lib-dict/dict.h index 7d4e4a65dc..ed9c1c36db 100644 --- a/src/lib-dict/dict.h +++ b/src/lib-dict/dict.h @@ -124,10 +124,14 @@ void dict_iterate_set_limit(struct dict_iterate_context *ctx, uint64_t max_rows); /* If dict_iterate() returns FALSE, the iteration may be finished or if this is an async iteration it may be waiting for more data. If this function - returns TRUE, the dict callback is called again with more data. */ + returns TRUE, the dict callback is called again with more data. If dict + supports multiple values, dict_iterate_values() can be used to return all + of them. dict_iterate() returns only the first value and ignores the rest. */ bool dict_iterate_has_more(struct dict_iterate_context *ctx); bool dict_iterate(struct dict_iterate_context *ctx, const char **key_r, const char **value_r); +bool dict_iterate_values(struct dict_iterate_context *ctx, + const char **key_r, const char *const **values_r); /* Returns 0 = ok, -1 = iteration failed */ int dict_iterate_deinit(struct dict_iterate_context **ctx, const char **error_r);