]> source.dussan.org Git - rspamd.git/commitdiff
Fix multiple regexp in the cache for lua API
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Dec 2015 16:59:33 +0000 (16:59 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Dec 2015 16:59:33 +0000 (16:59 +0000)
src/libserver/re_cache.c
src/lua/lua_config.c

index 3174465bde62d6a7dd626267abc4b947542f230b..6b86dc9e0b7a0bee67cc21a04020d6eae8e6f060 100644 (file)
@@ -316,7 +316,6 @@ rspamd_re_cache_init (struct rspamd_re_cache *cache, struct rspamd_config *cfg)
                re_class = rspamd_regexp_get_class (re);
                g_assert (re_class != NULL);
                rspamd_regexp_set_cache_id (re, i);
-               msg_info_re_cache ("HUI: %d -> %s", i, rspamd_regexp_get_pattern (re));
 
                if (re_class->st == NULL) {
                        re_class->st = g_slice_alloc (sizeof (*re_class->st));
@@ -1143,7 +1142,6 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache,
                        else {
                                hs_ids[i] = rspamd_regexp_get_cache_id (re);
                                hs_pats[i] = rspamd_regexp_get_pattern (re);
-                               msg_info_re_cache("HUI: %d -> %s", hs_ids[i], hs_pats[i]);
                                i ++;
                                hs_free_database (test_db);
                        }
index 447125a87806cd981a7da08999a5d302bcd45813..f867cfabe5563ae558a39df018e1971f3bc55f6c 100644 (file)
@@ -1564,6 +1564,7 @@ lua_config_register_regexp (lua_State *L)
 {
        struct rspamd_config *cfg = lua_check_config (L, 1);
        struct rspamd_lua_regexp *re = NULL;
+       rspamd_regexp_t *cache_re;
        const gchar *type_str = NULL, *header_str = NULL;
        gsize header_len = 0;
        GError *err = NULL;
@@ -1613,8 +1614,25 @@ lua_config_register_regexp (lua_State *L)
                                        header_len = strlen (header_str) + 1;
                                }
 
-                               rspamd_re_cache_add (cfg->re_cache, re->re, type,
+                               cache_re = rspamd_re_cache_add (cfg->re_cache, re->re, type,
                                                (gpointer) header_str, header_len);
+
+                               /*
+                                * XXX: here are dragons!
+                                * Actually, lua regexp contains internal rspamd_regexp_t
+                                * and it owns it.
+                                * However, after this operation we have some OTHER regexp,
+                                * which we really would like to use.
+                                * So we do the following:
+                                * 1) Remove old re and unref it
+                                * 2) Replace the internal re with cached one
+                                * 3) Increase its refcount to share ownership between cache and
+                                *   lua object
+                                */
+                               if (cache_re != re->re) {
+                                       rspamd_regexp_unref (re->re);
+                                       re->re = rspamd_regexp_ref (cache_re);
+                               }
                        }
                }
        }