]> source.dussan.org Git - rspamd.git/commitdiff
Fix cache usage for rspamd_regexp.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 7 Mar 2015 22:46:13 +0000 (22:46 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 7 Mar 2015 22:46:13 +0000 (22:46 +0000)
src/libmime/expressions.c

index aab78df5c4f501c12cc0f9863b19384226b3701e..547cc0d589f166f909658803351bdb744854aca0 100644 (file)
@@ -653,6 +653,7 @@ parse_regexp (rspamd_mempool_t * pool, const gchar *line, gboolean raw_mode)
        const gchar *begin, *end, *p, *src, *start;
        gchar *dbegin, *dend;
        struct rspamd_regexp_element *result;
+       rspamd_regexp_t *re;
        GError *err = NULL;
        GString *re_flags;
 
@@ -661,6 +662,10 @@ parse_regexp (rspamd_mempool_t * pool, const gchar *line, gboolean raw_mode)
                return NULL;
        }
 
+       if ((re = rspamd_regexp_cache_query (NULL, line, NULL)) != NULL) {
+               return ((struct rspamd_regexp_element *)rspamd_regexp_get_ud (re));
+       }
+
        src = line;
        result = rspamd_mempool_alloc0 (pool, sizeof (struct rspamd_regexp_element));
        /* Skip whitespaces */
@@ -798,7 +803,7 @@ parse_regexp (rspamd_mempool_t * pool, const gchar *line, gboolean raw_mode)
                g_string_append_c (re_flags, 'r');
        }
 
-       result->regexp = rspamd_regexp_cache_create (NULL, dbegin, re_flags->str,
+       result->regexp = rspamd_regexp_new (dbegin, re_flags->str,
                        &err);
 
        g_string_free (re_flags, TRUE);
@@ -814,6 +819,10 @@ parse_regexp (rspamd_mempool_t * pool, const gchar *line, gboolean raw_mode)
                (rspamd_mempool_destruct_t) rspamd_regexp_unref,
                (void *)result->regexp);
 
+       rspamd_regexp_set_ud (result->regexp, result);
+
+       rspamd_regexp_cache_insert (NULL, line, NULL, result->regexp);
+
        *dend = '/';
 
        return result;