[dovecot-cvs] dovecot/src/lib-storage/list mailbox-list-maildir-iter.c, 1.4, 1.5

tss at dovecot.org tss at dovecot.org
Wed Apr 11 22:07:18 EEST 2007


Update of /var/lib/cvs/dovecot/src/lib-storage/list
In directory talvi:/tmp/cvs-serv3571/list

Modified Files:
	mailbox-list-maildir-iter.c 
Log Message:
Moved mailbox_tree iteration code from maildir++ to common code, and rewrote
it.



Index: mailbox-list-maildir-iter.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/list/mailbox-list-maildir-iter.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mailbox-list-maildir-iter.c	30 Mar 2007 19:45:54 -0000	1.4
+++ mailbox-list-maildir-iter.c	11 Apr 2007 19:07:16 -0000	1.5
@@ -19,10 +19,8 @@
 	const char *dir, *prefix;
 
         struct mailbox_tree_context *tree_ctx;
+	struct mailbox_tree_iterate_context *tree_iter;
 
-	string_t *node_path;
-	size_t parent_pos;
-	struct mailbox_node *root, *next_node;
 	struct mailbox_info info;
 };
 
@@ -279,8 +277,8 @@
 		}
 	}
 
-	ctx->node_path = str_new(pool, 256);
-	ctx->root = mailbox_tree_get(ctx->tree_ctx, NULL, NULL);
+	ctx->tree_iter = mailbox_tree_iterate_init(ctx->tree_ctx, NULL,
+						   MAILBOX_FLAG_MATCHED);
 	return &ctx->ctx;
 }
 
@@ -290,41 +288,13 @@
 		(struct maildir_list_iterate_context *)_ctx;
 	int ret = ctx->ctx.failed ? -1 : 0;
 
-	mailbox_tree_deinit(ctx->tree_ctx);
+	if (ctx->tree_iter != NULL)
+		mailbox_tree_iterate_deinit(&ctx->tree_iter);
+	mailbox_tree_deinit(&ctx->tree_ctx);
 	pool_unref(ctx->pool);
 	return ret;
 }
 
-static struct mailbox_node *find_next(struct mailbox_node **node,
-				      string_t *path, char hierarchy_sep)
-{
-	struct mailbox_node *child;
-	size_t len;
-
-	while (*node != NULL) {
-		if (((*node)->flags & MAILBOX_FLAG_MATCHED) != 0)
-			return *node;
-
-		if ((*node)->children != NULL) {
-			len = str_len(path);
-			if (len != 0)
-				str_append_c(path, hierarchy_sep);
-			str_append(path, (*node)->name);
-
-			child = find_next(&(*node)->children, path,
-					  hierarchy_sep);
-			if (child != NULL)
-				return child;
-
-			str_truncate(path, len);
-		}
-
-		*node = (*node)->next;
-	}
-
-	return NULL;
-}
-
 struct mailbox_info *
 maildir_list_iter_next(struct mailbox_list_iterate_context *_ctx)
 {
@@ -332,34 +302,13 @@
 		(struct maildir_list_iterate_context *)_ctx;
 	struct mailbox_node *node;
 
-	for (node = ctx->next_node; node != NULL; node = node->next) {
-		if ((node->flags & MAILBOX_FLAG_MATCHED) != 0)
-			break;
-	}
-
-	if (node == NULL) {
-		if (ctx->root == NULL)
-			return NULL;
-
-		str_truncate(ctx->node_path, 0);
-		node = find_next(&ctx->root, ctx->node_path,
-				 ctx->ctx.list->hierarchy_sep);
-                ctx->parent_pos = str_len(ctx->node_path);
-
-		if (node == NULL)
-			return NULL;
-	}
-	ctx->next_node = node->next;
-
-	i_assert((node->flags & MAILBOX_FLAG_MATCHED) != 0);
-	node->flags &= ~MAILBOX_FLAG_MATCHED;
+	if (ctx->ctx.failed)
+		return NULL;
 
-	str_truncate(ctx->node_path, ctx->parent_pos);
-	if (ctx->parent_pos != 0)
-		str_append_c(ctx->node_path, ctx->ctx.list->hierarchy_sep);
-	str_append(ctx->node_path, node->name);
+	node = mailbox_tree_iterate_next(ctx->tree_iter, &ctx->info.name);
+	if (node == NULL)
+		return NULL;
 
-	ctx->info.name = str_c(ctx->node_path);
 	ctx->info.flags = node->flags;
 	return &ctx->info;
 }



More information about the dovecot-cvs mailing list