]> source.dussan.org Git - rspamd.git/commitdiff
* Fix variables substitution
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 22 Apr 2009 14:15:43 +0000 (18:15 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 22 Apr 2009 14:15:43 +0000 (18:15 +0400)
src/cfg_file.l
src/cfg_utils.c
src/main.c

index 77eeca0a9f41c3e1decc2910304c2ca2add61696..ebabd3e0a9a630e52f8fa3fe135f95c2f18efe6c 100644 (file)
@@ -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 */;
index a68f057ecbb094e9e32c1cee653b21abe8ac891b..4907ce64c5a0bf9a47f57cb1ebd2bb8df491febe 100644 (file)
@@ -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
index fcf3f36673c16e633ca2593321186c432d18b44e..2bc79cf144b1a826653aaba0696f55ba413cda9b 100644 (file)
@@ -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