aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-28 13:21:02 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-28 13:21:02 +0100
commitf7d54ff789833242766d565c79ea2e0d174dde45 (patch)
tree8aca1a013f403b6504604a3a0758a35247bd38cf
parenta109540436f05ea4e67c50b4a2517023bd6b144b (diff)
downloadrspamd-f7d54ff789833242766d565c79ea2e0d174dde45.tar.gz
rspamd-f7d54ff789833242766d565c79ea2e0d174dde45.zip
[Feature] Add universal function to parse redis servers for plugins
-rw-r--r--src/lua/global_functions.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/lua/global_functions.lua b/src/lua/global_functions.lua
index e69de29bb..833832188 100644
--- a/src/lua/global_functions.lua
+++ b/src/lua/global_functions.lua
@@ -0,0 +1,56 @@
+
+-- This function parses redis server definition using either
+-- specific server string for this module or global
+-- redis section
+function rspamd_parse_redis_server(module_name)
+
+ local default_port = 6379
+ local logger = require "rspamd_logger"
+
+ local function try_load_redis_servers(options)
+ local key = options['servers']
+
+ if not key then key = options['server'] end
+
+ if key then
+ local upstreams = upstream_list.create(rspamd_config, key, default_port)
+
+ if upstreams then
+ return upstreams
+ end
+ end
+
+ return nil
+ end
+
+ local opts = rspamd_config:get_all_opt(module_name)
+ local ret
+
+ if opts then
+ ret = try_load_redis_servers(opts)
+ end
+
+ if ret then
+ return ret
+ end
+
+ opts = rspamd_config:get_all_opt('redis')
+
+ if opts then
+ if opts[module_name] then
+ ret = try_load_redis_servers(opts[module_name])
+ if ret then
+ return ret
+ end
+ else
+ ret = try_load_redis_servers(opts)
+
+ if ret then
+ logger.infox(rspamd_config, "using default redis server for module %s",
+ module_name)
+ end
+ end
+ end
+
+ return ret
+end