Skip to content

Commit

Permalink
lib-index: Remove extension record sync handlers
Browse files Browse the repository at this point in the history
This is no longer used by anything, and it makes the fix in the following
commit much easier.

This was originally added in 6a19e10 to
allow dovecot.index.cache updating to hook into updating cache offsets to
link cache records together. This was reimplemented in a different way in
131b073
  • Loading branch information
sirainen committed Apr 30, 2018
1 parent 1540fdd commit 0aaf09c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 75 deletions.
14 changes: 0 additions & 14 deletions src/lib-index/mail-index-private.h
Expand Up @@ -45,9 +45,6 @@ struct mail_index_sync_map_ctx;
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) \
Expand Down Expand Up @@ -93,19 +90,13 @@ enum mail_index_sync_handler_type {
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 */
uint32_t hdr_size; /* size of mail_index_ext_header.data[] */
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;
Expand Down Expand Up @@ -242,11 +233,6 @@ void mail_index_register_expunge_handler(struct mail_index *index,
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,
Expand Down
38 changes: 2 additions & 36 deletions src/lib-index/mail-index-sync-ext.c
Expand Up @@ -94,26 +94,8 @@ void mail_index_sync_init_handlers(struct mail_index_sync_map_ctx *ctx)

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 *
Expand Down Expand Up @@ -660,10 +642,8 @@ mail_index_sync_ext_rec_update(struct mail_index_sync_map_ctx *ctx,
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);
Expand All @@ -684,20 +664,6 @@ mail_index_sync_ext_rec_update(struct mail_index_sync_map_ctx *ctx,
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) {
Expand Down
25 changes: 0 additions & 25 deletions src/lib-index/mail-index.c
Expand Up @@ -315,31 +315,6 @@ void mail_index_unregister_expunge_handler(struct mail_index *index,
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)
{
Expand Down

0 comments on commit 0aaf09c

Please sign in to comment.