dovecot-2.2: lib-dict: Added DICT_ITERATE_FLAG_EXACT_KEY flag.

dovecot at dovecot.org dovecot at dovecot.org
Mon May 11 18:50:49 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/bb7d35fa9b43
changeset: 18638:bb7d35fa9b43
user:      Timo Sirainen <tss at iki.fi>
date:      Mon May 11 19:12:45 2015 +0300
description:
lib-dict: Added DICT_ITERATE_FLAG_EXACT_KEY flag.
This is mainly useful with SQL for iterating through a result that has
multiple rows.

diffstat:

 src/lib-dict/dict-file.c |  12 +++++++++---
 src/lib-dict/dict-fs.c   |   1 +
 src/lib-dict/dict-sql.c  |   8 ++++++--
 src/lib-dict/dict.h      |  10 +++++++++-
 4 files changed, 25 insertions(+), 6 deletions(-)

diffs (74 lines):

diff -r 44a87e17f988 -r bb7d35fa9b43 src/lib-dict/dict-file.c
--- a/src/lib-dict/dict-file.c	Mon May 11 16:01:13 2015 +0300
+++ b/src/lib-dict/dict-file.c	Mon May 11 19:12:45 2015 +0300
@@ -261,9 +261,15 @@
 		if (path == NULL)
 			continue;
 
-		if ((ctx->flags & DICT_ITERATE_FLAG_RECURSE) == 0 &&
-		    strchr(key + path->len, '/') != NULL)
-			continue;
+		if ((ctx->flags & DICT_ITERATE_FLAG_RECURSE) != 0) {
+			/* match everything */
+		} else if ((ctx->flags & DICT_ITERATE_FLAG_EXACT_KEY) != 0) {
+			if (key[path->len] != '\0')
+				continue;
+		} else {
+			if (strchr(key + path->len, '/') != NULL)
+				continue;
+		}
 
 		*key_r = key;
 		*value_r = value;
diff -r 44a87e17f988 -r bb7d35fa9b43 src/lib-dict/dict-fs.c
--- a/src/lib-dict/dict-fs.c	Mon May 11 16:01:13 2015 +0300
+++ b/src/lib-dict/dict-fs.c	Mon May 11 19:12:45 2015 +0300
@@ -125,6 +125,7 @@
 
 	/* these flags are not supported for now */
 	i_assert((flags & DICT_ITERATE_FLAG_RECURSE) == 0);
+	i_assert((flags & DICT_ITERATE_FLAG_EXACT_KEY) == 0);
 	i_assert((flags & (DICT_ITERATE_FLAG_SORT_BY_KEY |
 			   DICT_ITERATE_FLAG_SORT_BY_VALUE)) == 0);
 
diff -r 44a87e17f988 -r bb7d35fa9b43 src/lib-dict/dict-sql.c
--- a/src/lib-dict/dict-sql.c	Mon May 11 16:01:13 2015 +0300
+++ b/src/lib-dict/dict-sql.c	Mon May 11 19:12:45 2015 +0300
@@ -377,8 +377,12 @@
 
 		str_printfa(query, " FROM %s", map->table);
 
-		recurse_type = (ctx->flags & DICT_ITERATE_FLAG_RECURSE) == 0 ?
-			SQL_DICT_RECURSE_ONE : SQL_DICT_RECURSE_FULL;
+		if ((ctx->flags & DICT_ITERATE_FLAG_RECURSE) != 0)
+			recurse_type = SQL_DICT_RECURSE_FULL;
+		else if ((ctx->flags & DICT_ITERATE_FLAG_EXACT_KEY) != 0)
+			recurse_type = SQL_DICT_RECURSE_NONE;
+		else
+			recurse_type = SQL_DICT_RECURSE_ONE;
 		sql_dict_where_build(dict, map, &values,
 				     ctx->paths[ctx->path_idx][0],
 				     recurse_type, query);
diff -r 44a87e17f988 -r bb7d35fa9b43 src/lib-dict/dict.h
--- a/src/lib-dict/dict.h	Mon May 11 16:01:13 2015 +0300
+++ b/src/lib-dict/dict.h	Mon May 11 19:12:45 2015 +0300
@@ -7,10 +7,18 @@
 struct dict;
 
 enum dict_iterate_flags {
+	/* Recurse to all the sub-hierarchies (e.g. iterating "foo/" will
+	   return "foo/a", but should it return "foo/a/b"?) */
 	DICT_ITERATE_FLAG_RECURSE             = 0x01,
+	/* Sort returned results by key */
 	DICT_ITERATE_FLAG_SORT_BY_KEY         = 0x02,
+	/* Sort returned results by value */
 	DICT_ITERATE_FLAG_SORT_BY_VALUE       = 0x04,
-	DICT_ITERATE_FLAG_NO_VALUE            = 0x08
+	/* Don't return values, only keys */
+	DICT_ITERATE_FLAG_NO_VALUE            = 0x08,
+	/* Don't recurse at all. This is basically the same as dict_lookup(),
+	   but it'll return all the rows instead of only the first one. */
+	DICT_ITERATE_FLAG_EXACT_KEY           = 0x10
 };
 
 enum dict_data_type {


More information about the dovecot-cvs mailing list