]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: convert dbox-single to use container_of
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Fri, 1 Sep 2017 12:09:00 +0000 (15:09 +0300)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Thu, 7 Sep 2017 07:43:55 +0000 (10:43 +0300)
src/lib-storage/index/dbox-single/sdbox-copy.c
src/lib-storage/index/dbox-single/sdbox-mail.c
src/lib-storage/index/dbox-single/sdbox-save.c
src/lib-storage/index/dbox-single/sdbox-storage.c
src/lib-storage/index/dbox-single/sdbox-storage.h
src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c
src/lib-storage/index/dbox-single/sdbox-sync.c

index 4362f228dd5cdaa5c54d75427eb15d4c420c58c6..f21358ed3943b0528f5d2cc7dbcd3a7ebcf887a9 100644 (file)
@@ -93,15 +93,14 @@ static int
 sdbox_copy_hardlink(struct mail_save_context *_ctx, struct mail *mail)
 {
        struct dbox_save_context *ctx = DBOX_SAVECTX(_ctx);
-       struct sdbox_mailbox *dest_mbox =
-               (struct sdbox_mailbox *)_ctx->transaction->box;
+       struct sdbox_mailbox *dest_mbox = SDBOX_MAILBOX(_ctx->transaction->box);
        struct sdbox_mailbox *src_mbox;
        struct dbox_file *src_file, *dest_file;
        const char *src_path, *dest_path;
        int ret;
 
        if (strcmp(mail->box->storage->name, SDBOX_STORAGE_NAME) == 0)
-               src_mbox = (struct sdbox_mailbox *)mail->box;
+               src_mbox = SDBOX_MAILBOX(mail->box);
        else {
                /* Source storage isn't sdbox, can't hard link */
                return 0;
index 535ea940fea48d443287530e62dea4503ccf5c1a..7702d80ff769ceb43d430b87c96551fcd782e46c 100644 (file)
@@ -30,7 +30,7 @@ static void sdbox_mail_set_expunged(struct dbox_mail *mail)
 static int sdbox_mail_file_set(struct dbox_mail *mail)
 {
        struct mail *_mail = &mail->imail.mail.mail;
-       struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)_mail->box;
+       struct sdbox_mailbox *mbox = SDBOX_MAILBOX(_mail->box);
        bool deleted;
        int ret;
 
@@ -64,7 +64,7 @@ static int
 sdbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
                       const char **value_r)
 {
-       struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)_mail->box;
+       struct sdbox_mailbox *mbox = SDBOX_MAILBOX(_mail->box);
        struct dbox_mail *mail = DBOX_MAIL(_mail);
        struct stat st;
 
index 14311e25ea0852f8f54ceaf3ed61df2139b7fe49..4a3333650bdd5cfa05b9061c027c2944a9229793 100644 (file)
@@ -33,11 +33,12 @@ struct sdbox_save_context {
        ARRAY(struct dbox_file *) files;
 };
 
+#define SDBOX_SAVECTX(s)       container_of(DBOX_SAVECTX(s), struct sdbox_save_context, ctx)
+
 struct dbox_file *
 sdbox_save_file_get_file(struct mailbox_transaction_context *t, uint32_t seq)
 {
-       struct sdbox_save_context *ctx =
-               (struct sdbox_save_context *)t->save_ctx;
+       struct sdbox_save_context *ctx = SDBOX_SAVECTX(t->save_ctx);
        struct dbox_file *const *files, *file;
        unsigned int count;
 
@@ -55,9 +56,8 @@ sdbox_save_file_get_file(struct mailbox_transaction_context *t, uint32_t seq)
 struct mail_save_context *
 sdbox_save_alloc(struct mailbox_transaction_context *t)
 {
-       struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)t->box;
-       struct sdbox_save_context *ctx =
-               (struct sdbox_save_context *)t->save_ctx;
+       struct sdbox_mailbox *mbox = SDBOX_MAILBOX(t->box);
+       struct sdbox_save_context *ctx = SDBOX_SAVECTX(t->save_ctx);
 
        i_assert((t->flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
 
@@ -81,7 +81,7 @@ sdbox_save_alloc(struct mailbox_transaction_context *t)
 
 void sdbox_save_add_file(struct mail_save_context *_ctx, struct dbox_file *file)
 {
-       struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
+       struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
        struct dbox_file *const *files;
        unsigned int count;
 
@@ -99,7 +99,7 @@ void sdbox_save_add_file(struct mail_save_context *_ctx, struct dbox_file *file)
 
 int sdbox_save_begin(struct mail_save_context *_ctx, struct istream *input)
 {
-       struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
+       struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
        struct dbox_file *file;
        int ret;
 
@@ -298,7 +298,7 @@ static void dbox_save_unref_files(struct sdbox_save_context *ctx)
 
 int sdbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
 {
-       struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
+       struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
        struct mailbox_transaction_context *_t = _ctx->transaction;
        const struct mail_index_header *hdr;
 
@@ -344,7 +344,7 @@ int sdbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
 void sdbox_transaction_save_commit_post(struct mail_save_context *_ctx,
                                        struct mail_index_transaction_commit_result *result)
 {
-       struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
+       struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
        struct mail_storage *storage = _ctx->transaction->box->storage;
 
        _ctx->transaction = NULL; /* transaction is already freed */
@@ -373,7 +373,7 @@ void sdbox_transaction_save_commit_post(struct mail_save_context *_ctx,
 
 void sdbox_transaction_save_rollback(struct mail_save_context *_ctx)
 {
-       struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
+       struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
 
        if (!ctx->ctx.finished)
                sdbox_save_cancel(_ctx);
index 3085d79ff743c1f6daabcdcecca294a19eaa3da7..57f43a9aab7bf3ff9f3d7eb681388b8285bd00d4 100644 (file)
@@ -134,7 +134,7 @@ sdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
        ibox->index_flags |= MAIL_INDEX_OPEN_FLAG_KEEP_BACKUPS |
                MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY;
 
-       mbox->storage = (struct sdbox_storage *)storage;
+       mbox->storage = SDBOX_STORAGE(storage);
        return &mbox->box;
 }
 
@@ -216,7 +216,7 @@ int sdbox_mailbox_create_indexes(struct mailbox *box,
                                 const struct mailbox_update *update,
                                 struct mail_index_transaction *trans)
 {
-       struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+       struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
        struct mail_index_transaction *new_trans = NULL;
        const struct mail_index_header *hdr;
        uint32_t uid_validity, uid_next;
@@ -291,7 +291,7 @@ sdbox_get_attachment_path_suffix(struct dbox_file *_file)
 
 void sdbox_set_mailbox_corrupted(struct mailbox *box)
 {
-       struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+       struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
        struct sdbox_index_header hdr;
        bool need_resize;
 
@@ -329,7 +329,7 @@ static int sdbox_mailbox_alloc_index(struct sdbox_mailbox *mbox)
 
 static int sdbox_mailbox_open(struct mailbox *box)
 {
-       struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+       struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
        struct sdbox_index_header hdr;
        bool need_resize;
        time_t path_ctime;
@@ -369,7 +369,7 @@ static int sdbox_mailbox_open(struct mailbox *box)
 
 static void sdbox_mailbox_close(struct mailbox *box)
 {
-       struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+       struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
 
        if (mbox->corrupted_rebuild_count != 0)
                (void)sdbox_sync(mbox, 0);
@@ -380,7 +380,7 @@ static int
 sdbox_mailbox_create(struct mailbox *box,
                     const struct mailbox_update *update, bool directory)
 {
-       struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+       struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
        struct sdbox_index_header hdr;
        bool need_resize;
 
@@ -407,7 +407,7 @@ sdbox_mailbox_get_metadata(struct mailbox *box,
                           enum mailbox_metadata_items items,
                           struct mailbox_metadata *metadata_r)
 {
-       struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+       struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
 
        if (index_mailbox_get_metadata(box, items, metadata_r) < 0)
                return -1;
index 8c0f7c5b7fe27aca7aea25efbb547f6187b54574..66d08daedc7e36b58ed55c100489326171b4b14a 100644 (file)
@@ -33,6 +33,9 @@ struct sdbox_mailbox {
        guid_128_t mailbox_guid;
 };
 
+#define SDBOX_STORAGE(s)       container_of(DBOX_STORAGE(s), struct sdbox_storage, storage)
+#define SDBOX_MAILBOX(s)       container_of(s, struct sdbox_mailbox, box)
+
 extern struct mail_vfuncs sdbox_mail_vfuncs;
 
 int sdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
index eb6281e65f1403be8373c336d3bdce57fc78cc57..317253136ccfff7b10f503d24f3bc039eee6775d 100644 (file)
@@ -68,7 +68,7 @@ static int
 sdbox_sync_add_file(struct index_rebuild_context *ctx,
                    const char *fname, bool primary)
 {
-       struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->box;
+       struct sdbox_mailbox *mbox = SDBOX_MAILBOX(ctx->box);
        struct dbox_file *file;
        uint32_t uid;
        int ret;
@@ -136,7 +136,7 @@ static int sdbox_sync_index_rebuild_dir(struct index_rebuild_context *ctx,
 
 static void sdbox_sync_update_header(struct index_rebuild_context *ctx)
 {
-       struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->box;
+       struct sdbox_mailbox *mbox = SDBOX_MAILBOX(ctx->box);
        struct sdbox_index_header hdr;
        bool need_resize;
 
index 58409bcaa4f7f37bb7ad9223ffee83decd42025c..ba6f9d2c70b44d8cb220ca94caabbdd039811f30 100644 (file)
@@ -309,7 +309,7 @@ int sdbox_sync(struct sdbox_mailbox *mbox, enum sdbox_sync_flags flags)
 struct mailbox_sync_context *
 sdbox_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
 {
-       struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+       struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
        enum sdbox_sync_flags sdbox_sync_flags = 0;
        int ret = 0;