From 9df56bc3b8a91bc8ee8a96d75a6b3f22dd0519ff Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Sat, 7 Feb 2004 17:37:50 +0000 Subject: [PATCH] - logging routines now use a MUTEX to be thread safe. - fix: local UA to UA RTP proxying did not proplery handle HOLD/unHOLDing a call --- ChangeLog | 1 + doc/siproxd.conf.example | 4 +++- src/log.c | 28 +++++++++++++++++++++++----- src/proxy.c | 6 +++--- src/rtpproxy_relay.c | 24 +++++++++++++++++++----- 5 files changed, 49 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index d657f37..e8c58de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ ===== 7-Feb-2004: - Fix for local-UA to local-UA RTP proxying, symmetric RTP was not working. + - logging routines now use a MUTEX to be thread safe. 1-Feb-2004: - Added handling of Max-Forwards header - a detected via loop results in an 482 Loop detected 31-Jan-2004: - Allow 2 of my vias in header to let 2 UA's sitting diff --git a/doc/siproxd.conf.example b/doc/siproxd.conf.example index 1a36a5f..5ed9a03 100644 --- a/doc/siproxd.conf.example +++ b/doc/siproxd.conf.example @@ -99,8 +99,10 @@ rtp_port_high = 7080 # Timeout for RTP streams # after this number of seconds, an RTP stream is considered dead # and proxying for it will be stopped. +# Be aware that this timeout also applies to streams that are +# in HOLD. # -rtp_timeout = 120 +rtp_timeout = 300 ###################################################################### # Proxy authentication diff --git a/src/log.c b/src/log.c index 6457bdb..fc4a87a 100644 --- a/src/log.c +++ b/src/log.c @@ -20,8 +20,9 @@ #include "config.h" -#include "log.h" +//#include "log.h" +#include #include #include #include @@ -46,6 +47,12 @@ static int debug_pattern=0; */ static int silence_level=0; +/* + * Mutex for threat synchronization when writing log data + * + * use a 'fast' mutex for synchronizing - as these are portable... + */ +static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; void log_set_pattern(int pattern) { debug_pattern=pattern; @@ -81,6 +88,7 @@ void log_debug(int class, char *file, int line, const char *format, ...) { va_start(ap, format); + pthread_mutex_lock(&log_mutex); if (! log_to_syslog) { /* not running as daemon - log to STDERR */ time(&t); @@ -89,14 +97,15 @@ void log_debug(int class, char *file, int line, const char *format, ...) { tim->tm_min, tim->tm_sec, file, line); vfprintf(stderr, format, ap); fprintf(stderr,"\n"); + fflush(stderr); } else if (silence_level < 1) { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); syslog(LOG_USER|LOG_DEBUG, "%s:%i %s", file, line, string); } + pthread_mutex_unlock(&log_mutex); va_end(ap); - fflush(stderr); return; } @@ -110,6 +119,7 @@ void log_error(char *file, int line, const char *format, ...) { va_start(ap, format); + pthread_mutex_lock(&log_mutex); if (! log_to_syslog) { /* not running as daemon - log to STDERR */ time(&t); @@ -118,14 +128,15 @@ void log_error(char *file, int line, const char *format, ...) { tim->tm_min, tim->tm_sec, file, line); vfprintf(stderr, format, ap); fprintf(stderr,"\n"); + fflush(stderr); } else if (silence_level < 4) { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); syslog(LOG_USER|LOG_WARNING, "%s:%i ERROR:%s", file, line, string); } + pthread_mutex_unlock(&log_mutex); va_end(ap); - fflush(stderr); return; } @@ -139,6 +150,7 @@ void log_warn(char *file, int line, const char *format, ...) { va_start(ap, format); + pthread_mutex_lock(&log_mutex); if (! log_to_syslog) { /* not running as daemon - log to STDERR */ time(&t); @@ -147,14 +159,15 @@ void log_warn(char *file, int line, const char *format, ...) { tim->tm_min, tim->tm_sec,file,line); vfprintf(stderr, format, ap); fprintf(stderr,"\n"); + fflush(stderr); } else if (silence_level < 3) { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); syslog(LOG_USER|LOG_NOTICE, "%s:%i WARNING:%s", file, line, string); } + pthread_mutex_unlock(&log_mutex); va_end(ap); - fflush(stderr); return; } @@ -168,6 +181,7 @@ void log_info(char *file, int line, const char *format, ...) { va_start(ap, format); + pthread_mutex_lock(&log_mutex); if (! log_to_syslog) { /* not running as daemon - log to STDERR */ time(&t); @@ -176,14 +190,15 @@ void log_info(char *file, int line, const char *format, ...) { tim->tm_min, tim->tm_sec,file,line); vfprintf(stderr, format, ap); fprintf(stderr,"\n"); + fflush(stderr); } else if (silence_level < 2) { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); syslog(LOG_USER|LOG_NOTICE, "%s:%i INFO:%s", file, line, string); } + pthread_mutex_unlock(&log_mutex); va_end(ap); - fflush(stderr); return; } @@ -197,6 +212,7 @@ void log_dump_buffer(int class, char *file, int line, if ((debug_pattern & class) == 0) return; if (log_to_syslog) return; + pthread_mutex_lock(&log_mutex); fprintf(stderr,"---BUFFER DUMP follows---\n"); for (i=0; ifrom->url->host ? response->from->url->host : "*NULL*"); + /* rewrite Contact header to represent the masqued address */ + sip_rewrite_contact(response, DIR_OUTGOING); + #define satoi atoi /* used in MSG_TEST_CODE macro ... */ /* If an 200 OK or 183 Trying answer to an INVITE request, * rewrite body */ @@ -723,9 +726,6 @@ int proxy_response (osip_message_t *response, struct sockaddr_in *from) { sts = proxy_rewrite_invitation_body(response, DIR_OUTGOING); } - /* rewrite Contact header to represent the masqued address */ - sip_rewrite_contact(response, DIR_OUTGOING); - break; default: diff --git a/src/rtpproxy_relay.c b/src/rtpproxy_relay.c index e8dbce6..0ae2232 100644 --- a/src/rtpproxy_relay.c +++ b/src/rtpproxy_relay.c @@ -50,11 +50,16 @@ extern struct siproxd_config configuration; */ rtp_proxytable_t rtp_proxytable[RTPPROXY_SIZE]; -/* use a 'fast' mutex for synchronizing - as these are portable... */ -pthread_mutex_t rtp_proxytable_mutex = PTHREAD_MUTEX_INITIALIZER; +/* + * Mutex for thread synchronization (locking when accessing common + * data structures -> rtp_proxytable[]). + * + * use a 'fast' mutex for synchronizing - as these are portable... + */ +static pthread_mutex_t rtp_proxytable_mutex = PTHREAD_MUTEX_INITIALIZER; /* thread id of RTP proxy */ -pthread_t rtpproxy_tid=0; +static pthread_t rtpproxy_tid=0; /* master fd_set */ static fd_set master_fdset; @@ -198,12 +203,21 @@ static void *rtpproxy_main(void *arg) { cid.number = rtp_proxytable[j].callid_number; cid.host = rtp_proxytable[j].callid_host; + /* match on: + * - same call ID + * - same media stream + * - opposite direction + * - different client ID + */ if ( (rtp_proxytable[j].rtp_rx_sock != 0) && - (rtp_direction != rtp_proxytable[j].direction) && - (media_stream_no == rtp_proxytable[j].media_stream_no) && (compare_callid(&callid, &cid) == STS_SUCCESS) && + (media_stream_no == rtp_proxytable[j].media_stream_no) && + (rtp_direction != rtp_proxytable[j].direction) && (strcmp(rtp_proxytable[j].client_id, client_id) != 0) ) { rtp_proxytable[i].rtp_tx_sock = rtp_proxytable[j].rtp_rx_sock; + DEBUGC(DBCLASS_RTP, "connected entry %i (fd=%i) <-> entry %i (fd=%i)", + j, rtp_proxytable[j].rtp_rx_sock, + i, rtp_proxytable[j].rtp_rx_sock); break; } }