dovecot-2.0: lib-settings: Fixed parsing settings when the key w...

dovecot at dovecot.org dovecot at dovecot.org
Mon Nov 15 18:45:01 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/656da7e0d6b9
changeset: 12423:656da7e0d6b9
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Nov 15 16:42:19 2010 +0000
description:
lib-settings: Fixed parsing settings when the key was duplicated to multiple roots.
Previously only the first one got the value set, now all of them get it.

diffstat:

 src/lib-settings/settings-parser.c |  36 +++++++++++++++++++++++++-----------
 1 files changed, 25 insertions(+), 11 deletions(-)

diffs (80 lines):

diff -r d9913925a111 -r 656da7e0d6b9 src/lib-settings/settings-parser.c
--- a/src/lib-settings/settings-parser.c	Mon Nov 15 16:33:27 2010 +0000
+++ b/src/lib-settings/settings-parser.c	Mon Nov 15 16:42:19 2010 +0000
@@ -651,9 +651,9 @@
 }
 
 static bool
-settings_find_key(struct setting_parser_context *ctx, const char *key,
-		  const struct setting_define **def_r,
-		  struct setting_link **link_r)
+settings_find_key_nth(struct setting_parser_context *ctx, const char *key,
+		      unsigned int n, const struct setting_define **def_r,
+		      struct setting_link **link_r)
 {
 	const struct setting_define *def;
 	struct setting_link *link;
@@ -663,12 +663,14 @@
 	/* try to find from roots */
 	for (i = 0; i < ctx->root_count; i++) {
 		def = setting_define_find(ctx->roots[i].info, key);
-		if (def != NULL) {
+		if (def != NULL && n-- == 0) {
 			*def_r = def;
 			*link_r = &ctx->roots[i];
 			return TRUE;
 		}
 	}
+	if (n > 0)
+		return FALSE;
 
 	/* try to find from links */
 	end = strrchr(key, SETTINGS_SEPARATOR);
@@ -689,6 +691,14 @@
 	}
 }
 
+static bool
+settings_find_key(struct setting_parser_context *ctx, const char *key,
+		  const struct setting_define **def_r,
+		  struct setting_link **link_r)
+{
+	return settings_find_key_nth(ctx, key, 0, def_r, link_r);
+}
+
 static void
 settings_parse_strlist(struct setting_parser_context *ctx,
 		       struct setting_link *link,
@@ -720,8 +730,15 @@
 {
 	const struct setting_define *def;
 	struct setting_link *link;
+	unsigned int n = 0;
 
-	if (settings_find_key(ctx, key, &def, &link)) {
+	if (!settings_find_key(ctx, key, &def, &link)) {
+		ctx->error = p_strconcat(ctx->parser_pool,
+					 "Unknown setting: ", key, NULL);
+		return 0;
+	}
+
+	do {
 		if (link->info == &strlist_info) {
 			settings_parse_strlist(ctx, link, key, value);
 			return 1;
@@ -729,12 +746,9 @@
 
 		if (settings_parse(ctx, link, def, key, value) < 0)
 			return -1;
-		return 1;
-	} else {
-		ctx->error = p_strconcat(ctx->parser_pool,
-					 "Unknown setting: ", key, NULL);
-		return 0;
-	}
+		/* there may be more instances of the setting */
+	} while (settings_find_key_nth(ctx, key, ++n, &def, &link));
+	return 1;
 }
 
 bool settings_parse_is_valid_key(struct setting_parser_context *ctx,


More information about the dovecot-cvs mailing list