dovecot-2.0-sslstream: config: Added support for dynamically loa...

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 02:55:39 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/4dc080520769
changeset: 10182:4dc080520769
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Oct 26 13:47:27 2009 -0400
description:
config: Added support for dynamically loaded settings.

diffstat:

6 files changed, 40 insertions(+), 2 deletions(-)
src/config/all-settings.h  |    3 ++-
src/config/config-parser.c |   30 ++++++++++++++++++++++++++++++
src/config/config-parser.h |    4 ++++
src/config/doveconf.c      |    1 +
src/config/main.c          |    1 +
src/config/settings-get.pl |    3 ++-

diffs (113 lines):

diff -r 2571cbc88302 -r 4dc080520769 src/config/all-settings.h
--- 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
diff -r 2571cbc88302 -r 4dc080520769 src/config/config-parser.c
--- 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 @@ 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 -r 2571cbc88302 -r 4dc080520769 src/config/config-parser.h
--- 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,5 +1,7 @@
 #ifndef CONFIG_PARSER_H
 #define CONFIG_PARSER_H
+
+#define CONFIG_MODULE_DIR MODULEDIR"/settings"
 
 struct config_module_parser {
 	const struct setting_parser_info *root;
@@ -14,4 +16,6 @@ int config_parse_file(const char *path, 
 int config_parse_file(const char *path, bool expand_files,
 		      const char **error_r);
 
+void config_parse_load_modules(void);
+
 #endif
diff -r 2571cbc88302 -r 4dc080520769 src/config/doveconf.c
--- 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 @@ 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 -r 2571cbc88302 -r 4dc080520769 src/config/main.c
--- 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 @@ 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 -r 2571cbc88302 -r 4dc080520769 src/config/settings-get.pl
--- 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(con
 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";


More information about the dovecot-cvs mailing list