diff options
author | Andrew Lewis <nerf@judo.za.org> | 2017-06-10 15:45:29 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2017-06-10 15:45:29 +0200 |
commit | c30cfcb21a5d1b2fa14944ff3633198a95ea3c2d (patch) | |
tree | a947837bbd92ed3bdf4a22b54dd6b492e9500246 /lualib | |
parent | cd0cc6187ed4b153e3506bbf79d28aa760a85f4a (diff) | |
download | rspamd-c30cfcb21a5d1b2fa14944ff3633198a95ea3c2d.tar.gz rspamd-c30cfcb21a5d1b2fa14944ff3633198a95ea3c2d.zip |
[Feature] Bayes expiry plugin
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/lua_redis.lua | 11 | ||||
-rw-r--r-- | lualib/lua_util.lua | 10 |
2 files changed, 19 insertions, 2 deletions
diff --git a/lualib/lua_redis.lua b/lualib/lua_redis.lua index 42a0aacef..0dc5872fe 100644 --- a/lualib/lua_redis.lua +++ b/lualib/lua_redis.lua @@ -5,7 +5,7 @@ local exports = {} -- This function parses redis server definition using either -- specific server string for this module or global -- redis section -local function rspamd_parse_redis_server(module_name) +local function rspamd_parse_redis_server(module_name, module_opts, no_fallback) local result = {} local default_port = 6379 @@ -71,7 +71,12 @@ local function rspamd_parse_redis_server(module_name) end -- Try local options - local opts = rspamd_config:get_all_opt(module_name) + local opts + if not module_opts then + opts = rspamd_config:get_all_opt(module_name) + else + opts = module_opts + end local ret = false if opts then @@ -82,6 +87,8 @@ local function rspamd_parse_redis_server(module_name) return result end + if no_fallback then return nil end + -- Try global options opts = rspamd_config:get_all_opt('redis') diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 0a824dca1..1f53d51ed 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -30,4 +30,14 @@ exports.round = function(num, numDecimalPlaces) return math.floor(num * mult) / mult end +exports.template = function(tmpl, keys) + local var_lit = lpeg.P { lpeg.R("az") + lpeg.R("AZ") + lpeg.R("09") + "_" } + local var = lpeg.P { (lpeg.P("$") / "") * ((var_lit^1) / keys) } + local var_braced = lpeg.P { (lpeg.P("${") / "") * ((var_lit^1) / keys) * (lpeg.P("}") / "") } + + local template_grammar = lpeg.Cs((var + var_braced + 1)^0) + + return lpeg.match(template_grammar, tmpl) +end + return exports |