dovecot: Use explicit IMAP_MATCH_* comparisons for imap_match() ...

dovecot at dovecot.org dovecot at dovecot.org
Sat Jun 30 00:48:21 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/1983995ae243
changeset: 5841:1983995ae243
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 29 22:41:40 2007 +0300
description:
Use explicit IMAP_MATCH_* comparisons for imap_match() instead of assuming
something about the values.

diffstat:

5 files changed, 26 insertions(+), 25 deletions(-)
src/imap/cmd-list.c                               |    2 -
src/lib-imap/imap-match.c                         |   25 +++++++++------------
src/lib-storage/list/mailbox-list-fs-iter.c       |   19 +++++++++------
src/lib-storage/list/mailbox-list-maildir-iter.c  |    3 +-
src/lib-storage/list/mailbox-list-subscriptions.c |    2 -

diffs (154 lines):

diff -r f4dac54df44e -r 1983995ae243 src/imap/cmd-list.c
--- a/src/imap/cmd-list.c	Fri Jun 29 21:21:44 2007 +0300
+++ b/src/imap/cmd-list.c	Fri Jun 29 22:41:40 2007 +0300
@@ -565,7 +565,7 @@ static void list_namespace_init(struct c
 		match = ((ns->flags & NAMESPACE_FLAG_LIST) == 0 &&
 			 list_pattern_has_wildcards(cur_pattern)) ?
 			IMAP_MATCH_NO : imap_match(ctx->glob, cur_ns_prefix);
-		if (match < 0)
+		if (match != IMAP_MATCH_YES && match != IMAP_MATCH_CHILDREN)
 			return;
 
 		if (match == IMAP_MATCH_YES &&
diff -r f4dac54df44e -r 1983995ae243 src/lib-imap/imap-match.c
--- a/src/lib-imap/imap-match.c	Fri Jun 29 21:21:44 2007 +0300
+++ b/src/lib-imap/imap-match.c	Fri Jun 29 22:41:40 2007 +0300
@@ -131,7 +131,7 @@ match_sub(const struct imap_match_glob *
 		while (*data != '\0') {
 			if (cmp_chr(glob, data, *pattern)) {
 				ret = match_sub(glob, &data, &pattern);
-				if (ret > 0)
+				if (ret == IMAP_MATCH_YES)
 					break;
 
 				if (ret == IMAP_MATCH_CHILDREN ||
@@ -168,7 +168,7 @@ imap_match(struct imap_match_glob *glob,
 imap_match(struct imap_match_glob *glob, const char *data)
 {
 	const char *pattern;
-	int ret;
+	enum imap_match_result ret;
 
 	if (glob->inboxcase &&
 	    strncasecmp(data, inbox, INBOXLEN) == 0 &&
@@ -179,24 +179,21 @@ imap_match(struct imap_match_glob *glob,
 
 	pattern = glob->pattern;
 	if (*pattern != '*') {
-		if ((ret = match_sub(glob, &data, &pattern)) <= 0)
+		ret = match_sub(glob, &data, &pattern);
+		if (ret != IMAP_MATCH_YES || *pattern == '\0')
 			return ret;
+	}
+
+	while (*pattern == '*') {
+		pattern++;
 
 		if (*pattern == '\0')
 			return IMAP_MATCH_YES;
-	}
-
-	while (*pattern == '*') {
-		pattern++;
-
-		if (*pattern == '\0')
-			return IMAP_MATCH_YES;
 
 		while (*data != '\0') {
-			if (cmp_chr(glob, data, *pattern)) {
-				if (match_sub(glob, &data, &pattern) > 0)
-					break;
-			}
+			if (cmp_chr(glob, data, *pattern) &&
+			    match_sub(glob, &data, &pattern) == IMAP_MATCH_YES)
+				break;
 
 			data++;
 		}
diff -r f4dac54df44e -r 1983995ae243 src/lib-storage/list/mailbox-list-fs-iter.c
--- a/src/lib-storage/list/mailbox-list-fs-iter.c	Fri Jun 29 21:21:44 2007 +0300
+++ b/src/lib-storage/list/mailbox-list-fs-iter.c	Fri Jun 29 22:41:40 2007 +0300
@@ -263,7 +263,8 @@ list_file(struct fs_list_iterate_context
 					"/", fname, NULL);
 	}
 
-	if ((match = imap_match(ctx->glob, list_path)) < 0)
+	match = imap_match(ctx->glob, list_path);
+	if (match != IMAP_MATCH_YES && match != IMAP_MATCH_CHILDREN)
 		return 0;
 
 	/* get the info.flags using callback */
@@ -324,14 +325,15 @@ list_file(struct fs_list_iterate_context
 		path = t_strconcat(list_path, "/", NULL);
 		match2 = imap_match(ctx->glob, path);
 
-		if (match > 0)
+		if (match == IMAP_MATCH_YES)
 			ctx->info.name = p_strdup(ctx->info_pool, list_path);
-		else if (match2 > 0)
+		else if (match2 == IMAP_MATCH_YES)
 			ctx->info.name = p_strdup(ctx->info_pool, path);
 		else
 			ctx->info.name = NULL;
 
-		ret = match2 < 0 ? 0 :
+		ret = match2 != IMAP_MATCH_YES &&
+			match2 != IMAP_MATCH_CHILDREN ? 0 :
 			list_opendir(ctx->ctx.list, real_path, FALSE, &dirp);
 		if (ret > 0) {
 			dir = i_new(struct list_dir_context, 1);
@@ -343,8 +345,8 @@ list_file(struct fs_list_iterate_context
 			ctx->dir = dir;
 		} else if (ret < 0)
 			return -1;
-		return match > 0 || match2 > 0;
-	} else if (match > 0) {
+		return match == IMAP_MATCH_YES || match2 == IMAP_MATCH_YES;
+	} else if (match == IMAP_MATCH_YES) {
 		ctx->info.name = p_strdup(ctx->info_pool, list_path);
 		return 1;
 	}
@@ -395,7 +397,7 @@ fs_list_path(struct fs_list_iterate_cont
 	ctx->info.name =
 		p_strconcat(ctx->info_pool, ctx->dir->virtual_path, "/", NULL);
 
-	if (imap_match(ctx->glob, ctx->info.name) > 0)
+	if (imap_match(ctx->glob, ctx->info.name) == IMAP_MATCH_YES)
 		return &ctx->info;
 	else
 		return ctx->next(ctx);
@@ -432,7 +434,8 @@ fs_list_next(struct fs_list_iterate_cont
 
 	if (!ctx->inbox_found &&
 	    (ctx->ctx.list->ns->flags & NAMESPACE_FLAG_INBOX) != 0 &&
-	    ctx->glob != NULL && imap_match(ctx->glob, "INBOX") > 0) {
+	    ctx->glob != NULL &&
+	    imap_match(ctx->glob, "INBOX") == IMAP_MATCH_YES) {
 		/* INBOX wasn't seen while listing other mailboxes. It might
 		   be located elsewhere. */
 		ctx->inbox_listed = TRUE;
diff -r f4dac54df44e -r 1983995ae243 src/lib-storage/list/mailbox-list-maildir-iter.c
--- a/src/lib-storage/list/mailbox-list-maildir-iter.c	Fri Jun 29 21:21:44 2007 +0300
+++ b/src/lib-storage/list/mailbox-list-maildir-iter.c	Fri Jun 29 22:41:40 2007 +0300
@@ -93,7 +93,8 @@ maildir_fill_readdir(struct maildir_list
 					    hierarchy_sep)) != NULL) {
 				str_truncate(mailbox, (size_t) (p-mailbox_c));
 				mailbox_c = str_c(mailbox);
-				if (imap_match(glob, mailbox_c) > 0)
+				if (imap_match(glob, mailbox_c) ==
+				    IMAP_MATCH_YES)
 					break;
 			}
 			i_assert(p != NULL);
diff -r f4dac54df44e -r 1983995ae243 src/lib-storage/list/mailbox-list-subscriptions.c
--- a/src/lib-storage/list/mailbox-list-subscriptions.c	Fri Jun 29 21:21:44 2007 +0300
+++ b/src/lib-storage/list/mailbox-list-subscriptions.c	Fri Jun 29 22:41:40 2007 +0300
@@ -64,7 +64,7 @@ int mailbox_list_subscriptions_fill(stru
 
 			while ((p = strrchr(name, hierarchy_sep)) != NULL) {
 				name = t_strdup_until(name, p);
-				if (imap_match(glob, name) > 0)
+				if (imap_match(glob, name) == IMAP_MATCH_YES)
 					break;
 			}
 			i_assert(p != NULL);


More information about the dovecot-cvs mailing list