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

index a5d2b63136b82d5cca741046cb1e045007ea794a..5a63437b91be345d3f74007cfba953eb845037ec 100644 (file)
@@ -27,7 +27,7 @@ pop3c_mail_alloc(struct mailbox_transaction_context *t,
 static void pop3c_mail_close(struct mail *_mail)
 {
        struct pop3c_mail *pmail = (struct pop3c_mail *)_mail;
-       struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)_mail->box;
+       struct pop3c_mailbox *mbox = POP3C_MAILBOX(_mail->box);
 
        /* wait for any prefetch to finish before closing the mail */
        while (pmail->prefetching)
@@ -39,7 +39,7 @@ static void pop3c_mail_close(struct mail *_mail)
 
 static int pop3c_mail_get_received_date(struct mail *_mail, time_t *date_r)
 {
-       struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)_mail->box;
+       struct pop3c_mailbox *mbox = POP3C_MAILBOX(_mail->box);
        int tz;
 
        if (mbox->storage->set->pop3c_quick_received_date) {
@@ -70,7 +70,7 @@ static int pop3c_mail_get_save_date(struct mail *_mail, time_t *date_r)
 static int pop3c_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
 {
        struct index_mail *mail = (struct index_mail *)_mail;
-       struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)_mail->box;
+       struct pop3c_mailbox *mbox = POP3C_MAILBOX(_mail->box);
        struct message_size hdr_size, body_size;
        struct istream *input;
 
@@ -141,7 +141,7 @@ pop3c_mail_prefetch_done(enum pop3c_command_state state,
 static bool pop3c_mail_prefetch(struct mail *_mail)
 {
        struct pop3c_mail *pmail = (struct pop3c_mail *)_mail;
-       struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)_mail->box;
+       struct pop3c_mailbox *mbox = POP3C_MAILBOX(_mail->box);
        enum pop3c_capability capa;
        const char *cmd;
 
@@ -172,7 +172,7 @@ pop3c_mail_get_stream(struct mail *_mail, bool get_body,
 {
        struct pop3c_mail *pmail = (struct pop3c_mail *)_mail;
        struct index_mail *mail = &pmail->imail;
-       struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)_mail->box;
+       struct pop3c_mailbox *mbox = POP3C_MAILBOX(_mail->box);
        enum pop3c_capability capa;
        const char *name, *cmd, *error;
        struct istream *input;
@@ -245,7 +245,7 @@ static int
 pop3c_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
                       const char **value_r)
 {
-       struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)_mail->box;
+       struct pop3c_mailbox *mbox = POP3C_MAILBOX(_mail->box);
 
        switch (field) {
        case MAIL_FETCH_UIDL_BACKEND:
index 87be0818600c8bfb5b1e809e09f3b0ee4522ca61..255b511e0882b0abff85c6612652ec13ee4bf63b 100644 (file)
@@ -33,7 +33,7 @@ pop3c_storage_create(struct mail_storage *_storage,
                     struct mail_namespace *ns,
                     const char **error_r)
 {
-       struct pop3c_storage *storage = (struct pop3c_storage *)_storage;
+       struct pop3c_storage *storage = POP3C_STORAGE(_storage);
 
        storage->set = mail_namespace_get_driver_settings(ns, _storage);
        if (storage->set->pop3c_host[0] == '\0') {
@@ -116,7 +116,7 @@ pop3c_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
        mbox->box.storage = storage;
        mbox->box.list = list;
        mbox->box.mail_vfuncs = &pop3c_mail_vfuncs;
-       mbox->storage = (struct pop3c_storage *)storage;
+       mbox->storage = POP3C_STORAGE(storage);
 
        index_storage_mailbox_alloc(&mbox->box, vname, flags, MAIL_INDEX_PREFIX);
        return &mbox->box;
@@ -161,7 +161,7 @@ static void pop3c_login_callback(enum pop3c_command_state state,
 
 static int pop3c_mailbox_open(struct mailbox *box)
 {
-       struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)box;
+       struct pop3c_mailbox *mbox = POP3C_MAILBOX(box);
 
        if (strcmp(box->name, "INBOX") != 0) {
                mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
@@ -181,7 +181,7 @@ static int pop3c_mailbox_open(struct mailbox *box)
 
 static void pop3c_mailbox_close(struct mailbox *box)
 {
-       struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)box;
+       struct pop3c_mailbox *mbox = POP3C_MAILBOX(box);
 
        if (mbox->uidl_pool != NULL)
                pool_unref(&mbox->uidl_pool);
@@ -218,7 +218,7 @@ static int pop3c_mailbox_get_status(struct mailbox *box,
                                    enum mailbox_status_items items,
                                    struct mailbox_status *status_r)
 {
-       struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)box;
+       struct pop3c_mailbox *mbox = POP3C_MAILBOX(box);
 
        if (index_storage_get_status(box, items, status_r) < 0)
                return -1;
@@ -288,7 +288,7 @@ pop3c_save_cancel(struct mail_save_context *ctx)
 
 static bool pop3c_storage_is_inconsistent(struct mailbox *box)
 {
-       struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)box;
+       struct pop3c_mailbox *mbox = POP3C_MAILBOX(box);
 
        return index_storage_is_inconsistent(box) ||
                !pop3c_client_is_connected(mbox->client);
index 0cb3657fc4ed35888319d1ad0ad5070d1f2532bb..33d07d1ce8eb71b0d83a7d38d6a40ae39ecba9e7 100644 (file)
@@ -37,6 +37,9 @@ struct pop3c_mail {
        bool prefetching_body:1;
 };
 
+#define POP3C_STORAGE(s)       container_of(s, struct pop3c_storage, storage)
+#define POP3C_MAILBOX(s)       container_of(s, struct pop3c_mailbox, box)
+
 struct mail *
 pop3c_mail_alloc(struct mailbox_transaction_context *t,
                 enum mail_fetch_field wanted_fields,
index 1bb996735770650f1fb7c803071b59993083bb2a..edfe91fc6a2a5a8118bf304e4d46950e6a58f1ce 100644 (file)
@@ -350,7 +350,7 @@ int pop3c_sync(struct pop3c_mailbox *mbox)
 struct mailbox_sync_context *
 pop3c_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
 {
-       struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)box;
+       struct pop3c_mailbox *mbox = POP3C_MAILBOX(box);
        int ret = 0;
 
        if ((flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0 &&