aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-01-11 12:08:48 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-01-11 12:08:48 +0000
commit4784b2685577df0f0e1263d024dc073e571b0328 (patch)
tree15ba57461ab5d9e8728d14a8949aeefbc62709e7
parentffa5f89df58beee17955ff5699e1863b73ed1a42 (diff)
downloadrspamd-4784b2685577df0f0e1263d024dc073e571b0328.tar.gz
rspamd-4784b2685577df0f0e1263d024dc073e571b0328.zip
[Fix] Fix adding maps from config in Lua
-rw-r--r--src/lua/global_functions.lua97
1 files changed, 56 insertions, 41 deletions
diff --git a/src/lua/global_functions.lua b/src/lua/global_functions.lua
index e89a5da64..750516190 100644
--- a/src/lua/global_functions.lua
+++ b/src/lua/global_functions.lua
@@ -429,59 +429,74 @@ function rspamd_map_add(mname, optname, mtype, description)
-- it might be plain map or map of plain elements
if opt[1] then
if mtype == 'radix' then
- local map = rspamd_config:radix_from_config(mname, optname)
+ if string.find(opt[1], '^%d') then
+ local map = rspamd_config:radix_from_config(mname, optname)
+
+ if map then
+ ret.__data = map
+ setmetatable(ret, ret_mt)
+ return ret
+ end
+ else
+ -- Plain table
+ local map = rspamd_config:add_map{
+ type = mtype,
+ description = description,
+ url = opt,
+ }
+ if map then
+ ret.__data = map
+ setmetatable(ret, ret_mt)
+ return ret
+ end
+ end
+ elseif mtype == 'regexp' then
+ -- Plain table
+ local map = rspamd_config:add_map{
+ type = mtype,
+ description = description,
+ url = opt,
+ }
if map then
ret.__data = map
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
- logger.errx(rspamd_config, "cannot create regexp from '%s'", elt)
- end
+ else
+ if string.find(opt[1], '^/%a') or string.find(opt[1], '^http') then
+ -- Plain table
+ local map = rspamd_config:add_map{
+ type = mtype,
+ description = description,
+ url = opt,
+ }
+ if map then
+ ret.__data = map
+ setmetatable(ret, ret_mt)
+ return ret
end
- end
-
- if #data > 0 then
- ret.__data = data
- ret.get_key = function(t, k)
- for _,re in ipairs(t.__data) do
- if re:match(k) then return true end
+ else
+ local data = {}
+ local nelts = 0
+ for _,elt in ipairs(opt) do
+ if type(elt) == 'string' then
+ data[elt] = true
+ nelts = nelts + 1
end
-
- return nil
- end
- return ret
- end
- else
- local data = {}
- local nelts = 0
- for _,elt in ipairs(opt) do
- if type(elt) == 'string' then
- data[elt] = true
- nelts = nelts + 1
end
- end
- if nelts > 0 then
- ret.__data = data
- ret.get_key = function(t, k)
- if k ~= '__data' then
- return t.__data[k]
- end
+ if nelts > 0 then
+ ret.__data = data
+ ret.get_key = function(t, k)
+ if k ~= '__data' then
+ return t.__data[k]
+ end
- return nil
+ return nil
+ end
+ return ret
end
- return ret
end
end
else