dovecot-1.1: IMAP FETCH: Binary searching fetch handlers was a b...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 1 21:36:33 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.1/rev/7b70c93061e2
changeset: 8302:7b70c93061e2
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jun 01 14:36:28 2009 -0400
description:
IMAP FETCH: Binary searching fetch handlers was a bit broken.

diffstat:

1 file changed, 10 insertions(+), 14 deletions(-)
src/imap/imap-fetch.c |   24 ++++++++++--------------

diffs (53 lines):

diff -r 8e04d71bd428 -r 7b70c93061e2 src/imap/imap-fetch.c
--- a/src/imap/imap-fetch.c	Mon Jun 01 01:47:05 2009 -0400
+++ b/src/imap/imap-fetch.c	Mon Jun 01 14:36:28 2009 -0400
@@ -14,6 +14,7 @@
 #include "imap-util.h"
 
 #include <stdlib.h>
+#include <ctype.h>
 
 #define BODY_NIL_REPLY \
 	"\"text\" \"plain\" NIL NIL NIL \"7bit\" 0 0"
@@ -49,32 +50,27 @@ static int imap_fetch_handler_bsearch(co
 {
 	const char *name = name_p;
         const struct imap_fetch_handler *h = handler_p;
-	int i;
-
-	for (i = 0; h->name[i] != '\0'; i++) {
-		if (h->name[i] != name[i]) {
-			if (name[i] < 'A' || name[i] >= 'Z')
-				return -1;
-			return name[i] - h->name[i];
-		}
-	}
-
-	return name[i] < 'A' || name[i] >= 'Z' ? 0 : -1;
+
+	return strcmp(name, h->name);
 }
 
 bool imap_fetch_init_handler(struct imap_fetch_context *ctx, const char *name,
 			     const struct imap_arg **args)
 {
 	const struct imap_fetch_handler *handler;
-
-	handler = bsearch(name, fetch_handlers->data,
+	const char *lookup_name, *p;
+
+	for (p = name; i_isalnum(*p); p++) ;
+	lookup_name = t_strdup_until(name, p);
+
+	handler = bsearch(lookup_name, fetch_handlers->data,
 			  fetch_handlers->used /
 			  sizeof(struct imap_fetch_handler),
                           sizeof(struct imap_fetch_handler),
 			  imap_fetch_handler_bsearch);
 	if (handler == NULL) {
 		client_send_command_error(ctx->cmd,
-			t_strconcat("Unknown command ", name, NULL));
+			t_strconcat("Unknown parameter ", name, NULL));
 		return FALSE;
 	}
 


More information about the dovecot-cvs mailing list