dovecot-2.0-sslstream: settings: Allow referencing strlists with...

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


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/9ecf2adadc4f
changeset: 10230:9ecf2adadc4f
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Oct 29 14:24:01 2009 -0400
description:
settings: Allow referencing strlists without section key (e.g. plugin/foo vs. plugin/0/foo)

diffstat:

1 file changed, 40 insertions(+), 17 deletions(-)
src/lib-settings/settings-parser.c |   57 +++++++++++++++++++++++++-----------

diffs (89 lines):

diff -r 988ea1049fa5 -r 9ecf2adadc4f src/lib-settings/settings-parser.c
--- a/src/lib-settings/settings-parser.c	Thu Oct 29 14:09:10 2009 -0400
+++ b/src/lib-settings/settings-parser.c	Thu Oct 29 14:24:01 2009 -0400
@@ -336,6 +336,30 @@ static int get_enum(struct setting_parse
 	return 0;
 }
 
+static int setting_link_add(struct setting_parser_context *ctx,
+			    const struct setting_define *def,
+			    const struct setting_link *link_copy, char *key)
+{
+	struct setting_link *link;
+
+	link = hash_table_lookup(ctx->links, key);
+	if (link != NULL) {
+		if (def != NULL && def->type == SET_DEFLIST_UNIQUE &&
+		    link->parent == link_copy->parent &&
+		    link->info == link_copy->info)
+			return 0;
+		ctx->error = p_strconcat(ctx->parser_pool, key,
+					 " already exists", NULL);
+		return -1;
+	}
+
+	link = p_new(ctx->parser_pool, struct setting_link, 1);
+	*link = *link_copy;
+	link->full_key = key;
+	hash_table_insert(ctx->links, key, link);
+	return 0;
+}
+
 static int
 get_deflist(struct setting_parser_context *ctx, struct setting_link *parent,
 	    const struct setting_define *def,
@@ -343,7 +367,7 @@ get_deflist(struct setting_parser_contex
 	    const char *key, const char *value, ARRAY_TYPE(void_array) *result,
 	    ARRAY_TYPE(void_array) *change_result)
 {
-	struct setting_link *link;
+	struct setting_link new_link;
 	const char *const *list;
 	char *full_key;
 
@@ -354,6 +378,20 @@ get_deflist(struct setting_parser_contex
 	if (change_result != NULL && !array_is_created(change_result))
 		p_array_init(change_result, ctx->set_pool, 5);
 
+	memset(&new_link, 0, sizeof(new_link));
+	new_link.parent = parent;
+	new_link.info = info;
+	new_link.array = result;
+	new_link.change_array = change_result;
+
+	if (info == &strlist_info) {
+		/* there are no sections below strlist, so allow referencing it
+		   without the key (e.g. plugin/foo instead of plugin/0/foo) */
+		full_key = p_strdup(ctx->parser_pool, key);
+		if (setting_link_add(ctx, def, &new_link, full_key) < 0)
+			return -1;
+	}
+
 	list = t_strsplit(value, "\t ");
 	for (; *list != NULL; list++) {
 		if (**list == '\0')
@@ -361,23 +399,8 @@ get_deflist(struct setting_parser_contex
 
 		full_key = p_strconcat(ctx->parser_pool, key,
 				       SETTINGS_SEPARATOR_S, *list, NULL);
-		link = hash_table_lookup(ctx->links, full_key);
-		if (link != NULL) {
-			if (def != NULL && def->type == SET_DEFLIST_UNIQUE &&
-			    link->parent == parent && link->info == info)
-				return 0;
-			ctx->error = p_strconcat(ctx->parser_pool, full_key,
-						 " already exists", NULL);
+		if (setting_link_add(ctx, def, &new_link, full_key) < 0)
 			return -1;
-		}
-
-		link = p_new(ctx->parser_pool, struct setting_link, 1);
-		link->full_key = full_key;
-		link->parent = parent;
-		link->info = info;
-		link->array = result;
-		link->change_array = change_result;
-		hash_table_insert(ctx->links, full_key, link);
 	}
 	return 0;
 }


More information about the dovecot-cvs mailing list