]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Added support for dynamically loaded settings.
authorTimo Sirainen <tss@iki.fi>
Mon, 26 Oct 2009 17:47:27 +0000 (13:47 -0400)
committerTimo Sirainen <tss@iki.fi>
Mon, 26 Oct 2009 17:47:27 +0000 (13:47 -0400)
--HG--
branch : HEAD

src/config/all-settings.h
src/config/config-parser.c
src/config/config-parser.h
src/config/doveconf.c
src/config/main.c
src/config/settings-get.pl

index 4e5a1fe666f639c1d504815b37b1fb4b27d63b21..d954a8ebae2ba48c3288750e9aeeddef00f576e8 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef ALL_SETTINGS_H
 #define ALL_SETTINGS_H
 
-extern const struct setting_parser_info *all_roots[];
+extern const struct setting_parser_info *const *all_roots;
+extern const struct setting_parser_info *all_default_roots[];
 
 #endif
index 5221b1b7d53f69e864bf3286f8a1fa8a83fae41d..90b5ea580e4dde145541c04578bf58635189178d 100644 (file)
@@ -6,6 +6,7 @@
 #include "hash.h"
 #include "strescape.h"
 #include "istream.h"
+#include "module-dir.h"
 #include "settings-parser.h"
 #include "all-settings.h"
 #include "config-filter.h"
@@ -712,3 +713,32 @@ prevfile:
        }
        return 1;
 }
+
+void config_parse_load_modules(void)
+{
+       struct module *modules, *m;
+       const struct setting_parser_info **roots;
+       ARRAY_DEFINE(new_roots, const struct setting_parser_info *);
+       unsigned int i;
+
+       modules = module_dir_load(CONFIG_MODULE_DIR, NULL, FALSE, NULL);
+       module_dir_init(modules);
+
+       i_array_init(&new_roots, 64);
+       for (m = modules; m != NULL; m = m->next) {
+               roots = module_get_symbol(m,
+                       t_strdup_printf("%s_set_roots", m->name));
+               if (roots != NULL) {
+                       for (i = 0; roots[i] != NULL; i++)
+                               array_append(&new_roots, &roots[i], 1);
+               }
+       }
+       if (array_count(&new_roots) > 0) {
+               /* modules added new settings. add the defaults and start
+                  using the new list. */
+               for (i = 0; all_roots[i] != NULL; i++)
+                       array_append(&new_roots, &all_roots[i], 1);
+               (void)array_append_space(&new_roots);
+               all_roots = array_idx(&new_roots, 0);
+       }
+}
index 800c81d9d8d83d6eb7b4a562701eac2194e65224..e84a5ebef43d76d5b84636eae646482e82a46773 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef CONFIG_PARSER_H
 #define CONFIG_PARSER_H
 
+#define CONFIG_MODULE_DIR MODULEDIR"/settings"
+
 struct config_module_parser {
        const struct setting_parser_info *root;
        struct setting_parser_context *parser;
@@ -14,4 +16,6 @@ extern struct config_filter_context *config_filter;
 int config_parse_file(const char *path, bool expand_files,
                      const char **error_r);
 
+void config_parse_load_modules(void);
+
 #endif
index 113316a23a76363d3c7fe0f71e5f533357117374..4168fab7de492835905b22d41e661d5cbf1b386c 100644 (file)
@@ -270,6 +270,7 @@ int main(int argc, char *argv[])
                fflush(stdout);
        }
        master_service_init_finish(master_service);
+       config_parse_load_modules();
 
        if ((ret = config_parse_file(config_path, FALSE, &error)) == 0 &&
            access(EXAMPLE_CONFIG_DIR, X_OK) == 0) {
index 5cf61e28bed8e85414079fca2122ad5d8963a7ce..af86a103d3d55e4a48a7485e908940d6c3eb9d0e 100644 (file)
@@ -23,6 +23,7 @@ int main(int argc, char *argv[])
 
        master_service_init_log(master_service, "config: ");
        master_service_init_finish(master_service);
+       config_parse_load_modules();
 
        path = master_service_get_config_path(master_service);
        if (config_parse_file(path, TRUE, &error) <= 0)
index fbde76ce890943e5a7fdaf583b7b01d105799ba7..6f6f26ebb234ee4578026e60136800fcea4f7bfa 100755 (executable)
@@ -105,7 +105,7 @@ print "buffer_t config_all_services_buf = {\n";
 print "\tconfig_all_services, sizeof(config_all_services), { 0, }\n";
 print "};\n";
 
-print "const struct setting_parser_info *all_roots[] = {\n";
+print "const struct setting_parser_info *all_default_roots[] = {\n";
 foreach my $name (keys %parsers) {
   my $module = $parsers{$name};
   next if (!$module);
@@ -114,3 +114,4 @@ foreach my $name (keys %parsers) {
 }
 print "\tNULL\n";
 print "};\n";
+print "const struct setting_parser_info *const *all_roots = all_default_roots;\n";