From: Timo Sirainen Date: Mon, 26 Oct 2009 17:47:27 +0000 (-0400) Subject: config: Added support for dynamically loaded settings. X-Git-Tag: 2.0.alpha3~114 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fc4b301e2dd86c096b9c41ad1b011b752fffd570;p=thirdparty%2Fdovecot%2Fcore.git config: Added support for dynamically loaded settings. --HG-- branch : HEAD --- diff --git a/src/config/all-settings.h b/src/config/all-settings.h index 4e5a1fe666..d954a8ebae 100644 --- a/src/config/all-settings.h +++ b/src/config/all-settings.h @@ -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 diff --git a/src/config/config-parser.c b/src/config/config-parser.c index 5221b1b7d5..90b5ea580e 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -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); + } +} diff --git a/src/config/config-parser.h b/src/config/config-parser.h index 800c81d9d8..e84a5ebef4 100644 --- a/src/config/config-parser.h +++ b/src/config/config-parser.h @@ -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 diff --git a/src/config/doveconf.c b/src/config/doveconf.c index 113316a23a..4168fab7de 100644 --- a/src/config/doveconf.c +++ b/src/config/doveconf.c @@ -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) { diff --git a/src/config/main.c b/src/config/main.c index 5cf61e28be..af86a103d3 100644 --- a/src/config/main.c +++ b/src/config/main.c @@ -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) diff --git a/src/config/settings-get.pl b/src/config/settings-get.pl index fbde76ce89..6f6f26ebb2 100755 --- a/src/config/settings-get.pl +++ b/src/config/settings-get.pl @@ -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";