summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-04-22 18:15:43 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-04-22 18:15:43 +0400
commitbf47a84713c6705326b0eb02e9fab7a061f86695 (patch)
treecc15a83bc7b008b00b9254cb5cdac2e1c2987220
parent4528dcf3cfb7ed8ea265bf740757d8813d14f515 (diff)
downloadrspamd-bf47a84713c6705326b0eb02e9fab7a061f86695.tar.gz
rspamd-bf47a84713c6705326b0eb02e9fab7a061f86695.zip
* Fix variables substitution
-rw-r--r--src/cfg_file.l2
-rw-r--r--src/cfg_utils.c21
-rw-r--r--src/main.c1
3 files changed, 14 insertions, 10 deletions
diff --git a/src/cfg_file.l b/src/cfg_file.l
index 77eeca0a9..ebabd3e0a 100644
--- a/src/cfg_file.l
+++ b/src/cfg_file.l
@@ -154,8 +154,8 @@ yes|YES|no|NO|[yY]|[nN] yylval.flag=parse_flag(yytext); return FLAG;
<module>\} BEGIN(INITIAL); return EBRACE;
<module>\; return SEMICOLON;
<module>= return EQSIGN;
-<module>[a-zA-Z0-9_%-]+ yylval.string=strdup(yytext); return PARAM;
<module>\$[a-zA-Z_][a-zA-Z0-9_]+ yylval.string=strdup(yytext + 1); return VARIABLE;
+<module>[a-zA-Z0-9_%-]+ yylval.string=strdup(yytext); return PARAM;
<module>\".+[^\\]\" yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; unescape_quotes(yylval.string); return QUOTEDSTRING;
<lua>\n /* ignore EOL */;
diff --git a/src/cfg_utils.c b/src/cfg_utils.c
index a68f057ec..4907ce64c 100644
--- a/src/cfg_utils.c
+++ b/src/cfg_utils.c
@@ -354,7 +354,7 @@ parse_flag (const char *str)
char *
substitute_variable (struct config_file *cfg, char *name, char *str, u_char recursive)
{
- char *var, *new, *v_begin, *v_end;
+ char *var, *new, *v_begin, *v_end, *p, t;
size_t len;
gboolean changed = FALSE;
@@ -362,30 +362,35 @@ substitute_variable (struct config_file *cfg, char *name, char *str, u_char recu
yywarn ("substitute_variable: trying to substitute variable in NULL string");
return NULL;
}
-
- while ((v_begin = strstr (str, "${")) != NULL) {
+
+ p = str;
+ while ((v_begin = strstr (p, "${")) != NULL) {
len = strlen (str);
*v_begin = '\0';
v_begin += 2;
if ((v_end = strstr (v_begin, "}")) == NULL) {
/* Not a variable, skip */
+ p = v_begin;
continue;
}
+ t = *v_end;
*v_end = '\0';
var = g_hash_table_lookup (cfg->variables, v_begin);
if (var == NULL) {
yywarn ("substitute_variable: variable %s is not defined", v_begin);
- /* Substitute unknown variables with empty string */
- var = "";
+ *v_end = t;
+ p = v_end + 1;
+ continue;
}
else if (recursive) {
- new = substitute_variable (cfg, v_begin, var, recursive);
+ var = substitute_variable (cfg, v_begin, var, recursive);
}
/* Allocate new string */
new = memory_pool_alloc (cfg->cfg_pool, len - strlen (v_begin) + strlen (var) + 3);
snprintf (new, len - strlen (v_begin) + strlen (var) + 3, "%s(%s)%s",
str, var, v_end + 1);
+ p = new;
str = new;
changed = TRUE;
}
@@ -393,6 +398,7 @@ substitute_variable (struct config_file *cfg, char *name, char *str, u_char recu
if (changed && name != NULL) {
g_hash_table_insert (cfg->variables, name, str);
}
+
return str;
}
@@ -414,10 +420,9 @@ static void
substitute_all_variables (gpointer key, gpointer value, gpointer data)
{
struct config_file *cfg = (struct config_file *)data;
- char *new;
/* Do recursive substitution */
- new = substitute_variable (cfg, (char *)key, (char *)value, 1);
+ (void)substitute_variable (cfg, (char *)key, (char *)value, 1);
}
static void
diff --git a/src/main.c b/src/main.c
index fcf3f3667..2bc79cf14 100644
--- a/src/main.c
+++ b/src/main.c
@@ -354,7 +354,6 @@ static void
dump_cfg_vars ()
{
g_hash_table_foreach (cfg->variables, dump_all_variables, NULL);
- g_hash_table_foreach (cfg->modules_opts, dump_module_variables, NULL);
}
static int