typedef int mail_index_expunge_handler_t(struct mail_index_sync_map_ctx *ctx,
uint32_t seq, const void *data,
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);
typedef void mail_index_sync_lost_handler_t(struct mail_index *index);
#define MAIL_INDEX_HEADER_SIZE_ALIGN(size) \
MAIL_INDEX_SYNC_HANDLER_VIEW = 0x04
};
-struct mail_index_sync_handler {
- mail_index_sync_handler_t *callback;
- enum mail_index_sync_handler_type type;
-};
-
struct mail_index_registered_ext {
const char *name;
uint32_t index_idx; /* index ext_id */
uint16_t record_size;
uint16_t record_align;
- struct mail_index_sync_handler sync_handler;
mail_index_expunge_handler_t *expunge_handler;
void *expunge_context;
void *context);
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,
- mail_index_sync_handler_t *cb,
- enum mail_index_sync_handler_type type);
-void mail_index_unregister_sync_handler(struct mail_index *index,
- uint32_t ext_id);
void mail_index_register_sync_lost_handler(struct mail_index *index,
mail_index_sync_lost_handler_t *cb);
void mail_index_unregister_sync_lost_handler(struct mail_index *index,
void mail_index_sync_deinit_handlers(struct mail_index_sync_map_ctx *ctx)
{
- const struct mail_index_registered_ext *rext;
- void **extra_contexts;
- unsigned int i, rext_count, context_count;
-
- if (!array_is_created(&ctx->extra_contexts))
- return;
-
- rext = array_get(&ctx->view->index->extensions, &rext_count);
- extra_contexts =
- array_get_modifiable(&ctx->extra_contexts, &context_count);
- i_assert(context_count <= rext_count);
-
- for (i = 0; i < context_count; i++) {
- if (extra_contexts[i] != NULL) {
- rext[i].sync_handler.callback(ctx, 0, NULL, NULL,
- &extra_contexts[i]);
- }
- }
-
- array_free(&ctx->extra_contexts);
+ if (array_is_created(&ctx->extra_contexts))
+ array_free(&ctx->extra_contexts);
}
static struct mail_index_ext_header *
struct mail_index_view *view = ctx->view;
struct mail_index_record *rec;
const struct mail_index_ext *ext;
- const struct mail_index_registered_ext *rext;
void *old_data;
uint32_t seq;
- int ret;
i_assert(ctx->cur_ext_map_idx != (uint32_t)-1);
i_assert(!ctx->cur_ext_ignore);
rec = MAIL_INDEX_REC_AT_SEQ(view->map, seq);
old_data = PTR_OFFSET(rec, ext->record_offset);
- rext = array_idx(&view->index->extensions, ext->index_idx);
-
- /* call sync handlers only when its registered type matches with
- current synchronization type (index/view) */
- if ((rext->sync_handler.type & ctx->type) != 0) {
- void **extra_context =
- array_idx_modifiable(&ctx->extra_contexts,
- ext->index_idx);
- ret = rext->sync_handler.callback(ctx, seq, old_data, u + 1,
- extra_context);
- if (ret <= 0)
- return ret;
- }
-
/* @UNSAFE */
memcpy(old_data, u + 1, ctx->cur_ext_record_size);
if (ctx->cur_ext_record_size < ext->record_size) {
rext->expunge_handler = NULL;
}
-void mail_index_register_sync_handler(struct mail_index *index, uint32_t ext_id,
- mail_index_sync_handler_t *cb,
- enum mail_index_sync_handler_type type)
-{
- struct mail_index_registered_ext *rext;
-
- rext = array_idx_modifiable(&index->extensions, ext_id);
- i_assert(rext->sync_handler.callback == NULL);
-
- rext->sync_handler.callback = cb;
- rext->sync_handler.type = type;
-}
-
-void mail_index_unregister_sync_handler(struct mail_index *index,
- uint32_t ext_id)
-{
- struct mail_index_registered_ext *rext;
-
- rext = array_idx_modifiable(&index->extensions, ext_id);
- i_assert(rext->sync_handler.callback != NULL);
-
- rext->sync_handler.callback = NULL;
- rext->sync_handler.type = 0;
-}
-
void mail_index_register_sync_lost_handler(struct mail_index *index,
mail_index_sync_lost_handler_t *cb)
{