summaryrefslogtreecommitdiffstats
path: root/src/cfg_utils.c
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 /src/cfg_utils.c
parent4528dcf3cfb7ed8ea265bf740757d8813d14f515 (diff)
downloadrspamd-bf47a84713c6705326b0eb02e9fab7a061f86695.tar.gz
rspamd-bf47a84713c6705326b0eb02e9fab7a061f86695.zip
* Fix variables substitution
Diffstat (limited to 'src/cfg_utils.c')
-rw-r--r--src/cfg_utils.c21
1 files changed, 13 insertions, 8 deletions
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