]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: convert dbox-common to use container_of
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Fri, 1 Sep 2017 12:06:54 +0000 (15:06 +0300)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Thu, 7 Sep 2017 07:43:55 +0000 (10:43 +0300)
12 files changed:
src/lib-storage/index/dbox-common/dbox-mail.c
src/lib-storage/index/dbox-common/dbox-mail.h
src/lib-storage/index/dbox-common/dbox-save.c
src/lib-storage/index/dbox-common/dbox-save.h
src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/index/dbox-common/dbox-storage.h
src/lib-storage/index/dbox-multi/mdbox-mail.c
src/lib-storage/index/dbox-multi/mdbox-save.c
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

index 28e740c1e9bed8445cbebd2fdbfa23a591bd24a6..b10e64796e9d70620c5eeb42d814839176a40d15 100644 (file)
@@ -30,7 +30,7 @@ dbox_mail_alloc(struct mailbox_transaction_context *t,
 
 void dbox_mail_close(struct mail *_mail)
 {
-       struct dbox_mail *mail = (struct dbox_mail *)_mail;
+       struct dbox_mail *mail = DBOX_MAIL(_mail);
 
        index_mail_close(_mail);
        /* close the dbox file only after index is closed, since it may still
@@ -42,7 +42,7 @@ void dbox_mail_close(struct mail *_mail)
 int dbox_mail_metadata_read(struct dbox_mail *mail, struct dbox_file **file_r)
 {
        struct dbox_storage *storage =
-               (struct dbox_storage *)mail->imail.mail.mail.box->storage;
+               DBOX_STORAGE(mail->imail.mail.mail.box->storage);
        uoff_t offset;
 
        if (storage->v.mail_open(mail, &offset, file_r) < 0)
@@ -76,7 +76,7 @@ dbox_mail_metadata_get(struct dbox_mail *mail, enum dbox_metadata_key key,
 
 int dbox_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
 {
-       struct dbox_mail *mail = (struct dbox_mail *)_mail;
+       struct dbox_mail *mail = DBOX_MAIL(_mail);
        struct index_mail_data *data = &mail->imail.data;
        struct dbox_file *file;
 
@@ -93,7 +93,7 @@ int dbox_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
 
 int dbox_mail_get_virtual_size(struct mail *_mail, uoff_t *size_r)
 {
-       struct dbox_mail *mail = (struct dbox_mail *)_mail;
+       struct dbox_mail *mail = DBOX_MAIL(_mail);
        struct index_mail_data *data = &mail->imail.data;
        const char *value;
        uintmax_t size;
@@ -116,7 +116,7 @@ int dbox_mail_get_virtual_size(struct mail *_mail, uoff_t *size_r)
 
 int dbox_mail_get_received_date(struct mail *_mail, time_t *date_r)
 {
-       struct dbox_mail *mail = (struct dbox_mail *)_mail;
+       struct dbox_mail *mail = DBOX_MAIL(_mail);
        struct index_mail_data *data = &mail->imail.data;
        const char *value;
        uintmax_t time;
@@ -139,9 +139,8 @@ int dbox_mail_get_received_date(struct mail *_mail, time_t *date_r)
 
 int dbox_mail_get_save_date(struct mail *_mail, time_t *date_r)
 {
-       struct dbox_storage *storage =
-               (struct dbox_storage *)_mail->box->storage;
-       struct dbox_mail *mail = (struct dbox_mail *)_mail;
+       struct dbox_storage *storage = DBOX_STORAGE(_mail->box->storage);
+       struct dbox_mail *mail = DBOX_MAIL(_mail);
        struct index_mail_data *data = &mail->imail.data;
        struct dbox_file *file;
        struct stat st;
@@ -223,7 +222,7 @@ dbox_get_cached_metadata(struct dbox_mail *mail, enum dbox_metadata_key key,
 int dbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
                          const char **value_r)
 {
-       struct dbox_mail *mail = (struct dbox_mail *)_mail;
+       struct dbox_mail *mail = DBOX_MAIL(_mail);
        int ret;
 
        /* keep the UIDL in cache file, otherwise POP3 would open all
@@ -290,9 +289,8 @@ int dbox_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED,
                         struct message_size *body_size,
                         struct istream **stream_r)
 {
-       struct dbox_storage *storage =
-               (struct dbox_storage *)_mail->box->storage;
-       struct dbox_mail *mail = (struct dbox_mail *)_mail;
+       struct dbox_storage *storage = DBOX_STORAGE(_mail->box->storage);
+       struct dbox_mail *mail = DBOX_MAIL(_mail);
        struct index_mail_data *data = &mail->imail.data;
        struct istream *input;
        uoff_t offset;
index 935d089f9e13a51e320e85a75f8dfed677aeece0..c03652cb040471d789e00cb43bfe08d80e35f01e 100644 (file)
@@ -10,6 +10,8 @@ struct dbox_mail {
        uoff_t offset;
 };
 
+#define DBOX_MAIL(s)   container_of(s, struct dbox_mail, imail.mail.mail)
+
 struct mail *
 dbox_mail_alloc(struct mailbox_transaction_context *t,
                enum mail_fetch_field wanted_fields,
index 548adb824f1216fefdb985065e64b4268ba34d26..633e2d48e6e781cb2a5e7c4bf4503f40603e240e 100644 (file)
@@ -39,7 +39,7 @@ void dbox_save_begin(struct dbox_save_context *ctx, struct istream *input)
 {
        struct mail_save_context *_ctx = &ctx->ctx;
        struct mail_storage *_storage = _ctx->transaction->box->storage;
-       struct dbox_storage *storage = (struct dbox_storage *)_storage;
+       struct dbox_storage *storage = DBOX_STORAGE(_storage);
        struct dbox_message_header dbox_msg_hdr;
        struct istream *crlf_input;
 
@@ -70,7 +70,7 @@ void dbox_save_begin(struct dbox_save_context *ctx, struct istream *input)
 
 int dbox_save_continue(struct mail_save_context *_ctx)
 {
-       struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
+       struct dbox_save_context *ctx = DBOX_SAVECTX(_ctx);
 
        if (ctx->failed)
                return -1;
@@ -120,7 +120,7 @@ void dbox_save_write_metadata(struct mail_save_context *_ctx,
                              const char *orig_mailbox_name,
                              guid_128_t guid_128)
 {
-       struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
+       struct dbox_save_context *ctx = DBOX_SAVECTX(_ctx);
        struct mail_save_data *mdata = &ctx->ctx.data;
        struct dbox_metadata_header metadata_hdr;
        const char *guid;
index 35818a0024be4f64c342b5928cf3317992c4d454..a17c923291fc7dccb2aa37cf4e729face3bf323e 100644 (file)
@@ -20,6 +20,8 @@ struct dbox_save_context {
        bool have_pop3_orders:1;
 };
 
+#define DBOX_SAVECTX(s)                container_of(s, struct dbox_save_context, ctx)
+
 void dbox_save_begin(struct dbox_save_context *ctx, struct istream *input);
 int dbox_save_continue(struct mail_save_context *_ctx);
 void dbox_save_end(struct dbox_save_context *ctx);
index d83f4e24bddab275f12c354542cf4983f0fcf477..6eff972a0a899c4c51ddcec7d9e55c343d9ff355 100644 (file)
@@ -91,7 +91,7 @@ int dbox_storage_create(struct mail_storage *_storage,
                        struct mail_namespace *ns,
                        const char **error_r)
 {
-       struct dbox_storage *storage = (struct dbox_storage *)_storage;
+       struct dbox_storage *storage = DBOX_STORAGE(_storage);
        const struct mail_storage_settings *set = _storage->set;
        const char *error;
 
@@ -134,7 +134,7 @@ int dbox_storage_create(struct mail_storage *_storage,
 
 void dbox_storage_destroy(struct mail_storage *_storage)
 {
-       struct dbox_storage *storage = (struct dbox_storage *)_storage;
+       struct dbox_storage *storage = DBOX_STORAGE(_storage);
 
        if (storage->attachment_fs != NULL)
                fs_deinit(&storage->attachment_fs);
@@ -310,7 +310,7 @@ static int dir_is_empty(struct mail_storage *storage, const char *path)
 int dbox_mailbox_create(struct mailbox *box,
                        const struct mailbox_update *update, bool directory)
 {
-       struct dbox_storage *storage = (struct dbox_storage *)box->storage;
+       struct dbox_storage *storage = DBOX_STORAGE(box->storage);
        const char *alt_path;
        struct stat st;
        int ret;
@@ -349,7 +349,7 @@ int dbox_mailbox_create(struct mailbox *box,
 int dbox_mailbox_create_indexes(struct mailbox *box,
                                const struct mailbox_update *update)
 {
-       struct dbox_storage *storage = (struct dbox_storage *)box->storage;
+       struct dbox_storage *storage = DBOX_STORAGE(box->storage);
        struct mail_index_sync_ctx *sync_ctx;
        struct mail_index_view *view;
        struct mail_index_transaction *trans;
index 5bf408d86f1a31067844850fdadf6307bedc2b70..af085df6babf9e1aefc5a01518a6f593038d821c 100644 (file)
@@ -62,6 +62,8 @@ struct dbox_storage {
        const char *attachment_dir;
 };
 
+#define DBOX_STORAGE(s)                container_of(s, struct dbox_storage, storage)
+
 void dbox_storage_get_list_settings(const struct mail_namespace *ns,
                                    struct mailbox_list_settings *set);
 int dbox_storage_create(struct mail_storage *storage,
index 0078637b5edc2903079b890f6e1002613bdee64d..b44f660cd795bc990dd5683c0e1b9404e12596b7 100644 (file)
@@ -173,7 +173,7 @@ static int
 mdbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
                       const char **value_r)
 {
-       struct dbox_mail *mail = (struct dbox_mail *)_mail;
+       struct dbox_mail *mail = DBOX_MAIL(_mail);
        struct mdbox_mailbox *mbox =
                (struct mdbox_mailbox *)_mail->transaction->box;
        struct mdbox_map_mail_index_record rec;
index 86fdb7ec261b01606af9134889b1040c40656cf5..ddaf8bddcebf278dd85001f45d8131e4416c50b6 100644 (file)
@@ -235,7 +235,7 @@ int mdbox_save_finish(struct mail_save_context *ctx)
 
 void mdbox_save_cancel(struct mail_save_context *_ctx)
 {
-       struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
+       struct dbox_save_context *ctx = DBOX_SAVECTX(_ctx);
 
        ctx->failed = TRUE;
        (void)mdbox_save_finish(_ctx);
index e03a0a868d336dc870103573ce50511730239054..4362f228dd5cdaa5c54d75427eb15d4c420c58c6 100644 (file)
@@ -92,7 +92,7 @@ sdbox_file_copy_attachments(struct sdbox_file *src_file,
 static int
 sdbox_copy_hardlink(struct mail_save_context *_ctx, struct mail *mail)
 {
-       struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
+       struct dbox_save_context *ctx = DBOX_SAVECTX(_ctx);
        struct sdbox_mailbox *dest_mbox =
                (struct sdbox_mailbox *)_ctx->transaction->box;
        struct sdbox_mailbox *src_mbox;
index 68344471f2735ee463bb5efcbb08a450f47cb9f7..535ea940fea48d443287530e62dea4503ccf5c1a 100644 (file)
@@ -65,7 +65,7 @@ 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 dbox_mail *mail = (struct dbox_mail *)_mail;
+       struct dbox_mail *mail = DBOX_MAIL(_mail);
        struct stat st;
 
        switch (field) {
index feb2fd28c12ee2774e5ffed8e81e14a964cafe4a..14311e25ea0852f8f54ceaf3ed61df2139b7fe49 100644 (file)
@@ -224,7 +224,7 @@ int sdbox_save_finish(struct mail_save_context *ctx)
 
 void sdbox_save_cancel(struct mail_save_context *_ctx)
 {
-       struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
+       struct dbox_save_context *ctx = DBOX_SAVECTX(_ctx);
 
        ctx->failed = TRUE;
        (void)sdbox_save_finish(_ctx);
index 0d92d3f288f7c87c28369479631f5a60b12c69b5..3085d79ff743c1f6daabcdcecca294a19eaa3da7 100644 (file)
@@ -34,7 +34,7 @@ static int sdbox_storage_create(struct mail_storage *_storage,
                                struct mail_namespace *ns,
                                const char **error_r)
 {
-       struct dbox_storage *storage = (struct dbox_storage *)_storage;
+       struct dbox_storage *storage = DBOX_STORAGE(_storage);
        enum fs_properties props;
 
        if (dbox_storage_create(_storage, ns, error_r) < 0)