dovecot-2.2: dsync: Fixed talking to earlier dsync without mailb...

dovecot at dovecot.org dovecot at dovecot.org
Sun Apr 7 15:37:12 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/d79cf48f1072
changeset: 16222:d79cf48f1072
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Apr 07 15:36:35 2013 +0300
description:
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Most importantly it can now be used as an example how to add more features
to dsync.

diffstat:

 src/doveadm/dsync/dsync-brain-mailbox-tree.c |   2 +-
 src/doveadm/dsync/dsync-brain-mailbox.c      |   2 +-
 src/doveadm/dsync/dsync-brain-mails.c        |   8 ++++----
 src/doveadm/dsync/dsync-brain.c              |   2 +-
 src/doveadm/dsync/dsync-ibc-pipe.c           |   3 ++-
 src/doveadm/dsync/dsync-ibc-private.h        |   3 ++-
 src/doveadm/dsync/dsync-ibc-stream.c         |  21 +++++++++++++++++----
 src/doveadm/dsync/dsync-ibc.c                |   4 ++--
 src/doveadm/dsync/dsync-ibc.h                |  12 +++++++++++-
 9 files changed, 41 insertions(+), 16 deletions(-)

diffs (210 lines):

diff -r cb2e3676547d -r d79cf48f1072 src/doveadm/dsync/dsync-brain-mailbox-tree.c
--- a/src/doveadm/dsync/dsync-brain-mailbox-tree.c	Sun Apr 07 15:10:36 2013 +0300
+++ b/src/doveadm/dsync/dsync-brain-mailbox-tree.c	Sun Apr 07 15:36:35 2013 +0300
@@ -124,7 +124,7 @@
 			return;
 	}
 	dsync_mailbox_tree_iter_deinit(&brain->local_tree_iter);
-	dsync_ibc_send_end_of_list(brain->ibc);
+	dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAILBOX_TREE);
 
 	brain->state = DSYNC_STATE_SEND_MAILBOX_TREE_DELETES;
 }
diff -r cb2e3676547d -r d79cf48f1072 src/doveadm/dsync/dsync-brain-mailbox.c
--- a/src/doveadm/dsync/dsync-brain-mailbox.c	Sun Apr 07 15:10:36 2013 +0300
+++ b/src/doveadm/dsync/dsync-brain-mailbox.c	Sun Apr 07 15:36:35 2013 +0300
@@ -412,7 +412,7 @@
 
 	if (!dsync_brain_next_mailbox(brain, &box, &dsync_box)) {
 		brain->state = DSYNC_STATE_DONE;
-		dsync_ibc_send_end_of_list(brain->ibc);
+		dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAILBOX);
 		return;
 	}
 
diff -r cb2e3676547d -r d79cf48f1072 src/doveadm/dsync/dsync-brain-mails.c
--- a/src/doveadm/dsync/dsync-brain-mails.c	Sun Apr 07 15:10:36 2013 +0300
+++ b/src/doveadm/dsync/dsync-brain-mails.c	Sun Apr 07 15:36:35 2013 +0300
@@ -87,7 +87,7 @@
 		if (dsync_ibc_send_mailbox_attribute(brain->ibc, attr) == 0)
 			return;
 	}
-	dsync_ibc_send_end_of_list(brain->ibc);
+	dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAILBOX_ATTRIBUTE);
 	brain->box_send_state = DSYNC_BOX_STATE_CHANGES;
 }
 
@@ -119,7 +119,7 @@
 		if (dsync_ibc_send_change(brain->ibc, change) == 0)
 			return;
 	}
-	dsync_ibc_send_end_of_list(brain->ibc);
+	dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAIL_CHANGES);
 	if (brain->mail_requests && brain->box_importer != NULL)
 		brain->box_send_state = DSYNC_BOX_STATE_MAIL_REQUESTS;
 	else
@@ -159,7 +159,7 @@
 	if (brain->box_recv_state < DSYNC_BOX_STATE_MAIL_REQUESTS)
 		return FALSE;
 
-	dsync_ibc_send_end_of_list(brain->ibc);
+	dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAIL_REQUESTS);
 	if (brain->box_exporter != NULL)
 		brain->box_send_state = DSYNC_BOX_STATE_MAILS;
 	else {
@@ -257,7 +257,7 @@
 	}
 
 	brain->box_send_state = DSYNC_BOX_STATE_DONE;
-	dsync_ibc_send_end_of_list(brain->ibc);
+	dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAILS);
 
 	dsync_brain_sync_half_finished(brain);
 	return TRUE;
diff -r cb2e3676547d -r d79cf48f1072 src/doveadm/dsync/dsync-brain.c
--- a/src/doveadm/dsync/dsync-brain.c	Sun Apr 07 15:10:36 2013 +0300
+++ b/src/doveadm/dsync/dsync-brain.c	Sun Apr 07 15:36:35 2013 +0300
@@ -344,7 +344,7 @@
 	}
 	hash_table_iterate_deinit(&brain->mailbox_states_iter);
 
-	dsync_ibc_send_end_of_list(brain->ibc);
+	dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAILBOX_STATE);
 	brain->state = DSYNC_STATE_SEND_MAILBOX_TREE;
 }
 
diff -r cb2e3676547d -r d79cf48f1072 src/doveadm/dsync/dsync-ibc-pipe.c
--- a/src/doveadm/dsync/dsync-ibc-pipe.c	Sun Apr 07 15:10:36 2013 +0300
+++ b/src/doveadm/dsync/dsync-ibc-pipe.c	Sun Apr 07 15:36:35 2013 +0300
@@ -195,7 +195,8 @@
 }
 
 static void
-dsync_ibc_pipe_send_end_of_list(struct dsync_ibc *ibc)
+dsync_ibc_pipe_send_end_of_list(struct dsync_ibc *ibc,
+				enum dsync_ibc_eol_type type ATTR_UNUSED)
 {
 	struct dsync_ibc_pipe *pipe = (struct dsync_ibc_pipe *)ibc;
 
diff -r cb2e3676547d -r d79cf48f1072 src/doveadm/dsync/dsync-ibc-private.h
--- a/src/doveadm/dsync/dsync-ibc-private.h	Sun Apr 07 15:10:36 2013 +0300
+++ b/src/doveadm/dsync/dsync-ibc-private.h	Sun Apr 07 15:36:35 2013 +0300
@@ -12,7 +12,8 @@
 		(*recv_handshake)(struct dsync_ibc *ibc,
 				  const struct dsync_ibc_settings **set_r);
 
-	void (*send_end_of_list)(struct dsync_ibc *ibc);
+	void (*send_end_of_list)(struct dsync_ibc *ibc,
+				 enum dsync_ibc_eol_type type);
 
 	void (*send_mailbox_state)(struct dsync_ibc *ibc,
 				   const struct dsync_mailbox_state *state);
diff -r cb2e3676547d -r d79cf48f1072 src/doveadm/dsync/dsync-ibc-stream.c
--- a/src/doveadm/dsync/dsync-ibc-stream.c	Sun Apr 07 15:10:36 2013 +0300
+++ b/src/doveadm/dsync/dsync-ibc-stream.c	Sun Apr 07 15:36:35 2013 +0300
@@ -61,8 +61,9 @@
 	char chr;
 	const char *required_keys;
 	const char *optional_keys;
+	unsigned int min_minor_version;
 } items[ITEM_END_OF_LIST+1] = {
-	{ NULL, '\0', NULL, NULL },
+	{ NULL, '\0', NULL, NULL, 0 },
 	{ .name = "done",
 	  .chr = 'X',
 	  .optional_keys = ""
@@ -100,7 +101,8 @@
 	{ .name = "mailbox_attribute",
 	  .chr = 'A',
 	  .required_keys = "type key",
-	  .optional_keys = "value stream deleted last_change modseq"
+	  .optional_keys = "value stream deleted last_change modseq",
+	  .min_minor_version = DSYNC_PROTOCOL_MINOR_HAVE_ATTRIBUTES
 	},
 	{ .name = "mail_change",
 	  .chr = 'C',
@@ -123,7 +125,7 @@
 	  .optional_keys = "last_used"
 	},
 
-	{ "end_of_list", '\0', NULL, NULL }
+	{ "end_of_list", '\0', NULL, NULL, 0 }
 };
 
 struct dsync_ibc_stream {
@@ -453,6 +455,7 @@
 
 	for (i = ITEM_DONE + 1; i < ITEM_END_OF_LIST; i++) {
 		if (ibc->deserializers[i] == NULL &&
+		    ibc->minor_version >= items[i].min_minor_version &&
 		    (items[i].required_keys != NULL ||
 		     items[i].optional_keys != NULL)) {
 			dsync_ibc_input_error(ibc, NULL,
@@ -707,12 +710,22 @@
 }
 
 static void
-dsync_ibc_stream_send_end_of_list(struct dsync_ibc *_ibc)
+dsync_ibc_stream_send_end_of_list(struct dsync_ibc *_ibc,
+				  enum dsync_ibc_eol_type type)
 {
 	struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc;
 
 	i_assert(ibc->value_output == NULL);
 
+	switch (type) {
+	case DSYNC_IBC_EOL_MAILBOX_ATTRIBUTE:
+		if (ibc->minor_version < DSYNC_PROTOCOL_MINOR_HAVE_ATTRIBUTES)
+			return;
+		break;
+	default:
+		break;
+	}
+
 	o_stream_nsend_str(ibc->output, END_OF_LIST_LINE"\n");
 }
 
diff -r cb2e3676547d -r d79cf48f1072 src/doveadm/dsync/dsync-ibc.c
--- a/src/doveadm/dsync/dsync-ibc.c	Sun Apr 07 15:10:36 2013 +0300
+++ b/src/doveadm/dsync/dsync-ibc.c	Sun Apr 07 15:36:35 2013 +0300
@@ -41,9 +41,9 @@
 }
 
 enum dsync_ibc_send_ret
-dsync_ibc_send_end_of_list(struct dsync_ibc *ibc)
+dsync_ibc_send_end_of_list(struct dsync_ibc *ibc, enum dsync_ibc_eol_type type)
 {
-	ibc->v.send_end_of_list(ibc);
+	ibc->v.send_end_of_list(ibc, type);
 	return dsync_ibc_send_ret(ibc);
 }
 
diff -r cb2e3676547d -r d79cf48f1072 src/doveadm/dsync/dsync-ibc.h
--- a/src/doveadm/dsync/dsync-ibc.h	Sun Apr 07 15:10:36 2013 +0300
+++ b/src/doveadm/dsync/dsync-ibc.h	Sun Apr 07 15:36:35 2013 +0300
@@ -29,6 +29,16 @@
 	DSYNC_IBC_RECV_RET_OK		= 1
 };
 
+enum dsync_ibc_eol_type {
+	DSYNC_IBC_EOL_MAILBOX_STATE,
+	DSYNC_IBC_EOL_MAILBOX_TREE,
+	DSYNC_IBC_EOL_MAILBOX_ATTRIBUTE,
+	DSYNC_IBC_EOL_MAILBOX,
+	DSYNC_IBC_EOL_MAIL_CHANGES,
+	DSYNC_IBC_EOL_MAIL_REQUESTS,
+	DSYNC_IBC_EOL_MAILS
+};
+
 struct dsync_ibc_settings {
 	/* Server hostname. Used for determining which server does the
 	   locking. */
@@ -64,7 +74,7 @@
 			 const struct dsync_ibc_settings **set_r);
 
 enum dsync_ibc_send_ret ATTR_NOWARN_UNUSED_RESULT
-dsync_ibc_send_end_of_list(struct dsync_ibc *ibc);
+dsync_ibc_send_end_of_list(struct dsync_ibc *ibc, enum dsync_ibc_eol_type type);
 
 enum dsync_ibc_send_ret ATTR_NOWARN_UNUSED_RESULT
 dsync_ibc_send_mailbox_state(struct dsync_ibc *ibc,


More information about the dovecot-cvs mailing list