diff --git a/daemon/Makefile b/daemon/Makefile index b4aa39b..81b1637 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -1,14 +1,9 @@ -REDIS=yes - CC= gcc CFLAGS= -g -Wall `pkg-config --cflags glib-2.0` `pcre-config --cflags` -fno-strict-aliasing CFLAGS+= -I/lib/modules/`uname -r`/build/include/ -I../kernel-module/ CFLAGS+= -D_GNU_SOURCE CFLAGS+= -DMEDIAPROXY_VERSION="\"$(shell dpkg-parsechangelog -l../debian/changelog | awk '/^Version: / {print $$2}')\"" - -ifneq ($(REDIS),yes) -CFLAGS+= -DNO_REDIS=1 -endif +CFLAGS+= -DMP_PLUGIN_DIR="\"/usr/lib/mediaproxy-ng\"" ifeq ($(DBG),yes) CFLAGS+= -D__DEBUG=1 @@ -18,27 +13,17 @@ endif LDFLAGS= `pkg-config --libs glib-2.0` `pcre-config --libs` LDFLAGS+= `xmlrpc-c-config client --libs` +LDFLAGS+= -ldl -rdynamic -ifeq ($(REDIS),yes) -LDFLAGS+= -lhiredis -luuid -endif - -SRCS= main.c kernel.c poller.c aux.c control.c streambuf.c call.c control_udp.c -ifeq ($(REDIS),yes) -SRCS+= redis.c -endif - +SRCS= main.c kernel.c poller.c aux.c control.c streambuf.c call.c control_udp.c redis.c OBJS= $(SRCS:.c=.o) -.PHONY: all dep clean tests no-redis debug +.PHONY: all dep clean tests debug all: $(MAKE) mediaproxy-ng -no-redis: - $(MAKE) REDIS=no all - debug: $(MAKE) DBG=yes all diff --git a/daemon/call.c b/daemon/call.c index 60a3366..7edfdf7 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -8,9 +8,6 @@ #include #include #include -#ifndef NO_REDIS -#include -#endif #include #include #include @@ -22,9 +19,8 @@ #include "kernel.h" #include "control.h" #include "streambuf.h" -#ifndef NO_REDIS #include "redis.h" -#endif +#include "xt_MEDIAPROXY.h" @@ -101,7 +97,7 @@ static void stream_closed(int fd, void *p) { -static void kernelize(struct callstream *c) { +void kernelize(struct callstream *c) { int i, j; struct peer *p, *pp; struct streamrelay *r, *rp; @@ -224,9 +220,8 @@ static int stream_packet(struct streamrelay *r, char *b, int l, struct sockaddr_ if (pe->confirmed && pe2->confirmed && pe2->filled) kernelize(cs); -#ifndef NO_REDIS - redis_update(c); -#endif + if (redis_update) + redis_update(c); } skip: @@ -572,7 +567,9 @@ static void callmaster_timer(void *ptr) { if (ke->stats.packets != sr->kstats.packets) sr->last = po->now; - memcpy(&sr->kstats, &ke->stats, sizeof(sr->kstats)); + sr->kstats.packets = ke->stats.packets; + sr->kstats.bytes = ke->stats.bytes; + sr->kstats.errors = ke->stats.errors; next: g_slice_free1(sizeof(*ke), ke); @@ -885,7 +882,7 @@ static void steal_peer(struct peer *dest, struct peer *src) { } -static void callstream_init(struct callstream *s, struct call *ca, int port1, int port2, int num) { +void callstream_init(struct callstream *s, struct call *ca, int port1, int port2, int num) { int i, j, tport; struct peer *p; struct streamrelay *r; @@ -1159,9 +1156,8 @@ static void call_destroy(struct call *c) { g_hash_table_remove(m->callhash, c->callid); -#ifndef NO_REDIS - redis_delete(c); -#endif + if (redis_delete) + redis_delete(c); free(c->callid); g_hash_table_destroy(c->infohash); @@ -1278,7 +1274,7 @@ static struct call *call_create(const char *callid, struct callmaster *m) { return c; } -static struct call *call_get_or_create(const char *callid, const char *viabranch, struct callmaster *m) { +struct call *call_get_or_create(const char *callid, const char *viabranch, struct callmaster *m) { struct call *c; c = g_hash_table_lookup(m->callhash, callid); @@ -1359,9 +1355,8 @@ char *call_update_udp(const char **out, struct callmaster *m) { g_queue_clear(&q); -#ifndef NO_REDIS - redis_update(c); -#endif + if (redis_update) + redis_update(c); ret = streams_print(c->callstreams, 1, (num >= 0) ? 0 : 1, out[RE_UDP_COOKIE], 1); mylog(LOG_INFO, LOG_PREFIX_CI "Returning to SIP proxy: %s", LOG_PARAMS_CI(c), ret); @@ -1401,9 +1396,8 @@ char *call_lookup_udp(const char **out, struct callmaster *m) { g_queue_clear(&q); -#ifndef NO_REDIS - redis_update(c); -#endif + if (redis_update) + redis_update(c); ret = streams_print(c->callstreams, 1, (num >= 0) ? 1 : 0, out[RE_UDP_COOKIE], 1); mylog(LOG_INFO, LOG_PREFIX_CI "Returning to SIP proxy: %s", LOG_PARAMS_CI(c), ret); @@ -1431,9 +1425,8 @@ char *call_request(const char **out, struct callmaster *m) { num = call_streams(c, s, g_hash_table_lookup(c->infohash, "fromtag"), 0); streams_free(s); -#ifndef NO_REDIS - redis_update(c); -#endif + if (redis_update) + redis_update(c); ret = streams_print(c->callstreams, abs(num), (num >= 0) ? 0 : 1, NULL, 0); mylog(LOG_INFO, LOG_PREFIX_CI "Returning to SIP proxy: %s", LOG_PARAMS_CI(c), ret); @@ -1458,9 +1451,8 @@ char *call_lookup(const char **out, struct callmaster *m) { num = call_streams(c, s, g_hash_table_lookup(c->infohash, "totag"), 1); streams_free(s); -#ifndef NO_REDIS - redis_update(c); -#endif + if (redis_update) + redis_update(c); ret = streams_print(c->callstreams, abs(num), (num >= 0) ? 1 : 0, NULL, 0); mylog(LOG_INFO, LOG_PREFIX_CI "Returning to SIP proxy: %s", LOG_PARAMS_CI(c), ret); @@ -1625,73 +1617,11 @@ void calls_status(struct callmaster *m, struct control_stream *s) { -#ifndef NO_REDIS -void call_restore(struct callmaster *m, char *uuid, redisReply **hash, GList *streams, redisReply *branches) { - struct call *c; - struct callstream *cs; - redisReply *rps[2], *rp; - int i, kernel; - struct peer *p; - u_int32_t ipv4; - - c = call_get_or_create(hash[0]->str, NULL, m); - strcpy(c->redis_uuid, uuid); - c->created = strtoll(hash[1]->str, NULL, 10); - strdupfree(&c->calling_agent, "UNKNOWN(recovered)"); - strdupfree(&c->called_agent, "UNKNOWN(recovered)"); - - for (; streams; streams = streams->next) { - rps[0] = streams->data; - streams = streams->next; - rps[1] = streams->data; - - cs = g_slice_alloc(sizeof(*cs)); - callstream_init(cs, c, atoi(rps[0]->element[2]->str), atoi(rps[1]->element[2]->str), -1); /* XXX */ - kernel = 0; - - for (i = 0; i < 2; i++) { - p = &cs->peers[i]; - rp = rps[i]; - - if (inet_pton(AF_INET6, rp->element[0]->str, &p->rtps[0].peer.ip46) != 1) { - ipv4 = inet_addr(rp->element[0]->str); - if (ipv4 == -1) - continue; - in4_to_6(&p->rtps[0].peer.ip46, ipv4); - } - p->rtps[1].peer.ip46 = p->rtps[0].peer.ip46; - p->rtps[0].peer.port = atoi(rp->element[1]->str); - p->rtps[1].peer.port = p->rtps[0].peer.port + 1; - strdupfree(&p->tag, rp->element[6]->str); - kernel = atoi(rp->element[3]->str); - p->filled = atoi(rp->element[4]->str); - p->confirmed = atoi(rp->element[5]->str); - } - - g_queue_push_tail(c->callstreams, cs); - - if (kernel) - kernelize(cs); - } - - if (branches) { - for (i = 0; i < branches->elements; i++) { - rp = branches->element[i]; - if (rp->type != REDIS_REPLY_STRING) - continue; - g_hash_table_insert(c->branches, strdup(rp->str), (void *) 0x1); - } - } -} - - - - - static void calls_dump_iterator(void *key, void *val, void *ptr) { struct call *c = val; - redis_update(c); + if (redis_update) + redis_update(c); } void calls_dump_redis(struct callmaster *m) { @@ -1703,4 +1633,3 @@ void calls_dump_redis(struct callmaster *m) { g_hash_table_foreach(m->callhash, calls_dump_iterator, NULL); mylog(LOG_DEBUG, "Finished dumping all call data to Redis\n"); } -#endif diff --git a/daemon/call.h b/daemon/call.h index f26d917..c41dff3 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -6,11 +6,7 @@ #include #include -#ifndef NO_REDIS -#include -#endif #include -#include "xt_MEDIAPROXY.h" #include "control.h" #include "control_udp.h" @@ -24,13 +20,17 @@ struct peer; struct callstream; struct call; struct callmaster; -#ifndef NO_REDIS struct redis; -#endif +struct stats { + u_int64_t packets; + u_int64_t bytes; + u_int64_t errors; +}; + struct stream { struct in6_addr ip46; u_int16_t port; @@ -50,8 +50,8 @@ struct streamrelay { u_int16_t localport; unsigned char idx; struct peer *up; - struct mediaproxy_stats stats; - struct mediaproxy_stats kstats; + struct stats stats; + struct stats kstats; time_t last; }; struct peer { @@ -78,9 +78,7 @@ struct call { GQueue *callstreams; char *callid; -#ifndef NO_REDIS char redis_uuid[37]; -#endif time_t created; char *calling_agent; char *called_agent; @@ -94,13 +92,11 @@ struct call { struct callmaster { GHashTable *callhash; u_int16_t lastport; - struct mediaproxy_stats statsps; - struct mediaproxy_stats stats; + struct stats statsps; + struct stats stats; struct poller *poller; -#ifndef NO_REDIS struct redis *redis; -#endif int kernelfd; unsigned int kernelid; u_int32_t ipv4; @@ -131,10 +127,11 @@ char *call_delete_udp(const char **, struct callmaster *); void calls_status(struct callmaster *, struct control_stream *); -#ifndef NO_REDIS -void call_restore(struct callmaster *, char *, redisReply **, GList *, redisReply *); void calls_dump_redis(struct callmaster *); -#endif + +struct call *call_get_or_create(const char *callid, const char *viabranch, struct callmaster *m); +void callstream_init(struct callstream *s, struct call *ca, int port1, int port2, int num); +void kernelize(struct callstream *c); diff --git a/daemon/main.c b/daemon/main.c index 1df2fb5..1c5fd3e 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "poller.h" #include "control.h" @@ -14,14 +15,17 @@ #include "log.h" #include "call.h" #include "kernel.h" -#ifndef NO_REDIS #include "redis.h" -#endif #define die(x...) do { fprintf(stderr, x); exit(-1); } while(0) +#define dlresolve(m,n) do { \ + n = dlsym(m, "mod_" #n); \ + if (!n) \ + die("Failed to resolve symbol from plugin: %s\n", #n); \ + } while(0) @@ -44,11 +48,9 @@ static int timeout; static int silent_timeout; static int port_min; static int port_max; -#ifndef NO_REDIS static u_int32_t redis_ip; static u_int16_t redis_port; static int redis_db = -1; -#endif static char *b2b_url; @@ -150,9 +152,7 @@ static void options(int *argc, char ***argv) { static char *adv_ipv6s; static char *listenps; static char *listenudps; -#ifndef NO_REDIS static char *redisps; -#endif static int version; static GOptionEntry e[] = { @@ -172,10 +172,8 @@ static void options(int *argc, char ***argv) { { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Don't fork to background", NULL }, { "port-min", 'm', 0, G_OPTION_ARG_INT, &port_min, "Lowest port to use for RTP", "INT" }, { "port-max", 'M', 0, G_OPTION_ARG_INT, &port_max, "Highest port to use for RTP", "INT" }, -#ifndef NO_REDIS { "redis", 'r', 0, G_OPTION_ARG_STRING, &redisps, "Connect to Redis database", "IP:PORT" }, { "redis-db", 'R', 0, G_OPTION_ARG_INT, &redis_db, "Which Redis DB to use", "INT" }, -#endif { "b2b-url", 'b', 0, G_OPTION_ARG_STRING, &b2b_url, "XMLRPC URL of B2B UA" , "STRING" }, { NULL, } }; @@ -232,14 +230,12 @@ static void options(int *argc, char ***argv) { if (silent_timeout <= 0) silent_timeout = 3600; -#ifndef NO_REDIS if (redisps) { if (parse_ip_port(&redis_ip, &redis_port, redisps) || !redis_ip) die("Invalid IP or port (--redis)\n"); if (redis_db < 0) die("Must specify Redis DB number (--redis-db) when using Redis\n"); } -#endif } @@ -274,6 +270,8 @@ int main(int argc, char **argv) { struct control_udp *cu; int kfd = -1; int ret; + void *dlh; + const char **strp; options(&argc, &argv); signals(); @@ -332,13 +330,24 @@ int main(int argc, char **argv) { die("Failed to open UDP control connection port\n"); } -#ifndef NO_REDIS if (redis_ip) { + dlh = dlopen(MP_PLUGIN_DIR "/redis.so", RTLD_NOW | RTLD_GLOBAL); + if (!dlh) + die("Failed to open redis plugin, aborting (%s)\n", dlerror()); + strp = dlsym(dlh, "__module_version"); + if (!strp || !*strp || strcmp(*strp, "redis/1.0.0")) + die("Incorrect redis module version: %s\n", *strp); + + dlresolve(dlh, redis_new); + dlresolve(dlh, redis_restore); + dlresolve(dlh, redis_update); + dlresolve(dlh, redis_delete); + dlresolve(dlh, redis_wipe); + m->redis = redis_new(redis_ip, redis_port, redis_db); if (!m->redis) die("Cannot start up without Redis database\n"); } -#endif mylog(LOG_INFO, "Startup complete"); @@ -346,12 +355,10 @@ int main(int argc, char **argv) { daemonize(); wpidfile(); -#ifndef NO_REDIS if (m->redis) { if (redis_restore(m)) die("Refusing to continue without working Redis database\n"); } -#endif for (;;) { ret = poller_poll(p, 100); diff --git a/daemon/redis.c b/daemon/redis.c index 234b47b..532c257 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -1,407 +1,7 @@ -#include -#include -#include -#include -#include -#include - #include "redis.h" -#include "aux.h" -#include "call.h" -#include "log.h" - - - - - - - -/* - -To fill the redis DB with expiring test data: - - num=3000 - db=1 - expire=86400 - - for x in $(seq 1 $num); do - b=$(uuid) - echo "hmset $b callid $(uuid)@test created $(date +%s)" - c=$(uuid) - echo "rpush $b-streams $c" - echo "hmset $c:0 ip $(($RANDOM % 253 + 1)).$(($RANDOM % 253 + 1)).$(($RANDOM % 253 + 1)).$(($RANDOM % 253 + 1)) port $((($RANDOM % 10000) * 2 + 1024)) localport $((($RANDOM % 10000) * 2 + 1024)) kernel 1 filled 1 confirmed 1 tag $(uuid)" - echo "hmset $c:1 ip $(($RANDOM % 253 + 1)).$(($RANDOM % 253 + 1)).$(($RANDOM % 253 + 1)).$(($RANDOM % 253 + 1)) port $((($RANDOM % 10000) * 2 + 1024)) localport $((($RANDOM % 10000) * 2 + 1024)) kernel 1 filled 1 confirmed 1 tag $(uuid)" - echo "expire $b $expire" - echo "expire $b-streams $expire" - echo "expire $c:0 $expire" - echo "expire $c:1 $expire" - echo "sadd calls $b" - done | redis-cli -n $db - -*/ - - - - - -#define redisCommandNR(a...) (int)({ void *__tmp; __tmp = redisCommand(a); if (__tmp) freeReplyObject(__tmp); __tmp ? 0 : -1;}) - - - - - -static int redis_check_type(struct redis *r, char *key, char *suffix, char *type) { - redisReply *rp; - - rp = redisCommand(r->ctx, "TYPE %s%s", key, suffix ? : ""); - if (!rp) - return -1; - if (rp->type != REDIS_REPLY_STATUS) { - freeReplyObject(rp); - return -1; - } - if (strcmp(rp->str, type) && strcmp(rp->str, "none")) - redisCommandNR(r->ctx, "DEL %s%s", key, suffix ? : ""); - freeReplyObject(rp); - return 0; -} - - - - -static void redis_consume(struct redis *r, int count) { - redisReply *rp; - - while (count-- > 0) { - if (redisGetReply(r->ctx, (void **) &rp) == REDIS_OK) - freeReplyObject(rp); - } -} - - - - -static int redis_connect(struct redis *r, int wait) { - struct timeval tv; - redisReply *rp; - char *s; - - if (r->ctx) - redisFree(r->ctx); - r->ctx = NULL; - - tv.tv_sec = 1; - tv.tv_usec = 0; - r->ctx = redisConnectWithTimeout(r->host, r->port, tv); - - if (!r->ctx) - goto err; - if (r->ctx->err) - goto err2; - - if (redisCommandNR(r->ctx, "PING")) - goto err2; - - if (redisCommandNR(r->ctx, "SELECT %i", r->db)) - goto err2; - - while (wait-- >= 0) { - mylog(LOG_INFO, "Asking Redis whether it's master or slave...\n"); - rp = redisCommand(r->ctx, "INFO"); - if (!rp) - goto err2; - - s = strstr(rp->str, "role:"); - if (!s) - goto err3; - if (!memcmp(s, "role:master", 9)) - goto done; - else if (!memcmp(s, "role:slave", 8)) - goto next; - else - goto err3; - -next: - freeReplyObject(rp); - mylog(LOG_INFO, "Connected to Redis, but it's in slave mode\n"); - sleep(1); - } - - goto err2; - -done: - freeReplyObject(rp); - mylog(LOG_INFO, "Connected to Redis\n"); - return 0; - -err3: - freeReplyObject(rp); -err2: - if (r->ctx->err) - mylog(LOG_ERR, "Redis error: %s\n", r->ctx->errstr); - redisFree(r->ctx); - r->ctx = NULL; -err: - mylog(LOG_ERR, "Failed to connect to master Redis database\n"); - return -1; -} - - - - -struct redis *redis_new(u_int32_t ip, u_int16_t port, int db) { - struct redis *r; - - r = malloc(sizeof(*r)); - ZERO(*r); - - sprintf(r->host, IPF, IPP(ip)); - r->port = port; - r->db = db; - - if (redis_connect(r, 10)) - goto err; - - return r; - -err: - free(r); - return NULL; -} - - - - -static void redis_delete_uuid(char *uuid, struct callmaster *m) { - struct redis *r = m->redis; - redisReply *rp, *rp2; - int i, count = 0; - - if (!r) - return; - - rp = redisCommand(r->ctx, "LRANGE %s-streams 0 -1", uuid); - if (!rp) - return; - if (rp->type != REDIS_REPLY_ARRAY) { - freeReplyObject(rp); - return; - } - - for (i = 0; i < rp->elements; i++) { - rp2 = rp->element[i]; - if (rp2->type != REDIS_REPLY_STRING) - continue; - - redisAppendCommand(r->ctx, "DEL %s:0 %s:1", rp2->str, rp2->str); - count++; - } - - redisAppendCommand(r->ctx, "DEL %s-streams %s-viabranches %s", uuid, uuid, uuid); - redisAppendCommand(r->ctx, "SREM calls %s", uuid); - count += 2; - - redis_consume(r, count); - freeReplyObject(rp); -} - - - - -int redis_restore(struct callmaster *m) { - struct redis *r = m->redis; - redisReply *rp, *rp2, *rp3, *rp4, *rp5, *rp6, *rp7; - GQueue q = G_QUEUE_INIT; - int i, j, k, l; - - mylog(LOG_DEBUG, "Restoring calls from Redis...\n"); - - rp = redisCommand(r->ctx, "SMEMBERS calls"); - if (!rp || rp->type != REDIS_REPLY_ARRAY) { - mylog(LOG_ERR, "Could not retrieve call list from Redis: %s\n", r->ctx->errstr); - if (rp) - freeReplyObject(rp); - goto err; - } - - for (i = 0; i < rp->elements; i++) { - rp2 = rp->element[i]; - if (rp2->type != REDIS_REPLY_STRING) - continue; - - mylog(LOG_DEBUG, "Processing call GUID %s from Redis\n", rp2->str); - - rp3 = redisCommand(r->ctx, "HMGET %s callid created", rp2->str); - - if (!rp3) - goto del; - if (rp3->type != REDIS_REPLY_ARRAY) - goto del2; - if (rp3->elements != 2) - goto del2; - for (j = 0; j < rp3->elements; j++) { - if (rp3->element[j]->type != REDIS_REPLY_STRING) - goto del2; - } - - rp4 = redisCommand(r->ctx, "LRANGE %s-streams 0 -1", rp2->str); - if (!rp4) - goto del2; - if (rp4->type != REDIS_REPLY_ARRAY) - goto del3; - - for (j = 0; j < rp4->elements; j++) { - rp5 = rp4->element[j]; - if (rp5->type != REDIS_REPLY_STRING) - continue; - for (k = 0; k < 2; k++) { - rp6 = redisCommand(r->ctx, "HMGET %s:%i ip port localport kernel filled confirmed tag", rp5->str, k); - if (!rp6) - goto del4; - if (rp6->type != REDIS_REPLY_ARRAY) - goto del5; - if (rp6->elements != 7) - goto del5; - for (l = 0; l < rp6->elements; l++) { - if (rp6->element[l]->type != REDIS_REPLY_STRING) - goto del5; - } - g_queue_push_tail(&q, rp6); - } - } - - rp7 = redisCommand(r->ctx, "LRANGE %s-viabranches 0 -1", rp2->str); - if (rp7 && rp7->type != REDIS_REPLY_ARRAY) { - freeReplyObject(rp7); - rp7 = NULL; - } - - call_restore(m, rp2->str, rp3->element, q.head, rp7); - - if (q.head) - g_list_foreach(q.head, (GFunc) freeReplyObject, NULL); - g_queue_clear(&q); - freeReplyObject(rp4); - freeReplyObject(rp3); - if (rp7) - freeReplyObject(rp7); - - continue; - -del5: - freeReplyObject(rp6); -del4: - if (q.head) - g_list_foreach(q.head, (GFunc) freeReplyObject, NULL); - g_queue_clear(&q); -del3: - freeReplyObject(rp4); -del2: - freeReplyObject(rp3); -del: - mylog(LOG_WARNING, "Could not restore call with GUID %s from Redis DB due to incomplete data\n", rp2->str); - redis_delete_uuid(rp2->str, m); - } - - freeReplyObject(rp); - - return 0; - -err: - return -1; -} - - - - -void redis_update(struct call *c) { - struct callmaster *cm = c->callmaster; - struct redis *r = cm->redis; - char uuid[37]; - GList *l; - struct callstream *cs; - int i, count = 0; - struct peer *p; - redisReply *oldstreams; - char addr[64]; - - if (!r) - return; - - if (!c->redis_uuid[0]) - uuid_str_generate(c->redis_uuid); - - redis_check_type(r, c->redis_uuid, NULL, "hash"); - oldstreams = redisCommand(r->ctx, "LRANGE %s-streams 0 -1", c->redis_uuid); - - redisAppendCommand(r->ctx, "HMSET %s callid %s created %i", c->redis_uuid, c->callid, c->created); - redisAppendCommand(r->ctx, "DEL %s-streams-temp %s-viabranches-temp", c->redis_uuid, c->redis_uuid); - count += 2; - - for (l = c->callstreams->head; l; l = l->next) { - cs = l->data; - uuid_str_generate(uuid); - - for (i = 0; i < 2; i++) { - p = &cs->peers[i]; - - inet_ntop(AF_INET6, &p->rtps[0].peer.ip46, addr, sizeof(addr)); - redisAppendCommand(r->ctx, "DEL %s:%i", uuid, i); - redisAppendCommand(r->ctx, "HMSET %s:%i ip %s port %i localport %i kernel %i filled %i confirmed %i tag %s", uuid, i, addr, p->rtps[0].peer.port, p->rtps[0].localport, p->kernelized, p->filled, p->confirmed, p->tag); - redisAppendCommand(r->ctx, "EXPIRE %s:%i 86400", uuid, i); - count += 3; - } - - redisAppendCommand(r->ctx, "RPUSH %s-streams-temp %s", c->redis_uuid, uuid); - count++; - } - - for (l = g_hash_table_get_keys(c->branches); l; l = l->next) { - redisAppendCommand(r->ctx, "RPUSH %s-viabranches-temp %s", c->redis_uuid, l->data); - count++; - } - g_list_free(l); - - redisAppendCommand(r->ctx, "RENAME %s-streams-temp %s-streams", c->redis_uuid, c->redis_uuid); - redisAppendCommand(r->ctx, "RENAME %s-viabranches-temp %s-viabranches", c->redis_uuid, c->redis_uuid); - redisAppendCommand(r->ctx, "EXPIRE %s-streams 86400", c->redis_uuid); - redisAppendCommand(r->ctx, "EXPIRE %s-viabranches 86400", c->redis_uuid); - redisAppendCommand(r->ctx, "EXPIRE %s 86400", c->redis_uuid); - redisAppendCommand(r->ctx, "SADD calls %s", c->redis_uuid); - count += 6; - - if (oldstreams) { - if (oldstreams->type == REDIS_REPLY_ARRAY) { - for (i = 0; i < oldstreams->elements; i++) { - if (oldstreams->element[0]->type == REDIS_REPLY_STRING) { - redisAppendCommand(r->ctx, "DEL %s:0 %s:1", oldstreams->element[0]->str, oldstreams->element[0]->str); - count++; - } - } - } - freeReplyObject(oldstreams); - } - - redis_consume(r, count); -} - - - - - -void redis_delete(struct call *c) { - redis_delete_uuid(c->redis_uuid, c->callmaster); -} - - - - - -void redis_wipe(struct callmaster *m) { - struct redis *r = m->redis; - - if (!r) - return; - redisCommandNR(r->ctx, "DEL calls"); -} +struct redis *(*redis_new)(u_int32_t, u_int16_t, int); +int (*redis_restore)(struct callmaster *); +void (*redis_update)(struct call *); +void (*redis_delete)(struct call *); +void (*redis_wipe)(struct callmaster *); diff --git a/daemon/redis.h b/daemon/redis.h index 9440e7d..113967f 100644 --- a/daemon/redis.h +++ b/daemon/redis.h @@ -5,7 +5,6 @@ #include -#include @@ -15,22 +14,11 @@ struct call; -struct redis { - char host[32]; - int port; - - redisContext *ctx; - int db; -}; - - - - -struct redis *redis_new(u_int32_t, u_int16_t, int); -int redis_restore(struct callmaster *); -void redis_update(struct call *); -void redis_delete(struct call *); -void redis_wipe(struct callmaster *); +extern struct redis *(*redis_new)(u_int32_t, u_int16_t, int); +extern int (*redis_restore)(struct callmaster *); +extern void (*redis_update)(struct call *); +extern void (*redis_delete)(struct call *); +extern void (*redis_wipe)(struct callmaster *); diff --git a/debian/control b/debian/control index c01a0a8..086ce68 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: ngcp-mediaproxy-ng Section: net Priority: extra Maintainer: Sipwise Development Team -Build-Depends: debhelper (>= 5), iptables-dev (>= 1.4), libglib2.0-dev, libpcre3-dev, uuid-dev, libhiredis-dev, +Build-Depends: debhelper (>= 5), iptables-dev (>= 1.4), libglib2.0-dev, libpcre3-dev, libxmlrpc-c3-dev (>= 1.16.07) | libxmlrpc-core-c3-dev (>= 1.16.07), libcurl4-openssl-dev | libcurl4-gnutls-dev | libcurl3-openssl-dev | libcurl3-gnutls-dev Standards-Version: 3.9.2 diff --git a/debian/ngcp-mediaproxy-ng-dev.install b/debian/ngcp-mediaproxy-ng-dev.install index 85f2156..48aa522 100644 --- a/debian/ngcp-mediaproxy-ng-dev.install +++ b/debian/ngcp-mediaproxy-ng-dev.install @@ -1,3 +1 @@ daemon/*.h /usr/include/mediaproxy-ng/ -# FIXME - remove dependency -kernel-module/xt_MEDIAPROXY.h /usr/include/mediaproxy-ng/