]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Add ffi friendly version of process_regexp function
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 22 Sep 2016 11:48:41 +0000 (12:48 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 22 Sep 2016 11:48:41 +0000 (12:48 +0100)
src/libmime/mime_expressions.c
src/libserver/re_cache.c
src/libserver/re_cache.h
src/lua/lua_task.c

index 647e43f0e7de5ae6427e31bb113f3e6ba0716e45..bdf5644fd1fbdc489b8043afc77ac16f0ee4be4f 100644 (file)
@@ -806,7 +806,6 @@ rspamd_mime_expr_process_regexp (struct rspamd_regexp_atom *re,
 
        if (re->type == RSPAMD_RE_HEADER || re->type == RSPAMD_RE_RAWHEADER) {
                ret = rspamd_re_cache_process (task,
-                               task->re_rt,
                                re->regexp,
                                re->type,
                                re->header,
@@ -815,7 +814,6 @@ rspamd_mime_expr_process_regexp (struct rspamd_regexp_atom *re,
        }
        else {
                ret = rspamd_re_cache_process (task,
-                               task->re_rt,
                                re->regexp,
                                re->type,
                                NULL,
index 9719558f0127ba72607a50d95edd1a47f22818a6..c2ade15c52fd3f9269710f54166f71762f5ea78c 100644 (file)
@@ -22,6 +22,7 @@
 #include "libserver/cfg_file.h"
 #include "libutil/util.h"
 #include "libutil/regexp.h"
+#include "lua/lua_common.h"
 #ifdef WITH_HYPERSCAN
 #include "hs.h"
 #include "unix-std.h"
@@ -1050,7 +1051,6 @@ rspamd_re_cache_exec_re (struct rspamd_task *task,
 
 gint
 rspamd_re_cache_process (struct rspamd_task *task,
-               struct rspamd_re_runtime *rt,
                rspamd_regexp_t *re,
                enum rspamd_re_type type,
                gpointer type_data,
@@ -1060,9 +1060,11 @@ rspamd_re_cache_process (struct rspamd_task *task,
        guint64 re_id;
        struct rspamd_re_class *re_class;
        struct rspamd_re_cache *cache;
+       struct rspamd_re_runtime *rt;
 
-       g_assert (rt != NULL);
        g_assert (task != NULL);
+       rt = task->re_rt;
+       g_assert (rt != NULL);
        g_assert (re != NULL);
 
        cache = rt->cache;
@@ -1096,6 +1098,25 @@ rspamd_re_cache_process (struct rspamd_task *task,
        return 0;
 }
 
+int
+rspamd_re_cache_process_ffi (void *ptask,
+               void *pre,
+               int type,
+               void *type_data,
+               int is_strong)
+{
+       struct rspamd_lua_regexp **lua_re = pre;
+       struct rspamd_task **real_task = ptask;
+       gsize typelen = 0;
+
+       if (type_data) {
+               typelen = strlen (type_data);
+       }
+
+       return rspamd_re_cache_process (*real_task, (*lua_re)->re,
+                       type, type_data, typelen, is_strong);
+}
+
 void
 rspamd_re_cache_runtime_destroy (struct rspamd_re_runtime *rt)
 {
index 6b82fa7369a2ddf7efc77b61694e041b05d651cc..a138bcb4bd67a4faef148c12d96df505c2e6ce9d 100644 (file)
@@ -109,13 +109,18 @@ const struct rspamd_re_cache_stat *
  * @param is_strong use case sensitive match when looking for headers
  */
 gint rspamd_re_cache_process (struct rspamd_task *task,
-               struct rspamd_re_runtime *rt,
                rspamd_regexp_t *re,
                enum rspamd_re_type type,
                gpointer type_data,
                gsize datalen,
                gboolean is_strong);
 
+int rspamd_re_cache_process_ffi (void *ptask,
+               void *pre,
+               int type,
+               void *type_data,
+               int is_strong);
+
 /**
  * Destroy runtime data
  */
index 0c37f9e113636115aa55aad226c18307ec1c29aa..8c6a3473cdc1e776687d40ca59aa32536c72f4ae 100644 (file)
@@ -3072,7 +3072,7 @@ lua_task_process_regexp (lua_State *L)
                                                "header argument is mandatory for header/rawheader regexps");
                        }
                        else {
-                               ret = rspamd_re_cache_process (task, task->re_rt, re->re, type,
+                               ret = rspamd_re_cache_process (task, re->re, type,
                                                (gpointer) header_str, header_len, strong);
                        }
                }