From 0fd9e0dae4234e6bc30ca0d061b5fbaaee9a8fbe Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 27 Jul 2011 16:21:01 +0000 Subject: [PATCH] Create compile-time option ("make no-redis") to eliminate all redis-related code from binary --- daemon/Makefile | 22 +++++++++++++++++++--- daemon/call.c | 22 ++++++++++++++++++++++ daemon/call.h | 11 +++++++++++ daemon/main.c | 14 ++++++++++++++ 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/daemon/Makefile b/daemon/Makefile index 04dfd6383..41798c84f 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -1,25 +1,41 @@ +REDIS=yes + LIBREDISDIR= libhiredis-v0.10.0-3-gdf203bc CC= gcc CFLAGS= -g -Wall `pkg-config --cflags glib-2.0` `pcre-config --cflags` CFLAGS+= -I/lib/modules/`uname -r`/build/include/ -I../kernel-module/ CFLAGS+= -D_GNU_SOURCE -#CFLAGS+= -O2 +CFLAGS+= -O2 +ifeq ($(REDIS),yes) CFLAGS+= -I$(LIBREDISDIR) +else +CFLAGS+= -DNO_REDIS=1 +endif LDFLAGS= `pkg-config --libs glib-2.0` `pcre-config --libs` +ifeq ($(REDIS),yes) LDFLAGS+= -L$(LIBREDISDIR) -lhiredis -luuid +endif -SRCS= main.c kernel.c poller.c aux.c control.c streambuf.c call.c control_udp.c redis.c +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 OBJS= $(SRCS:.c=.o) -.PHONY: all dep clean tests +.PHONY: all dep clean tests no-redis all: +ifeq ($(REDIS),yes) make -C $(LIBREDISDIR) static +endif make mediaproxy-ng +no-redis: + make REDIS=no all + tests: make aux-test poller-test diff --git a/daemon/call.c b/daemon/call.c index 502e893a6..f372373e6 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -8,7 +8,9 @@ #include #include #include +#ifndef NO_REDIS #include +#endif #include #include "call.h" @@ -18,7 +20,9 @@ #include "kernel.h" #include "control.h" #include "streambuf.h" +#ifndef NO_REDIS #include "redis.h" +#endif @@ -193,7 +197,9 @@ static int stream_packet(struct streamrelay *r, char *b, int l, struct sockaddr_ if (pe2->confirmed && pe2->filled) kernelize(cs); +#ifndef NO_REDIS redis_update(c); +#endif } skip: @@ -237,6 +243,8 @@ skip: return -1; } + pe->used = 1; + drop: r->stats.packets++; r->stats.bytes += l; @@ -760,6 +768,8 @@ static unsigned int call_streams(struct call *c, GQueue *s, const char *tag, int cs = l->data; for (x = 0; x < 2; x++) { r = &cs->peers[x].rtps[0]; + if (r->up->used) + continue; if (r->peer.ip != t->ip) continue; if (r->peer.port != t->port) @@ -857,7 +867,9 @@ static void call_destroy(struct call *c) { struct callstream *s; g_hash_table_remove(m->callhash, c->callid); +#ifndef NO_REDIS redis_delete(c); +#endif free(c->callid); g_hash_table_destroy(c->infohash); @@ -957,7 +969,9 @@ char *call_update_udp(const char **o, struct callmaster *m) { g_queue_clear(&q); +#ifndef NO_REDIS redis_update(c); +#endif return streams_print(c->callstreams, 1, 0, o[1], 1); @@ -994,7 +1008,9 @@ char *call_lookup_udp(const char **o, struct callmaster *m) { g_queue_clear(&q); +#ifndef NO_REDIS redis_update(c); +#endif return streams_print(c->callstreams, 1, 1, o[1], 1); @@ -1016,7 +1032,9 @@ char *call_request(const char **o, 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 return streams_print(c->callstreams, num, 0, NULL, 0); } @@ -1038,7 +1056,9 @@ char *call_lookup(const char **o, 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 return streams_print(c->callstreams, num, 1, NULL, 0); } @@ -1135,6 +1155,7 @@ 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) { struct call *c; struct callstream *cs; @@ -1196,3 +1217,4 @@ 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 2a7fa1b58..936e9b811 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -6,7 +6,9 @@ #include #include +#ifndef NO_REDIS #include +#endif #include "ipt_MEDIAPROXY.h" @@ -20,7 +22,9 @@ struct peer; struct callstream; struct call; struct callmaster; +#ifndef NO_REDIS struct redis; +#endif @@ -50,6 +54,7 @@ struct peer { int kernelized:1; int filled:1; int confirmed:1; + int used:1; }; struct callstream { struct peer peers[2]; @@ -62,7 +67,9 @@ struct call { GQueue *callstreams; char *callid; +#ifndef NO_REDIS char redis_uuid[37]; +#endif time_t created; char *calling_agent; char *called_agent; @@ -76,7 +83,9 @@ struct callmaster { struct mediaproxy_stats stats; struct poller *poller; +#ifndef NO_REDIS struct redis *redis; +#endif int kernelfd; unsigned int kernelid; u_int32_t ip; @@ -104,8 +113,10 @@ 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 *); void calls_dump_redis(struct callmaster *); +#endif diff --git a/daemon/main.c b/daemon/main.c index ba499d38e..fb6de3b45 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -14,7 +14,9 @@ #include "log.h" #include "call.h" #include "kernel.h" +#ifndef NO_REDIS #include "redis.h" +#endif @@ -39,9 +41,11 @@ 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 @@ -108,7 +112,9 @@ static void options(int *argc, char ***argv) { static char *adv_ips; static char *listenps; static char *listenudps; +#ifndef NO_REDIS static char *redisps; +#endif static GOptionEntry e[] = { { "table", 't', 0, G_OPTION_ARG_INT, &table, "Kernel table to use", "INT" }, @@ -123,8 +129,10 @@ 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 { NULL, } }; @@ -168,12 +176,14 @@ 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 } @@ -251,11 +261,13 @@ int main(int argc, char **argv) { die("Failed to open UDP control connection port\n"); } +#ifndef NO_REDIS if (redis_ip) { 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"); @@ -263,10 +275,12 @@ 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);