dovecot-2.0-sslstream: dsync: Added support for different source...

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 02:56:32 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/ff403fe262e5
changeset: 10357:ff403fe262e5
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Nov 17 20:55:04 2009 -0500
description:
dsync: Added support for different source/dest hierarchy separators.

diffstat:

9 files changed, 98 insertions(+), 49 deletions(-)
src/dsync/dsync-brain.c                 |    2 -
src/dsync/dsync-data.h                  |    1 
src/dsync/dsync-proxy.c                 |   40 ++++++++++++++++++----------
src/dsync/dsync-worker-local.c          |   28 +++++++++++++++++++
src/dsync/dsync-worker.h                |    3 +-
src/dsync/dsync.c                       |   13 ++++++---
src/dsync/test-dsync-brain.c            |   44 +++++++++++++++----------------
src/dsync/test-dsync-proxy-server-cmd.c |   15 +++++++---
src/dsync/test-dsync-proxy.c            |    1 

diffs (truncated from 417 to 300 lines):

diff -r a7be031eb51d -r ff403fe262e5 src/dsync/dsync-brain.c
--- a/src/dsync/dsync-brain.c	Tue Nov 17 20:32:35 2009 -0500
+++ b/src/dsync/dsync-brain.c	Tue Nov 17 20:55:04 2009 -0500
@@ -525,8 +525,6 @@ dsync_brain_msg_sync_update_mailbox(stru
 {
 	const struct dsync_brain_mailbox *mailbox;
 
-	/* FIXME: handle different hierarchy separators? */
-
 	array_foreach(&brain->mailbox_sync->mailboxes, mailbox) {
 		dsync_worker_update_mailbox(brain->src_worker, &mailbox->box);
 		dsync_worker_update_mailbox(brain->dest_worker, &mailbox->box);
diff -r a7be031eb51d -r ff403fe262e5 src/dsync/dsync-data.h
--- a/src/dsync/dsync-data.h	Tue Nov 17 20:32:35 2009 -0500
+++ b/src/dsync/dsync-data.h	Tue Nov 17 20:55:04 2009 -0500
@@ -15,6 +15,7 @@ enum dsync_mailbox_flags {
 
 struct dsync_mailbox {
 	const char *name;
+	char name_sep;
 	/* Mailbox directory's GUID. Not necessarily set if mailbox is
 	   deleted. */
 	mailbox_guid_t dir_guid;
diff -r a7be031eb51d -r ff403fe262e5 src/dsync/dsync-proxy.c
--- a/src/dsync/dsync-proxy.c	Tue Nov 17 20:32:35 2009 -0500
+++ b/src/dsync/dsync-proxy.c	Tue Nov 17 20:55:04 2009 -0500
@@ -155,7 +155,12 @@ void dsync_proxy_mailbox_export(string_t
 void dsync_proxy_mailbox_export(string_t *str,
 				const struct dsync_mailbox *box)
 {
+	char s[2];
+
 	str_tabescape_write(str, box->name);
+	str_append_c(str, '\t');
+	s[0] = box->name_sep; s[1] = '\0';
+	str_tabescape_write(str, s);
 	str_append_c(str, '\t');
 	dsync_proxy_mailbox_guid_export(str, &box->dir_guid);
 	str_printfa(str, "\t%lu\t%u", (unsigned long)box->last_renamed,
@@ -178,65 +183,72 @@ int dsync_proxy_mailbox_import_unescaped
 					 struct dsync_mailbox *box_r,
 					 const char **error_r)
 {
-	unsigned int i, count;
+	unsigned int i = 0, count;
 	char *p;
 
 	memset(box_r, 0, sizeof(*box_r));
 
 	count = str_array_length(args);
-	if (count != 4 && count < 8) {
+	if (count != 5 && count < 9) {
 		*error_r = "Mailbox missing parameters";
 		return -1;
 	}
 
 	/* name dir_guid mailbox_guid uid_validity uid_next highest_modseq */
-	box_r->name = p_strdup(pool, args[0]);
-
-	if (dsync_proxy_mailbox_guid_import(args[1], &box_r->dir_guid) < 0) {
+	box_r->name = p_strdup(pool, args[i++]);
+
+	if (strlen(args[i]) != 1) {
+		*error_r = "Invalid mailbox name hierarchy separator";
+		return -1;
+	}
+	box_r->name_sep = args[i++][0];
+
+	if (dsync_proxy_mailbox_guid_import(args[i++], &box_r->dir_guid) < 0) {
 		*error_r = "Invalid dir GUID";
 		return -1;
 	}
-	box_r->last_renamed = strtoul(args[2], &p, 10);
+	box_r->last_renamed = strtoul(args[i++], &p, 10);
 	if (*p != '\0') {
 		*error_r = "Invalid mailbox last_renamed";
 		return -1;
 	}
-	box_r->flags = strtoul(args[3], &p, 10);
+	box_r->flags = strtoul(args[i++], &p, 10);
 	if (*p != '\0') {
 		*error_r = "Invalid mailbox flags";
 		return -1;
 	}
 
-	if (args[4] == NULL) {
+	if (args[i] == NULL) {
 		/* \noselect mailbox */
 		return 0;
 	}
 
-	if (dsync_proxy_mailbox_guid_import(args[4], &box_r->mailbox_guid) < 0) {
+	if (dsync_proxy_mailbox_guid_import(args[i++],
+					    &box_r->mailbox_guid) < 0) {
 		*error_r = "Invalid mailbox GUID";
 		return -1;
 	}
 
-	box_r->uid_validity = strtoul(args[5], &p, 10);
+	box_r->uid_validity = strtoul(args[i++], &p, 10);
 	if (box_r->uid_validity == 0 || *p != '\0') {
 		*error_r = "Invalid mailbox uid_validity";
 		return -1;
 	}
 
-	box_r->uid_next = strtoul(args[6], &p, 10);
+	box_r->uid_next = strtoul(args[i++], &p, 10);
 	if (box_r->uid_validity == 0 || *p != '\0') {
 		*error_r = "Invalid mailbox uid_next";
 		return -1;
 	}
 
-	box_r->highest_modseq = strtoull(args[7], &p, 10);
+	box_r->highest_modseq = strtoull(args[i++], &p, 10);
 	if (*p != '\0') {
 		*error_r = "Invalid mailbox highest_modseq";
 		return -1;
 	}
 
-	args += 8;
-	count -= 8;
+	args += i;
+	count -= i;
 	p_array_init(&box_r->cache_fields, pool, count + 1);
 	for (i = 0; i < count; i++) {
 		const char *field_name = p_strdup(pool, args[i]);
diff -r a7be031eb51d -r ff403fe262e5 src/dsync/dsync-worker-local.c
--- a/src/dsync/dsync-worker-local.c	Tue Nov 17 20:32:35 2009 -0500
+++ b/src/dsync/dsync-worker-local.c	Tue Nov 17 20:55:04 2009 -0500
@@ -71,6 +71,8 @@ struct local_dsync_worker {
 	/* mailbox_guid_t -> struct local_dsync_subscription_change */
 	struct hash_table *subscription_changes_hash;
 
+	char alt_hierarchy_char;
+
 	mailbox_guid_t selected_box_guid;
 	struct mailbox *selected_box;
 	struct mail *mail, *ext_mail;
@@ -116,7 +118,8 @@ static unsigned int mailbox_guid_hash(co
 	return h;
 }
 
-struct dsync_worker *dsync_worker_init_local(struct mail_user *user)
+struct dsync_worker *
+dsync_worker_init_local(struct mail_user *user, char alt_hierarchy_char)
 {
 	struct local_dsync_worker *worker;
 	pool_t pool;
@@ -126,6 +129,7 @@ struct dsync_worker *dsync_worker_init_l
 	worker->worker.v = local_dsync_worker;
 	worker->user = user;
 	worker->pool = pool;
+	worker->alt_hierarchy_char = alt_hierarchy_char;
 	worker->mailbox_hash =
 		hash_table_create(default_pool, pool, 0,
 				  mailbox_guid_hash, mailbox_guid_cmp);
@@ -416,6 +420,7 @@ local_worker_mailbox_iter_next(struct ds
 
 	storage_name = mail_namespace_get_storage_name(info->ns, info->name);
 	dsync_box_r->name = info->name;
+	dsync_box_r->name_sep = info->ns->sep;
 	if (mailbox_list_get_guid(info->ns->list, storage_name,
 				  dsync_box_r->dir_guid.guid) < 0) {
 		i_error("Failed to get dir GUID for mailbox %s: %s", info->name,
@@ -856,6 +861,22 @@ local_worker_copy_mailbox_update(const s
 	update_r->min_highest_modseq = dsync_box->highest_modseq;
 }
 
+static const char *
+mailbox_name_convert(struct local_dsync_worker *worker,
+		     const char *name, char src_sep, char dest_sep)
+{
+	char *dest_name, *p;
+
+	dest_name = t_strdup_noconst(name);
+	for (p = dest_name; *p != '\0'; p++) {
+		if (*p == dest_sep && worker->alt_hierarchy_char != '\0')
+			*p = worker->alt_hierarchy_char;
+		else if (*p == src_sep)
+			*p = dest_sep;
+	}
+	return dest_name;
+}
+
 static struct mailbox *
 local_worker_mailbox_alloc(struct local_dsync_worker *worker,
 			   const struct dsync_mailbox *dsync_box)
@@ -870,6 +891,11 @@ local_worker_mailbox_alloc(struct local_
 		return NULL;
 	}
 
+	if (dsync_box->name_sep != ns->sep) {
+		/* mailbox names use different separators. convert them. */
+		name = mailbox_name_convert(worker, name,
+					    dsync_box->name_sep, ns->sep);
+	}
 	return mailbox_alloc(ns->list, name, NULL, 0);
 }
 
diff -r a7be031eb51d -r ff403fe262e5 src/dsync/dsync-worker.h
--- a/src/dsync/dsync-worker.h	Tue Nov 17 20:32:35 2009 -0500
+++ b/src/dsync/dsync-worker.h	Tue Nov 17 20:55:04 2009 -0500
@@ -28,7 +28,8 @@ typedef void dsync_worker_msg_callback_t
 					 void *context);
 typedef void dsync_worker_finish_callback_t(bool success, void *context);
 
-struct dsync_worker *dsync_worker_init_local(struct mail_user *user);
+struct dsync_worker *
+dsync_worker_init_local(struct mail_user *user, char alt_hierarchy_char);
 struct dsync_worker *dsync_worker_init_proxy_client(int fd_in, int fd_out);
 void dsync_worker_deinit(struct dsync_worker **worker);
 
diff -r a7be031eb51d -r ff403fe262e5 src/dsync/dsync.c
--- a/src/dsync/dsync.c	Tue Nov 17 20:32:35 2009 -0500
+++ b/src/dsync/dsync.c	Tue Nov 17 20:55:04 2009 -0500
@@ -58,7 +58,7 @@ usage(void)
 usage(void)
 {
 	fprintf(stderr,
-"usage: dsync [-b <mailbox>] [-r] [-u <user>] [-v]\n"
+"usage: dsync [-a <alt hierarchy sep>] [-b <mailbox>] [-r] [-u <user>] [-v]\n"
 "  mirror  <command to execute remote dsync>\n"
 "  convert <source mail_location>\n"
 );
@@ -84,18 +84,22 @@ int main(int argc, char *argv[])
 	const char *error, *username, *mailbox = NULL, *mirror_cmd = NULL;
 	const char *convert_location = NULL;
 	bool dsync_server = FALSE, readonly = FALSE;
+	char alt_hierarchy_char = '_';
 	int c, ret, fd_in = STDIN_FILENO, fd_out = STDOUT_FILENO;
 
 	master_service = master_service_init("dsync",
 					     MASTER_SERVICE_FLAG_STANDALONE |
 					     MASTER_SERVICE_FLAG_STD_CLIENT,
-					     &argc, &argv, "b:fru:v");
+					     &argc, &argv, "A:b:fru:v");
 
 	username = getenv("USER");
 	while ((c = master_getopt(master_service)) > 0) {
 		if (c == '-')
 			break;
 		switch (c) {
+		case 'A':
+			alt_hierarchy_char = optarg[0];
+			break;
 		case 'b':
 			mailbox = optarg;
 			break;
@@ -152,7 +156,7 @@ int main(int argc, char *argv[])
 	}
 
 	/* create the first local worker */
-	worker1 = dsync_worker_init_local(mail_user);
+	worker1 = dsync_worker_init_local(mail_user, alt_hierarchy_char);
 	if (convert_location != NULL) {
 		/* update mail_location and create another user for the
 		   second location. */
@@ -168,7 +172,8 @@ int main(int argc, char *argv[])
 						     &error) <= 0)
 			i_fatal("%s", error);
 
-		worker2 = dsync_worker_init_local(mail_user2);
+		worker2 = dsync_worker_init_local(mail_user2,
+						  alt_hierarchy_char);
 
 		i_set_failure_prefix(t_strdup_printf("dsync(%s): ", username));
 		brain = dsync_brain_init(worker1, worker2,
diff -r a7be031eb51d -r ff403fe262e5 src/dsync/test-dsync-brain.c
--- a/src/dsync/test-dsync-brain.c	Tue Nov 17 20:32:35 2009 -0500
+++ b/src/dsync/test-dsync-brain.c	Tue Nov 17 20:55:04 2009 -0500
@@ -121,28 +121,28 @@ static void test_dsync_brain(void)
 static void test_dsync_brain(void)
 {
 	static struct dsync_mailbox src_boxes[] = {
-		{ "box1", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
-		{ "box2", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
-		{ "box3", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
-		{ "box4", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
-		{ "box5", { { 0, } }, { { 0, } }, 1234567890, 5433, 123123123123ULL, 3636, 0, ARRAY_INIT },
-		{ "box6", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123124ULL, 3636, 0, ARRAY_INIT },
-		{ "boxx", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
-		{ "boxd1", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
-		{ "boxd2", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, DSYNC_MAILBOX_FLAG_DELETED_MAILBOX, ARRAY_INIT },
-		{ NULL, { { 0, } }, { { 0, } }, 0, 0, 0, 0, 0, ARRAY_INIT }
+		{ "box1", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+		{ "box2", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+		{ "box3", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+		{ "box4", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+		{ "box5", '/', { { 0, } }, { { 0, } }, 1234567890, 5433, 123123123123ULL, 3636, 0, ARRAY_INIT },
+		{ "box6", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123124ULL, 3636, 0, ARRAY_INIT },
+		{ "boxx", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+		{ "boxd1", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+		{ "boxd2", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, DSYNC_MAILBOX_FLAG_DELETED_MAILBOX, ARRAY_INIT },
+		{ NULL, 0, { { 0, } }, { { 0, } }, 0, 0, 0, 0, 0, ARRAY_INIT }
 	};
 	static struct dsync_mailbox dest_boxes[] = {
-		{ "box1", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
-		{ "box2", { { 0, } }, { { 0, } }, 1234567891, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
-		{ "box3", { { 0, } }, { { 0, } }, 1234567890, 5433, 123123123123ULL, 3636, 0, ARRAY_INIT },
-		{ "box4", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123124ULL, 3636, 0, ARRAY_INIT },


More information about the dovecot-cvs mailing list