From c1552624181039806e20491588f79f5e458e2813 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 22 Feb 2011 15:00:37 +0200 Subject: [PATCH] lib-settings: Fixed setting "strlist/key=value" when strlist hadn't been initialized yet. This happened when using -O parameter. --- src/lib-settings/settings-parser.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/lib-settings/settings-parser.c b/src/lib-settings/settings-parser.c index 0b21d972b4..7af9c05baa 100644 --- a/src/lib-settings/settings-parser.c +++ b/src/lib-settings/settings-parser.c @@ -66,6 +66,9 @@ static const struct setting_parser_info strlist_info = { .parent_offset = (size_t)-1 }; +static int settings_parse_keyvalue(struct setting_parser_context *ctx, + const char *key, const char *value); + static void setting_parser_copy_defaults(struct setting_parser_context *ctx, const struct setting_parser_info *info, @@ -657,7 +660,7 @@ settings_find_key_nth(struct setting_parser_context *ctx, const char *key, { const struct setting_define *def; struct setting_link *link; - const char *end; + const char *end, *parent_key; unsigned int i; /* try to find from roots */ @@ -679,9 +682,27 @@ settings_find_key_nth(struct setting_parser_context *ctx, const char *key, if (end == NULL) return FALSE; - link = hash_table_lookup(ctx->links, t_strdup_until(key, end)); - if (link == NULL) - return FALSE; + parent_key = t_strdup_until(key, end); + link = hash_table_lookup(ctx->links, parent_key); + if (link == NULL) { + /* maybe this is the first strlist value */ + unsigned int parent_n = 0; + const struct setting_define *parent_def; + struct setting_link *parent_link; + + if (!settings_find_key_nth(ctx, parent_key, &parent_n, + &parent_def, &parent_link)) + return FALSE; + if (parent_def->type != SET_STRLIST) + return FALSE; + + /* setting parent_key=0 adds it to links list */ + if (settings_parse_keyvalue(ctx, parent_key, "0") <= 0) + return FALSE; + + link = hash_table_lookup(ctx->links, parent_key); + i_assert(link != NULL); + } *link_r = link; if (link->info == &strlist_info) { -- 2.47.3