[asterisk-commits] may: branch may/chan_ooh323_rework r224852 - in /team/may/chan_ooh323_rework/...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Oct 20 16:57:24 CDT 2009
Author: may
Date: Tue Oct 20 16:57:20 2009
New Revision: 224852
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=224852
Log:
introduce pool of threads for processing calls.
call thread exit after idle time or begin process next call on signal
jitter buffer config options (only common setting for all channels)
rtpmask is regexp now
additional bound checking of H225/H245 messages. We can receive crash
with bogus messages without this checking.
Modified:
team/may/chan_ooh323_rework/addons/chan_ooh323.c
team/may/chan_ooh323_rework/addons/chan_ooh323.h
team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.c
team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.h
team/may/chan_ooh323_rework/addons/ooh323c/src/ooCapability.c
team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.c
team/may/chan_ooh323_rework/addons/ooh323c/src/oochannels.c
team/may/chan_ooh323_rework/addons/ooh323c/src/ooh245.c
team/may/chan_ooh323_rework/addons/ooh323c/src/ooh323.c
team/may/chan_ooh323_rework/addons/ooh323c/src/ooq931.c
team/may/chan_ooh323_rework/addons/ooh323cDriver.c
team/may/chan_ooh323_rework/addons/ooh323cDriver.h
Modified: team/may/chan_ooh323_rework/addons/chan_ooh323.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/chan_ooh323.c?view=diff&rev=224852&r1=224851&r2=224852
==============================================================================
--- team/may/chan_ooh323_rework/addons/chan_ooh323.c (original)
+++ team/may/chan_ooh323_rework/addons/chan_ooh323.c Tue Oct 20 16:57:20 2009
@@ -53,6 +53,14 @@
static const char tdesc[] = "Objective Systems H323 Channel Driver";
static const char config[] = "ooh323.conf";
+static struct ast_jb_conf default_jbconf =
+{
+ .flags = 0,
+ .max_size = -1,
+ .resync_threshold = -1,
+ .impl = ""
+};
+static struct ast_jb_conf global_jbconf;
/* Channel Definition */
static struct ast_channel *ooh323_request(const char *type, int format,
@@ -172,7 +180,8 @@
int amaflags;
int progsent; /* progress is sent */
struct ast_dsp *vad;
- char *rtpmask; /* rtp ip address mask */
+ struct OOH323Regex *rtpmask; /* rtp ip regexp */
+ char rtpmaskstr[120];
struct ooh323_pvt *next; /* Next entity */
} *iflist = NULL;
@@ -196,7 +205,8 @@
int rtptimeout;
int mUseIP; /* Use IP address or H323-ID to search user */
char mIP[20];
- char rtpmask[20];
+ struct OOH323Regex *rtpmask;
+ char rtpmaskstr[120];
struct ooh323_user *next;
};
@@ -221,7 +231,8 @@
char *url; /* url alias, which asterisk will register with gk to reach this peer*/
char *e164; /* e164 alias, which asterisk will register with gk to reach this peer*/
int rtptimeout;
- char rtpmask[20];
+ struct OOH323Regex *rtpmask;
+ char rtpmaskstr[120];
struct ooh323_peer *next;
};
@@ -348,6 +359,8 @@
ast_channel_set_fd(ch, 1, ast_rtp_instance_fd(i->rtp, 1));
ast_channel_set_fd(ch, 5, ast_udptl_fd(i->udptl));
+ ast_jb_configure(ch, &global_jbconf);
+
if (state == AST_STATE_RING)
ch->rings = 1;
@@ -517,8 +530,9 @@
/*
Possible data values - peername, exten/peername, exten at ip
*/
-static struct ast_channel *ooh323_request(const char *type, int format, const struct ast_channel *requestor,
- void *data, int *cause)
+static struct ast_channel *ooh323_request(const char *type, int format,
+ const struct ast_channel *requestor, void *data, int *cause)
+
{
struct ast_channel *chan = NULL;
struct ooh323_pvt *p = NULL;
@@ -602,8 +616,10 @@
p->dtmfmode |= peer->dtmfmode;
p->dtmfcodec = peer->dtmfcodec;
p->t38support = peer->t38support;
- if (peer->rtpmask)
- p->rtpmask = ast_strdup(peer->rtpmask);
+ if (peer->rtpmask && peer->rtpmaskstr[0]) {
+ p->rtpmask = peer->rtpmask;
+ ast_copy_string(p->rtpmaskstr, peer->rtpmaskstr, sizeof(p->rtpmaskstr));
+ }
ast_copy_string(p->accountcode, peer->accountcode, sizeof(p->accountcode));
p->amaflags = peer->amaflags;
} else {
@@ -976,10 +992,8 @@
ast_verbose(" hanging %s with cause: %d\n", p->username, q931cause);
ast->tech_pvt = NULL;
if (!ast_test_flag(p, H323_ALREADYGONE)) {
- ast_mutex_lock(&ooh323c_cmd_lock);
ooHangCall(p->callToken,
ooh323_convert_hangupcause_asteriskToH323(q931cause), q931cause);
- ast_mutex_unlock(&ooh323c_cmd_lock);
ast_set_flag(p, H323_ALREADYGONE);
/* ast_mutex_unlock(&p->lock); */
} else
@@ -1025,9 +1039,7 @@
if (option_debug)
ast_debug(1, "ooh323_answer(%s)\n", ast->name);
ast_channel_unlock(ast);
- /* ast_mutex_lock(&ooh323c_cmd_lock); */
ooAnswerCall(p->callToken);
- /* ast_mutex_unlock(&ooh323c_cmd_lock); */
}
ast_mutex_unlock(&p->lock);
}
@@ -1180,21 +1192,18 @@
if (gH323Debug)
ast_verbose("----- ooh323_indicate %d on call %s\n", condition, callToken);
- ast_mutex_lock(&p->lock);
+ ast_mutex_lock(&p->lock);
switch (condition) {
case AST_CONTROL_CONGESTION:
if (!ast_test_flag(p, H323_ALREADYGONE)) {
- ast_mutex_lock(&ooh323c_cmd_lock);
- ooHangCall(callToken, OO_REASON_LOCAL_CONGESTED, AST_CAUSE_SWITCH_CONGESTION);
- ast_mutex_unlock(&ooh323c_cmd_lock);
+ ooHangCall(callToken, OO_REASON_LOCAL_CONGESTED,
+ AST_CAUSE_SWITCH_CONGESTION);
ast_set_flag(p, H323_ALREADYGONE);
}
break;
case AST_CONTROL_BUSY:
if (!ast_test_flag(p, H323_ALREADYGONE)) {
- ast_mutex_lock(&ooh323c_cmd_lock);
- ooHangCall(callToken, OO_REASON_LOCAL_BUSY, AST_CAUSE_USER_BUSY);
- ast_mutex_unlock(&ooh323c_cmd_lock);
+ ooHangCall(callToken, OO_REASON_LOCAL_BUSY, AST_CAUSE_USER_BUSY);
ast_set_flag(p, H323_ALREADYGONE);
}
break;
@@ -1724,8 +1733,11 @@
p->dtmfmode |= user->dtmfmode;
p->dtmfcodec = user->dtmfcodec;
p->t38support = user->t38support;
- if (user->rtpmask)
- p->rtpmask = ast_strdup(user->rtpmask);
+ if (user->rtpmask && user->rtpmaskstr[0]) {
+ p->rtpmask = user->rtpmask;
+ ast_copy_string(p->rtpmaskstr, user->rtpmaskstr,
+ sizeof(p->rtpmaskstr));
+ }
/* Since, call is coming from a pbx user, no need to use gk */
/* OO_SETFLAG(p->flags, H323_DISABLEGK);
OO_SETFLAG(call->flags, OO_M_DISABLEGK); */
@@ -1737,17 +1749,14 @@
} else {
ast_mutex_unlock(&p->lock);
ast_log(LOG_ERROR, "Unacceptable ip %s\n", call->remoteIP);
- ast_mutex_lock(&ooh323c_cmd_lock);
if (!user)
ooHangCall(call->callToken, ooh323_convert_hangupcause_asteriskToH323(AST_CAUSE_CALL_REJECTED), AST_CAUSE_CALL_REJECTED);
else
ooHangCall(call->callToken, ooh323_convert_hangupcause_asteriskToH323(AST_CAUSE_NORMAL_CIRCUIT_CONGESTION), AST_CAUSE_NORMAL_CIRCUIT_CONGESTION);
- ast_mutex_unlock(&ooh323c_cmd_lock);
ast_set_flag(p, H323_NEEDDESTROY);
return -1;
}
}
-/* } */
ooh323c_set_capability_for_call(call, &p->prefs, p->capability, p->dtmfmode, p->dtmfcodec,
p->t38support);
@@ -1822,8 +1831,13 @@
ooCallAddAliasH323ID(call, p->callerid_num);
}
}
- if (p->rtpmask)
- ast_copy_string(call->rtpMask, p->rtpmask, sizeof(call->rtpMask));
+ if (p->rtpmask && p->rtpmaskstr[0]) {
+ call->rtpMask = p->rtpmask;
+ ast_mutex_lock(&call->rtpMask->lock);
+ call->rtpMask->inuse++;
+ ast_mutex_unlock(&call->rtpMask->lock);
+ ast_copy_string(call->rtpMaskStr, p->rtpmaskstr, sizeof(call->rtpMaskStr));
+ }
ast_mutex_unlock(&p->lock);
}
@@ -1983,7 +1997,7 @@
while (p->owner) {
if (ast_channel_trylock(p->owner)) {
ooTrace(OOTRCLVLINFO, "Failed to grab lock, trying again\n");
- ast_log(LOG_DEBUG,"Failed to grab lock, trying again\n");
+ ast_log(LOG_DEBUG,"Failed to grab lock, trying again\n");
ast_mutex_unlock(&p->lock);
usleep(1);
ast_mutex_lock(&p->lock);
@@ -2134,7 +2148,14 @@
if (user->rtptimeout < 0)
user->rtptimeout = gRTPTimeout;
} else if (!strcasecmp(v->name, "rtpmask")) {
- ast_copy_string(user->rtpmask, v->value, sizeof(user->rtpmask));
+ if ((user->rtpmask = malloc(sizeof(struct OOH323Regex))) &&
+ (regcomp(&user->rtpmask->regex, v->value, REG_EXTENDED)
+ == 0)) {
+ ast_mutex_init(&user->rtpmask->lock);
+ user->rtpmask->inuse = 1;
+ ast_copy_string(user->rtpmaskstr, v->value,
+ sizeof(user->rtpmaskstr));
+ } else user->rtpmask = NULL;
} else if (!strcasecmp(v->name, "disallow")) {
ast_parse_allow_disallow(&user->prefs,
&user->capability, v->value, 0);
@@ -2263,7 +2284,14 @@
if(peer->rtptimeout < 0)
peer->rtptimeout = gRTPTimeout;
} else if (!strcasecmp(v->name, "rtpmask")) {
- ast_copy_string(peer->rtpmask, v->value, sizeof(peer->rtpmask));
+ if ((peer->rtpmask = malloc(sizeof(struct OOH323Regex))) &&
+ (regcomp(&peer->rtpmask->regex, v->value, REG_EXTENDED)
+ == 0)) {
+ ast_mutex_init(&peer->rtpmask->lock);
+ peer->rtpmask->inuse = 1;
+ ast_copy_string(peer->rtpmaskstr, v->value,
+ sizeof(peer->rtpmaskstr));
+ } else peer->rtpmask = NULL;
} else if (!strcasecmp(v->name, "disallow")) {
ast_parse_allow_disallow(&peer->prefs, &peer->capability,
v->value, 0);
@@ -2435,9 +2463,15 @@
gMediaWaitForConnect = 0;
ooconfig.mTCPPortStart = 12030;
ooconfig.mTCPPortEnd = 12230;
+ memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
v = ast_variable_browse(cfg, "general");
while (v) {
+
+ if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) {
+ v = v->next;
+ continue;
+ }
if (!strcasecmp(v->name, "port")) {
gPort = (int)strtol(v->value, NULL, 10);
@@ -2657,7 +2691,7 @@
ast_config_destroy(cfg);
- /* Determine ip address if necessary */
+ /* Determine ip address if neccessary */
if (ast_strlen_zero(gIP)) {
ooGetLocalIPAddress(gIP);
if (!strcmp(gIP, "127.0.0.1")) {
@@ -2748,9 +2782,9 @@
ast_cli(a->fd, "%-15.15s%s\n", "IP:Port: ", ip_port);
ast_cli(a->fd, "%-15.15s%d\n", "OutgoingLimit: ", peer->outgoinglimit);
ast_cli(a->fd, "%-15.15s%d\n", "rtptimeout: ", peer->rtptimeout);
- if (peer->rtpmask[0])
- ast_cli(a->fd, "%-15.15s%s\n", "rtpmask: ", peer->rtpmask);
- ast_mutex_unlock(&peer->lock);
+ if (peer->rtpmaskstr[0])
+ ast_cli(a->fd, "%-15.15s%s\n", "rtpmask: ", peer->rtpmaskstr);
+ ast_mutex_unlock(&peer->lock);
} else {
ast_cli(a->fd, "Peer %s not found\n", a->argv[3]);
ast_cli(a->fd, "\n");
@@ -2892,8 +2926,8 @@
ast_cli(a->fd, "%-15.15s%d\n", "IncomingLimit: ", user->incominglimit);
ast_cli(a->fd, "%-15.15s%d\n", "InUse: ", user->inUse);
ast_cli(a->fd, "%-15.15s%d\n", "rtptimeout: ", user->rtptimeout);
- if (user->rtpmask[0])
- ast_cli(a->fd, "%-15.15s%s\n", "rtpmask: ", user->rtpmask);
+ if (user->rtpmaskstr[0])
+ ast_cli(a->fd, "%-15.15s%s\n", "rtpmask: ", user->rtpmaskstr);
ast_mutex_unlock(&user->lock);
} else {
ast_cli(a->fd, "User %s not found\n", a->argv[3]);
@@ -3412,12 +3446,6 @@
cur->callerid_num = 0;
}
- if (cur->rtpmask) {
- free(cur->rtpmask);
- cur->rtpmask = NULL;
- }
-
-
if (cur->rtp) {
ast_rtp_instance_destroy(cur->rtp);
cur->rtp = NULL;
@@ -3489,6 +3517,16 @@
if(prev->email) free(prev->email);
if(prev->url) free(prev->url);
if(prev->e164) free(prev->e164);
+ if(prev->rtpmask) {
+ ast_mutex_lock(&prev->rtpmask->lock);
+ prev->rtpmask->inuse--;
+ ast_mutex_unlock(&prev->rtpmask->lock);
+ if (prev->rtpmask->inuse == 0) {
+ regfree(&prev->rtpmask->regex);
+ ast_mutex_destroy(&prev->rtpmask->lock);
+ free(prev->rtpmask);
+ }
+ }
free(prev);
if (cur == peerl.peers) {
@@ -3509,6 +3547,17 @@
prev = cur;
cur = cur->next;
ast_mutex_destroy(&prev->lock);
+
+ if(prev->rtpmask) {
+ ast_mutex_lock(&prev->rtpmask->lock);
+ prev->rtpmask->inuse--;
+ ast_mutex_unlock(&prev->rtpmask->lock);
+ if (prev->rtpmask->inuse == 0) {
+ regfree(&prev->rtpmask->regex);
+ ast_mutex_destroy(&prev->rtpmask->lock);
+ free(prev->rtpmask);
+ }
+ }
free(prev);
if (cur == userl.users) {
break;
Modified: team/may/chan_ooh323_rework/addons/chan_ooh323.h
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/chan_ooh323.h?view=diff&rev=224852&r1=224851&r2=224852
==============================================================================
--- team/may/chan_ooh323_rework/addons/chan_ooh323.h (original)
+++ team/may/chan_ooh323_rework/addons/chan_ooh323.h Tue Oct 20 16:57:20 2009
@@ -50,7 +50,6 @@
#include <asterisk/sched.h>
#include <asterisk/io.h>
#include <asterisk/causes.h>
-#include <asterisk/rtp.h>
#include <asterisk/rtp_engine.h>
#include <asterisk/acl.h>
#include <asterisk/callerid.h>
Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.c?view=diff&rev=224852&r1=224851&r2=224852
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.c Tue Oct 20 16:57:20 2009
@@ -302,7 +302,7 @@
/* First clean all the logical channels, if not already cleaned. */
if(call->logicalChans)
ooClearAllLogicalChannels(call);
-
+
/* Close H.245 connection, if not already closed */
if(call->h245SessionState != OO_H245SESSION_CLOSED)
ooCloseH245Connection(call);
@@ -356,6 +356,17 @@
else {
if(gH323ep.h323Callbacks.onCallCleared)
gH323ep.h323Callbacks.onCallCleared(call);
+ }
+
+ if (call->rtpMask) {
+ ast_mutex_lock(&call->rtpMask->lock);
+ call->rtpMask->inuse--;
+ ast_mutex_unlock(&call->rtpMask->lock);
+ if ((call->rtpMask->inuse) == 0) {
+ regfree(&call->rtpMask->regex);
+ ast_mutex_destroy(&call->rtpMask->lock);
+ free(call->rtpMask);
+ }
}
pctxt = call->msgctxt;
Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.h
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.h?view=diff&rev=224852&r1=224851&r2=224852
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.h (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.h Tue Oct 20 16:57:20 2009
@@ -22,6 +22,7 @@
#include "ooLogChan.h"
#include "ooCapability.h"
+#include <regex.h>
#ifdef __cplusplus
extern "C" {
@@ -132,6 +133,12 @@
ASN1UINT n;
ASN1DynOctStr *elem;
} FastStartResponse;
+
+typedef struct OOH323Regex {
+ regex_t regex;
+ int inuse;
+ ast_mutex_t lock;
+} OOH323Regex;
/**
@@ -208,9 +215,10 @@
ASN1UINT t38sides;
H235TimeStamp alertingTime, connectTime, endTime; /* time data for gatekeeper */
FastStartResponse *pFastStartRes; /* fast start response */
- char rtpMask[20];
- char lastDTMF;
- ASN1UINT nextDTMFstamp;
+ struct OOH323Regex* rtpMask;
+ char rtpMaskStr[120];
+ char lastDTMF;
+ ASN1UINT nextDTMFstamp;
void *usrData; /*!<User can set this to user specific data*/
struct OOH323CallData* next;
struct OOH323CallData* prev;
Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooCapability.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooCapability.c?view=diff&rev=224852&r1=224851&r2=224852
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooCapability.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooCapability.c Tue Oct 20 16:57:20 2009
@@ -2238,7 +2238,7 @@
{
int cap = 0;
ooH323EpCapability *cur=NULL, *epCap=NULL;
- OOH263CapParams *params= NULL;
+ OOCapParams *params= NULL;
/* Find similar capability */
switch(t38Cap->application.t)
{
Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.c?view=diff&rev=224852&r1=224851&r2=224852
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.c Tue Oct 20 16:57:20 2009
@@ -273,8 +273,10 @@
if (bind (socket, (struct sockaddr *) (void*) &m_addr,
sizeof (m_addr)) == -1)
{
- perror ("bind");
- OOTRACEERR1("Error:Bind failed\n");
+ if (errno != EADDRINUSE) {
+ perror ("bind");
+ OOTRACEERR2("Error:Bind failed, error: %d\n", errno);
+ }
return ASN_E_INVSOCKET;
}
Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/oochannels.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/oochannels.c?view=diff&rev=224852&r1=224851&r2=224852
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/oochannels.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/oochannels.c Tue Oct 20 16:57:20 2009
@@ -1037,6 +1037,21 @@
/* Remaining message length is length - tpkt length */
len = len - 4;
+ if(len > MAXMSGLEN - 4)
+ {
+ OOTRACEERR4("Error: Invalid TPKT header for H225 message "
+ "Len = %d (%s, %s)\n", len, call->callType,
+ call->callToken);
+ ooCloseH225Connection(call);
+ ooFreeQ931Message(pctxt, pmsg);
+ if(call->callState < OO_CALL_CLEAR)
+ {
+ call->callEndReason = OO_REASON_INVALIDMESSAGE;
+ call->callState = OO_CALL_CLEAR;
+ }
+ return OO_FAILED;
+ }
+
/* Now read actual Q931 message body. We should make sure that we
receive complete message as indicated by len. If we don't then there
is something wrong. The loop below receives message, then checks whether
@@ -1198,6 +1213,20 @@
for remaining bytes of the message. If message is not received in 3
seconds, then we have a problem. Report an error and exit.
*/
+
+ if(len > MAXMSGLEN - 4)
+ {
+ OOTRACEERR4("Error: Invalid TPKT header length %d for H245 message (%s, %s)\n",
+ len, call->callType, call->callToken);
+ ooFreeH245Message(call, pmsg);
+ if(call->callState < OO_CALL_CLEAR)
+ {
+ call->callEndReason = OO_REASON_INVALIDMESSAGE;
+ call->callState = OO_CALL_CLEAR;
+ }
+ return OO_FAILED;
+ }
+
while(total < len)
{
recvLen = ooSocketRecv (call->pH245Channel->sock, message1, len-total);
Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooh245.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooh245.c?view=diff&rev=224852&r1=224851&r2=224852
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooh245.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooh245.c Tue Oct 20 16:57:20 2009
@@ -1769,7 +1769,8 @@
int ooOnReceivedOpenLogicalChannelAck(OOH323CallData *call,
H245OpenLogicalChannelAck *olcAck)
{
- char remoteip[20], remoteip3[20];
+ char remoteip[20];
+ regmatch_t pmatch[1];
int i;
ooLogicalChannel *pLogicalChannel;
H245H2250LogicalChannelAckParameters *h2250lcap;
@@ -1816,11 +1817,6 @@
iPAddress = unicastAddr->u.iPAddress;
sprintf(remoteip,"%d.%d.%d.%d", iPAddress->network.data[0],
- iPAddress->network.data[1],
- iPAddress->network.data[2],
- iPAddress->network.data[3]);
-
- sprintf(remoteip3,"%03d.%03d.%03d.%03d", iPAddress->network.data[0],
iPAddress->network.data[1],
iPAddress->network.data[2],
iPAddress->network.data[3]);
@@ -1870,14 +1866,12 @@
/* Populate ports &ip for channel */
- if (call->rtpMask[0]) {
- for (i=0;i<strlen(call->rtpMask) && i<strlen(remoteip3);i++)
- if (call->rtpMask[i] != 'x' && call->rtpMask[i] != remoteip3[i]) {
- OOTRACEERR5("ERROR:H245 Address is not matched with filter %s/%s"
- "(%s, %s)\n", remoteip3, call->rtpMask, call->callType, call->callToken);
+ if (call->rtpMaskStr[0]) {
+ if (regexec(&call->rtpMask->regex, remoteip, 1, pmatch, 0)) {
+ OOTRACEERR5("ERROR:H245 Address is not matched with filter %s/%s"
+ "(%s, %s)\n", remoteip, call->rtpMaskStr, call->callType, call->callToken);
return OO_FAILED;
}
-
}
strcpy(pLogicalChannel->remoteIP, remoteip);
@@ -2582,6 +2576,8 @@
call->h245SessionState = OO_H245SESSION_ACTIVE;
ooOnReceivedTerminalCapabilitySet(call, pH245);
+ if(call->localTermCapState == OO_LocalTermCapExchange_Idle)
+ ooSendTermCapMsg(call);
break;
case T_H245RequestMessage_masterSlaveDetermination:
ooHandleMasterSlave(call,
@@ -2886,7 +2882,7 @@
call->nextDTMFstamp && indication->u.signal->m.rtpPresent &&
indication->u.signal->rtp.m.timestampPresent) {
if(call->nextDTMFstamp > indication->u.signal->rtp.timestamp) {
- OOTRACEERR4("Duplicate dtmf %c on ((%s, %s)\n", call->lastDTMF, call->callType,
+ OOTRACEERR4("ERROR:Duplicate dtmf %c on ((%s, %s)\n", call->lastDTMF, call->callType,
call->callToken);
return OO_OK;
}
@@ -2927,7 +2923,8 @@
ooSendTerminalCapabilitySetReject(call, tcs->sequenceNumber,
T_H245TerminalCapabilitySetReject_cause_unspecified);
return OO_OK;
- } else {
+
+ } else {
/* 20090924 */
/* bogus soft-switch can send more than one request with cap set
if it goto to next choice. Right swith don't send but not all are right ;(
@@ -4049,7 +4046,7 @@
H245UnicastAddress *unicastAddress = NULL;
H245UnicastAddress_iPAddress *ipAddress = NULL;
int i;
- char ip3[20];
+ regmatch_t pmatch[1];
if(h245Address->t != T_H245TransportAddress_unicastAddress)
{
@@ -4073,19 +4070,14 @@
ipAddress->network.data[1],
ipAddress->network.data[2],
ipAddress->network.data[3]);
- sprintf(ip3, "%03d.%03d.%03d.%03d", ipAddress->network.data[0],
- ipAddress->network.data[1],
- ipAddress->network.data[2],
- ipAddress->network.data[3]);
- if (call->rtpMask[0]) {
- for (i=0;i<strlen(call->rtpMask) && i<strlen(ip3);i++)
- if (call->rtpMask[i] != 'x' && call->rtpMask[i] != ip3[i]) {
- OOTRACEERR5("ERROR:H245 Address is not matched with filter %s/%s"
- "(%s, %s)\n", ip3, call->rtpMask, call->callType, call->callToken);
+ if (call->rtpMaskStr[0]) {
+ if (regexec(&call->rtpMask->regex, ip, 1, pmatch, 0)) {
+ OOTRACEERR5("ERROR:H245 Address is not matched with filter %s/%s"
+ "(%s, %s)\n", ip, call->rtpMaskStr, call->callType, call->callToken);
return OO_FAILED;
}
-
- }
+ }
+
return OO_OK;
}
Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooh323.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooh323.c?view=diff&rev=224852&r1=224851&r2=224852
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooh323.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooh323.c Tue Oct 20 16:57:20 2009
@@ -217,7 +217,7 @@
}
}
} else if (OO_TESTFLAG (call->flags, OO_M_TUNNELING)) {
- ret =ooSendCapsAndMSdeterm(call);
+ ret =ooSendTCSandMSD(call);
if (ret != OO_OK)
return ret;
}
@@ -777,7 +777,7 @@
}
}
} else if (OO_TESTFLAG (call->flags, OO_M_TUNNELING)) {
- ret =ooSendCapsAndMSdeterm(call);
+ ret =ooSendTCSandMSD(call);
if (ret != OO_OK)
return ret;
}
@@ -999,7 +999,7 @@
}
}
} else if (OO_TESTFLAG (call->flags, OO_M_TUNNELING)) {
- ret =ooSendCapsAndMSdeterm(call);
+ ret =ooSendTCSandMSD(call);
if (ret != OO_OK)
return ret;
}
@@ -1222,7 +1222,7 @@
}
}
} else if (OO_TESTFLAG (call->flags, OO_M_TUNNELING)) {
- ret =ooSendCapsAndMSdeterm(call);
+ ret =ooSendTCSandMSD(call);
if (ret != OO_OK)
return ret;
}
Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooq931.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooq931.c?view=diff&rev=224852&r1=224851&r2=224852
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooq931.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooq931.c Tue Oct 20 16:57:20 2009
@@ -1198,7 +1198,7 @@
*/
-int ooSendCapsAndMSdeterm(OOH323CallData *call)
+int ooSendTCSandMSD(OOH323CallData *call)
{
int ret;
if(call->localTermCapState == OO_LocalTermCapExchange_Idle) {
@@ -1455,10 +1455,8 @@
OOTRACEERR3("Error: Failed to enqueue Alerting message to outbound queue. (%s, %s)\n", call->callType, call->callToken);
}
- ooSendCapsAndMSdeterm(call);
-
- /* memReset(&gH323ep.msgctxt); */
- memReset(call->msgctxt);
+ ooSendTCSandMSD(call);
+ memReset (call->msgctxt);
return ret;
}
@@ -1591,11 +1589,8 @@
OOTRACEERR3("Error: Failed to enqueue Alerting message to outbound queue. (%s, %s)\n", call->callType, call->callToken);
}
- ooSendCapsAndMSdeterm(call);
-
-
- /* memReset(&gH323ep.msgctxt); */
- memReset(call->msgctxt);
+ ooSendTCSandMSD(call);
+ memReset (call->msgctxt);
return ret;
}
Modified: team/may/chan_ooh323_rework/addons/ooh323cDriver.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323cDriver.c?view=diff&rev=224852&r1=224851&r2=224852
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323cDriver.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323cDriver.c Tue Oct 20 16:57:20 2009
@@ -16,11 +16,16 @@
#include "ooh323cDriver.h"
+#include <asterisk.h>
+#include <asterisk/lock.h>
+
#include <asterisk/pbx.h>
#include <asterisk/logger.h>
#undef AST_BACKGROUND_STACKSIZE
#define AST_BACKGROUND_STACKSIZE 768 * 1024
+
+#define SEC_TO_HOLD_THREAD 24
extern OOBOOL gH323Debug;
extern OOH323EndPoint gH323ep;
@@ -31,6 +36,17 @@
static int gtxframes = 20;
+static struct callthread {
+ ast_mutex_t lock;
+ int thePipe[2];
+ OOBOOL inUse;
+ ooCallData* call;
+ struct callthread *next, *prev;
+} *callThreads = NULL;
+
+AST_MUTEX_DEFINE_STATIC(callThreadsLock);
+
+
int ooh323c_start_receive_channel(ooCallData *call, ooLogicalChannel *pChannel);
int ooh323c_start_transmit_channel(ooCallData *call, ooLogicalChannel *pChannel);
int ooh323c_stop_receive_channel(ooCallData *call, ooLogicalChannel *pChannel);
@@ -57,36 +73,111 @@
void* ooh323c_call_thread(void* dummy)
{
- ooMonitorCallChannels((ooCallData*)dummy);
- /* ast_mutex_lock(&call->Lock);
- ast_mutex_unlock(&call->Lock);
- ast_mutex_destroy(&call->Lock);
- memFreePtr(&gH323ep.ctxt, call); */
+ struct callthread* mycthread = (struct callthread *)dummy;
+ struct timespec ts;
+ struct pollfd pfds[1];
+ char c;
+
+ do {
+
+ ooMonitorCallChannels((ooCallData*)mycthread->call);
+ mycthread->call = NULL;
+ mycthread->prev = NULL;
+ mycthread->inUse = FALSE;
+
+ ast_mutex_lock(&callThreadsLock);
+ mycthread->next = callThreads;
+ callThreads = mycthread;
+ if (mycthread->next) mycthread->next->prev = mycthread;
+ ast_mutex_unlock(&callThreadsLock);
+
+ pfds[0].fd = mycthread->thePipe[0];
+ pfds[0].events = POLLIN;
+ ooSocketPoll(pfds, 1, SEC_TO_HOLD_THREAD * 1000);
+ if (ooPDRead(pfds, 1, mycthread->thePipe[0]))
+ read(mycthread->thePipe[0], &c, 1);
+
+ ast_mutex_lock(&callThreadsLock);
+ ast_mutex_lock(&mycthread->lock);
+ if (mycthread->prev)
+ mycthread->prev->next = mycthread->next;
+ else
+ callThreads = mycthread->next;
+ if (mycthread->next)
+ mycthread->next->prev = mycthread->prev;
+ ast_mutex_unlock(&mycthread->lock);
+ ast_mutex_unlock(&callThreadsLock);
+
+ } while (mycthread->call != NULL);
+
+
+ ast_mutex_destroy(&mycthread->lock);
+
+ free(mycthread);
return dummy;
}
-
-/* int ooh323c_start_call_thread(ooCallData *call) {
- if(ast_pthread_create(&call->callThread, NULL, ooh323c_call_thread, call) < 0)
- {
- ast_log(LOG_ERROR, "Unable to start ooh323c call thread for call %s\n", call->callToken);
- return -1;
- }
- return 0;
-} */
int ooh323c_start_call_thread(ooCallData *call) {
pthread_attr_t attr;
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- if(ast_pthread_create_background(&call->callThread, &attr, ooh323c_call_thread, call) < 0)
- {
- ast_log(LOG_ERROR, "Unable to start ooh323c call thread for call %s\n", call->callToken);
- pthread_attr_destroy(&attr);
- return -1;
+ char c = 'c';
+ struct callthread *cur = callThreads;
+
+ ast_mutex_lock(&callThreadsLock);
+ while (cur != NULL && (cur->inUse || ast_mutex_trylock(&cur->lock))) {
+ cur = cur->next;
}
- pthread_attr_destroy(&attr);
+ ast_mutex_unlock(&callThreadsLock);
+
+ if (cur != NULL && cur->inUse) {
+ ast_mutex_unlock(&cur->lock);
+ cur = NULL;
+ }
+
+/* make new thread */
+ if (cur == NULL) {
+ if (!(cur = ast_malloc(sizeof(struct callthread)))) {
+ ast_log(LOG_ERROR, "Unable to allocate thread structure for call %s\n",
+ call->callToken);
+ return -1;
+ }
+
+ memset(cur, 0, sizeof(cur));
+ if ((socketpair(PF_LOCAL, SOCK_STREAM, 0, cur->thePipe)) == -1) {
+ ast_log(LOG_ERROR, "Can't create thread pipe for call %s\n", call->callToken);
+ free(cur);
+ return -1;
+ }
+ cur->inUse = TRUE;
+ cur->call = call;
+
+ ast_mutex_init(&cur->lock);
+
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ if (gH323Debug)
+ ast_debug(1,"new call thread created for call %s\n", call->callToken);
+
+ if(ast_pthread_create_background(&call->callThread, &attr, ooh323c_call_thread, cur) < 0)
+ {
+ ast_log(LOG_ERROR, "Unable to start ooh323c call thread for call %s\n",
+ call->callToken);
+ pthread_attr_destroy(&attr);
+ ast_mutex_destroy(&cur->lock);
+ free(cur);
+ return -1;
+ }
+ pthread_attr_destroy(&attr);
+
+ } else {
+ if (gH323Debug)
+ ast_debug(1,"using existing call thread for call %s\n", call->callToken);
+ cur->inUse = TRUE;
+ cur->call = call;
+ write(cur->thePipe[1], &c, 1);
+ ast_mutex_unlock(&cur->lock);
+
+ }
return 0;
}
@@ -94,8 +185,6 @@
int ooh323c_stop_call_thread(ooCallData *call) {
if (call->callThread != AST_PTHREADT_NULL) {
ooStopMonitorCallChannels(call);
- /* pthread_join(call->callThread, NULL);
- call->callThread = AST_PTHREADT_NULL;*/
}
return 0;
}
@@ -188,7 +277,7 @@
{
if(gH323Debug)
ast_verbose("\tAdding g7231 capability to H323 endpoint\n");
- ret = ooH323EpAddG7231Capability(OO_G7231, 4, 7, FALSE,
+ ret = ooH323EpAddG7231Capability(OO_G7231, 1, 1, FALSE,
OORXANDTX, &ooh323c_start_receive_channel,
&ooh323c_start_transmit_channel,
&ooh323c_stop_receive_channel,
Modified: team/may/chan_ooh323_rework/addons/ooh323cDriver.h
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323cDriver.h?view=diff&rev=224852&r1=224851&r2=224852
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323cDriver.h (original)
+++ team/may/chan_ooh323_rework/addons/ooh323cDriver.h Tue Oct 20 16:57:20 2009
@@ -38,5 +38,5 @@
int convertH323CapToAsteriskCap(int cap);
int ooh323c_set_capability_for_call
(ooCallData *call, struct ast_codec_pref *prefs, int capability, int dtmf, int dtmfcodec,
- int t38support);
+ int t38support);
#endif
More information about the asterisk-commits
mailing list