dovecot-2.1: lib-dict: Allow backends to have iteration methods ...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jul 23 17:24:26 EEST 2012
details: http://hg.dovecot.org/dovecot-2.1/rev/522e03dd4268
changeset: 14628:522e03dd4268
user: Timo Sirainen <tss at iki.fi>
date: Mon Jul 23 17:23:37 2012 +0300
description:
lib-dict: Allow backends to have iteration methods as NULL if they don't support it.
diffstat:
src/lib-dict/dict.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diffs (42 lines):
diff -r a946a37af082 -r 522e03dd4268 src/lib-dict/dict.c
--- a/src/lib-dict/dict.c Mon Jul 23 14:23:32 2012 +0300
+++ b/src/lib-dict/dict.c Mon Jul 23 17:23:37 2012 +0300
@@ -7,6 +7,7 @@
#include "dict-private.h"
static ARRAY_DEFINE(dict_drivers, struct dict *);
+static struct dict_iterate_context dict_iter_unsupported;
static struct dict *dict_driver_lookup(const char *name)
{
@@ -136,13 +137,19 @@
i_assert(paths[0] != NULL);
for (i = 0; paths[i] != NULL; i++)
i_assert(dict_key_prefix_is_valid(paths[i]));
+ if (dict->v.iterate_init == NULL) {
+ /* not supported by backend */
+ i_error("%s: dict iteration not supported", dict->name);
+ return &dict_iter_unsupported;
+ }
return dict->v.iterate_init(dict, paths, flags);
}
bool dict_iterate(struct dict_iterate_context *ctx,
const char **key_r, const char **value_r)
{
- return ctx->dict->v.iterate(ctx, key_r, value_r);
+ return ctx == &dict_iter_unsupported ? FALSE :
+ ctx->dict->v.iterate(ctx, key_r, value_r);
}
int dict_iterate_deinit(struct dict_iterate_context **_ctx)
@@ -150,7 +157,8 @@
struct dict_iterate_context *ctx = *_ctx;
*_ctx = NULL;
- return ctx->dict->v.iterate_deinit(ctx);
+ return ctx == &dict_iter_unsupported ? -1 :
+ ctx->dict->v.iterate_deinit(ctx);
}
struct dict_transaction_context *dict_transaction_begin(struct dict *dict)
More information about the dovecot-cvs
mailing list