aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lua/spamassassin.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/lua/spamassassin.lua')
-rw-r--r--src/plugins/lua/spamassassin.lua41
1 files changed, 36 insertions, 5 deletions
diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua
index a752f67a5..62030e947 100644
--- a/src/plugins/lua/spamassassin.lua
+++ b/src/plugins/lua/spamassassin.lua
@@ -150,6 +150,37 @@ local function trim(s)
return s:match "^%s*(.-)%s*$"
end
+local ffi
+if type(jit) == 'table' then
+ ffi = require("ffi")
+ ffi.cdef[[
+ int rspamd_re_cache_type_from_string (const char *str);
+ int rspamd_re_cache_process_ffi (void *ptask,
+ void *pre,
+ int type,
+ const char *type_data,
+ int is_strong);
+]]
+end
+
+local function process_regexp_opt(re, task, re_type, header, strong)
+ if type(jit) == 'table' then
+ -- Use ffi call
+ local itype = ffi.C.rspamd_re_cache_type_from_string(re_type)
+
+ if not strong then
+ strong = 0
+ else
+ string = 1
+ end
+ local iret = ffi.C.rspamd_re_cache_process_ffi (task, re, itype, header, strong)
+
+ return tonumber(iret)
+ else
+ return task:process_regexp(re, re_type, header, strong)
+ end
+end
+
local function is_pcre_only(name)
if pcre_only_regexps[name] then
return true
@@ -185,7 +216,7 @@ local function handle_header_def(hline, cur_rule)
return 0
end
- return task:process_regexp(re, 'allheader')
+ return process_regexp_opt(re, task, 'allheader')
end
else
local args = split(h, '[^:]+')
@@ -1218,7 +1249,7 @@ local function post_process()
return 0
end
- local ret = task:process_regexp(r['re'], t, h['header'], h['strong'])
+ local ret = process_regexp_opt(r.re, task, t, h.header, h.strong)
if r['not'] then
if ret ~= 0 then
@@ -1345,7 +1376,7 @@ local function post_process()
local t = 'mime'
if r['raw'] then t = 'rawmime' end
- return task:process_regexp(r['re'], t)
+ return process_regexp_opt(r.re, task, t)
end
if r['score'] then
local real_score = r['score'] * calculate_score(k, r)
@@ -1369,7 +1400,7 @@ local function post_process()
local t = r['type']
- local ret = task:process_regexp(r['re'], t)
+ local ret = process_regexp_opt(r.re, task, t)
return ret
end
if r['score'] then
@@ -1392,7 +1423,7 @@ local function post_process()
return 0
end
- return task:process_regexp(r['re'], 'url')
+ return process_regexp_opt(r.re, task, 'url')
end
if r['score'] then
local real_score = r['score'] * calculate_score(k, r)