From: Vsevolod Stakhov Date: Sun, 24 Nov 2013 22:12:44 +0000 (+0000) Subject: Import from libucl. X-Git-Tag: 0.6.0~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fd2259322f17d95700c9eea1d83710a564a42a0a;p=rspamd.git Import from libucl. --- diff --git a/src/ucl/src/ucl_parser.c b/src/ucl/src/ucl_parser.c index f93886427..2e4816874 100644 --- a/src/ucl/src/ucl_parser.c +++ b/src/ucl/src/ucl_parser.c @@ -1393,6 +1393,7 @@ ucl_state_machine (struct ucl_parser *parser) struct ucl_chunk *chunk = parser->chunks; struct ucl_stack *st; const unsigned char *p, *c = NULL, *macro_start = NULL; + unsigned char *macro_escaped; size_t macro_len = 0; struct ucl_macro *macro = NULL; @@ -1495,7 +1496,8 @@ ucl_state_machine (struct ucl_parser *parser) /* We got macro name */ HASH_FIND (hh, parser->macroes, c, (p - c), macro); if (macro == NULL) { - ucl_set_err (chunk, UCL_EMACRO, "unknown macro", &parser->err); + ucl_create_err (&parser->err, "error on line %d at column %d: unknown macro: '%.*s', character: '%c'", + chunk->line, chunk->column, (int)(p - c), c, *chunk->pos); parser->state = UCL_STATE_ERROR; return false; } @@ -1523,9 +1525,19 @@ ucl_state_machine (struct ucl_parser *parser) parser->state = UCL_STATE_ERROR; return false; } - parser->state = parser->prev_state; - if (!macro->handler (macro_start, macro_len, macro->ud)) { - return false; + macro_len = ucl_expand_variable (parser, ¯o_escaped, macro_start, macro_len); + parser->state = UCL_STATE_AFTER_VALUE; + if (macro_escaped == macro_start) { + if (!macro->handler (macro_start, macro_len, macro->ud)) { + return false; + } + } + else { + if (!macro->handler (macro_escaped, macro_len, macro->ud)) { + UCL_FREE (macro_len + 1, macro_escaped); + return false; + } + UCL_FREE (macro_len + 1, macro_escaped); } p = chunk->pos; break;