]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: convert cydir to use container_of
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Mon, 28 Aug 2017 08:52:52 +0000 (11:52 +0300)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Thu, 7 Sep 2017 07:43:55 +0000 (10:43 +0300)
src/lib-storage/index/cydir/cydir-save.c
src/lib-storage/index/cydir/cydir-storage.c
src/lib-storage/index/cydir/cydir-storage.h
src/lib-storage/index/cydir/cydir-sync.c

index cf20b27140712ffd779b20161d7c8e9864ed1486..86693485631d75806ece2a18fc0cf6f08b57a3e2 100644 (file)
@@ -34,6 +34,8 @@ struct cydir_save_context {
        bool finished:1;
 };
 
+#define CYDIR_SAVECTX(s)       container_of(s, struct cydir_save_context, ctx)
+
 static char *cydir_generate_tmp_filename(void)
 {
        static unsigned int create_count = 0;
@@ -56,7 +58,7 @@ cydir_get_save_path(struct cydir_save_context *ctx, unsigned int num)
 struct mail_save_context *
 cydir_save_alloc(struct mailbox_transaction_context *t)
 {
-       struct cydir_mailbox *mbox = (struct cydir_mailbox *)t->box;
+       struct cydir_mailbox *mbox = CYDIR_MAILBOX(t->box);
        struct cydir_save_context *ctx;
 
        i_assert((t->flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
@@ -125,7 +127,7 @@ int cydir_save_begin(struct mail_save_context *_ctx, struct istream *input)
 
 int cydir_save_continue(struct mail_save_context *_ctx)
 {
-       struct cydir_save_context *ctx = (struct cydir_save_context *)_ctx;
+       struct cydir_save_context *ctx = CYDIR_SAVECTX(_ctx);
 
        if (ctx->failed)
                return -1;
@@ -190,7 +192,7 @@ static int cydir_save_flush(struct cydir_save_context *ctx, const char *path)
 
 int cydir_save_finish(struct mail_save_context *_ctx)
 {
-       struct cydir_save_context *ctx = (struct cydir_save_context *)_ctx;
+       struct cydir_save_context *ctx = CYDIR_SAVECTX(_ctx);
        const char *path = cydir_get_save_path(ctx, ctx->mail_count);
 
        ctx->finished = TRUE;
@@ -216,7 +218,7 @@ int cydir_save_finish(struct mail_save_context *_ctx)
 
 void cydir_save_cancel(struct mail_save_context *_ctx)
 {
-       struct cydir_save_context *ctx = (struct cydir_save_context *)_ctx;
+       struct cydir_save_context *ctx = CYDIR_SAVECTX(_ctx);
 
        ctx->failed = TRUE;
        (void)cydir_save_finish(_ctx);
@@ -224,7 +226,7 @@ void cydir_save_cancel(struct mail_save_context *_ctx)
 
 int cydir_transaction_save_commit_pre(struct mail_save_context *_ctx)
 {
-       struct cydir_save_context *ctx = (struct cydir_save_context *)_ctx;
+       struct cydir_save_context *ctx = CYDIR_SAVECTX(_ctx);
        struct mailbox_transaction_context *_t = _ctx->transaction;
        const struct mail_index_header *hdr;
        struct seq_range_iter iter;
@@ -280,7 +282,7 @@ int cydir_transaction_save_commit_pre(struct mail_save_context *_ctx)
 void cydir_transaction_save_commit_post(struct mail_save_context *_ctx,
                                        struct mail_index_transaction_commit_result *result)
 {
-       struct cydir_save_context *ctx = (struct cydir_save_context *)_ctx;
+       struct cydir_save_context *ctx = CYDIR_SAVECTX(_ctx);
 
        _ctx->transaction = NULL; /* transaction is already freed */
 
@@ -293,7 +295,7 @@ void cydir_transaction_save_commit_post(struct mail_save_context *_ctx,
 
 void cydir_transaction_save_rollback(struct mail_save_context *_ctx)
 {
-       struct cydir_save_context *ctx = (struct cydir_save_context *)_ctx;
+       struct cydir_save_context *ctx = CYDIR_SAVECTX(_ctx);
 
        if (!ctx->finished)
                cydir_save_cancel(&ctx->ctx);
index ace0b97f2d407df76de1965b04bbbcba91e5b331..eec578abb5f4472590ddaa6f775a0e47991d13ba 100644 (file)
@@ -54,7 +54,7 @@ cydir_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
 
        index_storage_mailbox_alloc(&mbox->box, vname, flags, MAIL_INDEX_PREFIX);
 
-       mbox->storage = (struct cydir_storage *)storage;
+       mbox->storage = CYDIR_STORAGE(storage);
        return &mbox->box;
 }
 
index bc5643e4f82d096a2daee55dfc885bc7f565a391..6040f8d9955ada9a0fb118a4b7386558f55aad63 100644 (file)
@@ -15,6 +15,9 @@ struct cydir_mailbox {
        struct cydir_storage *storage;
 };
 
+#define CYDIR_STORAGE(s)       container_of(s, struct cydir_storage, storage)
+#define CYDIR_MAILBOX(s)       container_of(s, struct cydir_mailbox, box)
+
 extern struct mail_vfuncs cydir_mail_vfuncs;
 
 struct mail_save_context *
index 200601f167e1882aefeb5f536782204413b78267..6529be1e3ff6876e70b14f26d645b8941622f334 100644 (file)
@@ -163,7 +163,7 @@ static int cydir_sync(struct cydir_mailbox *mbox)
 struct mailbox_sync_context *
 cydir_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
 {
-       struct cydir_mailbox *mbox = (struct cydir_mailbox *)box;
+       struct cydir_mailbox *mbox = CYDIR_MAILBOX(box);
        int ret = 0;
 
        if (index_mailbox_want_full_sync(&mbox->box, flags))