- 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
This commit is contained in:
Thomas Ries
2004-02-07 17:37:50 +00:00
parent c9d86d78d7
commit 9df56bc3b8
5 changed files with 49 additions and 14 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -20,8 +20,9 @@
#include "config.h"
#include "log.h"
//#include "log.h"
#include <pthread.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
@@ -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; i<length; i+=16) {
@@ -213,5 +229,7 @@ void log_dump_buffer(int class, char *file, int line,
fprintf(stderr,"\n---end of BUFFER DUMP---\n");
fflush(stderr);
pthread_mutex_unlock(&log_mutex);
return;
}

View File

@@ -713,6 +713,9 @@ int proxy_response (osip_message_t *response, struct sockaddr_in *from) {
response->from->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:

View File

@@ -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;
}
}