]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add and use mail_driver_settings
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 6 Mar 2025 17:47:39 +0000 (19:47 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Mar 2025 13:01:57 +0000 (13:01 +0000)
It only has mail_driver setting. This is much efficient to lookup than
the full large mail_storage_settings.

src/lib-storage/index/shared/shared-storage.c
src/lib-storage/mail-storage-settings.c
src/lib-storage/mail-storage-settings.h
src/lib-storage/mail-storage.c
src/lib-storage/mailbox-list.c

index 0e6b33f17a85fbbb5177818fc8ff2697c01e4218..e2bf3185612a1ee64712d9ef222b998d3b3630fc 100644 (file)
@@ -68,8 +68,8 @@ shared_storage_create(struct mail_storage *_storage, struct mail_namespace *ns,
        struct shared_storage *storage = SHARED_STORAGE(_storage);
        char *wildcardp;
 
-       struct mail_storage_settings *set;
-       if (settings_get(ns->list->event, &mail_storage_setting_parser_info, 0,
+       struct mail_driver_settings *set;
+       if (settings_get(ns->list->event, &mail_driver_setting_parser_info, 0,
                         &set, error_r) < 0)
                return -1;
 
index 666af31255644f30eaf588405b6a8e51bb120629..10bee08e3742bc4620444fc3f655662035ff31ac 100644 (file)
@@ -224,6 +224,29 @@ const struct setting_parser_info mail_storage_setting_parser_info = {
        .ext_check_func = mail_storage_settings_ext_check,
 };
 
+#undef DEF
+#define DEF(type, name) \
+       SETTING_DEFINE_STRUCT_##type(#name, name, struct mail_driver_settings)
+
+static const struct setting_define mail_driver_setting_defines[] = {
+       DEF(STR, mail_driver),
+       SETTING_DEFINE_LIST_END
+};
+
+const struct mail_driver_settings mail_driver_default_settings = {
+       .mail_driver = "",
+};
+
+const struct setting_parser_info mail_driver_setting_parser_info = {
+       .name = "mail_driver",
+
+       .defines = mail_driver_setting_defines,
+       .defaults = &mail_driver_default_settings,
+
+       .struct_size = sizeof(struct mail_driver_settings),
+       .pool_offset1 = 1 + offsetof(struct mail_driver_settings, pool),
+};
+
 #undef DEF
 #define DEF(type, name) \
        SETTING_DEFINE_STRUCT_##type("mailbox_"#name, name, struct mailbox_settings)
index b212fdfbe53280748a1800b121d6b54b146ab5c5..0f3019997e5832a549043940bcfa4564985ebfc2 100644 (file)
@@ -16,6 +16,11 @@ struct smtp_address;
 struct setting_parser_context;
 struct settings_instance;
 
+struct mail_driver_settings {
+       pool_t pool;
+       const char *mail_driver;
+};
+
 struct mail_storage_settings {
        pool_t pool;
        const char *mail_driver;
@@ -187,6 +192,7 @@ struct mail_user_settings {
 
 extern const struct setting_parser_info mail_user_setting_parser_info;
 extern const struct setting_parser_info mail_namespace_setting_parser_info;
+extern const struct setting_parser_info mail_driver_setting_parser_info;
 extern const struct setting_parser_info mail_storage_setting_parser_info;
 extern const struct setting_parser_info mailbox_setting_parser_info;
 extern const struct mail_namespace_settings mail_namespace_default_settings;
index 4dd48f7282bee2eb9e1074de8478bf8203fa9d97..8127c627433a4a2368a509aef65e502293e80516 100644 (file)
@@ -159,7 +159,7 @@ mail_storage_autodetect(const struct mail_namespace *ns,
 
 static struct mail_storage *
 mail_storage_get_class(struct mail_namespace *ns, const char *driver,
-                      const struct mail_storage_settings *mail_set,
+                      struct event *set_event,
                       const char **root_path_override,
                       const char **inbox_path_override, const char **error_r)
 {
@@ -182,11 +182,17 @@ mail_storage_get_class(struct mail_namespace *ns, const char *driver,
        if (storage_class != NULL)
                return storage_class;
 
-       storage_class = mail_storage_autodetect(ns, mail_set,
-                                               root_path_override,
+       const struct mail_storage_settings *mail_set;
+       if (settings_get(set_event, &mail_storage_setting_parser_info, 0,
+                        &mail_set, error_r) < 0)
+               return NULL;
+
+       storage_class = mail_storage_autodetect(ns, mail_set, root_path_override,
                                                inbox_path_override);
-       if (storage_class != NULL)
+       if (storage_class != NULL) {
+               settings_free(mail_set);
                return storage_class;
+       }
 
        (void)mail_user_get_home(ns->user, &home);
        if (home == NULL || *home == '\0') home = "(not set)";
@@ -195,6 +201,7 @@ mail_storage_get_class(struct mail_namespace *ns, const char *driver,
                "Mail storage autodetection failed (home=%s, mail_path=%s) - "
                "Set mail_driver explicitly",
                home, mail_set->mail_path);
+       settings_free(mail_set);
        return NULL;
 }
 
@@ -438,7 +445,7 @@ mail_storage_create_real(struct mail_namespace *ns, struct event *set_event,
                         struct mail_storage **storage_r, const char **error_r)
 {
        struct mail_storage *storage_class, *storage = NULL;
-       const struct mail_storage_settings *mail_set;
+       const struct mail_driver_settings *driver_set;
        const char *driver = NULL;
        const char *inbox_path_override = NULL;
        const char *root_path_override = NULL;
@@ -446,10 +453,10 @@ mail_storage_create_real(struct mail_namespace *ns, struct event *set_event,
        /* Lookup initial mailbox list settings. Once they're found, another
           settings lookup is done with mailbox format as an additional
           filter. */
-       if (settings_get(set_event, &mail_storage_setting_parser_info, 0,
-                        &mail_set, error_r) < 0)
+       if (settings_get(set_event, &mail_driver_setting_parser_info, 0,
+                        &driver_set, error_r) < 0)
                return -1;
-       driver = mail_set->mail_driver;
+       driver = driver_set->mail_driver;
 
        if ((flags & MAIL_STORAGE_FLAG_SHARED_DYNAMIC) != 0) {
                /* internal shared namespace */
@@ -457,10 +464,10 @@ mail_storage_create_real(struct mail_namespace *ns, struct event *set_event,
                root_path_override = ns->user->set->base_dir;
        }
 
-       storage_class = mail_storage_get_class(ns, driver, mail_set,
+       storage_class = mail_storage_get_class(ns, driver, set_event,
                                               &root_path_override,
                                               &inbox_path_override, error_r);
-       settings_free(mail_set);
+       settings_free(driver_set);
        if (storage_class == NULL)
                return -1;
 
index 8f6b97a714629335a5a59312e36323c62e5aa688..fb120096b8758be13c5ecdad353872ab478f7188 100644 (file)
@@ -617,11 +617,11 @@ int mailbox_list_default_get_storage(struct mailbox_list **list,
                                     enum mailbox_list_get_storage_flags flags ATTR_UNUSED,
                                     struct mail_storage **storage_r)
 {
-       const struct mail_storage_settings *set;
+       const struct mail_driver_settings *set;
        const char *error;
        struct event *event =
                mail_storage_mailbox_create_event((*list)->event, *list, *vname);
-       if (settings_get(event, &mail_storage_setting_parser_info, 0,
+       if (settings_get(event, &mail_driver_setting_parser_info, 0,
                         &set, &error) < 0) {
                mailbox_list_set_critical(*list, "%s", error);
                event_unref(&event);