]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Change storage-specific settings to regular settings roots (1/3)
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Sun, 27 Feb 2022 21:08:31 +0000 (22:08 +0100)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 30 Nov 2022 12:49:09 +0000 (14:49 +0200)
This removes the need to have support for "dynamic settings".

This unfortunately also breaks Dovecot for the next two commits. The commits
are large enough that it doesn't make sense to squash them, and trying to
get them to work in the intermediate commits seems to be too much effort.

src/lib-storage/mail-storage-service.c
src/lib-storage/mail-storage-service.h
src/lib-storage/mail-storage-settings.c

index 661015a13c57bd43a8d61ce1cb9d49105467a0a5..c2e5179af20abb10456903dfa1284859a5a9780d 100644 (file)
@@ -23,6 +23,7 @@
 #include "mail-user.h"
 #include "mail-namespace.h"
 #include "mail-storage.h"
+#include "mail-storage-private.h"
 #include "mail-storage-service.h"
 
 #include <sys/stat.h>
@@ -976,9 +977,11 @@ mail_storage_service_init(struct master_service *service,
                count = 0;
        else
                for (count = 0; set_roots[count] != NULL; count++) ;
-       p_array_init(&ctx->set_roots, pool, count + 1);
+       p_array_init(&ctx->set_roots, pool, count + 16);
        const struct setting_parser_info *info = &mail_user_setting_parser_info;
        array_push_back(&ctx->set_roots, &info);
+       info = &mail_storage_setting_parser_info;
+       array_push_back(&ctx->set_roots, &info);
        array_append(&ctx->set_roots, set_roots, count);
 
        /* note: we may not have read any settings yet, so this logging
@@ -1029,9 +1032,35 @@ mail_storage_service_get_set_roots(struct mail_storage_service_ctx *ctx)
        return array_front(&ctx->set_roots);
 }
 
+static void
+mail_storage_service_add_set_info(struct mail_storage_service_ctx *ctx,
+                                 const struct setting_parser_info *info)
+{
+       const struct setting_parser_info *old_info;
+
+       array_foreach_elem(&ctx->set_roots, old_info) {
+               if (old_info == info)
+                       return;
+       }
+       array_push_back(&ctx->set_roots, &info);
+}
+
+static void
+mail_storage_service_add_storage_set_roots(struct mail_storage_service_ctx *ctx)
+{
+       struct mail_storage *storage;
+
+       array_foreach_elem(&mail_storage_classes, storage) {
+               if (storage->v.get_setting_parser_info != NULL) {
+                       mail_storage_service_add_set_info(ctx,
+                               storage->v.get_setting_parser_info());
+               }
+       }
+}
+
 int mail_storage_service_read_settings(struct mail_storage_service_ctx *ctx,
                                       const struct mail_storage_service_input *input,
-                                      pool_t pool,
+                                      pool_t pool ATTR_UNUSED,
                                       const struct setting_parser_info **user_info_r,
                                       const struct setting_parser_context **parser_r,
                                       const char **error_r)
@@ -1039,7 +1068,6 @@ int mail_storage_service_read_settings(struct mail_storage_service_ctx *ctx,
        struct master_service_settings_input set_input;
        const struct setting_parser_info *const *roots;
        struct master_service_settings_output set_output;
-       const struct dynamic_settings_parser *dyn_parsers;
        enum mail_storage_service_flags flags;
        unsigned int i;
 
@@ -1048,6 +1076,7 @@ int mail_storage_service_read_settings(struct mail_storage_service_ctx *ctx,
        flags = input == NULL ? ctx->flags :
                mail_storage_service_input_get_flags(ctx, input);
 
+       mail_storage_service_add_storage_set_roots(ctx);
        i_zero(&set_input);
        set_input.roots = mail_storage_service_get_set_roots(ctx);
        set_input.preserve_user = TRUE;
@@ -1081,19 +1110,17 @@ int mail_storage_service_read_settings(struct mail_storage_service_ctx *ctx,
                set_input.never_exec = TRUE;
        }
 
-       dyn_parsers = mail_storage_get_dynamic_parsers(pool);
        if (null_strcmp(set_input.module, ctx->set_cache_module) == 0 &&
            null_strcmp(set_input.service, ctx->set_cache_service) == 0 &&
            ctx->set_cache != NULL) {
                if (master_service_settings_cache_read(ctx->set_cache,
-                                                      &set_input, dyn_parsers,
+                                                      &set_input, NULL,
                                                       parser_r, error_r) < 0) {
                        *error_r = t_strdup_printf(
                                "Error reading configuration: %s", *error_r);
                        return -1;
                }
        } else {
-               settings_parser_dyn_update(pool, &set_input.roots, dyn_parsers);
                if (master_service_settings_read(ctx->service, &set_input,
                                                 &set_output, error_r) < 0) {
                        *error_r = t_strdup_printf(
index 80c57aca95d1cef8618bd788ab1ce208456334bc..61c995f6ef183794a3ca736c052e4d9b93bf2a83 100644 (file)
@@ -169,6 +169,9 @@ pool_t mail_storage_service_user_get_pool(struct mail_storage_service_user *user
 const char *
 mail_storage_service_user_get_log_prefix(struct mail_storage_service_user *user);
 
+/* Return all service settings roots. This includes the roots given to
+   mail_storage_service_init() as well as all dynamically created
+   mail_storage_classes. */
 const struct setting_parser_info *const *
 mail_storage_service_get_set_roots(struct mail_storage_service_ctx *ctx);
 const char *
index 131c5adaf46c4c9842d7d23d87203383a387a039..6a4c9d10690ae6c5fcd15c7a6c555c24baa7a5d8 100644 (file)
@@ -349,19 +349,12 @@ const struct setting_parser_info mail_user_setting_parser_info = {
 };
 
 const void *
-mail_user_set_get_driver_settings(const struct setting_parser_context *set_parser ATTR_UNUSED,
-                                 const struct setting_parser_info *base_info,
-                                 const struct mail_user_settings *set,
+mail_user_set_get_driver_settings(const struct setting_parser_context *set_parser,
+                                 const struct setting_parser_info *base_info ATTR_UNUSED,
+                                 const struct mail_user_settings *set ATTR_UNUSED,
                                  const struct setting_parser_info *info)
 {
-       const void *dset;
-
-       dset = settings_find_dynamic_by_info(base_info, set, info);
-       if (dset == NULL) {
-               i_panic("Default settings not found for storage driver %s",
-                       info->module_name);
-       }
-       return dset;
+       return settings_parser_get_root_set(set_parser, info);
 }
 
 const struct mail_storage_settings *