diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-11-24 12:14:39 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-11-24 12:14:39 +0000 |
commit | a1cc7d879c128fe0ff23614dc4e4bc774b69a754 (patch) | |
tree | 06c67749fa922c82959d7da6a73a7c606b2da609 /src | |
parent | e6b6f6bb9c0d29c261e2c4c9457b552b82317136 (diff) | |
download | rspamd-a1cc7d879c128fe0ff23614dc4e4bc774b69a754.tar.gz rspamd-a1cc7d879c128fe0ff23614dc4e4bc774b69a754.zip |
[Fix] Add handling of regexp maps
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/global_functions.lua | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/lua/global_functions.lua b/src/lua/global_functions.lua index 64f4f6b72..d3b84b4ea 100644 --- a/src/lua/global_functions.lua +++ b/src/lua/global_functions.lua @@ -436,17 +436,45 @@ function rspamd_map_add(mname, optname, mtype, description) setmetatable(ret, ret_mt) return ret end + elseif mtype == 'regexp' then + local data = {} + local rspamd_regexp = require "rspamd_regexp" + for _,elt in ipairs(opt) do + if type(elt) == 'string' then + local re = rspamd_regexp:create_cached(elt) + + if re then + table.insert(data, re) + else + local logger = require "rspamd_logger" + logger.errx(rspamd_config, "cannot create regexp from '%s'", elt) + end + end + end + + ret.__data = data + ret.get_key = function(t, k) + for _,re in ipairs(t.__data) do + if re:match(k) then return true end + end + + return nil + end else local data = {} for _,elt in ipairs(opt) do if type(elt) == 'string' then - data[elt] = '1' + data[elt] = true end end ret.__data = data ret.get_key = function(t, k) - return t.__data[k] + if k ~= '__data' then + return t.__data[k] + end + + return nil end end else |