changeset 10181:4dc080520769 HEAD

config: Added support for dynamically loaded settings.
author Timo Sirainen <tss@iki.fi>
date Mon, 26 Oct 2009 13:47:27 -0400
parents 2571cbc88302
children 2b9eb115fbd7
files 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
diffstat 6 files changed, 40 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/config/all-settings.h	Fri Oct 23 21:48:42 2009 -0400
+++ b/src/config/all-settings.h	Mon Oct 26 13:47:27 2009 -0400
@@ -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
--- a/src/config/config-parser.c	Fri Oct 23 21:48:42 2009 -0400
+++ b/src/config/config-parser.c	Mon Oct 26 13:47:27 2009 -0400
@@ -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 @@
 	}
 	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);
+	}
+}
--- a/src/config/config-parser.h	Fri Oct 23 21:48:42 2009 -0400
+++ b/src/config/config-parser.h	Mon Oct 26 13:47:27 2009 -0400
@@ -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 @@
 int config_parse_file(const char *path, bool expand_files,
 		      const char **error_r);
 
+void config_parse_load_modules(void);
+
 #endif
--- a/src/config/doveconf.c	Fri Oct 23 21:48:42 2009 -0400
+++ b/src/config/doveconf.c	Mon Oct 26 13:47:27 2009 -0400
@@ -270,6 +270,7 @@
 		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) {
--- a/src/config/main.c	Fri Oct 23 21:48:42 2009 -0400
+++ b/src/config/main.c	Mon Oct 26 13:47:27 2009 -0400
@@ -23,6 +23,7 @@
 
 	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)
--- a/src/config/settings-get.pl	Fri Oct 23 21:48:42 2009 -0400
+++ b/src/config/settings-get.pl	Mon Oct 26 13:47:27 2009 -0400
@@ -105,7 +105,7 @@
 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 @@
 }
 print "\tNULL\n";
 print "};\n";
+print "const struct setting_parser_info *const *all_roots = all_default_roots;\n";