Merge branch '1and1-redis-onekey-concept-master'

changes/94/11294/1
Richard Fuchs 8 years ago
commit 458d359379

@ -175,7 +175,8 @@ option and which are reproduced below:
-w, --redis-write=[PW@]IP:PORT/INT Connect to Redis write database
-k, --subscribe-keyspace Subscription keyspace list
--redis-num-threads=INT Number of Redis restore threads
--redis-expires=INT Expire time in seconds for redis keys
--redis-expires=INT Expire time in seconds for redis keys
--redis-multikey Use multiple redis keys for storing the call (old behaviour) DEPRECATED
-q, --no-redis-required Start even if can't connect to redis databases
-b, --b2b-url=STRING XMLRPC URL of B2B UA
-L, --log-level=INT Mask log priorities above this level
@ -426,6 +427,10 @@ The options are described in more detail below.
Expire time in seconds for redis keys. Default is 86400.
* --redis-multikey
Use multiple redis keys for storing the call (old behaviour) DEPRECATED
* -q, --no-redis-required
When this paramter is present or NO_REDIS_REQUIRED='yes' or '1' in config file, rtpengine starts even
if there is no initial connection to redis databases(either to -r or to -w or to both redis).

@ -8,6 +8,7 @@ CFLAGS+= `pkg-config --cflags zlib`
CFLAGS+= `pkg-config --cflags openssl`
CFLAGS+= `pkg-config --cflags libevent_pthreads`
CFLAGS+= `pcre-config --cflags`
CFLAGS+= `pkg-config --cflags json-glib-1.0`
CFLAGS+= -I. -I../kernel-module/ -I../lib/
CFLAGS+= -D_GNU_SOURCE
@ -30,6 +31,7 @@ LDFLAGS+= -lpcap
LDFLAGS+= `pcre-config --libs`
LDFLAGS+= `xmlrpc-c-config client --libs`
LDFLAGS+= -lhiredis
LDFLAGS+= `pkg-config --libs json-glib-1.0`
include ../lib/lib.Makefile

@ -594,8 +594,13 @@ static void callmaster_timer(void *ptr) {
rwlock_unlock_r(&sfd->call->master_lock);
if (update)
redis_update(ps->call, m->conf.redis_write);
if (update) {
if (m->conf.redis_multikey) {
redis_update(ps->call, m->conf.redis_write);
} else {
redis_update_onekey(ps->call, m->conf.redis_write);
}
}
next:
g_hash_table_remove(hlp.addr_sfd, &ep);

@ -5,7 +5,8 @@
/* XXX split everything into call_signalling.[ch] and call_packets.[ch] or w/e */
#include <glib-object.h>
#include <json-glib/json-glib.h>
#include <sys/types.h>
#include <glib.h>
@ -443,6 +444,7 @@ struct call {
unsigned int foreign_call; // created_via_redis_notify call
struct recording *recording;
JsonReader *root_reader;
};
struct callmaster_config {
@ -460,7 +462,8 @@ struct callmaster_config {
struct event_base *redis_notify_event_base;
GQueue *redis_subscribed_keyspaces;
struct redisAsyncContext *redis_notify_async_context;
unsigned int redis_expires_secs;
unsigned int redis_expires_secs;
unsigned int redis_multikey;
char *b2b_url;
unsigned char default_tos;
enum xmlrpc_format fmt;

@ -186,7 +186,11 @@ static str *call_update_lookup_udp(char **out, struct callmaster *m, enum call_o
sp.index, sp.index, out[RE_UDP_COOKIE], SAF_UDP);
rwlock_unlock_w(&c->master_lock);
redis_update(c, m->conf.redis_write);
if (m->conf.redis_multikey) {
redis_update(c, m->conf.redis_write);
} else {
redis_update_onekey(c, m->conf.redis_write);
}
gettimeofday(&(monologue->started), NULL);
@ -334,7 +338,11 @@ out2:
rwlock_unlock_w(&c->master_lock);
streams_free(&s);
redis_update(c, m->conf.redis_write);
if (m->conf.redis_multikey) {
redis_update(c, m->conf.redis_write);
} else {
redis_update_onekey(c, m->conf.redis_write);
}
ilog(LOG_INFO, "Returning to SIP proxy: "STR_FORMAT"", STR_FMT0(ret));
obj_put(c);
@ -764,10 +772,16 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster
}
rwlock_unlock_w(&call->master_lock);
if (!flags.no_redis_update)
redis_update(call, m->conf.redis_write);
else
if (!flags.no_redis_update) {
if (m->conf.redis_multikey) {
redis_update(call, m->conf.redis_write);
} else {
redis_update_onekey(call,m->conf.redis_write);
}
} else {
ilog(LOG_DEBUG, "Not updating Redis due to present no-redis-update flag");
}
obj_put(call);
gettimeofday(&(monologue->started), NULL);

@ -62,6 +62,7 @@ static unsigned int timeout;
static unsigned int silent_timeout;
static unsigned int final_timeout;
static unsigned int redis_expires = 86400;
static unsigned int redis_multikey = 0;
static int port_min = 30000;
static int port_max = 40000;
static int max_sessions = -1;
@ -298,6 +299,7 @@ static void options(int *argc, char ***argv) {
{ "redis-write",'w', 0, G_OPTION_ARG_STRING, &redisps_write, "Connect to Redis write database", "[PW@]IP:PORT/INT" },
{ "redis-num-threads", 0, 0, G_OPTION_ARG_INT, &redis_num_threads, "Number of Redis restore threads", "INT" },
{ "redis-expires", 0, 0, G_OPTION_ARG_INT, &redis_expires, "Expire time in seconds for redis keys", "INT" },
{ "redis-multikey", 0, 0, G_OPTION_ARG_NONE, &redis_multikey, "Use multiple redis keys for storing the call (old behaviour) DEPRECATED", NULL },
{ "no-redis-required", 'q', 0, G_OPTION_ARG_NONE, &no_redis_required, "Start no matter of redis connection state", NULL },
{ "b2b-url", 'b', 0, G_OPTION_ARG_STRING, &b2b_url, "XMLRPC URL of B2B UA" , "STRING" },
{ "log-facility",0, 0, G_OPTION_ARG_STRING, &log_facility_s, "Syslog facility to use for logging", "daemon|local0|...|local7"},
@ -502,6 +504,11 @@ static void init_everything() {
#if !GLIB_CHECK_VERSION(2,32,0)
g_thread_init(NULL);
#endif
#if !(GLIB_CHECK_VERSION(2,36,0))
g_type_init();
#endif
if (!_log_stderr)
openlog("rtpengine", LOG_PID | LOG_NDELAY, _log_facility);
signals();
@ -621,6 +628,7 @@ no_kernel:
}
mc.redis_expires_secs = redis_expires;
mc.redis_multikey = redis_multikey;
ctx->m->conf = mc;

@ -1471,8 +1471,13 @@ static void stream_fd_readable(int fd, void *p, uintptr_t u) {
out:
ca = sfd->call ? : NULL;
if (ca && update)
redis_update(ca, ca->callmaster->conf.redis_write);
if (ca && update) {
if (ca->callmaster->conf.redis_multikey) {
redis_update(ca, ca->callmaster->conf.redis_write);
} else {
redis_update_onekey(ca, ca->callmaster->conf.redis_write);
}
}
done:
log_info_clear();
}

File diff suppressed because it is too large Load Diff

@ -91,23 +91,15 @@ INLINE gboolean g_hash_table_insert_check(GHashTable *h, gpointer k, gpointer v)
#endif
#define rlog(l, x...) ilog(l | LOG_FLAG_RESTORE, x)
#define REDIS_FMT(x) (x)->len, (x)->str
void redis_notify_loop(void *d);
struct redis *redis_new(const endpoint_t *, int, const char *, enum redis_role, int no_redis_required);
int redis_restore(struct callmaster *, struct redis *);
void redis_update(struct call *, struct redis *);
void redis_update_onekey(struct call *c, struct redis *r);
void redis_delete(struct call *, struct redis *);
void redis_wipe(struct redis *);
int redis_notify_event_base_action(struct callmaster *cm, enum event_base_action);

@ -48,3 +48,51 @@ char *rand_hex_str(char *rand_str, int num_bytes) {
}
return rand_str;
}
static const char *hex_chars = "0123456789abcdef";
int str_uri_encode_len(char *out, const char *in, int len) {
const char *end = in + len;
char *ori_out = out;
while (in < end) {
if (*in < ' ' || *in > '~' || *in == '%' || *in == '\\' || *in == '\'' || *in == '"') {
*(out++) = '%';
*(out++) = hex_chars[(*((unsigned char *) in)) >> 4];
*(out++) = hex_chars[(*((unsigned char *) in)) & 0xf];
in++;
continue;
}
*(out++) = *(in++);
}
*out = 0;
return out - ori_out;
}
int str_uri_decode_len(char **out, const char *in, int in_len) {
const char *end = in + in_len;
*out = malloc(in_len + 1);
char *outp = *out;
while (in < end) {
if (*in != '%') {
*(outp++) = (*in++);
continue;
}
if (end - in < 3 || !g_ascii_isxdigit(in[1]) || !g_ascii_isxdigit(in[2])) {
free(*out);
*out = NULL;
return -1;
}
unsigned char c = g_ascii_xdigit_value(in[1]) << 4 | g_ascii_xdigit_value(in[2]);
*(outp++) = c;
in += 3;
}
*outp = 0;
return outp - *out;
}

1
debian/control vendored

@ -13,6 +13,7 @@ Build-Depends: debhelper (>= 5),
libevent-dev (>= 2.0),
libglib2.0-dev (>= 2.30),
libhiredis-dev,
libjson-glib-dev,
libpcap0.8-dev | libpcap-dev,
libpcre3-dev,
libssl-dev (>= 1.0.1),

@ -74,6 +74,7 @@ fi
[ -z "$REDIS_WRITE_AUTH_PW" ] || export RTPENGINE_REDIS_WRITE_AUTH_PW="$REDIS_WRITE_AUTH_PW"
[ -z "$REDIS_NUM_THREADS" ] || OPTIONS="$OPTIONS --redis-num-threads=$REDIS_NUM_THREADS"
[ -z "$REDIS_EXPIRES" ] || OPTIONS="$OPTIONS --redis-expires=$REDIS_EXPIRES"
[ -z "$REDIS_MULTIKEY" ] || OPTIONS="$OPTIONS --redis-multikey=$REDIS_MULTIKEY"
[ -z "$NO_REDIS_REQUIRED" -o \( "$NO_REDIS_REQUIRED" != "1" -a "$NO_REDIS_REQUIRED" != "yes" \) ] || OPTIONS="$OPTIONS --no-redis-required"
[ -z "$B2B_URL" ] || OPTIONS="$OPTIONS --b2b-url=$B2B_URL"
[ -z "$NO_FALLBACK" -o \( "$NO_FALLBACK" != "1" -a "$NO_FALLBACK" != "yes" \) ] || OPTIONS="$OPTIONS --no-fallback"

@ -56,6 +56,8 @@ INLINE str *str_dup(const str *s);
INLINE str *str_chunk_insert(GStringChunk *c, const str *s);
/* shifts pointer by len chars and decrements len. returns -1 if buffer too short, 0 otherwise */
INLINE int str_shift(str *s, int len);
/* eats the supplied string from the beginning of s. returns -1 if string head doesn't match */
INLINE int str_shift_cmp(str *s, const char *);
/* binary compares str object with memory chunk of equal size */
INLINE int str_memcmp(const str *s, void *m);
/* locate a substring within a string, returns character index or -1 */
@ -85,6 +87,12 @@ gboolean str_equal(gconstpointer a, gconstpointer b);
/* destroy function, frees a slice-alloc'd str */
void str_slice_free(void *);
/* saves "in" into "out" pseudo-URI encoded. "out" point to a buffer with sufficient length. returns length */
int str_uri_encode_len(char *out, const char *in, int in_len);
INLINE int str_uri_encode(char *out, const str *in);
/* reverse of the above. stores newly allocated buffer in *out. returns length */
int str_uri_decode_len(char **out, const char *in, int in_len);
@ -105,6 +113,16 @@ INLINE int str_shift(str *s, int len) {
s->len -= len;
return 0;
}
INLINE int str_shift_cmp(str *s, const char *t) {
int len = strlen(t);
if (s->len < len)
return -1;
if (memcmp(s->s, t, len))
return -1;
s->s += len;
s->len -= len;
return 0;
}
INLINE char *str_chr(const str *s, int c) {
return memchr(s->s, c, s->len);
}
@ -292,6 +310,10 @@ INLINE int str_token(str *new_token, str *ori_and_remainder, int sep) {
return 0;
}
INLINE int str_uri_encode(char *out, const str *in) {
return str_uri_encode_len(out, in->s, in->len);
}
/* Generates a hex string representing n random bytes. len(rand_str) = 2*num_bytes + 1 */
char *rand_hex_str(char *rand_str, int num_bytes);

Loading…
Cancel
Save