dovecot-2.0: doveconf: Show protocol/remote/local sections.

dovecot at dovecot.org dovecot at dovecot.org
Sat Mar 13 15:13:20 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/6acd45009331
changeset: 10890:6acd45009331
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Mar 13 15:13:03 2010 +0200
description:
doveconf: Show protocol/remote/local sections.

diffstat:

 src/config/config-connection.c |    3 +-
 src/config/config-filter.c     |   42 ++++++++
 src/config/config-filter.h     |    5 +
 src/config/config-request.c    |   30 ++++-
 src/config/config-request.h    |    7 +-
 src/config/doveconf.c          |  204 ++++++++++++++++++++++++++++++++--------
 6 files changed, 237 insertions(+), 54 deletions(-)

diffs (truncated from 511 to 300 lines):

diff -r 653ae02bf8cf -r 6acd45009331 src/config/config-connection.c
--- a/src/config/config-connection.c	Fri Mar 12 15:01:11 2010 +0200
+++ b/src/config/config-connection.c	Sat Mar 13 15:13:03 2010 +0200
@@ -110,8 +110,9 @@
 
 	o_stream_cork(conn->output);
 
-	ctx = config_export_init(&filter, module, CONFIG_DUMP_SCOPE_SET, 0,
+	ctx = config_export_init(module, CONFIG_DUMP_SCOPE_SET, 0,
 				 config_request_output, conn->output);
+	config_export_by_filter(ctx, &filter);
 	config_export_get_output(ctx, &output);
 
 	if (output.service_uses_local)
diff -r 653ae02bf8cf -r 6acd45009331 src/config/config-filter.c
--- a/src/config/config-filter.c	Fri Mar 12 15:01:11 2010 +0200
+++ b/src/config/config-filter.c	Sat Mar 13 15:13:03 2010 +0200
@@ -148,6 +148,13 @@
 	return 0;
 }
 
+static int
+config_filter_parser_cmp_rev(struct config_filter_parser *const *p1,
+			     struct config_filter_parser *const *p2)
+{
+	return -config_filter_parser_cmp(p1, p2);
+}
+
 static struct config_filter_parser *const *
 config_filter_find_all(struct config_filter_context *ctx,
 		       const struct config_filter *filter,
@@ -182,6 +189,41 @@
 	return array_idx(&matches, 0);
 }
 
+struct config_filter_parser *const *
+config_filter_find_subset(struct config_filter_context *ctx,
+			  const struct config_filter *filter)
+{
+	ARRAY_TYPE(config_filter_parsers) matches;
+	struct config_filter tmp_mask;
+	unsigned int i;
+
+	t_array_init(&matches, 8);
+	for (i = 0; ctx->parsers[i] != NULL; i++) {
+		const struct config_filter *mask = &ctx->parsers[i]->filter;
+
+		if (filter->service != NULL) {
+			if (!config_filter_match_service(mask, filter))
+				continue;
+		}
+
+		tmp_mask = *mask;
+		if (filter->local_host == NULL)
+			tmp_mask.local_host = NULL;
+		if (filter->remote_host == NULL)
+			tmp_mask.remote_host = NULL;
+		if (filter->local_bits == 0)
+			tmp_mask.local_bits = 0;
+		if (filter->remote_bits == 0)
+			tmp_mask.remote_bits = 0;
+
+		if (config_filter_match_rest(&tmp_mask, filter))
+			array_append(&matches, &ctx->parsers[i], 1);
+	}
+	array_sort(&matches, config_filter_parser_cmp_rev);
+	(void)array_append_space(&matches);
+	return array_idx(&matches, 0);
+}
+
 static bool
 config_filter_is_superset(const struct config_filter *sup,
 			  const struct config_filter *filter)
diff -r 653ae02bf8cf -r 6acd45009331 src/config/config-filter.h
--- a/src/config/config-filter.h	Fri Mar 12 15:01:11 2010 +0200
+++ b/src/config/config-filter.h	Sat Mar 13 15:13:03 2010 +0200
@@ -35,6 +35,11 @@
 			      const char **error_r);
 void config_filter_parsers_free(struct config_module_parser *parsers);
 
+/* Return a list of filters that are a subset of the given filter. */
+struct config_filter_parser *const *
+config_filter_find_subset(struct config_filter_context *ctx,
+			  const struct config_filter *filter);
+
 /* Returns TRUE if filter matches mask. */
 bool config_filter_match(const struct config_filter *mask,
 			 const struct config_filter *filter);
diff -r 653ae02bf8cf -r 6acd45009331 src/config/config-request.c
--- a/src/config/config-request.c	Fri Mar 12 15:01:11 2010 +0200
+++ b/src/config/config-request.c	Sat Mar 13 15:13:03 2010 +0200
@@ -23,7 +23,8 @@
 
 	const char *module;
 	enum config_dump_flags flags;
-	struct config_module_parser *parsers;
+	const struct config_module_parser *parsers;
+	struct config_module_parser *dup_parsers;
 	struct master_service_settings_output output;
 
 	bool failed;
@@ -335,13 +336,11 @@
 }
 
 struct config_export_context *
-config_export_init(const struct config_filter *filter,
-		   const char *module, enum config_dump_scope scope,
+config_export_init(const char *module, enum config_dump_scope scope,
 		   enum config_dump_flags flags,
 		   config_request_callback_t *callback, void *context)
 {
 	struct config_export_context *ctx;
-	const char *error;
 	pool_t pool;
 
 	pool = pool_alloconly_create("config export", 1024*64);
@@ -357,14 +356,27 @@
 	ctx->prefix = t_str_new(64);
 	ctx->keys = hash_table_create(default_pool, ctx->pool, 0,
 				      str_hash, (hash_cmp_callback_t *)strcmp);
+	return ctx;
+}
+
+void config_export_by_filter(struct config_export_context *ctx,
+			     const struct config_filter *filter)
+{
+	const char *error;
 
 	if (config_filter_parsers_get(config_filter, ctx->pool, filter,
-				      &ctx->parsers, &ctx->output,
+				      &ctx->dup_parsers, &ctx->output,
 				      &error) < 0) {
 		i_error("%s", error);
 		ctx->failed = TRUE;
 	}
-	return ctx;
+	ctx->parsers = ctx->dup_parsers;
+}
+
+void config_export_parsers(struct config_export_context *ctx,
+			   const struct config_module_parser *parsers)
+{
+	ctx->parsers = parsers;
 }
 
 void config_export_get_output(struct config_export_context *ctx,
@@ -375,8 +387,8 @@
 
 static void config_export_free(struct config_export_context *ctx)
 {
-	if (ctx->parsers != NULL)
-		config_filter_parsers_free(ctx->parsers);
+	if (ctx->dup_parsers != NULL)
+		config_filter_parsers_free(ctx->dup_parsers);
 	hash_table_destroy(&ctx->keys);
 	pool_unref(&ctx->pool);
 }
@@ -384,7 +396,7 @@
 int config_export_finish(struct config_export_context **_ctx)
 {
 	struct config_export_context *ctx = *_ctx;
-	struct config_module_parser *parser;
+	const struct config_module_parser *parser;
 	const char *error;
 	unsigned int i;
 	int ret = 0;
diff -r 653ae02bf8cf -r 6acd45009331 src/config/config-request.h
--- a/src/config/config-request.h	Fri Mar 12 15:01:11 2010 +0200
+++ b/src/config/config-request.h	Sat Mar 13 15:13:03 2010 +0200
@@ -38,10 +38,13 @@
 			enum setting_type type, bool dump_default,
 			bool *dump_r);
 struct config_export_context *
-config_export_init(const struct config_filter *filter,
-		   const char *module, enum config_dump_scope scope,
+config_export_init(const char *module, enum config_dump_scope scope,
 		   enum config_dump_flags flags,
 		   config_request_callback_t *callback, void *context);
+void config_export_by_filter(struct config_export_context *ctx,
+			     const struct config_filter *filter);
+void config_export_parsers(struct config_export_context *ctx,
+			   const struct config_module_parser *parsers);
 void config_export_get_output(struct config_export_context *ctx,
 			      struct master_service_settings_output *output_r);
 int config_export_finish(struct config_export_context **ctx);
diff -r 653ae02bf8cf -r 6acd45009331 src/config/doveconf.c
--- a/src/config/doveconf.c	Fri Mar 12 15:01:11 2010 +0200
+++ b/src/config/doveconf.c	Sat Mar 13 15:13:03 2010 +0200
@@ -23,20 +23,26 @@
 };
 ARRAY_DEFINE_TYPE(prefix_stack, struct prefix_stack);
 
-struct config_request_get_string_ctx {
+struct config_dump_human_context {
 	pool_t pool;
+	string_t *list_prefix;
 	ARRAY_TYPE(const_string) strings;
 	ARRAY_TYPE(const_string) errors;
+	struct config_export_context *export_ctx;
+
+	unsigned int list_prefix_sent:1;
 };
 
 #define LIST_KEY_PREFIX "\001"
 #define UNIQUE_KEY_SUFFIX "\xff"
 
+static const char *indent_str = "                              !!!!";
+
 static void
 config_request_get_strings(const char *key, const char *value,
 			   enum config_key_type type, void *context)
 {
-	struct config_request_get_string_ctx *ctx = context;
+	struct config_dump_human_context *ctx = context;
 	const char *p;
 
 	switch (type) {
@@ -106,45 +112,64 @@
 		s->str_pos = -1U;
 }
 
-static int config_connection_request_human(struct ostream *output,
-					   const struct config_filter *filter,
-					   const char *module,
-					   enum config_dump_scope scope)
+static struct config_dump_human_context *
+config_dump_human_init(const char *module, enum config_dump_scope scope,
+		       bool check_settings)
 {
-	static const char *indent_str = "               ";
+	struct config_dump_human_context *ctx;
+	enum config_dump_flags flags;
+	pool_t pool;
+
+	pool = pool_alloconly_create("config human strings", 10240);
+	ctx = p_new(pool, struct config_dump_human_context, 1);
+	ctx->pool = pool;
+	ctx->list_prefix = str_new(ctx->pool, 128);
+	i_array_init(&ctx->strings, 256);
+	i_array_init(&ctx->errors, 256);
+
+	flags = CONFIG_DUMP_FLAG_HIDE_LIST_DEFAULTS |
+		CONFIG_DUMP_FLAG_CALLBACK_ERRORS;
+	if (check_settings)
+		flags |= CONFIG_DUMP_FLAG_CHECK_SETTINGS;
+
+	ctx->export_ctx = config_export_init(module, scope, flags,
+					     config_request_get_strings, ctx);
+	return ctx;
+}
+
+static void config_dump_human_deinit(struct config_dump_human_context *ctx)
+{
+	array_free(&ctx->strings);
+	array_free(&ctx->errors);
+	pool_unref(&ctx->pool);
+}
+
+static int
+config_dump_human_output(struct config_dump_human_context *ctx,
+			 struct ostream *output, unsigned int indent)
+{
 	ARRAY_TYPE(const_string) prefixes_arr;
 	ARRAY_TYPE(prefix_stack) prefix_stack;
-	struct config_export_context *export_ctx;
 	struct prefix_stack prefix;
-	struct config_request_get_string_ctx ctx;
 	const char *const *strings, *const *args, *p, *str, *const *prefixes;
 	const char *key, *key2, *value;
 	unsigned int i, j, count, len, prefix_count, skip_len;
-	unsigned int indent = 0, prefix_idx = -1U;
-	string_t *list_prefix;
+	unsigned int prefix_idx = -1U;
 	bool unique_key;
 	int ret = 0;
 
-	ctx.pool = pool_alloconly_create("config human strings", 10240);
-	i_array_init(&ctx.strings, 256);
-	i_array_init(&ctx.errors, 256);
-	export_ctx = config_export_init(filter, module, scope,
-					CONFIG_DUMP_FLAG_CHECK_SETTINGS |
-					CONFIG_DUMP_FLAG_HIDE_LIST_DEFAULTS |
-					CONFIG_DUMP_FLAG_CALLBACK_ERRORS,
-					config_request_get_strings, &ctx);
-	if (config_export_finish(&export_ctx) < 0)
+	if (config_export_finish(&ctx->export_ctx) < 0)
 		return -1;
 
-	array_sort(&ctx.strings, config_string_cmp);
-	strings = array_get(&ctx.strings, &count);
+	array_sort(&ctx->strings, config_string_cmp);
+	strings = array_get(&ctx->strings, &count);
 
-	p_array_init(&prefixes_arr, ctx.pool, 32);
+	p_array_init(&prefixes_arr, ctx->pool, 32);
 	for (i = 0; i < count && strings[i][0] == LIST_KEY_PREFIX[0]; i++) T_BEGIN {
 		p = strchr(strings[i], '=');
 		i_assert(p != NULL);
 		for (args = t_strsplit(p + 1, " "); *args != NULL; args++) {
-			str = p_strdup_printf(ctx.pool, "%s/%s/",


More information about the dovecot-cvs mailing list