]> source.dussan.org Git - rspamd.git/commitdiff
* Another fix to regexps parser
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 23 Apr 2009 13:32:44 +0000 (17:32 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 23 Apr 2009 13:32:44 +0000 (17:32 +0400)
src/expressions.c
src/expressions.h
src/plugins/regexp.c

index 98a21bf81f62608ce7abc0c3961f014c0e51f111..7202a2b3849c587fbc284ffbd087eb66438fe67f 100644 (file)
@@ -383,8 +383,8 @@ parse_expression (memory_pool_t *pool, char *line)
                                                if (*(p + 1) == '\0') {
                                                        p++;
                                                }
-                                               str = memory_pool_alloc (pool, p - c + 2);
-                                               g_strlcpy (str, c - 1, (p - c + 2));
+                                               str = memory_pool_alloc (pool, p - c + 1);
+                                               g_strlcpy (str, c - 1, (p - c + 1));
                                                g_strstrip (str);
                                                if (strlen (str) > 0) {
                                                        insert_expression (pool, &expr, EXPR_REGEXP, 0, str);
index 9d80587b4a5e055c189bfa52801e85e4e953d9a5..06034c4850538852c23f9268ec681221a68416db 100644 (file)
@@ -34,7 +34,13 @@ struct expression_argument {
  * Logic expression 
  */
 struct expression {
-       enum { EXPR_REGEXP, EXPR_OPERATION, EXPR_FUNCTION, EXPR_STR } type;     /**< expression type                                                            */
+       enum { 
+               EXPR_REGEXP,
+               EXPR_OPERATION, 
+               EXPR_FUNCTION, 
+               EXPR_STR, 
+               EXPR_REGEXP_PARSED,
+       } type;                                                                                                         /**< expression type                                                            */
        union {
                void *operand;
                char operation;
index 3acfddc5b8538f49e2be0d79a12d59f496f7cc9f..340e099640179a8f2ddfe8c4f2584d18d2c1e70e 100644 (file)
@@ -94,6 +94,7 @@ read_regexp_expression (memory_pool_t *pool, struct regexp_module_item *chain, c
                                msg_warn ("read_regexp_expression: cannot parse regexp, skip expression %s = \"%s\"", symbol, line);
                                return FALSE;
                        }
+                       cur->type = EXPR_REGEXP_PARSED;
                }
                cur = cur->next;
        }
@@ -336,10 +337,10 @@ process_regexp_expression (struct expression *expr, struct worker_task *task)
        stack = g_queue_new ();
 
        while (it) {
-               if (it->type == EXPR_REGEXP) {
+               if (it->type == EXPR_REGEXP_PARSED) {
                        /* Find corresponding symbol */
                        cur = process_regexp ((struct rspamd_regexp *)it->content.operand, task);
-                       msg_debug ("process_regexp_item: regexp %s found", cur ? "is" : "is not");
+                       msg_debug ("process_regexp_expression: regexp %s found", cur ? "is" : "is not");
                        if (try_optimize) {
                                try_optimize = optimize_regexp_expression (&it, stack, cur);
                        } else {
@@ -348,13 +349,23 @@ process_regexp_expression (struct expression *expr, struct worker_task *task)
 
                } else if (it->type == EXPR_FUNCTION) {
                        cur = (gsize)call_expression_function ((struct expression_function *)it->content.operand, task);
-                       msg_debug ("process_regexp_item: function %s returned %s", ((struct expression_function *)it->content.operand)->name,
+                       msg_debug ("process_regexp_expression: function %s returned %s", ((struct expression_function *)it->content.operand)->name,
                                                                                                                        cur ? "true" : "false");
                        if (try_optimize) {
                                try_optimize = optimize_regexp_expression (&it, stack, cur);
                        } else {
                                g_queue_push_head (stack, GSIZE_TO_POINTER (cur));
                        }
+               } else if (it->type == EXPR_REGEXP) {
+                       /* Compile regexp if it is not parsed */
+                       it->content.operand = parse_regexp (task->task_pool, it->content.operand, task->cfg->raw_mode);
+                       if (it->content.operand == NULL) {
+                               msg_warn ("process_regexp_expression: cannot parse regexp, skip expression");
+                               return FALSE;
+                       }
+                       it->type = EXPR_REGEXP_PARSED;
+                       /* Continue with this regexp once again */
+                       continue;
                } else if (it->type == EXPR_OPERATION) {
                        if (g_queue_is_empty (stack)) {
                                /* Queue has no operands for operation, exiting */