# HG changeset patch # User Timo Sirainen # Date 1252449927 14400 # Node ID 5f61efdc9f3590d8d49467d6f50337c0a96eb7d6 # Parent 6d3732cf8b3c0b0acaafe726aa55532bda6442e4 config: When reporting errors in variable-strings, skip over the "0" prefix. diff -r 6d3732cf8b3c -r 5f61efdc9f35 src/config/config-parser.c --- a/src/config/config-parser.c Tue Sep 08 18:16:27 2009 -0400 +++ b/src/config/config-parser.c Tue Sep 08 18:45:27 2009 -0400 @@ -261,6 +261,7 @@ 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 -r 6d3732cf8b3c -r 5f61efdc9f35 src/config/config-request.c --- a/src/config/config-request.c Tue Sep 08 18:16:27 2009 -0400 +++ b/src/config/config-request.c Tue Sep 08 18:45:27 2009 -0400 @@ -271,6 +271,7 @@ 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 -r 6d3732cf8b3c -r 5f61efdc9f35 src/lib-settings/settings-parser.c --- a/src/lib-settings/settings-parser.c Tue Sep 08 18:16:27 2009 -0400 +++ b/src/lib-settings/settings-parser.c Tue Sep 08 18:45:27 2009 -0400 @@ -743,6 +743,42 @@ 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 @@ 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 @@ } } -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 -r 6d3732cf8b3c -r 5f61efdc9f35 src/lib-settings/settings-parser.h --- a/src/lib-settings/settings-parser.h Tue Sep 08 18:16:27 2009 -0400 +++ b/src/lib-settings/settings-parser.h Tue Sep 08 18:45:27 2009 -0400 @@ -135,6 +135,10 @@ 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,