dovecot-2.2: config: Support looking up config for multiple modu...

dovecot at dovecot.org dovecot at dovecot.org
Wed Sep 19 15:34:25 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/8c003fe6f5a6
changeset: 15087:8c003fe6f5a6
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Sep 19 15:33:10 2012 +0300
description:
config: Support looking up config for multiple modules at the same time.

diffstat:

 src/config/config-connection.c     |  21 +++++++++++++++------
 src/config/config-filter.c         |  16 ++++++++--------
 src/config/config-filter.h         |   4 ++--
 src/config/config-parser-private.h |   2 +-
 src/config/config-parser.c         |  26 ++++++++++++--------------
 src/config/config-parser.h         |  10 ++++++----
 src/config/config-request.c        |  15 +++++++--------
 src/config/config-request.h        |   4 ++--
 src/config/doveconf.c              |  38 +++++++++++++++++++++++---------------
 src/config/main.c                  |   2 +-
 10 files changed, 77 insertions(+), 61 deletions(-)

diffs (truncated from 498 to 300 lines):

diff -r 04580a59dc53 -r 8c003fe6f5a6 src/config/config-connection.c
--- a/src/config/config-connection.c	Tue Sep 18 05:12:28 2012 +0300
+++ b/src/config/config-connection.c	Wed Sep 19 15:33:10 2012 +0300
@@ -1,6 +1,7 @@
 /* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "array.h"
 #include "llist.h"
 #include "istream.h"
 #include "ostream.h"
@@ -69,16 +70,22 @@
 	struct config_export_context *ctx;
 	struct master_service_settings_output output;
 	struct config_filter filter;
-	const char *path, *error, *module = "";
+	const char *path, *error, *module;
+	ARRAY(const char *) modules;
+	bool is_master = FALSE;
 
 	/* [<args>] */
+	t_array_init(&modules, 4);
 	memset(&filter, 0, sizeof(filter));
 	for (; *args != NULL; args++) {
 		if (strncmp(*args, "service=", 8) == 0)
 			filter.service = *args + 8;
-		else if (strncmp(*args, "module=", 7) == 0)
+		else if (strncmp(*args, "module=", 7) == 0) {
 			module = *args + 7;
-		else if (strncmp(*args, "lname=", 6) == 0)
+			if (strcmp(module, "master") == 0)
+				is_master = TRUE;
+			array_append(&modules, &module, 1);
+		} else if (strncmp(*args, "lname=", 6) == 0)
 			filter.local_name = *args + 6;
 		else if (strncmp(*args, "lip=", 4) == 0) {
 			if (net_addr2ip(*args + 4, &filter.local_net) == 0) {
@@ -94,11 +101,12 @@
 			}
 		}
 	}
+	array_append_zero(&modules);
 
-	if (strcmp(module, "master") == 0) {
+	if (is_master) {
 		/* master reads configuration only when reloading settings */
 		path = master_service_get_config_path(master_service);
-		if (config_parse_file(path, TRUE, "", &error) <= 0) {
+		if (config_parse_file(path, TRUE, NULL, &error) <= 0) {
 			o_stream_nsend_str(conn->output,
 				t_strconcat("\nERROR ", error, "\n", NULL));
 			config_connection_destroy(conn);
@@ -108,7 +116,8 @@
 
 	o_stream_cork(conn->output);
 
-	ctx = config_export_init(module, CONFIG_DUMP_SCOPE_SET, 0,
+	ctx = config_export_init(array_idx(&modules, 0),
+				 CONFIG_DUMP_SCOPE_SET, 0,
 				 config_request_output, conn->output);
 	config_export_by_filter(ctx, &filter);
 	config_export_get_output(ctx, &output);
diff -r 04580a59dc53 -r 8c003fe6f5a6 src/config/config-filter.c
--- a/src/config/config-filter.c	Tue Sep 18 05:12:28 2012 +0300
+++ b/src/config/config-filter.c	Wed Sep 19 15:33:10 2012 +0300
@@ -164,15 +164,14 @@
 }
 
 static bool have_changed_settings(const struct config_filter_parser *parser,
-				  const char *module)
+				  const char *const *modules)
 {
 	const unsigned char *changes;
 	unsigned int i, j, size;
 
 	for (i = 0; parser->parsers[i].root != NULL; i++) {
-		if (*module != '\0' &&
-		    !config_module_want_parser(config_module_parsers,
-					       module, parser->parsers[i].root))
+		if (!config_module_want_parser(config_module_parsers,
+					       modules, parser->parsers[i].root))
 			continue;
 
 		changes = settings_parser_get_changes(parser->parsers[i].parser);
@@ -186,7 +185,8 @@
 }
 
 static struct config_filter_parser *const *
-config_filter_find_all(struct config_filter_context *ctx, const char *module,
+config_filter_find_all(struct config_filter_context *ctx,
+		       const char *const *modules,
 		       const struct config_filter *filter,
 		       struct master_service_settings_output *output_r)
 {
@@ -203,7 +203,7 @@
 
 		if (!config_filter_match_service(mask, filter)) {
 			if (!str_array_contains(&service_names, mask->service) &&
-			    have_changed_settings(ctx->parsers[i], module))
+			    have_changed_settings(ctx->parsers[i], modules))
 				array_append(&service_names, &mask->service, 1);
 			continue;
 		}
@@ -306,7 +306,7 @@
 }
 
 int config_filter_parsers_get(struct config_filter_context *ctx, pool_t pool,
-			      const char *module,
+			      const char *const *modules,
 			      const struct config_filter *filter,
 			      struct config_module_parser **parsers_r,
 			      struct master_service_settings_output *output_r,
@@ -322,7 +322,7 @@
 	   with an error. Merging SET_STRLIST types requires
 	   settings_parser_apply_changes() to work a bit unintuitively by
 	   letting the destination settings override the source settings. */
-	src = config_filter_find_all(ctx, module, filter, output_r);
+	src = config_filter_find_all(ctx, modules, filter, output_r);
 
 	/* all of them should have the same number of parsers.
 	   duplicate our initial parsers from the first match */
diff -r 04580a59dc53 -r 8c003fe6f5a6 src/config/config-filter.h
--- a/src/config/config-filter.h	Tue Sep 18 05:12:28 2012 +0300
+++ b/src/config/config-filter.h	Wed Sep 19 15:33:10 2012 +0300
@@ -33,11 +33,11 @@
 
 /* Build new parsers from all existing ones matching the given filter. */
 int config_filter_parsers_get(struct config_filter_context *ctx, pool_t pool,
-			      const char *module,
+			      const char *const *modules,
 			      const struct config_filter *filter,
 			      struct config_module_parser **parsers_r,
 			      struct master_service_settings_output *output_r,
-			      const char **error_r);
+			      const char **error_r) ATTR_NULL(3);
 void config_filter_parsers_free(struct config_module_parser *parsers);
 
 /* Return a list of filters that are a subset of the given filter. */
diff -r 04580a59dc53 -r 8c003fe6f5a6 src/config/config-parser-private.h
--- a/src/config/config-parser-private.h	Tue Sep 18 05:12:28 2012 +0300
+++ b/src/config/config-parser-private.h	Wed Sep 19 15:33:10 2012 +0300
@@ -39,7 +39,7 @@
 struct config_parser_context {
 	pool_t pool;
 	const char *path;
-	const char *module;
+	const char *const *modules;
 
 	ARRAY(struct config_filter_parser *) all_parsers;
 	struct config_module_parser *root_parsers;
diff -r 04580a59dc53 -r 8c003fe6f5a6 src/config/config-parser.c
--- a/src/config/config-parser.c	Tue Sep 18 05:12:28 2012 +0300
+++ b/src/config/config-parser.c	Wed Sep 19 15:33:10 2012 +0300
@@ -334,9 +334,8 @@
 {
 	for (; p->root != NULL; p++) {
 		/* skip checking settings we don't care about */
-		if (*ctx->module != '\0' &&
-		    !config_module_want_parser(ctx->root_parsers,
-					       ctx->module, p->root))
+		if (!config_module_want_parser(ctx->root_parsers,
+					       ctx->modules, p->root))
 			continue;
 
 		settings_parse_var_skip(p->parser);
@@ -396,7 +395,7 @@
 
 	global_ssl_set = get_str_setting(parsers[0], "ssl", "");
 	for (i = 0; i < count && ret == 0; i++) {
-		if (config_filter_parsers_get(new_filter, tmp_pool, "",
+		if (config_filter_parsers_get(new_filter, tmp_pool, NULL,
 					      &parsers[i]->filter,
 					      &tmp_parsers, &output,
 					      error_r) < 0) {
@@ -728,12 +727,12 @@
 {
 	struct config_module_parser *l;
 
-	if (*ctx->module == '\0')
+	if (ctx->modules == NULL)
 		return TRUE;
 
 	for (l = ctx->cur_section->parsers; l->root != NULL; l++) {
 		if (config_module_want_parser(ctx->root_parsers,
-					      ctx->module, l->root) &&
+					      ctx->modules, l->root) &&
 		    settings_parse_is_valid_key(l->parser, key))
 			return TRUE;
 	}
@@ -881,8 +880,8 @@
 	}
 }
 
-int config_parse_file(const char *path, bool expand_values, const char *module,
-		      const char **error_r)
+int config_parse_file(const char *path, bool expand_values,
+		      const char *const *modules, const char **error_r)
 {
 	struct input_stack root;
 	struct config_parser_context ctx;
@@ -924,7 +923,7 @@
 	root.path = path;
 	ctx.cur_input = &root;
 	ctx.expand_values = expand_values;
-	ctx.module = module;
+	ctx.modules = modules;
 
 	p_array_init(&ctx.all_parsers, ctx.pool, 128);
 	ctx.cur_section = p_new(ctx.pool, struct config_section_stack, 1);
@@ -1052,21 +1051,20 @@
 }
 
 bool config_module_want_parser(struct config_module_parser *parsers,
-			       const char *module,
+			       const char *const *modules,
 			       const struct setting_parser_info *root)
 {
 	struct config_module_parser *l;
 
-	if (strcmp(root->module_name, module) == 0)
+	if (modules == NULL)
 		return TRUE;
-	if (root == &master_service_setting_parser_info ||
-	    root == &master_service_ssl_setting_parser_info) {
+	if (root == &master_service_setting_parser_info) {
 		/* everyone wants master service settings */
 		return TRUE;
 	}
 
 	for (l = parsers; l->root != NULL; l++) {
-		if (strcmp(l->root->module_name, module) != 0)
+		if (!str_array_find(modules, l->root->module_name))
 			continue;
 
 		/* see if we can find a way to get from the original parser
diff -r 04580a59dc53 -r 8c003fe6f5a6 src/config/config-parser.h
--- a/src/config/config-parser.h	Tue Sep 18 05:12:28 2012 +0300
+++ b/src/config/config-parser.h	Wed Sep 19 15:33:10 2012 +0300
@@ -18,13 +18,15 @@
 
 int config_parse_net(const char *value, struct ip_addr *ip_r,
 		     unsigned int *bits_r, const char **error_r);
-int config_parse_file(const char *path, bool expand_values, const char *module,
-		      const char **error_r);
+int config_parse_file(const char *path, bool expand_values,
+		      const char *const *modules, const char **error_r)
+	ATTR_NULL(3);
 
 void config_parse_load_modules(void);
 
 bool config_module_want_parser(struct config_module_parser *parsers,
-			       const char *module,
-			       const struct setting_parser_info *root);
+			       const char *const *modules,
+			       const struct setting_parser_info *root)
+	ATTR_NULL(2);
 
 #endif
diff -r 04580a59dc53 -r 8c003fe6f5a6 src/config/config-request.c
--- a/src/config/config-request.c	Tue Sep 18 05:12:28 2012 +0300
+++ b/src/config/config-request.c	Wed Sep 19 15:33:10 2012 +0300
@@ -21,7 +21,7 @@
 	config_request_callback_t *callback;
 	void *context;
 
-	const char *module;
+	const char *const *modules;
 	enum config_dump_flags flags;
 	const struct config_module_parser *parsers;
 	struct config_module_parser *dup_parsers;
@@ -341,20 +341,20 @@
 }
 
 struct config_export_context *
-config_export_init(const char *module, enum config_dump_scope scope,
+config_export_init(const char *const *modules, enum config_dump_scope scope,
 		   enum config_dump_flags flags,
 		   config_request_callback_t *callback, void *context)
 {
 	struct config_export_context *ctx;
 	pool_t pool;
 
-	i_assert(module != NULL);
+	i_assert(modules != NULL);
 
 	pool = pool_alloconly_create(MEMPOOL_GROWING"config export", 1024*64);
 	ctx = p_new(pool, struct config_export_context, 1);
 	ctx->pool = pool;
 
-	ctx->module = p_strdup(pool, module);
+	ctx->modules = p_strarray_dup(pool, modules);
 	ctx->flags = flags;
 	ctx->callback = callback;
 	ctx->context = context;
@@ -371,7 +371,7 @@
 	const char *error;
 
 	if (config_filter_parsers_get(config_filter, ctx->pool,
-				      ctx->module, filter,
+				      ctx->modules, filter,


More information about the dovecot-cvs mailing list