protect against seg on busy systems. Bug #2249

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3809 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Jeremy McNamara
2004-09-19 16:53:01 +00:00
parent 5dad6f4319
commit 199ec4356a
4 changed files with 47 additions and 30 deletions

View File

@@ -821,7 +821,7 @@ static struct oh323_pvt *oh323_alloc(int callid)
return p; 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; struct oh323_pvt *p;
@@ -830,14 +830,23 @@ static struct oh323_pvt *find_call(int call_reference)
while(p) { while(p) {
if ((signed int)p->cd.call_reference == call_reference) { if ((signed int)p->cd.call_reference == call_reference) {
/* Found the call */ /* Found the call */
ast_mutex_unlock(&iflock);
return p;
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; p = p->next;
} }
ast_mutex_unlock(&iflock); 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 * 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 oh323_pvt *p;
struct ast_frame f; struct ast_frame f;
ast_log(LOG_DEBUG, "Recieved Digit: %c\n", digit); ast_log(LOG_DEBUG, "Recieved Digit: %c\n", digit);
p = find_call(call_reference);
p = find_call(call_reference, token);
if (!p) { if (!p) {
ast_log(LOG_ERROR, "Private structure not found in send_digit.\n"); 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 * 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 oh323_pvt *p;
struct sockaddr_in us; struct sockaddr_in us;
struct sockaddr_in them; struct sockaddr_in them;
struct rtp_info *info; struct rtp_info *info;
/* XXX This is sooooo bugus. inet_ntoa is not reentrant /* XXX This is sooooo bugus. inet_ntoa is not reentrant
but this function wants to return a static variable so but this function wants to return a static variable so
the only way to do this will be to declare iabuf within 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)); info = (struct rtp_info *) malloc(sizeof(struct rtp_info));
p = find_call(call_reference); p = find_call(call_reference, token);
if (!p) { if (!p) {
ast_log(LOG_ERROR, "Unable to allocate private structure, this is very bad.\n"); ast_log(LOG_ERROR, "Unable to allocate private structure, this is very bad.\n");
@@ -1180,13 +1191,13 @@ exit:
* *
* Returns 1 on success * 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 oh323_pvt *p = NULL;
struct ast_channel *c = NULL; struct ast_channel *c = NULL;
/* Find the call or allocate a private structure if call not found */ /* 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) { if (!p) {
ast_log(LOG_ERROR, "Something is wrong: answer_call\n"); ast_log(LOG_ERROR, "Something is wrong: answer_call\n");
@@ -1229,13 +1240,13 @@ if (!p) {
* *
* Returns nothing * 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 oh323_pvt *p = NULL;
struct sockaddr_in them; struct sockaddr_in them;
/* Find the call or allocate a private structure if call not found */ /* 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) { if (!p) {
ast_log(LOG_ERROR, "Something is wrong: rtp\n"); 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 * Call-back function to signal asterisk that the channel has been answered
* Returns nothing * Returns nothing
*/ */
void connection_made(unsigned call_reference) void connection_made(unsigned call_reference, const char *token)
{ {
struct ast_channel *c = NULL; struct ast_channel *c = NULL;
struct oh323_pvt *p = NULL; struct oh323_pvt *p = NULL;
p = find_call(call_reference); p = find_call(call_reference, token);
if (!p) { if (!p) {
ast_log(LOG_ERROR, "Something is wrong: connection\n"); 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 * Call-back function to signal asterisk that the channel is ringing
* Returns nothing * Returns nothing
*/ */
void chan_ringing(unsigned call_reference) void chan_ringing(unsigned call_reference, const char *token)
{ {
struct ast_channel *c = NULL; struct ast_channel *c = NULL;
struct oh323_pvt *p = NULL; struct oh323_pvt *p = NULL;
p = find_call(call_reference); p = find_call(call_reference, token);
if (!p) { if (!p) {
ast_log(LOG_ERROR, "Something is wrong: ringing\n"); 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 oh323_user *user = NULL;
struct ast_rtp *rtp = NULL; struct ast_rtp *rtp = NULL;
p = find_call(cd.call_reference); p = find_call(cd.call_reference, cd.call_token);
if (!p) { if (!p) {
return; return;

View File

@@ -359,7 +359,7 @@ void MyH323EndPoint::OnConnectionEstablished(H323Connection & connection, const
if (h323debug) { if (h323debug) {
cout << " -- Connection Established with \"" << connection.GetRemotePartyName() << "\"" << endl; 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 /** OnConnectionCleared callback function is called upon the dropping of an established
@@ -493,6 +493,7 @@ MyH323Connection::MyH323Connection(MyH323EndPoint & ep, unsigned callReference,
if (h323debug) { if (h323debug) {
cout << " == New H.323 Connection created." << endl; cout << " == New H.323 Connection created." << endl;
} }
return; return;
} }
@@ -508,7 +509,9 @@ H323Connection::AnswerCallResponse MyH323Connection::OnAnswerCall(const PString
const H323SignalPDU & /*setupPDU*/, const H323SignalPDU & /*setupPDU*/,
H323SignalPDU & /*connectPDU*/) H323SignalPDU & /*connectPDU*/)
{ {
if (!on_answer_call(GetCallReference()))
if (!on_answer_call(GetCallReference(), (const char *)GetCallToken()))
return H323Connection::AnswerCallDenied; return H323Connection::AnswerCallDenied;
/* The call will be answered later with "AnsweringCall()" function. /* The call will be answered later with "AnsweringCall()" function.
@@ -522,7 +525,7 @@ BOOL MyH323Connection::OnAlerting(const H323SignalPDU & /*alertingPDU*/, const
if (h323debug) { if (h323debug) {
cout << " -- Ringing phone for \"" << username << "\"" << endl; cout << " -- Ringing phone for \"" << username << "\"" << endl;
} }
on_chan_ringing(GetCallReference()); on_chan_ringing(GetCallReference(), (const char *)GetCallToken());
return TRUE; return TRUE;
} }
@@ -712,7 +715,7 @@ H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capabilit
WORD port; WORD port;
/* Determine the Local (A side) IP Address and 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) { if (!info) {
return NULL; return NULL;
@@ -720,7 +723,7 @@ H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capabilit
GetControlChannel().GetLocalAddress().GetIpAndPort(externalIpAddress, port); GetControlChannel().GetLocalAddress().GetIpAndPort(externalIpAddress, port);
externalPort = info->port; externalPort = info->port;
if (h323debug) { if (h323debug) {
cout << " =*= In CreateRealTimeLogicalChannel for call " << GetCallReference() << endl; cout << " =*= In CreateRealTimeLogicalChannel for call " << GetCallReference() << endl;
cout << " -- externalIpAddress: " << externalIpAddress << endl; cout << " -- externalIpAddress: " << externalIpAddress << endl;
@@ -728,6 +731,7 @@ H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capabilit
cout << " -- SessionID: " << sessionID << endl; cout << " -- SessionID: " << sessionID << endl;
cout << " -- Direction: " << dir << endl; cout << " -- Direction: " << dir << endl;
} }
return new MyH323_ExternalRTPChannel(*this, capability, dir, sessionID, externalIpAddress, externalPort); 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)) { if (H323_ExternalRTPChannel::OnReceivedAckPDU(param)) {
H323_ExternalRTPChannel::GetRemoteAddress(remoteIpAddress, remotePort); H323_ExternalRTPChannel::GetRemoteAddress(remoteIpAddress, remotePort);
/* Notify Asterisk of remote RTP information */ /* 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 TRUE;
} }
return FALSE; return FALSE;

View File

@@ -241,6 +241,7 @@ class MyH323Connection : public H323Connection {
WORD externalPort; WORD externalPort;
WORD sessionId; WORD sessionId;
BOOL bridging; BOOL bridging;
}; };
class MyH323_ExternalRTPChannel : public H323_ExternalRTPChannel { class MyH323_ExternalRTPChannel : public H323_ExternalRTPChannel {

View File

@@ -119,7 +119,7 @@ extern send_digit_cb on_send_digit;
/* This is a callback prototype function, called to collect /* This is a callback prototype function, called to collect
the external RTP port from Asterisk. */ 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; extern on_connection_cb on_create_connection;
/* This is a callback prototype function, called upon /* 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 /* This is a callback prototype function, called when the openh323
OnStartLogicalChannel is invoked. */ 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; extern start_logchan_cb on_start_logical_channel;
/* This is a callback prototype function, called when openh323 /* This is a callback prototype function, called when openh323
OnAlerting is invoked */ OnAlerting is invoked */
typedef void (*chan_ringing_cb)(unsigned); typedef void (*chan_ringing_cb)(unsigned, const char *);
extern chan_ringing_cb on_chan_ringing; extern chan_ringing_cb on_chan_ringing;
/* This is a callback protoype function, called when the openh323 /* This is a callback protoype function, called when the openh323
OnConnectionEstablished is inovked */ OnConnectionEstablished is inovked */
typedef void (*con_established_cb)(unsigned); typedef void (*con_established_cb)(unsigned, const char *);
extern con_established_cb on_connection_established; extern con_established_cb on_connection_established;
/* This is a callback prototype function, called when the openH323 /* 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); typedef void (*clear_con_cb)(call_details_t);
extern clear_con_cb on_connection_cleared; 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; extern answer_call_cb on_answer_call;
/* debug flag */ /* debug flag */