diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-09-02 13:44:04 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-09-02 13:44:04 +0100 |
commit | dc3fd1d5f97aa70c8c0429ea4958792031b4976a (patch) | |
tree | ba64e2d875199e2faf145915edadcc6732cc3163 /lualib | |
parent | d3f6d9088865aa2605e1c084861a6aa3e44ea154 (diff) | |
download | rspamd-dc3fd1d5f97aa70c8c0429ea4958792031b4976a.tar.gz rspamd-dc3fd1d5f97aa70c8c0429ea4958792031b4976a.zip |
[Feature] Allow to use global lua maps in settings
Issue: #1802
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/maps.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lualib/maps.lua b/lualib/maps.lua index 3cd01dcfe..917c6ca8e 100644 --- a/lualib/maps.lua +++ b/lualib/maps.lua @@ -131,4 +131,35 @@ end exports.rspamd_map_add = rspamd_map_add +-- Check `what` for being lua_map name, otherwise just compares key with what +local function rspamd_maybe_check_map(key, what) + local fun = require "fun" + + local function starts(where,st) + return string.sub(where,1,string.len(st))==st + end + + if type(what) == "table" then + return fun.any(function(elt) return rspamd_maybe_check_map(key, elt) end, what) + end + if type(rspamd_maps) == "table" then + local mn + if starts(what, "map:") then + mn = string.sub(what, 4) + elseif starts(what, "map://") then + mn = string.sub(what, 6) + end + + if mn and rspamd_maps[mn] then + return rspamd_maps[mn]:get_key(key) + end + else + return what:lower() == key + end + + return false +end + +exports.rspamd_maybe_check_map = rspamd_maybe_check_map + return exports |