]> source.dussan.org Git - rspamd.git/commitdiff
* Some more bugs are (hopefuly) fixed
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 23 Apr 2009 15:42:34 +0000 (19:42 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 23 Apr 2009 15:42:34 +0000 (19:42 +0400)
src/expressions.c
src/plugins/regexp.c

index cc5e090722c2cd820f62cf7398221c9dc3ce0104..0ad9f1a726d8f6a98d55a5e5235a4d13fa3e2988 100644 (file)
@@ -210,6 +210,7 @@ is_regexp_flag (char a)
                case 's':
                case 'u':
                case 'o':
+               case 'r':
                case 'H':
                case 'M':
                case 'P':
@@ -297,6 +298,8 @@ parse_expression (memory_pool_t *pool, char *line)
        if (line == NULL || pool == NULL) {
                return NULL;
        } 
+
+       msg_debug ("parse_expression: parsing expression {{ %s }}", line);
        
        function_stack = g_queue_new ();
        p = line;
@@ -379,13 +382,13 @@ parse_expression (memory_pool_t *pool, char *line)
                        case READ_REGEXP_FLAGS:
                                if (!is_regexp_flag (*p) || *(p + 1) == '\0') {
                                        if (c != p) {
-                                               /* Copy operand */
-                                               if (*(p + 1) == '\0' || *(p - 1) == '/') {
-                                                       p++;
+                                               if (is_regexp_flag (*p) && *(p + 1) == '\0') {
+                                                       p ++;
                                                }
-                                               str = memory_pool_alloc (pool, p - c + 1);
-                                               g_strlcpy (str, c - 1, (p - c + 1));
+                                               str = memory_pool_alloc (pool, p - c + 2);
+                                               g_strlcpy (str, c - 1, (p - c + 2));
                                                g_strstrip (str);
+                                               msg_debug ("parse_expression: found regexp: %s", str);
                                                if (strlen (str) > 0) {
                                                        insert_expression (pool, &expr, EXPR_REGEXP, 0, str);
                                                }
index 87d484ccffa343f874808f1fee05b85bf87b3f7b..a0d7e1f98e2fd477831accc5c05a05aaf59c925c 100644 (file)
@@ -155,6 +155,7 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task)
        GRegex *regexp;
        struct uri *url;
        int r;
+       
 
        if (re == NULL) {
                msg_info ("process_regexp: invalid regexp passed");
@@ -162,11 +163,13 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task)
        }
        
        if ((r = task_cache_check (task, re)) != -1) {
+               msg_debug ("process_regexp: regexp /%s/ is found in cache, result: %d", re->regexp_text, r);
                return r == 1;
        }
 
        switch (re->type) {
                case REGEXP_NONE:
+                       msg_warn ("process_regexp: bad error detected: /%s/ has invalid regexp type", re->regexp_text);
                        return 0;
                case REGEXP_HEADER:
                        if (re->header == NULL) {
@@ -282,6 +285,8 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task)
                        *c = t;
                        task_cache_add (task, re, 0);
                        return 0;
+               default:
+                       msg_warn ("process_regexp: bad error detected: %p is not a valid regexp object", re);
        }
 
        /* Not reached */
@@ -332,6 +337,7 @@ process_regexp_expression (struct expression *expr, struct worker_task *task)
        GQueue *stack;
        gsize cur, op1, op2;
        struct expression *it = expr;
+       struct rspamd_regexp *re;
        gboolean try_optimize = TRUE;
        
        stack = g_queue_new ();
@@ -362,11 +368,12 @@ process_regexp_expression (struct expression *expr, struct worker_task *task)
                                it = it->next;
                                continue;
                        }
-                       it->content.operand = parse_regexp (task->cfg->cfg_pool, it->content.operand, task->cfg->raw_mode);
-                       if (it->content.operand == NULL) {
+                       re = parse_regexp (task->cfg->cfg_pool, it->content.operand, task->cfg->raw_mode);
+                       if (re == NULL) {
                                msg_warn ("process_regexp_expression: cannot parse regexp, skip expression");
                                return FALSE;
                        }
+                       it->content.operand = re;
                        it->type = EXPR_REGEXP_PARSED;
                        /* Continue with this regexp once again */
                        continue;