summaryrefslogtreecommitdiffstats
path: root/src/lua/lua_redis.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-26 10:42:13 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-26 10:42:13 +0000
commit34a6bf56c735e54c5e8a8e4e34782bb83219c236 (patch)
treeb5f2216864dfc73f316f40af95cfdff3ab9b39fb /src/lua/lua_redis.c
parent252ac59dd93e12ab042217827e999c446db6b7e4 (diff)
downloadrspamd-34a6bf56c735e54c5e8a8e4e34782bb83219c236.tar.gz
rspamd-34a6bf56c735e54c5e8a8e4e34782bb83219c236.zip
Allow to set redis db and password in lua_redis
Diffstat (limited to 'src/lua/lua_redis.c')
-rw-r--r--src/lua/lua_redis.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c
index 4ef563782..4f09c3a96 100644
--- a/src/lua/lua_redis.c
+++ b/src/lua/lua_redis.c
@@ -383,6 +383,8 @@ lua_redis_connect_cb (const struct redisAsyncContext *c, int status)
#endif
}
+
+
/***
* @function rspamd_redis.make_request({params})
* Make request to redis server, params is a table of key=value arguments in any order
@@ -403,6 +405,7 @@ lua_redis_make_request (lua_State *L)
struct rspamd_lua_ip *addr = NULL;
struct rspamd_task *task = NULL;
const gchar *cmd = NULL, *host;
+ const gchar *password = NULL, *dbname = NULL;
gint top, cbref = -1;
struct timeval tv;
gboolean ret = FALSE;
@@ -467,6 +470,21 @@ lua_redis_make_request (lua_State *L)
}
lua_pop (L, 1);
+ lua_pushstring (L, "password");
+ lua_gettable (L, -2);
+ if (lua_type (L, -1) == LUA_TSTRING) {
+ password = lua_tostring (L, -1);
+ }
+ lua_pop (L, 1);
+
+ lua_pushstring (L, "dbname");
+ lua_gettable (L, -2);
+ if (lua_type (L, -1) == LUA_TSTRING) {
+ dbname = lua_tostring (L, -1);
+ }
+ lua_pop (L, 1);
+
+
if (task != NULL && addr != NULL && cbref != -1 && cmd != NULL) {
ctx = g_slice_alloc0 (sizeof (struct lua_redis_ctx));
REF_INIT_RETAIN (ctx, lua_redis_dtor);
@@ -542,6 +560,14 @@ lua_redis_make_request (lua_State *L)
redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb);
redisLibeventAttach (ud->ctx, ud->task->ev_base);
+
+ if (password) {
+ redisAsyncCommand (ud->ctx, NULL, NULL, "AUTH %s", password);
+ }
+ if (dbname) {
+ redisAsyncCommand (ud->ctx, NULL, NULL, "SELECT %s", dbname);
+ }
+
ret = redisAsyncCommandArgv (ud->ctx,
lua_redis_callback,
ctx,