]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dict: Add dict_iterate_values()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 17 Nov 2020 12:20:40 +0000 (14:20 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 23 Nov 2020 12:04:46 +0000 (12:04 +0000)
src/lib-dict/dict.c
src/lib-dict/dict.h

index 936c747c4fbf1d5eaecd98cb515962cb79aad9c9..b6eff42228061464cd8a9165471ebe5dc6c18173 100644 (file)
@@ -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;
index 7d4e4a65dc791a205591ad91eeab41f2d13fbdc5..ed9c1c36db3167cd7091c8d81937e958c58f112f 100644 (file)
@@ -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);