]> source.dussan.org Git - rspamd.git/commitdiff
* When parse regexp save it to cache to make unique link between
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Sun, 5 Apr 2009 16:42:45 +0000 (20:42 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Sun, 5 Apr 2009 16:42:45 +0000 (20:42 +0400)
  regexp text and regexp parsed structure

src/expressions.c

index e3747c01301584324d1e600d81d7a94e58fbb0f0..4cacea02909a9f6a6f4ab5a631125f8805c57ee8 100644 (file)
@@ -485,7 +485,7 @@ struct rspamd_regexp*
 parse_regexp (memory_pool_t *pool, char *line)
 {
        char *begin, *end, *p, *src;
-       struct rspamd_regexp *result;
+       struct rspamd_regexp *result, *check;
        int regexp_flags = 0;
        GError *err = NULL;
        
@@ -614,6 +614,21 @@ parse_regexp (memory_pool_t *pool, char *line)
        }
 
        *end = '\0';
+
+       /* Avoid multiply regexp structures for similar regexps */
+       if ((check = (struct rspamd_regexp *)re_cache_check (begin)) != NULL) {
+               /* Additional check for headers */
+               if (result->type == REGEXP_HEADER || result->type == REGEXP_RAW_HEADER) {
+                       if (result->header && check->header) {
+                               if (strcmp (result->header, check->header) == 0) {
+                                       return check;
+                               }
+                       }
+               }
+               else {
+                       return check;
+               }
+       }
        result->regexp = g_regex_new (begin, regexp_flags, 0, &err);
        result->regexp_text = memory_pool_strdup (pool, begin);
        memory_pool_add_destructor (pool, (pool_destruct_func)g_regex_unref, (void *)result->regexp);
@@ -623,7 +638,9 @@ parse_regexp (memory_pool_t *pool, char *line)
                msg_warn ("parse_regexp: could not read regexp: %s while reading regexp %s", err->message, src);
                return NULL;
        }
-
+       
+       /* Add to cache for further usage */
+       re_cache_add (result->regexp_text, result);
        return result;
 }