diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-19 13:41:12 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-19 13:41:12 +0100 |
commit | f7a044a1cb297b891af84e6cefae32217e97c300 (patch) | |
tree | ec6aa8043f7899f8a0d54f54261edffef2430ae8 /lualib/lua_maps.lua | |
parent | eed0d9aaf9c1a495ce96da86db0d65aa056c002f (diff) | |
download | rspamd-f7a044a1cb297b891af84e6cefae32217e97c300.tar.gz rspamd-f7a044a1cb297b891af84e6cefae32217e97c300.zip |
[Feature] Lua_maps: Allow static maps for key-value pairs
Diffstat (limited to 'lualib/lua_maps.lua')
-rw-r--r-- | lualib/lua_maps.lua | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lualib/lua_maps.lua b/lualib/lua_maps.lua index 6b1a37590..6b478ded8 100644 --- a/lualib/lua_maps.lua +++ b/lualib/lua_maps.lua @@ -206,14 +206,30 @@ local function rspamd_map_add_from_ucl(opt, mtype, description) else local data = {} local nelts = 0 + -- Plain array of keys, count merely numeric elts for _,elt in ipairs(opt) do if type(elt) == 'string' then - data[elt] = true + -- Numeric table + if mtype == 'hash' then + -- Treat as KV pair + local lua_util = require "lua_util" + local pieces = lua_util.str_split(elt, ' ') + if #pieces > 1 then + local key = table.remove(pieces, 1) + data[key] = table.concat(pieces, ' ') + else + data[elt] = true + end + else + data[elt] = true + end + nelts = nelts + 1 end end if nelts > 0 then + -- Plain Lua table that is used as a map ret.__data = data ret.get_key = function(t, k) if k ~= '__data' then @@ -222,11 +238,17 @@ local function rspamd_map_add_from_ucl(opt, mtype, description) return nil end + return ret + else + -- Empty map, huh? + rspamd_logger.errx(rspamd_config, 'invalid map element: %s', + opt) end end end else + -- We have some non-trivial object so let C code to deal with it somehow... local map = rspamd_config:add_map{ type = mtype, description = description, @@ -237,7 +259,7 @@ local function rspamd_map_add_from_ucl(opt, mtype, description) setmetatable(ret, ret_mt) return ret end - end + end -- opt[1] end return nil |