protect against seg on busy systems. Bug #2249
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3809 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
parent
701d17cfbf
commit
efbfbe86bf
|
@ -821,7 +821,7 @@ static struct oh323_pvt *oh323_alloc(int callid)
|
|||
return p;
|
||||
}
|
||||
|
||||
static struct oh323_pvt *find_call(int call_reference)
|
||||
static struct oh323_pvt *find_call(int call_reference, const char *token)
|
||||
{
|
||||
struct oh323_pvt *p;
|
||||
|
||||
|
@ -830,14 +830,23 @@ static struct oh323_pvt *find_call(int call_reference)
|
|||
|
||||
while(p) {
|
||||
if ((signed int)p->cd.call_reference == call_reference) {
|
||||
/* Found the call */
|
||||
ast_mutex_unlock(&iflock);
|
||||
return p;
|
||||
/* Found the call */
|
||||
|
||||
|
||||
if ((token != NULL) && (strcmp(p->cd.call_token, token) == 0)) {
|
||||
ast_mutex_unlock(&iflock);
|
||||
return p;
|
||||
} else if(token == NULL) {
|
||||
ast_log(LOG_DEBUG, "token is NULL, skipping comparition\n");
|
||||
ast_mutex_unlock(&iflock);
|
||||
return p;
|
||||
}
|
||||
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
ast_mutex_unlock(&iflock);
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
@ -979,13 +988,14 @@ struct oh323_peer *find_peer(char *dest_peer)
|
|||
* Callback for sending digits from H.323 up to asterisk
|
||||
*
|
||||
*/
|
||||
int send_digit(unsigned call_reference, char digit)
|
||||
int send_digit(unsigned call_reference, char digit, const char *token)
|
||||
{
|
||||
struct oh323_pvt *p;
|
||||
struct ast_frame f;
|
||||
|
||||
ast_log(LOG_DEBUG, "Recieved Digit: %c\n", digit);
|
||||
p = find_call(call_reference);
|
||||
|
||||
p = find_call(call_reference, token);
|
||||
|
||||
if (!p) {
|
||||
ast_log(LOG_ERROR, "Private structure not found in send_digit.\n");
|
||||
|
@ -1009,12 +1019,13 @@ int send_digit(unsigned call_reference, char digit)
|
|||
*
|
||||
* Returns the local RTP information
|
||||
*/
|
||||
struct rtp_info *create_connection(unsigned call_reference)
|
||||
struct rtp_info *create_connection(unsigned call_reference, const char * token)
|
||||
{
|
||||
struct oh323_pvt *p;
|
||||
struct sockaddr_in us;
|
||||
struct sockaddr_in them;
|
||||
struct rtp_info *info;
|
||||
|
||||
/* XXX This is sooooo bugus. inet_ntoa is not reentrant
|
||||
but this function wants to return a static variable so
|
||||
the only way to do this will be to declare iabuf within
|
||||
|
@ -1023,7 +1034,7 @@ struct rtp_info *create_connection(unsigned call_reference)
|
|||
|
||||
info = (struct rtp_info *) malloc(sizeof(struct rtp_info));
|
||||
|
||||
p = find_call(call_reference);
|
||||
p = find_call(call_reference, token);
|
||||
|
||||
if (!p) {
|
||||
ast_log(LOG_ERROR, "Unable to allocate private structure, this is very bad.\n");
|
||||
|
@ -1180,13 +1191,13 @@ exit:
|
|||
*
|
||||
* Returns 1 on success
|
||||
*/
|
||||
static int answer_call(unsigned call_reference)
|
||||
static int answer_call(unsigned call_reference, const char *token)
|
||||
{
|
||||
struct oh323_pvt *p = NULL;
|
||||
struct ast_channel *c = NULL;
|
||||
|
||||
|
||||
/* Find the call or allocate a private structure if call not found */
|
||||
p = find_call(call_reference);
|
||||
p = find_call(call_reference, token);
|
||||
|
||||
if (!p) {
|
||||
ast_log(LOG_ERROR, "Something is wrong: answer_call\n");
|
||||
|
@ -1229,13 +1240,13 @@ if (!p) {
|
|||
*
|
||||
* Returns nothing
|
||||
*/
|
||||
void setup_rtp_connection(unsigned call_reference, const char *remoteIp, int remotePort)
|
||||
void setup_rtp_connection(unsigned call_reference, const char *remoteIp, int remotePort, const char *token)
|
||||
{
|
||||
struct oh323_pvt *p = NULL;
|
||||
struct sockaddr_in them;
|
||||
|
||||
/* Find the call or allocate a private structure if call not found */
|
||||
p = find_call(call_reference);
|
||||
p = find_call(call_reference, token);
|
||||
|
||||
if (!p) {
|
||||
ast_log(LOG_ERROR, "Something is wrong: rtp\n");
|
||||
|
@ -1254,12 +1265,12 @@ void setup_rtp_connection(unsigned call_reference, const char *remoteIp, int rem
|
|||
* Call-back function to signal asterisk that the channel has been answered
|
||||
* Returns nothing
|
||||
*/
|
||||
void connection_made(unsigned call_reference)
|
||||
void connection_made(unsigned call_reference, const char *token)
|
||||
{
|
||||
struct ast_channel *c = NULL;
|
||||
struct oh323_pvt *p = NULL;
|
||||
|
||||
p = find_call(call_reference);
|
||||
p = find_call(call_reference, token);
|
||||
|
||||
if (!p) {
|
||||
ast_log(LOG_ERROR, "Something is wrong: connection\n");
|
||||
|
@ -1281,12 +1292,12 @@ void connection_made(unsigned call_reference)
|
|||
* Call-back function to signal asterisk that the channel is ringing
|
||||
* Returns nothing
|
||||
*/
|
||||
void chan_ringing(unsigned call_reference)
|
||||
void chan_ringing(unsigned call_reference, const char *token)
|
||||
{
|
||||
struct ast_channel *c = NULL;
|
||||
struct oh323_pvt *p = NULL;
|
||||
|
||||
p = find_call(call_reference);
|
||||
p = find_call(call_reference, token);
|
||||
|
||||
if (!p) {
|
||||
ast_log(LOG_ERROR, "Something is wrong: ringing\n");
|
||||
|
@ -1339,7 +1350,7 @@ void cleanup_connection(call_details_t cd)
|
|||
struct oh323_user *user = NULL;
|
||||
struct ast_rtp *rtp = NULL;
|
||||
|
||||
p = find_call(cd.call_reference);
|
||||
p = find_call(cd.call_reference, cd.call_token);
|
||||
|
||||
if (!p) {
|
||||
return;
|
||||
|
|
|
@ -359,7 +359,7 @@ void MyH323EndPoint::OnConnectionEstablished(H323Connection & connection, const
|
|||
if (h323debug) {
|
||||
cout << " -- Connection Established with \"" << connection.GetRemotePartyName() << "\"" << endl;
|
||||
}
|
||||
on_connection_established(connection.GetCallReference());
|
||||
on_connection_established(connection.GetCallReference(), (const char *)connection.GetCallToken());
|
||||
}
|
||||
|
||||
/** OnConnectionCleared callback function is called upon the dropping of an established
|
||||
|
@ -493,6 +493,7 @@ MyH323Connection::MyH323Connection(MyH323EndPoint & ep, unsigned callReference,
|
|||
if (h323debug) {
|
||||
cout << " == New H.323 Connection created." << endl;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -508,7 +509,9 @@ H323Connection::AnswerCallResponse MyH323Connection::OnAnswerCall(const PString
|
|||
const H323SignalPDU & /*setupPDU*/,
|
||||
H323SignalPDU & /*connectPDU*/)
|
||||
{
|
||||
if (!on_answer_call(GetCallReference()))
|
||||
|
||||
|
||||
if (!on_answer_call(GetCallReference(), (const char *)GetCallToken()))
|
||||
return H323Connection::AnswerCallDenied;
|
||||
|
||||
/* The call will be answered later with "AnsweringCall()" function.
|
||||
|
@ -522,7 +525,7 @@ BOOL MyH323Connection::OnAlerting(const H323SignalPDU & /*alertingPDU*/, const
|
|||
if (h323debug) {
|
||||
cout << " -- Ringing phone for \"" << username << "\"" << endl;
|
||||
}
|
||||
on_chan_ringing(GetCallReference());
|
||||
on_chan_ringing(GetCallReference(), (const char *)GetCallToken());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -712,7 +715,7 @@ H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capabilit
|
|||
WORD port;
|
||||
|
||||
/* Determine the Local (A side) IP Address and port */
|
||||
info = on_create_connection(GetCallReference());
|
||||
info = on_create_connection(GetCallReference(), (const char *)GetCallToken());
|
||||
|
||||
if (!info) {
|
||||
return NULL;
|
||||
|
@ -720,7 +723,7 @@ H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capabilit
|
|||
|
||||
GetControlChannel().GetLocalAddress().GetIpAndPort(externalIpAddress, port);
|
||||
externalPort = info->port;
|
||||
|
||||
|
||||
if (h323debug) {
|
||||
cout << " =*= In CreateRealTimeLogicalChannel for call " << GetCallReference() << endl;
|
||||
cout << " -- externalIpAddress: " << externalIpAddress << endl;
|
||||
|
@ -728,6 +731,7 @@ H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capabilit
|
|||
cout << " -- SessionID: " << sessionID << endl;
|
||||
cout << " -- Direction: " << dir << endl;
|
||||
}
|
||||
|
||||
return new MyH323_ExternalRTPChannel(*this, capability, dir, sessionID, externalIpAddress, externalPort);
|
||||
}
|
||||
|
||||
|
@ -793,7 +797,8 @@ BOOL MyH323_ExternalRTPChannel::OnReceivedAckPDU(const H245_H2250LogicalChannelA
|
|||
if (H323_ExternalRTPChannel::OnReceivedAckPDU(param)) {
|
||||
H323_ExternalRTPChannel::GetRemoteAddress(remoteIpAddress, remotePort);
|
||||
/* Notify Asterisk of remote RTP information */
|
||||
on_start_logical_channel(connection.GetCallReference(), (const char *)remoteIpAddress.AsString(), remotePort);
|
||||
on_start_logical_channel(connection.GetCallReference(), (const char *)remoteIpAddress.AsString(), remotePort,
|
||||
(const char *)connection.GetCallToken() );
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
|
|
@ -241,6 +241,7 @@ class MyH323Connection : public H323Connection {
|
|||
WORD externalPort;
|
||||
WORD sessionId;
|
||||
BOOL bridging;
|
||||
|
||||
};
|
||||
|
||||
class MyH323_ExternalRTPChannel : public H323_ExternalRTPChannel {
|
||||
|
|
|
@ -119,7 +119,7 @@ extern send_digit_cb on_send_digit;
|
|||
|
||||
/* This is a callback prototype function, called to collect
|
||||
the external RTP port from Asterisk. */
|
||||
typedef rtp_info_t *(*on_connection_cb)(unsigned);
|
||||
typedef rtp_info_t *(*on_connection_cb)(unsigned, const char *);
|
||||
extern on_connection_cb on_create_connection;
|
||||
|
||||
/* This is a callback prototype function, called upon
|
||||
|
@ -134,17 +134,17 @@ extern setup_outbound_cb on_outgoing_call;
|
|||
|
||||
/* This is a callback prototype function, called when the openh323
|
||||
OnStartLogicalChannel is invoked. */
|
||||
typedef void (*start_logchan_cb)(unsigned int, const char *, int);
|
||||
typedef void (*start_logchan_cb)(unsigned int, const char *, int, const char *);
|
||||
extern start_logchan_cb on_start_logical_channel;
|
||||
|
||||
/* This is a callback prototype function, called when openh323
|
||||
OnAlerting is invoked */
|
||||
typedef void (*chan_ringing_cb)(unsigned);
|
||||
typedef void (*chan_ringing_cb)(unsigned, const char *);
|
||||
extern chan_ringing_cb on_chan_ringing;
|
||||
|
||||
/* This is a callback protoype function, called when the openh323
|
||||
OnConnectionEstablished is inovked */
|
||||
typedef void (*con_established_cb)(unsigned);
|
||||
typedef void (*con_established_cb)(unsigned, const char *);
|
||||
extern con_established_cb on_connection_established;
|
||||
|
||||
/* This is a callback prototype function, called when the openH323
|
||||
|
@ -152,7 +152,7 @@ extern con_established_cb on_connection_established;
|
|||
typedef void (*clear_con_cb)(call_details_t);
|
||||
extern clear_con_cb on_connection_cleared;
|
||||
|
||||
typedef int (*answer_call_cb)(unsigned);
|
||||
typedef int (*answer_call_cb)(unsigned, const char *);
|
||||
extern answer_call_cb on_answer_call;
|
||||
|
||||
/* debug flag */
|
||||
|
|
Reference in New Issue