H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capability & capability, H323Channel::Directions dir, unsigned sessionID, const H245_H2250LogicalChannelParameters * /*param*/) { struct rtp_info *info; WORD port; /* Determine the Local (A side) IP Address and port */ info = on_create_connection(GetCallReference(), (const char *)GetCallToken()); if (!info) { return NULL; } GetControlChannel().GetLocalAddress().GetIpAndPort(externalIpAddress, port); externalPort = info->port; sessionId = sessionID; if (h323debug) { cout << " =*= In CreateRealTimeLogicalChannel for call " << GetCallReference() << endl; cout << " -- externalIpAddress: " << externalIpAddress << endl; cout << " -- externalPort: " << externalPort << endl; cout << " -- SessionID: " << sessionID << endl; cout << " -- Direction: " << dir << endl; } return new MyH323_ExternalRTPChannel(*this, capability, dir, sessionID, externalIpAddress, externalPort); }
BOOL MyH323Connection::OnAlerting(const H323SignalPDU & alertingPDU, const PString & username) { if (h323debug) { cout << "\t=-= In OnAlerting for call " << GetCallReference() << ": sessionId=" << sessionId << endl; cout << "\t-- Ringing phone for \"" << username << "\"" << endl; } if (on_progress) { BOOL isInband; unsigned alertingPI; if (!alertingPDU.GetQ931().GetProgressIndicator(alertingPI)) { alertingPI = 0; } if (h323debug) { cout << "\t\t- Progress Indicator: " << alertingPI << endl; } switch(alertingPI) { case Q931::ProgressNotEndToEndISDN: case Q931::ProgressInbandInformationAvailable: isInband = TRUE; break; default: isInband = FALSE; } on_progress(GetCallReference(), (const char *)GetCallToken(), isInband); } on_chan_ringing(GetCallReference(), (const char *)GetCallToken() ); return connectionState != ShuttingDownConnection; }
H323Connection::AnswerCallResponse MyH323Connection::OnAnswerCall(const PString & caller, 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; /* The call will be answered later with "AnsweringCall()" function. */ return H323Connection::AnswerCallDeferred; }
BOOL MyH323Connection::OnReceivedProgress(const H323SignalPDU &pdu) { BOOL isInband; unsigned pi; if (!H323Connection::OnReceivedProgress(pdu)) { return FALSE; } if (!pdu.GetQ931().GetProgressIndicator(pi)) pi = 0; if (h323debug) { cout << "\t- Progress Indicator: " << pi << endl; } switch(pi) { case Q931::ProgressNotEndToEndISDN: case Q931::ProgressInbandInformationAvailable: isInband = TRUE; break; default: isInband = FALSE; } on_progress(GetCallReference(), (const char *)GetCallToken(), isInband); return connectionState != ShuttingDownConnection; }
void MyH323Connection::SendUserInputTone(char tone, unsigned duration) { if (h323debug) { cout << "\t-- Sending user input tone (" << tone << ") to remote" << endl; } on_send_digit(GetCallReference(), tone, (const char *)GetCallToken()); H323Connection::SendUserInputTone(tone, duration); }
void MyH323Connection::OnUserInputString(const PString &value) { if (mode != H323_DTMF_INBAND) { if (h323debug) { cout << "\t-- Received user input string (" << value << ") from remote." << endl; } on_send_digit(GetCallReference(), value[0], (const char *)GetCallToken()); } }
void MyH323Connection::OnReceivedReleaseComplete(const H323SignalPDU & pdu) { if (h323debug) { cout << "\t-- Received RELEASE COMPLETE message..." << endl; } if (on_hangup) on_hangup(GetCallReference(), (const char *)GetCallToken(), pdu.GetQ931().GetCause()); return H323Connection::OnReceivedReleaseComplete(pdu); }
void MyH323Connection::OnUserInputTone(char tone, unsigned duration, unsigned logicalChannel, unsigned rtpTimestamp) { if (mode == H323_DTMF_INBAND) { if (h323debug) { cout << "\t-- Received user input tone (" << tone << ") from remote" << endl; } on_send_digit(GetCallReference(), tone, (const char *)GetCallToken()); } H323Connection::OnUserInputTone(tone, duration, logicalChannel, rtpTimestamp); }
BOOL MyH323Connection::OnAlerting(const H323SignalPDU & /*alertingPDU*/, const PString & username) { PIPSocket::Address remoteIpAddress; WORD remotePort; H323_ExternalRTPChannel * channel; 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; } ast_log(LOG_ERROR,"chan_h323: OnAlerting: Could not obtain connection lock"); return FALSE; }
H323Connection::AnswerCallResponse MyH323Connection::OnAnswerCall(const PString & caller, const H323SignalPDU & setupPDU, H323SignalPDU & /*connectPDU*/) { unsigned pi; if (h323debug) { cout << "\t=-= In OnAnswerCall for call " << GetCallReference() << endl; } if (connectionState == ShuttingDownConnection) return H323Connection::AnswerCallDenied; if (!setupPDU.GetQ931().GetProgressIndicator(pi)) { pi = 0; } if (h323debug) { cout << "\t\t- Progress Indicator: " << pi << endl; } if (progressAlert) { pi = progressAlert; } else if (pi == Q931::ProgressOriginNotISDN) { pi = Q931::ProgressInbandInformationAvailable; } if (pi) { alertingPDU->GetQ931().SetProgressIndicator(pi); } if (h323debug) { cout << "\t\t- Inserting PI of " << pi << " into ALERTING message" << endl; } if (!on_answer_call(GetCallReference(), (const char *)GetCallToken())) { return H323Connection::AnswerCallDenied; } /* The call will be answered later with "AnsweringCall()" function. */ return H323Connection::AnswerCallDeferredWithMedia; }
BOOL MyH323Connection::OnSendSignalSetup(H323SignalPDU & setupPDU) { call_details_t cd; char *s, *s1; if (h323debug) { cout << " -- Sending SETUP message" << endl; } sourceAliases = setupPDU.GetSourceAliases(); destAliases = setupPDU.GetDestinationAlias(); sourceE164 = ""; setupPDU.GetSourceE164(sourceE164); destE164 = ""; setupPDU.GetDestinationE164(destE164); /* Convert complex strings */ // FIXME: deal more than one source alias if ((s = strchr(sourceAliases, ' ')) != NULL) *s = '\0'; if ((s = strchr(sourceAliases, '\t')) != NULL) *s = '\0'; if ((s1 = strchr(destAliases, ' ')) != NULL) *s1 = '\0'; if ((s1 = strchr(destAliases, '\t')) != NULL) *s1 = '\0'; cd.call_reference = GetCallReference(); Lock(); cd.call_token = strdup((const char *)GetCallToken()); Unlock(); cd.call_source_aliases = strdup((const char *)sourceAliases); cd.call_dest_alias = strdup((const char *)destAliases); cd.call_source_e164 = strdup((const char *)sourceE164); cd.call_dest_e164 = strdup((const char *)destE164); int res = on_outgoing_call(cd); if (!res) { if (h323debug) { cout << " -- Call Failed" << endl; } return FALSE; } return H323Connection::OnSendSignalSetup(setupPDU); }
BOOL MyH323Connection::OnReceivedCapabilitySet(const H323Capabilities & remoteCaps, const H245_MultiplexCapability * muxCap, H245_TerminalCapabilitySetReject & reject) { if (!H323Connection::OnReceivedCapabilitySet(remoteCaps, muxCap, reject)) { return FALSE; } const H323Capability * cap = remoteCaps.FindCapability(H323_UserInputCapability::SubTypeNames[H323_UserInputCapability::SignalToneRFC2833]); if (cap != NULL) { RTP_DataFrame::PayloadTypes pt = ((H323_UserInputCapability*)cap)->GetPayloadType(); on_set_rfc2833_payload(GetCallReference(), (const char *)GetCallToken(), (int)pt); if (h323debug) { cout << "\t-- Inbound RFC2833 on payload " << pt << endl; } } return TRUE; }
/** This callback function is invoked once upon creation of each * channel for an H323 session */ 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 << (const char *)(channel.GetCapability()).GetFormatName() << endl; } /* adjust the count of channels we have open */ channelsOpen++; if (h323debug) { 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; }
void MyH323Connection::OnSendCapabilitySet(H245_TerminalCapabilitySet & pdu) { PINDEX i; H323Connection::OnSendCapabilitySet(pdu); H245_ArrayOf_CapabilityTableEntry & tables = pdu.m_capabilityTable; for(i = 0; i < tables.GetSize(); i++) { H245_CapabilityTableEntry & entry = tables[i]; if (entry.HasOptionalField(H245_CapabilityTableEntry::e_capability)) { H245_Capability & cap = entry.m_capability; if (cap.GetTag() == H245_Capability::e_receiveRTPAudioTelephonyEventCapability) { H245_AudioTelephonyEventCapability & atec = cap; atec.m_dynamicRTPPayloadType = dtmfCodec; on_set_rfc2833_payload(GetCallReference(), (const char *)GetCallToken(), (int)dtmfCodec); if (h323debug) { cout << "\t-- Transmitting RFC2833 on payload " << atec.m_dynamicRTPPayloadType << endl; } } } } }
BOOL MyH323Connection::OnReceivedSignalSetup(const H323SignalPDU & setupPDU) { call_details_t cd; PString sourceE164; PString destE164; PString sourceName; PString sourceAliases; PString destAliases; PIPSocket::Address Ip; WORD sourcePort; char *s, *s1; if (h323debug) { cout << ("\t--Received SETUP message\n"); } if (connectionState == ShuttingDownConnection) return FALSE; sourceAliases = setupPDU.GetSourceAliases(); destAliases = setupPDU.GetDestinationAlias(); sourceE164 = ""; setupPDU.GetSourceE164(sourceE164); sourceName = ""; sourceName=setupPDU.GetQ931().GetDisplayName(); destE164 = ""; setupPDU.GetDestinationE164(destE164); /* Convert complex strings */ // FIXME: deal more than one source alias if ((s = strchr(sourceAliases, ' ')) != NULL) { *s = '\0'; } if ((s = strchr(sourceAliases, '\t')) != NULL) { *s = '\0'; } if ((s1 = strchr(destAliases, ' ')) != NULL) { *s1 = '\0'; } if ((s1 = strchr(destAliases, '\t')) != NULL) { *s1 = '\0'; } memset(&cd, 0, sizeof(cd)); cd.call_reference = GetCallReference(); cd.call_token = strdup((const char *)GetCallToken()); cd.call_source_aliases = strdup((const char *)sourceAliases); cd.call_dest_alias = strdup((const char *)destAliases); cd.call_source_e164 = strdup((const char *)sourceE164); cd.call_dest_e164 = strdup((const char *)destE164); cd.call_source_name = strdup((const char *)sourceName); GetSignallingChannel()->GetRemoteAddress().GetIpAndPort(Ip, sourcePort); cd.sourceIp = strdup((const char *)Ip.AsString()); /* Notify Asterisk of the request */ call_options_t *res = on_incoming_call(&cd); if (!res) { if (h323debug) { cout << " -- Call Failed" << endl; } return FALSE; } progressSetup = res->progress_setup; progressAlert = res->progress_alert; dtmfCodec = (RTP_DataFrame::PayloadTypes)res->dtmfcodec; return H323Connection::OnReceivedSignalSetup(setupPDU); }
void MyH323Connection::OnSetLocalCapabilities() { if (on_setcapabilities) on_setcapabilities(GetCallReference(), (const char *)callToken); }
BOOL MyH323Connection::OnReceivedSignalSetup(const H323SignalPDU & setupPDU) { if (h323debug) { ast_verbose(" -- Received SETUP message\n"); } call_details_t cd; PString sourceE164; PString destE164; PString sourceName; PString sourceAliases; PString destAliases; PIPSocket::Address Ip; WORD sourcePort; char *s, *s1; sourceAliases = setupPDU.GetSourceAliases(); destAliases = setupPDU.GetDestinationAlias(); sourceE164 = ""; setupPDU.GetSourceE164(sourceE164); sourceName = ""; sourceName=setupPDU.GetQ931().GetDisplayName(); destE164 = ""; setupPDU.GetDestinationE164(destE164); /* Convert complex strings */ // FIXME: deal more than one source alias if ((s = strchr(sourceAliases, ' ')) != NULL) *s = '\0'; if ((s = strchr(sourceAliases, '\t')) != NULL) *s = '\0'; if ((s1 = strchr(destAliases, ' ')) != NULL) *s1 = '\0'; if ((s1 = strchr(destAliases, '\t')) != NULL) *s1 = '\0'; cd.call_reference = GetCallReference(); Lock(); cd.call_token = strdup((const char *)GetCallToken()); Unlock(); cd.call_source_aliases = strdup((const char *)sourceAliases); cd.call_dest_alias = strdup((const char *)destAliases); cd.call_source_e164 = strdup((const char *)sourceE164); cd.call_dest_e164 = strdup((const char *)destE164); cd.call_source_name = strdup((const char *)sourceName); GetSignallingChannel()->GetRemoteAddress().GetIpAndPort(Ip, sourcePort); cd.sourceIp = strdup((const char *)Ip.AsString()); /* Notify Asterisk of the request */ int res = on_incoming_call(cd); if (!res) { if (h323debug) { cout << " -- Call Failed" << endl; } return FALSE; } return H323Connection::OnReceivedSignalSetup(setupPDU); }
BOOL MyH323Connection::OnSendSignalSetup(H323SignalPDU & setupPDU) { call_details_t cd; char *s, *s1; if (h323debug) { cout << " -- Sending SETUP message" << endl; } if (connectionState == ShuttingDownConnection) return FALSE; if (!ast_cid_num.IsEmpty()) { setupPDU.GetQ931().SetCallingPartyNumber(ast_cid_num); } if (!ast_cid_name.IsEmpty()) { setupPDU.GetQ931().SetDisplayName(ast_cid_name); } sourceAliases = setupPDU.GetSourceAliases(); destAliases = setupPDU.GetDestinationAlias(); sourceE164 = ""; setupPDU.GetSourceE164(sourceE164); destE164 = ""; setupPDU.GetDestinationE164(destE164); /* Convert complex strings */ // FIXME: deal more than one source alias if ((s = strchr(sourceAliases, ' ')) != NULL) { *s = '\0'; } if ((s = strchr(sourceAliases, '\t')) != NULL) { *s = '\0'; } if ((s1 = strchr(destAliases, ' ')) != NULL) { *s1 = '\0'; } if ((s1 = strchr(destAliases, '\t')) != NULL) { *s1 = '\0'; } memset(&cd, 0, sizeof(cd)); cd.call_reference = GetCallReference(); cd.call_token = strdup((const char *)GetCallToken()); cd.call_source_aliases = strdup((const char *)sourceAliases); cd.call_dest_alias = strdup((const char *)destAliases); cd.call_source_e164 = strdup((const char *)sourceE164); cd.call_dest_e164 = strdup((const char *)destE164); int res = on_outgoing_call(&cd); if (!res) { if (h323debug) { cout << "\t-- Call Failed" << endl; } return FALSE; } if (progressSetup) { setupPDU.GetQ931().SetProgressIndicator(progressSetup); } return H323Connection::OnSendSignalSetup(setupPDU); }