Module: sip-router
Branch: master
Commit: ca5e3d93e3f117651d2152dccdfd4c299bf7f508
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ca5e3d9…
Author: Vicente Hernando <vhernando(a)systemonenoc.com>
Committer: Vicente Hernando <vhernando(a)systemonenoc.com>
Date: Tue Jul 10 05:48:45 2012 -0400
ndb_redis: redis_cmd changed into a variadic function.
- command string can be split into several strings.
---
modules/ndb_redis/ndb_redis_mod.c | 65 ++++++++++++++++++++++++++++---------
modules/ndb_redis/redis_client.c | 24 +++++++++----
modules/ndb_redis/redis_client.h | 3 +-
3 files changed, 66 insertions(+), 26 deletions(-)
diff --git a/modules/ndb_redis/ndb_redis_mod.c b/modules/ndb_redis/ndb_redis_mod.c
index c1f2b13..ecce4e9 100644
--- a/modules/ndb_redis/ndb_redis_mod.c
+++ b/modules/ndb_redis/ndb_redis_mod.c
@@ -161,7 +161,7 @@ static int w_redis_cmd3(struct sip_msg* msg, char* ssrv, char* scmd,
char* sres)
return -1;
}
- if(redisc_exec(&s[0], &s[1], NULL, NULL, NULL, &s[2])<0)
+ if(redisc_exec(&s[0], &s[2], &s[1])<0)
return -1;
return 1;
}
@@ -172,7 +172,9 @@ static int w_redis_cmd3(struct sip_msg* msg, char* ssrv, char* scmd,
char* sres)
static int w_redis_cmd4(struct sip_msg* msg, char* ssrv, char* scmd,
char *sargv1, char* sres)
{
- str s[4];
+ str s[3];
+ str arg1;
+ char c1;
if(fixup_get_svalue(msg, (gparam_t*)ssrv, &s[0])!=0)
{
@@ -184,19 +186,24 @@ static int w_redis_cmd4(struct sip_msg* msg, char* ssrv, char*
scmd,
LM_ERR("no redis command\n");
return -1;
}
- if(fixup_get_svalue(msg, (gparam_t*)sargv1, &s[2])!=0)
+ if(fixup_get_svalue(msg, (gparam_t*)sargv1, &arg1)!=0)
{
LM_ERR("no argument 1\n");
return -1;
}
- if(fixup_get_svalue(msg, (gparam_t*)sres, &s[3])!=0)
+ if(fixup_get_svalue(msg, (gparam_t*)sres, &s[2])!=0)
{
LM_ERR("no redis reply name\n");
return -1;
}
- if(redisc_exec(&s[0], &s[1], &s[2], NULL, NULL, &s[3])<0)
+ c1 = arg1.s[arg1.len];
+ arg1.s[arg1.len] = '\0';
+ if(redisc_exec(&s[0], &s[2], &s[1], arg1.s)<0) {
+ arg1.s[arg1.len] = c1;
return -1;
+ }
+ arg1.s[arg1.len] = c1;
return 1;
}
@@ -206,7 +213,9 @@ static int w_redis_cmd4(struct sip_msg* msg, char* ssrv, char* scmd,
static int w_redis_cmd5(struct sip_msg* msg, char* ssrv, char* scmd,
char *sargv1, char *sargv2, char* sres)
{
- str s[5];
+ str s[3];
+ str arg1, arg2;
+ char c1, c2;
if(fixup_get_svalue(msg, (gparam_t*)ssrv, &s[0])!=0)
{
@@ -218,24 +227,33 @@ static int w_redis_cmd5(struct sip_msg* msg, char* ssrv, char*
scmd,
LM_ERR("no redis command\n");
return -1;
}
- if(fixup_get_svalue(msg, (gparam_t*)sargv1, &s[2])!=0)
+ if(fixup_get_svalue(msg, (gparam_t*)sargv1, &arg1)!=0)
{
LM_ERR("no argument 1\n");
return -1;
}
- if(fixup_get_svalue(msg, (gparam_t*)sargv2, &s[3])!=0)
+ if(fixup_get_svalue(msg, (gparam_t*)sargv2, &arg2)!=0)
{
LM_ERR("no argument 2\n");
return -1;
}
- if(fixup_get_svalue(msg, (gparam_t*)sres, &s[4])!=0)
+ if(fixup_get_svalue(msg, (gparam_t*)sres, &s[2])!=0)
{
LM_ERR("no redis reply name\n");
return -1;
}
- if(redisc_exec(&s[0], &s[1], &s[2], &s[3], NULL, &s[4])<0)
+ c1 = arg1.s[arg1.len];
+ c2 = arg2.s[arg2.len];
+ arg1.s[arg1.len] = '\0';
+ arg2.s[arg2.len] = '\0';
+ if(redisc_exec(&s[0], &s[2], &s[1], arg1.s, arg2.s)<0) {
+ c1 = arg1.s[arg1.len];
+ c2 = arg2.s[arg2.len];
return -1;
+ }
+ c1 = arg1.s[arg1.len];
+ c2 = arg2.s[arg2.len];
return 1;
}
@@ -245,7 +263,9 @@ static int w_redis_cmd5(struct sip_msg* msg, char* ssrv, char* scmd,
static int w_redis_cmd6(struct sip_msg* msg, char* ssrv, char* scmd,
char *sargv1, char *sargv2, char *sargv3, char* sres)
{
- str s[6];
+ str s[3];
+ str arg1, arg2, arg3;
+ char c1, c2, c3;
if(fixup_get_svalue(msg, (gparam_t*)ssrv, &s[0])!=0)
{
@@ -257,29 +277,42 @@ static int w_redis_cmd6(struct sip_msg* msg, char* ssrv, char*
scmd,
LM_ERR("no redis command\n");
return -1;
}
- if(fixup_get_svalue(msg, (gparam_t*)sargv1, &s[2])!=0)
+ if(fixup_get_svalue(msg, (gparam_t*)sargv1, &arg1)!=0)
{
LM_ERR("no argument 1\n");
return -1;
}
- if(fixup_get_svalue(msg, (gparam_t*)sargv2, &s[3])!=0)
+ if(fixup_get_svalue(msg, (gparam_t*)sargv2, &arg2)!=0)
{
LM_ERR("no argument 2\n");
return -1;
}
- if(fixup_get_svalue(msg, (gparam_t*)sargv3, &s[4])!=0)
+ if(fixup_get_svalue(msg, (gparam_t*)sargv3, &arg3)!=0)
{
LM_ERR("no argument 3\n");
return -1;
}
- if(fixup_get_svalue(msg, (gparam_t*)sres, &s[5])!=0)
+ if(fixup_get_svalue(msg, (gparam_t*)sres, &s[2])!=0)
{
LM_ERR("no redis reply name\n");
return -1;
}
- if(redisc_exec(&s[0], &s[1], &s[2], &s[3], &s[4], &s[5])<0)
+ c1 = arg1.s[arg1.len];
+ c2 = arg2.s[arg2.len];
+ c3 = arg3.s[arg3.len];
+ arg1.s[arg1.len] = '\0';
+ arg2.s[arg2.len] = '\0';
+ arg3.s[arg3.len] = '\0';
+ if(redisc_exec(&s[0], &s[2], &s[1], arg1.s, arg2.s, arg3.s)<0) {
+ c1 = arg1.s[arg1.len];
+ c2 = arg2.s[arg2.len];
+ c3 = arg3.s[arg3.len];
return -1;
+ }
+ c1 = arg1.s[arg1.len];
+ c2 = arg2.s[arg2.len];
+ c3 = arg3.s[arg3.len];
return 1;
}
diff --git a/modules/ndb_redis/redis_client.c b/modules/ndb_redis/redis_client.c
index 267c8f5..84e9e9e 100644
--- a/modules/ndb_redis/redis_client.c
+++ b/modules/ndb_redis/redis_client.c
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
+#include <stdarg.h>
#include "../../mem/mem.h"
#include "../../dprint.h"
@@ -310,23 +311,25 @@ err:
/**
*
*/
-int redisc_exec(str *srv, str *cmd, str *argv1, str *argv2, str *argv3,
- str *res)
+int redisc_exec(str *srv, str *res, str *cmd, ...)
{
redisc_server_t *rsrv=NULL;
redisc_reply_t *rpl;
char c;
+ va_list ap;
+
+ va_start(ap, cmd);
rsrv = redisc_get_server(srv);
if(srv==NULL || cmd==NULL || res==NULL)
{
LM_ERR("invalid parameters");
- return -1;
+ goto error_exec;
}
if(rsrv==NULL)
{
LM_ERR("no redis server found: %.*s\n", srv->len, srv->s);
- return -1;
+ goto error_exec;
}
if(rsrv->ctxRedis==NULL)
{
@@ -337,7 +340,7 @@ int redisc_exec(str *srv, str *cmd, str *argv1, str *argv2, str
*argv3,
if(rpl==NULL)
{
LM_ERR("no redis reply id found: %.*s\n", res->len, res->s);
- return -1;
+ goto error_exec;
}
if(rpl->rplRedis!=NULL)
{
@@ -347,19 +350,24 @@ int redisc_exec(str *srv, str *cmd, str *argv1, str *argv2, str
*argv3,
}
c = cmd->s[cmd->len];
cmd->s[cmd->len] = '\0';
- rpl->rplRedis = redisCommand(rsrv->ctxRedis, cmd->s);
+ rpl->rplRedis = redisvCommand(rsrv->ctxRedis, cmd->s, ap );
if(rpl->rplRedis == NULL)
{
/* null reply, reconnect and try again */
if(redisc_reconnect_server(rsrv)==0)
{
- rpl->rplRedis = redisCommand(rsrv->ctxRedis, cmd->s);
+ rpl->rplRedis = redisvCommand(rsrv->ctxRedis, cmd->s, ap);
}
}
cmd->s[cmd->len] = c;
+ va_end(ap);
return 0;
-}
+error_exec:
+ va_end(ap);
+ return -1;
+
+}
/**
*
diff --git a/modules/ndb_redis/redis_client.h b/modules/ndb_redis/redis_client.h
index f4d29f4..8aebe77 100644
--- a/modules/ndb_redis/redis_client.h
+++ b/modules/ndb_redis/redis_client.h
@@ -33,8 +33,7 @@
int redisc_init(void);
int redisc_destroy(void);
int redisc_add_server(char *spec);
-int redisc_exec(str *srv, str *cmd, str *argv1, str *argv2, str *argv3,
- str *res);
+int redisc_exec(str *srv, str *res, str *cmd, ...);
typedef struct redisc_server {
str *sname;