dovecot: Implemented mail_index_update_header_ext()

dovecot at dovecot.org dovecot at dovecot.org
Sun Jul 8 20:03:36 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/3ec9ce7cd5e7
changeset: 5897:3ec9ce7cd5e7
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Jul 08 19:46:31 2007 +0300
description:
Implemented mail_index_update_header_ext()

diffstat:

3 files changed, 74 insertions(+), 4 deletions(-)
src/lib-index/mail-index-transaction-private.h |    9 +++++
src/lib-index/mail-index-transaction.c         |   26 +++++++++++++-
src/lib-index/mail-transaction-log-append.c    |   43 ++++++++++++++++++++++--

diffs (174 lines):

diff -r a4c80b0ee22b -r 3ec9ce7cd5e7 src/lib-index/mail-index-transaction-private.h
--- a/src/lib-index/mail-index-transaction-private.h	Sun Jul 08 19:45:59 2007 +0300
+++ b/src/lib-index/mail-index-transaction-private.h	Sun Jul 08 19:46:31 2007 +0300
@@ -7,6 +7,13 @@ struct mail_index_transaction_keyword_up
 struct mail_index_transaction_keyword_update {
 	ARRAY_TYPE(seq_range) add_seq;
 	ARRAY_TYPE(seq_range) remove_seq;
+};
+
+struct mail_index_transaction_ext_hdr_update {
+	uint32_t ext_id;
+	uint16_t offset;
+	uint16_t size;
+	/* unsigned char data[]; */
 };
 
 struct mail_index_transaction_vfuncs {
@@ -39,6 +46,8 @@ struct mail_index_transaction {
 	unsigned char post_hdr_change[sizeof(struct mail_index_header)];
 	unsigned char post_hdr_mask[sizeof(struct mail_index_header)];
 
+	ARRAY_DEFINE(ext_hdr_updates,
+		     struct mail_index_transaction_ext_hdr_update *);
 	ARRAY_DEFINE(ext_rec_updates, ARRAY_TYPE(seq_array));
 	ARRAY_DEFINE(ext_resizes, struct mail_transaction_ext_intro);
 	ARRAY_DEFINE(ext_resets, uint32_t);
diff -r a4c80b0ee22b -r 3ec9ce7cd5e7 src/lib-index/mail-index-transaction.c
--- a/src/lib-index/mail-index-transaction.c	Sun Jul 08 19:45:59 2007 +0300
+++ b/src/lib-index/mail-index-transaction.c	Sun Jul 08 19:46:31 2007 +0300
@@ -23,6 +23,7 @@ void mail_index_transaction_reset(struct
 void mail_index_transaction_reset(struct mail_index_transaction *t)
 {
 	ARRAY_TYPE(seq_array) *recs;
+	struct mail_index_transaction_ext_hdr_update **ext_hdrs;
 	unsigned i, count;
 
 	if (array_is_created(&t->ext_rec_updates)) {
@@ -33,6 +34,13 @@ void mail_index_transaction_reset(struct
 				array_free(&recs[i]);
 		}
 		array_free(&t->ext_rec_updates);
+	}
+	if (array_is_created(&t->ext_hdr_updates)) {
+		ext_hdrs = array_get_modifiable(&t->ext_hdr_updates, &count);
+
+		for (i = 0; i < count; i++)
+			i_free(ext_hdrs[i]);
+		array_free(&t->ext_hdr_updates);
 	}
 
 	if (array_is_created(&t->keyword_updates)) {
@@ -860,7 +868,23 @@ void mail_index_update_header_ext(struct
 				  uint32_t ext_id, size_t offset,
 				  const void *data, size_t size)
 {
-	// FIXME
+	struct mail_index_transaction_ext_hdr_update *hdr, **pos;
+
+	hdr = i_malloc(sizeof(*hdr) + size);
+	hdr->ext_id = ext_id;
+	hdr->offset = offset;
+	hdr->size = size;
+	memcpy(hdr + 1, data, size);
+
+	if (!array_is_created(&t->ext_hdr_updates))
+		i_array_init(&t->ext_hdr_updates, ext_id + 2);
+
+	pos = array_idx_modifiable(&t->ext_hdr_updates, ext_id);
+	if (*pos != NULL) {
+		i_panic("mail_index_update_header_ext() doesn't currently "
+			"support multiple updates to the same ext header");
+	}
+	*pos = hdr;
 }
 
 void mail_index_update_ext(struct mail_index_transaction *t, uint32_t seq,
diff -r a4c80b0ee22b -r 3ec9ce7cd5e7 src/lib-index/mail-transaction-log-append.c
--- a/src/lib-index/mail-transaction-log-append.c	Sun Jul 08 19:45:59 2007 +0300
+++ b/src/lib-index/mail-transaction-log-append.c	Sun Jul 08 19:46:31 2007 +0300
@@ -226,12 +226,33 @@ static void log_append_ext_intro(struct 
 }
 
 static void
+log_append_ext_hdr_update(struct log_append_context *ctx,
+			  struct mail_index_transaction_ext_hdr_update *hdr)
+{
+	struct mail_transaction_ext_hdr_update *trans_hdr;
+	buffer_t *buf;
+	unsigned int hdr_size;
+
+	t_push();
+	hdr_size = sizeof(*trans_hdr) + hdr->size;
+	buf = buffer_create_static_hard(pool_datastack_create(), hdr_size);
+	trans_hdr = buffer_append_space_unsafe(buf, sizeof(*trans_hdr));
+	trans_hdr->offset = hdr->offset;
+	trans_hdr->size = hdr->size;
+	buffer_append(buf, hdr + 1, hdr->size);
+	log_append_buffer(ctx, buf, NULL, MAIL_TRANSACTION_EXT_HDR_UPDATE);
+	t_pop();
+}
+
+static void
 mail_transaction_log_append_ext_intros(struct log_append_context *ctx)
 {
 	struct mail_index_transaction *t = ctx->trans;
         const struct mail_transaction_ext_intro *resize;
+	struct mail_index_transaction_ext_hdr_update *const *hdrs;
 	struct mail_transaction_ext_reset ext_reset;
-	unsigned int update_count, resize_count, reset_count, ext_count;
+	unsigned int update_count, resize_count, reset_count, ext_count = 0;
+	unsigned int hdrs_count;
 	uint32_t ext_id;
 	const uint32_t *reset;
 	const ARRAY_TYPE(seq_array) *update;
@@ -242,6 +263,7 @@ mail_transaction_log_append_ext_intros(s
 		update_count = 0;
 	} else {
 		update = array_get(&t->ext_rec_updates, &update_count);
+		ext_count = update_count;
 	}
 
 	if (!array_is_created(&t->ext_resizes)) {
@@ -249,6 +271,8 @@ mail_transaction_log_append_ext_intros(s
 		resize_count = 0;
 	} else {
 		resize = array_get(&t->ext_resizes, &resize_count);
+		if (ext_count < resize_count)
+			ext_count = resize_count;
 	}
 
 	if (!array_is_created(&t->ext_resets)) {
@@ -256,6 +280,17 @@ mail_transaction_log_append_ext_intros(s
 		reset_count = 0;
 	} else {
 		reset = array_get(&t->ext_resets, &reset_count);
+		if (ext_count < reset_count)
+			ext_count = reset_count;
+	}
+
+	if (!array_is_created(&t->ext_hdr_updates)) {
+		hdrs = NULL;
+		hdrs_count = 0;
+	} else {
+		hdrs = array_get(&t->ext_hdr_updates, &hdrs_count);
+		if (ext_count < hdrs_count)
+			ext_count = hdrs_count;
 	}
 
 	memset(&ext_reset, 0, sizeof(ext_reset));
@@ -263,7 +298,6 @@ mail_transaction_log_append_ext_intros(s
 	buf = buffer_create_data(pool_datastack_create(),
 				 &ext_reset, sizeof(ext_reset));
 	buffer_set_used_size(buf, sizeof(ext_reset));
-	ext_count = I_MAX(I_MAX(update_count, resize_count), reset_count);
 
 	for (ext_id = 0; ext_id < ext_count; ext_id++) {
 		ext_reset.new_reset_id =
@@ -272,12 +306,15 @@ mail_transaction_log_append_ext_intros(s
 		if ((ext_id < resize_count && resize[ext_id].name_size) ||
 		    (ext_id < update_count &&
 		     array_is_created(&update[ext_id])) ||
-		    ext_reset.new_reset_id != 0)
+		    ext_reset.new_reset_id != 0 ||
+		    (ext_id < hdrs_count && hdrs[ext_id] != NULL))
 			log_append_ext_intro(ctx, ext_id, 0);
 		if (ext_reset.new_reset_id != 0) {
 			log_append_buffer(ctx, buf, NULL,
 					  MAIL_TRANSACTION_EXT_RESET);
 		}
+		if (ext_id < hdrs_count && hdrs[ext_id] != NULL)
+			log_append_ext_hdr_update(ctx, hdrs[ext_id]);
 	}
 }
 


More information about the dovecot-cvs mailing list