localAliasNames.RemoveAll();
connection->SetLocalPartyName(PString(callerid));
}
+
+ connection->AST_Outgoing = TRUE;
connection->Unlock();
void MyH323EndPoint::OnConnectionEstablished(H323Connection & connection, const PString & estCallToken)
{
if (h323debug) {
- cout << " -- Connection Established with \"" << connection.GetRemotePartyName() << "\"" << endl;
+ cout << "\t=-= In OnConnectionEstablished for call " << connection.GetCallReference() << endl;
+ cout << "\t\t-- Connection Established with \"" << connection.GetRemotePartyName() << "\"" << endl;
}
on_connection_established(connection.GetCallReference(), (const char *)connection.GetCallToken());
}
if (noFastStart)
options |= H323Connection::FastStartOptionDisable;
+ else
+ options |= H323Connection::FastStartOptionEnable;
if (noH245Tunneling)
options |= H323Connection::H245TunnelingOptionDisable;
+ else
+ options |= H323Connection::H245TunnelingOptionEnable;
return new MyH323Connection(*this, callReference, options);
}
if (h323debug) {
cout << " == New H.323 Connection created." << endl;
}
-
+ AST_RTP_Connected = FALSE;
+ AST_Outgoing = FALSE;
return;
}
}
H323Connection::AnswerCallResponse MyH323Connection::OnAnswerCall(const PString & caller,
- const H323SignalPDU & /*setupPDU*/,
- H323SignalPDU & /*connectPDU*/)
+ const H323SignalPDU & /*setupPDU*/,
+ H323SignalPDU & /*connectPDU*/)
{
+ if (h323debug)
+ cout << "\t=-= In OnAnswerCall for call " << GetCallReference() << endl;
if (!on_answer_call(GetCallReference(), (const char *)GetCallToken()))
return H323Connection::AnswerCallDenied;
BOOL MyH323Connection::OnAlerting(const H323SignalPDU & /*alertingPDU*/, const PString & username)
{
+ PIPSocket::Address remoteIpAddress;
+ WORD remotePort;
+ H323_ExternalRTPChannel * channel;
- if (h323debug) {
- cout << " -- Ringing phone for \"" << username << "\"" << endl;
+ if (h323debug)
+ cout << "\t =-= In OnAlerting for call " << GetCallReference()
+ << ": sessionId=" << sessionId << endl;
+
+ /* Connect RTP if logical channel has already been opened */
+ if (Lock()) {
+ if ( (channel = (H323_ExternalRTPChannel*) FindChannel(sessionId,TRUE)) ) {
+ channel->GetRemoteAddress(remoteIpAddress, remotePort);
+ if (h323debug) {
+ cout << "\t\t--- found logical channel. Connecting RTP" << endl;
+ cout << "\t\tRTP channel id " << sessionId << " parameters:" << endl;
+ cout << "\t\t-- remoteIpAddress: " << remoteIpAddress << endl;
+ cout << "\t\t-- remotePort: " << remotePort << endl;
+ cout << "\t\t-- ExternalIpAddress: " << externalIpAddress << endl;
+ cout << "\t\t-- ExternalPort: " << externalPort << endl;
+ }
+ on_start_logical_channel(GetCallReference(),(const char *)remoteIpAddress.AsString(), remotePort,
+ (const char *)GetCallToken() );
+ AST_RTP_Connected=TRUE;
+ } else
+ if (h323debug)
+ cout << "\t\t--- no logical channels" << endl;
+
+ if (h323debug) {
+ cout << " -- Ringing phone for \"" << username << "\"" << endl;
+ }
+
+ on_chan_ringing(GetCallReference(), (const char *)GetCallToken() );
+ Unlock();
+ return TRUE;
}
- on_chan_ringing(GetCallReference(), (const char *)GetCallToken());
- return TRUE;
+ ast_log(LOG_ERROR,"chan_h323: OnAlerting: Could not obtain connection lock");
+ return FALSE;
}
BOOL MyH323Connection::OnReceivedSignalSetup(const H323SignalPDU & setupPDU)
GetControlChannel().GetLocalAddress().GetIpAndPort(externalIpAddress, port);
externalPort = info->port;
+ sessionId = sessionID;
if (h323debug) {
cout << " =*= In CreateRealTimeLogicalChannel for call " << GetCallReference() << endl;
*/
BOOL MyH323Connection::OnStartLogicalChannel(H323Channel & channel)
{
+ PIPSocket::Address remoteIpAddress;
+ WORD remotePort;
+
if (h323debug) {
cout << " -- Started logical channel: ";
cout << ((channel.GetDirection()==H323Channel::IsTransmitter)?"sending ":((channel.GetDirection()==H323Channel::IsReceiver)?"receiving ":" "));
cout << " -- channelsOpen = " << channelsOpen << endl;
}
+ if (!Lock()) {
+ ast_log(LOG_ERROR,"chan_h323: OnStartLogicalChannel: Could not obtain connection lock");
+ return FALSE;
+ }
+ /* Connect RTP for incoming calls */
+ if (!AST_Outgoing) {
+ H323_ExternalRTPChannel & external = (H323_ExternalRTPChannel &)channel;
+ external.GetRemoteAddress(remoteIpAddress, remotePort);
+ if (h323debug) {
+ cout << "\t\tRTP channel id " << sessionId << " parameters:" << endl;
+ cout << "\t\t-- remoteIpAddress: " << remoteIpAddress << endl;
+ cout << "\t\t-- remotePort: " << remotePort << endl;
+ cout << "\t\t-- ExternalIpAddress: " << externalIpAddress << endl;
+ cout << "\t\t-- ExternalPort: " << externalPort << endl;
+ }
+ /* Notify Asterisk of remote RTP information */
+ on_start_logical_channel(GetCallReference(), (const char *)remoteIpAddress.AsString(), remotePort,
+ (const char *)GetCallToken());
+ AST_RTP_Connected = TRUE;
+ }
+ Unlock();
return TRUE;
}
{
PIPSocket::Address remoteIpAddress;
WORD remotePort;
-
- 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,
- (const char *)connection.GetCallToken() );
- return TRUE;
- }
- return FALSE;
-
+ MyH323Connection* conn = (MyH323Connection*) &connection;
+
+ if (h323debug)
+ cout << "\t=-= In OnReceivedAckPDU for call " << connection.GetCallReference() << endl;
+
+ if (H323_ExternalRTPChannel::OnReceivedAckPDU(param)) {
+ if (!connection.Lock()) {
+ ast_log(LOG_ERROR,"chan_h323: OnReceivedAckPDU: Could not obtain connection lock");
+ return FALSE;
+ }
+ /* if RTP hasn't been connected yet */
+ if (!conn->AST_RTP_Connected) {
+ H323_ExternalRTPChannel::GetRemoteAddress(remoteIpAddress, remotePort);
+ if (h323debug) {
+ cout << "\t\tRTP channel id " << sessionID << " parameters:" << endl;
+ cout << "\t\t-- remoteIpAddress: " << remoteIpAddress << endl;
+ cout << "\t\t-- remotePort: " << remotePort << endl;
+ cout << "\t\t-- ExternalIpAddress: " << conn->externalIpAddress << endl;
+ cout << "\t\t-- ExternalPort: " << conn->externalPort << endl;
+ }
+
+ /* Notify Asterisk of remote RTP information */
+ on_start_logical_channel(connection.GetCallReference(), (const char *)remoteIpAddress.AsString(), remotePort,
+ (const char *)conn->GetCallToken());
+ conn->AST_RTP_Connected = TRUE;
+ }
+ connection.Unlock();
+ return TRUE;
+ }
+ return FALSE;
}
/** IMPLEMENTATION OF C FUNCTIONS */
connection = endPoint->FindConnectionWithLock(currentToken);
+ if (h323debug)
+ ast_verbose("\tSending alerting\n");
+
if (!connection) {
cout << "No connection found for " << token << endl;
return -1;
}
if (!busy) {
+ if (h323debug)
+ ast_verbose("\tanswering call\n");
connection->AnsweringCall(H323Connection::AnswerCallNow);
} else {
+ if (h323debug)
+ ast_verbose("\tdenying call\n");
connection->AnsweringCall(H323Connection::AnswerCallDenied);
}
connection->Unlock();
}
+/* set defalt h323 options */
+void h323_set_options(int nofs, int noh245tun) {
+ noFastStart = nofs;
+ noH245Tunneling = noh245tun;
+ return;
+}
+
} /* extern "C" */