コード例 #1
0
BOOL MyH323_ExternalRTPChannel::OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param)
{
       PIPSocket::Address remoteIpAddress;
       WORD remotePort;
       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;
}
コード例 #2
0
/** 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;	
}
BOOL MyH323_ExternalRTPChannel::OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param)
{
	PIPSocket::Address remoteIpAddress;
	WORD remotePort;

	if (h323debug) {
		cout << "	MyH323_ExternalRTPChannel::OnReceivedAckPDU" << endl;
	}

	if (H323_ExternalRTPChannel::OnReceivedAckPDU(param)) {
		GetRemoteAddress(remoteIpAddress, remotePort);
		if (h323debug) {
			cout << "		-- remoteIpAddress: " << remoteIpAddress << endl;
			cout << "		-- remotePort: " << remotePort << endl;
		}
		on_start_rtp_channel(connection.GetCallReference(), (const char *)remoteIpAddress.AsString(),
				remotePort, (const char *)connection.GetCallToken(), (int)payloadCode);
		return TRUE;
	}
	return FALSE;
}
コード例 #4
0
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;
}
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);
}
コード例 #6
0
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);
}
コード例 #7
0
/** OnConnectionCleared callback function is called upon the dropping of an established
  * H323 connection. 
  */
void MyH323EndPoint::OnConnectionCleared(H323Connection & connection, const PString & clearedCallToken)
{
	PString remoteName;
	call_details_t cd;
        PIPSocket::Address Ip;
	WORD sourcePort;

	remoteName = connection.GetRemotePartyName();

	cd.call_reference = connection.GetCallReference();
	cd.call_token = strdup((const char *)clearedCallToken);
	cd.call_source_aliases = strdup((const char *)connection.GetRemotePartyName());
	
  	connection.GetSignallingChannel()->GetRemoteAddress().GetIpAndPort(Ip, sourcePort);
	cd.sourceIp = strdup((const char *)Ip.AsString());
	
	/* Convert complex strings */
	char *s;
	if ((s = strchr(cd.call_source_aliases, ' ')) != NULL)
		*s = '\0';

	switch (connection.GetCallEndReason()) {
		case H323Connection::EndedByCallForwarded :
			if (h323debug)
				cout << " -- " << remoteName << " has forwarded the call" << endl;
			break;
		case H323Connection::EndedByRemoteUser :
			if (h323debug)
				cout << " -- " << remoteName << " has cleared the call" << endl;
			break;
		case H323Connection::EndedByCallerAbort :
			if (h323debug)
				cout << " -- " << remoteName << " has stopped calling" << endl;
			break;
		case H323Connection::EndedByRefusal :
			if (h323debug)
				cout << " -- " << remoteName << " did not accept your call" << endl;
			break;
		case H323Connection::EndedByRemoteBusy :
			if (h323debug)
			cout << " -- " << remoteName << " was busy" << endl;
			break;
		case H323Connection::EndedByRemoteCongestion :
			if (h323debug)
				cout << " -- Congested link to " << remoteName << endl;
			break;
		case H323Connection::EndedByNoAnswer :
			if (h323debug)
				cout << " -- " << remoteName << " did not answer your call" << endl;
			break;
		case H323Connection::EndedByTransportFail :
			if (h323debug)
				cout << " -- Call with " << remoteName << " ended abnormally" << endl;
			break;
		case H323Connection::EndedByCapabilityExchange :
			if (h323debug)
				cout << " -- Could not find common codec with " << remoteName << endl;
			break;
		case H323Connection::EndedByNoAccept :
			if (h323debug)
				cout << " -- Did not accept incoming call from " << remoteName << endl;
			break;
		case H323Connection::EndedByAnswerDenied :
			if (h323debug)
				cout << " -- Refused incoming call from " << remoteName << endl;
			break;
		case H323Connection::EndedByNoUser :
			if (h323debug)
				cout << " -- Remote endpoint could not find user: "******" -- Call to " << remoteName << " aborted, insufficient bandwidth." << endl;
			break;
		case H323Connection::EndedByUnreachable :
			if (h323debug)
				cout << " -- " << remoteName << " could not be reached." << endl;
			break;
		case H323Connection::EndedByHostOffline :
			if (h323debug)
				cout << " -- " << remoteName << " is not online." << endl;
			break;
		case H323Connection::EndedByNoEndPoint :
			if (h323debug)
				cout << " -- No phone running for " << remoteName << endl;
			break;
		case H323Connection::EndedByConnectFail :
			if (h323debug)
				cout << " -- Transport error calling " << remoteName << endl;
			break;
		default :
			if (h323debug)
				cout << " -- Call with " << remoteName << " completed (" << connection.GetCallEndReason() << ")" << endl;

	}

	if(connection.IsEstablished()) 
		if (h323debug)
			cout << "	 -- Call duration " << setprecision(0) << setw(5) << (PTime() - connection.GetConnectionStartTime()) << endl;

	/* Invoke the PBX application registered callback */
	on_connection_cleared(cd);

	return;
}