From: Timo Sirainen Date: Tue, 8 Sep 2009 22:45:27 +0000 (-0400) Subject: config: When reporting errors in variable-strings, skip over the "0" prefix. X-Git-Tag: 2.0.alpha1~142 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=df6551ce47053de2c366f490bef60803207beaa4;p=thirdparty%2Fdovecot%2Fcore.git config: When reporting errors in variable-strings, skip over the "0" prefix. --HG-- branch : HEAD --- diff --git a/src/config/config-parser.c b/src/config/config-parser.c index ebd005d1cd..7dc2ae9779 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -261,6 +261,7 @@ config_filter_parser_check(struct parser_context *ctx, const char **error_r) { for (; p->module_name != NULL; p++) { + settings_parse_var_skip(p->parser); if (!settings_parser_check(p->parser, ctx->pool, error_r)) return -1; } diff --git a/src/config/config-request.c b/src/config/config-request.c index a3ce2f3d9f..2686a13ff6 100644 --- a/src/config/config-request.c +++ b/src/config/config-request.c @@ -271,6 +271,7 @@ int config_request_handle(const struct config_filter *filter, settings_parser_get_changes(parser->parser)); if (check_settings) { + settings_parse_var_skip(parser->parser); if (!settings_parser_check(parser->parser, ctx.pool, &error)) { i_error("%s", error); diff --git a/src/lib-settings/settings-parser.c b/src/lib-settings/settings-parser.c index 2da926d625..93087b1547 100644 --- a/src/lib-settings/settings-parser.c +++ b/src/lib-settings/settings-parser.c @@ -743,6 +743,42 @@ void settings_parse_set_expanded(struct setting_parser_context *ctx, ctx->str_vars_are_expanded = is_expanded; } +void settings_parse_set_key_expandeded(struct setting_parser_context *ctx, + pool_t pool, const char *key) +{ + const struct setting_define *def; + struct setting_link *link; + const char **val; + + if (!settings_find_key(ctx, key, &def, &link)) + return; + + val = PTR_OFFSET(link->set_struct, def->offset); + if (def->type == SET_STR_VARS && *val != NULL) { + i_assert(**val == SETTING_STRVAR_UNEXPANDED[0] || + **val == SETTING_STRVAR_EXPANDED[0]); + *val = p_strconcat(pool, SETTING_STRVAR_EXPANDED, + *val + 1, NULL); + } +} + +void settings_parse_set_keys_expandeded(struct setting_parser_context *ctx, + pool_t pool, const char *const *keys) +{ + for (; *keys != NULL; keys++) + settings_parse_set_key_expandeded(ctx, pool, *keys); +} + +void settings_parse_var_skip(struct setting_parser_context *ctx) +{ + unsigned int i; + + for (i = 0; i < ctx->root_count; i++) { + settings_var_expand(ctx->roots[i].info, + ctx->roots[i].set_struct, NULL, NULL); + } +} + static void settings_var_expand_info(const struct setting_parser_info *info, pool_t pool, void *set, @@ -761,7 +797,11 @@ settings_var_expand_info(const struct setting_parser_info *info, if (*val == NULL) break; - if (**val == SETTING_STRVAR_UNEXPANDED[0]) { + if (table == NULL) { + i_assert(**val == SETTING_STRVAR_EXPANDED[0] || + **val == SETTING_STRVAR_UNEXPANDED[0]); + *val += 1; + } else if (**val == SETTING_STRVAR_UNEXPANDED[0]) { str_truncate(str, 0); var_expand(str, *val + 1, table); *val = p_strdup(pool, str_c(str)); @@ -791,32 +831,6 @@ settings_var_expand_info(const struct setting_parser_info *info, } } -void settings_parse_set_key_expandeded(struct setting_parser_context *ctx, - pool_t pool, const char *key) -{ - const struct setting_define *def; - struct setting_link *link; - const char **val; - - if (!settings_find_key(ctx, key, &def, &link)) - return; - - val = PTR_OFFSET(link->set_struct, def->offset); - if (def->type == SET_STR_VARS && *val != NULL) { - i_assert(**val == SETTING_STRVAR_UNEXPANDED[0] || - **val == SETTING_STRVAR_EXPANDED[0]); - *val = p_strconcat(pool, SETTING_STRVAR_EXPANDED, - *val + 1, NULL); - } -} - -void settings_parse_set_keys_expandeded(struct setting_parser_context *ctx, - pool_t pool, const char *const *keys) -{ - for (; *keys != NULL; keys++) - settings_parse_set_key_expandeded(ctx, pool, *keys); -} - void settings_var_expand(const struct setting_parser_info *info, void *set, pool_t pool, const struct var_expand_table *table) diff --git a/src/lib-settings/settings-parser.h b/src/lib-settings/settings-parser.h index 0587f7450b..19de436d9c 100644 --- a/src/lib-settings/settings-parser.h +++ b/src/lib-settings/settings-parser.h @@ -135,6 +135,10 @@ void settings_parse_set_key_expandeded(struct setting_parser_context *ctx, pool_t pool, const char *key); void settings_parse_set_keys_expandeded(struct setting_parser_context *ctx, pool_t pool, const char *const *keys); +/* Update variable string pointers to skip over the '1' or '0'. + This is mainly useful when you want to run settings_parser_check() without + actually knowing what the variables are. */ +void settings_parse_var_skip(struct setting_parser_context *ctx); /* Expand all unexpanded variables using the given table. Update the string pointers so that they can be used without skipping over the '1'. */ void settings_var_expand(const struct setting_parser_info *info,