dovecot: Store namespaces sorted by their prefix length.

dovecot at dovecot.org dovecot at dovecot.org
Wed Jun 27 16:38:21 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/c7f35a9beb0b
changeset: 5804:c7f35a9beb0b
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jun 27 16:24:50 2007 +0300
description:
Store namespaces sorted by their prefix length.

diffstat:

2 files changed, 20 insertions(+)
src/lib-storage/mail-namespace.c |   19 +++++++++++++++++++
src/lib-storage/mail-namespace.h |    1 +

diffs (47 lines):

diff -r 6ae0dc6dc3b3 -r c7f35a9beb0b src/lib-storage/mail-namespace.c
--- a/src/lib-storage/mail-namespace.c	Wed Jun 27 16:10:00 2007 +0300
+++ b/src/lib-storage/mail-namespace.c	Wed Jun 27 16:24:50 2007 +0300
@@ -140,6 +140,24 @@ static bool namespaces_check(struct mail
 	return TRUE;
 }
 
+static struct mail_namespace *
+namespaces_sort(struct mail_namespace *src)
+{
+	struct mail_namespace **tmp, *next, *dest = NULL;
+
+	for (; src != NULL; src = next) {
+		next = src->next;
+
+		for (tmp = &dest; *tmp != NULL; tmp = &(*tmp)->next) {
+			if (strlen(src->prefix) < strlen((*tmp)->prefix))
+				break;
+		}
+		src->next = *tmp;
+		*tmp = src;
+	}
+	return dest;
+}
+
 int mail_namespaces_init(pool_t pool, const char *user,
 			 struct mail_namespace **namespaces_r)
 {
@@ -175,6 +193,7 @@ int mail_namespaces_init(pool_t pool, co
 	if (namespaces != NULL) {
 		if (!namespaces_check(namespaces))
 			return -1;
+		namespaces = namespaces_sort(namespaces);
 		*namespaces_r = namespaces;
 		return 0;
 	}
diff -r 6ae0dc6dc3b3 -r c7f35a9beb0b src/lib-storage/mail-namespace.h
--- a/src/lib-storage/mail-namespace.h	Wed Jun 27 16:10:00 2007 +0300
+++ b/src/lib-storage/mail-namespace.h	Wed Jun 27 16:24:50 2007 +0300
@@ -8,6 +8,7 @@ enum namespace_type {
 };
 
 struct mail_namespace {
+	/* Namespaces are sorted by their prefix length, "" comes first */
 	struct mail_namespace *next;
 
         enum namespace_type type;


More information about the dovecot-cvs mailing list