From: Vsevolod Stakhov Date: Thu, 24 Nov 2016 12:14:39 +0000 (+0000) Subject: [Fix] Add handling of regexp maps X-Git-Tag: 1.4.1~80 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a1cc7d879c128fe0ff23614dc4e4bc774b69a754;p=rspamd.git [Fix] Add handling of regexp maps --- 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