]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Fix re cache replacement method
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 6 Dec 2015 13:55:59 +0000 (13:55 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 6 Dec 2015 13:55:59 +0000 (13:55 +0000)
src/libserver/re_cache.c
src/libserver/re_cache.h
src/lua/lua_config.c

index 7d3dea30ac41805cf6bf50567d94da9296c80712..1ba2a82344ff3be477fcdfe7b35c870b2b31d652 100644 (file)
@@ -138,6 +138,7 @@ rspamd_re_cache_add (struct rspamd_re_cache *cache, rspamd_regexp_t *re,
         * We set re id based on the global position in the cache
         */
        rspamd_regexp_set_cache_id (re, cache->nre ++);
+       rspamd_regexp_set_class (re, re_class);
        nre = rspamd_regexp_ref (re);
        g_hash_table_insert (re_class->re, nre, nre);
 }
@@ -145,12 +146,9 @@ rspamd_re_cache_add (struct rspamd_re_cache *cache, rspamd_regexp_t *re,
 void
 rspamd_re_cache_replace (struct rspamd_re_cache *cache,
                rspamd_regexp_t *what,
-               enum rspamd_re_type type,
-               gpointer type_data,
-               gsize datalen,
                rspamd_regexp_t *with)
 {
-       guint64 class_id, re_id;
+       guint64 re_id;
        struct rspamd_re_class *re_class;
        rspamd_regexp_t *src;
 
@@ -158,8 +156,7 @@ rspamd_re_cache_replace (struct rspamd_re_cache *cache,
        g_assert (what != NULL);
        g_assert (with != NULL);
 
-       class_id = rspamd_re_cache_class_id (type, type_data, datalen);
-       re_class = g_hash_table_lookup (cache->re_classes, &class_id);
+       re_class = rspamd_regexp_get_class (what);
 
        if (re_class != NULL) {
                re_id = rspamd_regexp_get_cache_id (what);
@@ -168,8 +165,12 @@ rspamd_re_cache_replace (struct rspamd_re_cache *cache,
                src = g_hash_table_lookup (re_class->re, what);
 
                if (src) {
+                       rspamd_regexp_set_cache_id (what, RSPAMD_INVALID_ID);
+                       rspamd_regexp_set_class (what, NULL);
+                       rspamd_regexp_set_cache_id (with, re_id);
+                       rspamd_regexp_set_class (with, re_class);
                        /*
-                        * On calling of this function, we actually unref old re
+                        * On calling of this function, we actually unref old re (what)
                         */
                        g_hash_table_insert (re_class->re, what, rspamd_regexp_ref (with));
                }
index 6f2c0f3121df7dc0091370f7b65ebe0f86440521..0ced10bd67118183f57f24bdb75372d76e1b8e5f 100644 (file)
@@ -59,16 +59,10 @@ void rspamd_re_cache_add (struct rspamd_re_cache *cache, rspamd_regexp_t *re,
  * Replace regexp in the cache with another regexp
  * @param cache cache object
  * @param what re to replace
- * @param type type of object
- * @param type_data associated data with the type (e.g. header name)
- * @param datalen associated data length
  * @param with regexp object to replace the origin
  */
 void rspamd_re_cache_replace (struct rspamd_re_cache *cache,
                rspamd_regexp_t *what,
-               enum rspamd_re_type type,
-               gpointer type_data,
-               gsize datalen,
                rspamd_regexp_t *with);
 
 /**
index 5743a5ad155afeba332d8e9a78d63488c0bcf96e..d495d0c9ec3b03e3781a5ff2868de9d8b5c1ea6f 100644 (file)
@@ -369,15 +369,8 @@ LUA_FUNCTION_DEF (config, register_regexp);
  * @method rspamd_config:replace_regexp(params)
  * Replaces regexp with a new one
  * Params is the table with the follwoing fields (mandatory fields are marked with `*`):
- * - `old_re`* : old regular expression object
- * - `new_re`* : old regular expression object
- * - `type`*: type of regular expression:
- *   + `mime`: mime regexp
- *   + `header`: header regexp
- *   + `rawheader`: raw header expression
- *   + `body`: raw body regexp
- *   + `url`: url regexp
- * - `header`: for header and rawheader regexp means the name of header
+ * - `old_re`* : old regular expression object (must be in the cache)
+ * - `new_re`* : old regular expression object (must not be in the cache)
  */
 LUA_FUNCTION_DEF (config, replace_regexp);
 
@@ -1631,15 +1624,12 @@ lua_config_replace_regexp (lua_State *L)
 {
        struct rspamd_config *cfg = lua_check_config (L, 1);
        struct rspamd_lua_regexp *old_re = NULL, *new_re = NULL;
-       const gchar *type_str = NULL, *header_str = NULL;
-       gsize header_len = 0;
        GError *err = NULL;
-       enum rspamd_re_type type = RSPAMD_RE_BODY;
 
        if (cfg != NULL) {
                if (!rspamd_lua_parse_table_arguments (L, 2, &err,
-                               "*old_re=U{regexp};*new_re=U{regexp};*type=S;header=V",
-                               &old_re, &new_re, &type_str, &header_len, &header_str)) {
+                               "*old_re=U{regexp};*new_re=U{regexp}",
+                               &old_re, &new_re)) {
                        msg_err_config ("cannot get parameters list: %e", err);
 
                        if (err) {
@@ -1647,31 +1637,7 @@ lua_config_replace_regexp (lua_State *L)
                        }
                }
                else {
-                       if (strcmp (type_str, "header") == 0) {
-                               type = RSPAMD_RE_HEADER;
-                       }
-                       else if (strcmp (type_str, "rawheader") == 0) {
-                               type = RSPAMD_RE_RAWHEADER;
-                       }
-                       else if (strcmp (type_str, "mime") == 0) {
-                               type = RSPAMD_RE_MIME;
-                       }
-                       else if (strcmp (type_str, "body") == 0) {
-                               type = RSPAMD_RE_BODY;
-                       }
-                       else if (strcmp (type_str, "url") == 0) {
-                               type = RSPAMD_RE_URL;
-                       }
-
-                       if ((type == RSPAMD_RE_HEADER || type == RSPAMD_RE_RAWHEADER)
-                                       && header_str == NULL) {
-                               msg_err_config (
-                                               "header argument is mandatory for header/rawheader regexps");
-                       }
-                       else {
-                               rspamd_re_cache_replace (cfg->re_cache, old_re->re,
-                                               type, (gpointer) header_str, header_len, new_re->re);
-                       }
+                       rspamd_re_cache_replace (cfg->re_cache, old_re->re, new_re->re);
                }
        }