[dovecot-cvs] dovecot/src/lib-index mail-index.c, 1.237, 1.238 mail-index-sync-update.c, 1.100, 1.101 mail-index-sync-private.h, 1.31, 1.32 mail-index-sync-ext.c, 1.19, 1.20 mail-index-private.h, 1.72, 1.73 mail-cache.c, 1.82, 1.83 mail-cache-sync-update.c, 1.10, 1.11 mail-cache-private.h, 1.30, 1.31

cras at dovecot.org cras at dovecot.org
Tue Jul 11 19:02:47 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv29254

Modified Files:
	mail-index.c mail-index-sync-update.c 
	mail-index-sync-private.h mail-index-sync-ext.c 
	mail-index-private.h mail-cache.c mail-cache-sync-update.c 
	mail-cache-private.h 
Log Message:
Added support for calling expunge handler for an extension even if the
extension isn't used in the opened index file. Added context-parameter to
the callback function. If the function returns -1, the sync is failed.



Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.237
retrieving revision 1.238
diff -u -d -r1.237 -r1.238
--- mail-index.c	28 Jun 2006 16:31:05 -0000	1.237
+++ mail-index.c	11 Jul 2006 16:02:42 -0000	1.238
@@ -113,7 +113,8 @@
 
 void mail_index_register_expunge_handler(struct mail_index *index,
 					 uint32_t ext_id,
-					 mail_index_expunge_handler_t *cb)
+					 mail_index_expunge_handler_t *cb,
+					 void *context, bool call_always)
 {
 	struct mail_index_registered_ext *rext;
 
@@ -121,6 +122,8 @@
 	i_assert(rext->expunge_handler == NULL);
 
 	rext->expunge_handler = cb;
+	rext->expunge_context = context;
+	rext->expunge_handler_call_always = call_always;
 }
 
 void mail_index_unregister_expunge_handler(struct mail_index *index,

Index: mail-index-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-update.c,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -d -r1.100 -r1.101
--- mail-index-sync-update.c	28 Jun 2006 13:10:38 -0000	1.100
+++ mail-index-sync-update.c	11 Jul 2006 16:02:42 -0000	1.101
@@ -195,9 +195,10 @@
 
 		for (seq = seq1; seq <= seq2; seq++) {
 			rec = MAIL_INDEX_MAP_IDX(map, seq-1);
-			eh->handler(ctx, seq,
-				    PTR_OFFSET(rec, eh->record_offset),
-				    eh->context);
+			if (eh->handler(ctx, seq,
+					PTR_OFFSET(rec, eh->record_offset),
+					eh->sync_context, eh->context) < 0)
+				return -1;
 		}
 	}
 

Index: mail-index-sync-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-private.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- mail-index-sync-private.h	28 Jun 2006 13:10:38 -0000	1.31
+++ mail-index-sync-private.h	11 Jul 2006 16:02:42 -0000	1.32
@@ -37,7 +37,8 @@
 
 struct mail_index_expunge_handler {
 	mail_index_expunge_handler_t *handler;
-	void **context;
+	void *context;
+	void **sync_context;
 	uint32_t record_offset;
 };
 

Index: mail-index-sync-ext.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-ext.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- mail-index-sync-ext.c	28 Jun 2006 13:10:38 -0000	1.19
+++ mail-index-sync-ext.c	11 Jul 2006 16:02:42 -0000	1.20
@@ -41,13 +41,15 @@
 	for (idx_ext_id = 0; idx_ext_id < id_map_count; idx_ext_id++) {
 		map_ext_id = id_map[idx_ext_id];
 		if (rext[idx_ext_id].expunge_handler == NULL ||
-		    map_ext_id == (uint32_t)-1)
+		    (map_ext_id == (uint32_t)-1 &&
+		     !rext[idx_ext_id].expunge_handler_call_always))
 			continue;
 
-		i_assert(map_ext_id < context_count);
 		eh.handler = rext[idx_ext_id].expunge_handler;
-		eh.context = &contexts[map_ext_id];
-		eh.record_offset = ext[map_ext_id].record_offset;
+		eh.context = rext[idx_ext_id].expunge_context;
+		eh.sync_context = &contexts[idx_ext_id];
+		eh.record_offset = map_ext_id == (uint32_t)-1 ? 0 :
+			ext[map_ext_id].record_offset;
 		array_append(&ctx->expunge_handlers, &eh, 1);
 	}
 	ctx->expunge_handlers_set = TRUE;
@@ -65,8 +67,10 @@
 
 	eh = array_get(&ctx->expunge_handlers, &count);
 	for (i = 0; i < count; i++) {
-		if (eh->context != NULL)
-			eh[i].handler(ctx, 0, NULL, eh->context);
+		if (eh->sync_context != NULL) {
+			eh[i].handler(ctx, 0, NULL, eh->sync_context,
+				      eh[i].context);
+		}
 	}
 
 	array_free(&ctx->expunge_handlers);
@@ -97,32 +101,22 @@
 
 void mail_index_sync_deinit_handlers(struct mail_index_sync_map_ctx *ctx)
 {
-	const struct mail_index_ext *ext;
 	const struct mail_index_registered_ext *rext;
 	void **extra_contexts;
-	unsigned int i, count, rext_count, context_count;
+	unsigned int i, rext_count, context_count;
 
 	if (!array_is_created(&ctx->extra_contexts))
 		return;
 
-	if (!array_is_created(&ctx->view->map->extensions)) {
-		ext = NULL;
-		count = 0;
-	} else {
-		ext = array_get(&ctx->view->map->extensions, &count);
-	}
 	rext = array_get(&ctx->view->index->extensions, &rext_count);
-
-	/* extra_contexts[] is ordered by map->extensions. */
 	extra_contexts =
 		array_get_modifiable(&ctx->extra_contexts, &context_count);
-	i_assert(count <= context_count);
+	i_assert(context_count <= rext_count);
 
-	for (i = 0; i < count; i++) {
+	for (i = 0; i < context_count; i++) {
 		if (extra_contexts[i] != NULL) {
-			rext[ext[i].index_idx].sync_handler.
-				callback(ctx, 0, NULL, NULL,
-					 &extra_contexts[i]);
+			rext[i].sync_handler.callback(ctx, 0, NULL, NULL,
+						      &extra_contexts[i]);
 		}
 	}
 
@@ -544,7 +538,7 @@
 	if ((rext->sync_handler.type & ctx->type) != 0) {
 		void **extra_context =
 			array_idx_modifiable(&ctx->extra_contexts,
-					     ctx->cur_ext_id);
+					     ext->index_idx);
 		ret = rext->sync_handler.callback(ctx, seq, old_data, u + 1,
 						  extra_context);
 		if (ret <= 0)

Index: mail-index-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-private.h,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- mail-index-private.h	28 Jun 2006 16:31:05 -0000	1.72
+++ mail-index-private.h	11 Jul 2006 16:02:42 -0000	1.73
@@ -35,7 +35,7 @@
 
 typedef int mail_index_expunge_handler_t(struct mail_index_sync_map_ctx *ctx,
 					 uint32_t seq, const void *data,
-					 void **context);
+					 void **sync_context, void *context);
 typedef int mail_index_sync_handler_t(struct mail_index_sync_map_ctx *ctx,
 				      uint32_t seq, void *old_data,
 				      const void *new_data, void **context);
@@ -98,7 +98,10 @@
 	uint16_t record_align;
 
 	struct mail_index_sync_handler sync_handler;
-        mail_index_expunge_handler_t *expunge_handler;
+	mail_index_expunge_handler_t *expunge_handler;
+
+	void *expunge_context;
+	unsigned int expunge_handler_call_always:1;
 };
 
 struct mail_index_map {
@@ -189,7 +192,8 @@
 /* Add/replace sync handler for specified extra record. */
 void mail_index_register_expunge_handler(struct mail_index *index,
 					 uint32_t ext_id,
-					 mail_index_expunge_handler_t *cb);
+					 mail_index_expunge_handler_t *cb,
+					 void *context, bool call_always);
 void mail_index_unregister_expunge_handler(struct mail_index *index,
 					   uint32_t ext_id);
 void mail_index_register_sync_handler(struct mail_index *index, uint32_t ext_id,

Index: mail-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- mail-cache.c	8 Jun 2006 18:28:07 -0000	1.82
+++ mail-cache.c	11 Jul 2006 16:02:42 -0000	1.83
@@ -302,7 +302,8 @@
 		mail_index_ext_register(index, "cache", 0,
 					sizeof(uint32_t), sizeof(uint32_t));
 	mail_index_register_expunge_handler(index, cache->ext_id,
-					    mail_cache_expunge_handler);
+					    mail_cache_expunge_handler,
+					    cache, FALSE);
 	mail_index_register_sync_handler(index, cache->ext_id,
 					 mail_cache_sync_handler,
                                          MAIL_INDEX_SYNC_HANDLER_FILE |

Index: mail-cache-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-sync-update.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- mail-cache-sync-update.c	30 May 2006 08:36:11 -0000	1.10
+++ mail-cache-sync-update.c	11 Jul 2006 16:02:42 -0000	1.11
@@ -60,40 +60,39 @@
 }
 
 int mail_cache_expunge_handler(struct mail_index_sync_map_ctx *sync_ctx,
-			       uint32_t seq __attr_unused__,
-			       const void *data, void **context)
+			       uint32_t seq __attr_unused__, const void *data,
+			       void **sync_context, void *context)
 {
-	struct mail_index_view *view = sync_ctx->view;
-	struct mail_cache_sync_context *ctx = *context;
-	struct mail_cache *cache = view->index->cache;
+	struct mail_cache *cache = context;
+	struct mail_cache_sync_context *ctx = *sync_context;
 	const uint32_t *cache_offset = data;
 	uint32_t cache_file_seq;
 	int ret;
 
 	if (data == NULL) {
 		mail_cache_handler_deinit(sync_ctx, ctx);
-		*context = NULL;
-		return 1;
+		*sync_context = NULL;
+		return 0;
 	}
 
 	if (*cache_offset == 0)
-		return 1;
+		return 0;
 
 	if (MAIL_CACHE_IS_UNUSABLE(cache))
-		return 1;
+		return 0;
 
 	ret = mail_cache_handler_init(&ctx, cache);
-	*context = ctx;
+	*sync_context = ctx;
 	if (ret <= 0)
-		return ret < 0 ? -1 : 1;
+		return ret;
 
-	if (!get_cache_file_seq(view, &cache_file_seq))
-		return 1;
+	if (!get_cache_file_seq(sync_ctx->view, &cache_file_seq))
+		return 0;
 
 	if (!MAIL_CACHE_IS_UNUSABLE(cache) &&
 	    cache_file_seq == cache->hdr->file_seq)
 		(void)mail_cache_delete(cache, *cache_offset);
-	return 1;
+	return 0;
 }
 
 int mail_cache_sync_handler(struct mail_index_sync_map_ctx *sync_ctx,

Index: mail-cache-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-private.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- mail-cache-private.h	28 Jun 2006 13:10:38 -0000	1.30
+++ mail-cache-private.h	11 Jul 2006 16:02:43 -0000	1.31
@@ -216,7 +216,8 @@
 			     unsigned int field);
 
 int mail_cache_expunge_handler(struct mail_index_sync_map_ctx *sync_ctx,
-			       uint32_t seq, const void *data, void **context);
+			       uint32_t seq, const void *data,
+			       void **sync_context, void *context);
 int mail_cache_sync_handler(struct mail_index_sync_map_ctx *sync_ctx,
 			    uint32_t seq, void *old_data, const void *new_data,
 			    void **context);



More information about the dovecot-cvs mailing list