]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: clean up mailbox_list_create to improve readability
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Wed, 12 Oct 2016 18:57:51 +0000 (14:57 -0400)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 19 Oct 2016 17:23:31 +0000 (20:23 +0300)
There is no reason to use mailbox_list_driver_find() here instead of
mailbox_list_find_class() as (1) we do not need the index into the list
driver array, and (2) dealing with double-pointers is harder than regular
pointers.

src/lib-storage/mailbox-list.c

index 3ada2ef5493608d71bedb7f917741e4ea290774b..4d3fe2343beed316accb25f0fd2daff68e55a6d0 100644 (file)
@@ -107,9 +107,8 @@ int mailbox_list_create(const char *driver, struct mail_namespace *ns,
                        enum mailbox_list_flags flags,
                        struct mailbox_list **list_r, const char **error_r)
 {
-       const struct mailbox_list *const *class_p;
+       const struct mailbox_list *class;
        struct mailbox_list *list;
-       unsigned int idx;
 
        i_assert(ns->list == NULL ||
                 (flags & MAILBOX_LIST_FLAG_SECONDARY) != 0);
@@ -117,27 +116,26 @@ int mailbox_list_create(const char *driver, struct mail_namespace *ns,
        i_assert(set->subscription_fname == NULL ||
                 *set->subscription_fname != '\0');
 
-       if (!mailbox_list_driver_find(driver, &idx)) {
+       if ((class = mailbox_list_find_class(driver)) == NULL) {
                *error_r = "Unknown driver name";
                return -1;
        }
 
-       class_p = array_idx(&mailbox_list_drivers, idx);
-       if (((*class_p)->props & MAILBOX_LIST_PROP_NO_MAILDIR_NAME) != 0 &&
+       if ((class->props & MAILBOX_LIST_PROP_NO_MAILDIR_NAME) != 0 &&
            *set->maildir_name != '\0') {
                *error_r = "maildir_name not supported by this driver";
                return -1;
        }
-       if (((*class_p)->props & MAILBOX_LIST_PROP_NO_ALT_DIR) != 0 &&
+       if ((class->props & MAILBOX_LIST_PROP_NO_ALT_DIR) != 0 &&
            set->alt_dir != NULL) {
                *error_r = "alt_dir not supported by this driver";
                return -1;
        }
 
        i_assert(set->root_dir == NULL || *set->root_dir != '\0' ||
-                ((*class_p)->props & MAILBOX_LIST_PROP_NO_ROOT) != 0);
+                (class->props & MAILBOX_LIST_PROP_NO_ROOT) != 0);
 
-       list = (*class_p)->v.alloc();
+       list = class->v.alloc();
        array_create(&list->module_contexts, list->pool, sizeof(void *), 5);
 
        list->ns = ns;