[asterisk-commits] pcadach: branch pcadach/chan_h323-live r42243 - /team/pcadach/chan_h323-live/...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Sep 7 02:57:53 MST 2006


Author: pcadach
Date: Thu Sep  7 04:57:52 2006
New Revision: 42243

URL: http://svn.digium.com/view/asterisk?rev=42243&view=rev
Log:
Move preparation code of call options and call details into single place

Modified:
    team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp
    team/pcadach/chan_h323-live/channels/h323/ast_h323.h

Modified: team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp
URL: http://svn.digium.com/view/asterisk/team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp?rev=42243&r1=42242&r2=42243&view=diff
==============================================================================
--- team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp (original)
+++ team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp Thu Sep  7 04:57:52 2006
@@ -161,8 +161,9 @@
 
 void MyProcess::Main()
 {
-	extern unsigned PTraceCurrentLevel;
-
+	PTrace::Initialise(PTrace::GetLevel(), NULL, PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine);
+	PTrace::SetStream(logstream);
+	
 	cout << "  == Creating H.323 Endpoint" << endl;
 	if (endPoint) {
 		cout << "  == ENDPOINT ALREADY CREATED" << endl;
@@ -174,8 +175,6 @@
 	   We are requesting 128 (64k in each direction), which is the worst case codec. */
         endPoint->SetInitialBandwidth(1280);
 
-	PTrace::Initialise(PTraceCurrentLevel, NULL, PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine);
-	PTrace::SetStream(logstream);
 }
 
 void PAssertFunc(const char *msg)
@@ -428,17 +427,6 @@
 	}
 	*callReference = connection->GetCallReference();	
 
-	if (opts->cid_num) {
-		connection->ast_cid_num = PString(opts->cid_num);
-	}
-	if (opts->cid_name) {
-		connection->ast_cid_name = PString(opts->cid_name);
-		connection->SetLocalPartyName(connection->ast_cid_name);
-	}
-
-	connection->dtmfCodec = (RTP_DataFrame::PayloadTypes)opts->dtmfcodec;
-	connection->dtmfMode = opts->dtmfmode;
-
 	if (h323debug) {
 		cout << "\t-- " << GetLocalUserName() << " is calling host " << fullAddress << endl;
 		cout << "\t-- Call token is " << (const char *)token << endl;
@@ -656,10 +644,11 @@
 	return;
 }
 
-H323Connection * MyH323EndPoint::CreateConnection(unsigned callReference, void *o)
+H323Connection * MyH323EndPoint::CreateConnection(unsigned callReference, void *userData, H323Transport *transport, H323SignalPDU *setupPDU)
 {
 	unsigned options = 0;
-	call_options_t *opts = (call_options_t *)o;
+	call_options_t *opts = (call_options_t *)userData;
+	MyH323Connection *conn;
 
 	if (opts && opts->noFastStart) {
 		options |= H323Connection::FastStartOptionDisable;
@@ -679,7 +668,11 @@
 		options |= H323Connection::SilenceSUppressionOptionEnable;
 	}
 #endif
-	return new MyH323Connection(*this, callReference, options);
+	conn = new MyH323Connection(*this, callReference, options);
+	if (conn && opts) {
+		conn->SetCallOptions(opts, (setupPDU ? TRUE : FALSE));
+	}
+	return conn;
 }
 
 /* MyH323Connection Implementation */    
@@ -802,17 +795,92 @@
         return connectionState != ShuttingDownConnection;
 }
 
-BOOL MyH323Connection::OnReceivedSignalSetup(const H323SignalPDU & setupPDU)
-{
-	call_details_t cd;
+void MyH323Connection::SetCallOptions(void *o, BOOL isIncoming)
+{
+	call_options_t *opts = (call_options_t *)o;
+
+	progressSetup = opts->progress_setup;
+	progressAlert = opts->progress_alert;
+	dtmfCodec = (RTP_DataFrame::PayloadTypes)opts->dtmfcodec;
+	dtmfMode = opts->dtmfmode;
+
+	if (isIncoming) {
+		if (opts->noFastStart)
+			fastStartState = FastStartDisabled;
+		else
+			fastStartState = FastStartInitiate;
+
+		if (opts->noH245Tunneling)
+			h245Tunneling = FALSE;
+		else
+			h245Tunneling = TRUE;
+	}
+
+	if (opts->cid_num)
+		ast_cid_num = PString(opts->cid_num);
+	if (opts->cid_name) {
+		ast_cid_name = PString(opts->cid_name);
+		if (!isIncoming)
+			SetLocalPartyName(ast_cid_name);
+	}
+}
+
+void MyH323Connection::SetCallDetails(void *callDetails, const H323SignalPDU &setupPDU, BOOL isIncoming)
+{
 	PString sourceE164;
 	PString destE164;
-	PString sourceName;
-	PString sourceAliases;	
+	PString sourceAliases;
 	PString destAliases;
-	PIPSocket::Address Ip;
-	WORD sourcePort;
-	char *s, *s1; 
+	char *s, *s1;
+	call_details_t *cd = (call_details_t *)callDetails;
+
+	memset(cd, 0, sizeof(*cd));
+	cd->call_reference = GetCallReference();
+	cd->call_token = strdup((const char *)GetCallToken());
+
+	sourceE164 = "";
+	setupPDU.GetSourceE164(sourceE164);
+	cd->call_source_e164 = strdup((const char *)sourceE164);
+
+	destE164 = "";
+	setupPDU.GetDestinationE164(destE164);
+	cd->call_dest_e164 = strdup((const char *)destE164);
+
+	/* XXX Is it possible to have this information for outgoing calls too? XXX */
+	if (isIncoming) {
+		PString sourceName;
+		PIPSocket::Address Ip;
+		WORD sourcePort;
+
+		sourceName = setupPDU.GetQ931().GetDisplayName();
+		cd->call_source_name = strdup((const char *)sourceName);
+
+		GetSignallingChannel()->GetRemoteAddress().GetIpAndPort(Ip, sourcePort);
+	 	cd->sourceIp = strdup((const char *)Ip.AsString());
+	}
+
+	/* Convert complex strings */
+	//  FIXME: deal more than one source alias 
+	sourceAliases = setupPDU.GetSourceAliases();
+	s1 = strdup((const char *)sourceAliases);
+	if ((s = strchr(s1, ' ')) != NULL)
+		*s = '\0';
+	if ((s = strchr(s1, '\t')) != NULL)
+		*s = '\0';
+	cd->call_source_aliases = s1;
+
+	destAliases = setupPDU.GetDestinationAlias();
+	s1 = strdup((const char *)destAliases);
+ 	if ((s = strchr(s1, ' ')) != NULL)
+ 		*s = '\0';
+	if ((s = strchr(s1, '\t')) != NULL)
+		*s = '\0';
+	cd->call_dest_alias = s1;
+}
+
+BOOL MyH323Connection::OnReceivedSignalSetup(const H323SignalPDU & setupPDU)
+{
+	call_details_t cd;
 
 	if (h323debug) {
 		cout << ("\t--Received SETUP message\n");
@@ -821,42 +889,7 @@
 	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());
+	SetCallDetails(&cd, setupPDU, TRUE);
 
 	/* Notify Asterisk of the request */
 	call_options_t *res = on_incoming_call(&cd);
@@ -868,19 +901,7 @@
 		return FALSE;
 	}
 
-	progressSetup = res->progress_setup;
-	progressAlert = res->progress_alert;
-	if (res->noFastStart)
-		fastStartState = FastStartDisabled;
-	else
-		fastStartState = FastStartInitiate;
-	if (res->noH245Tunneling)
-		h245Tunneling = FALSE;
-	else
-		h245Tunneling = TRUE;
-	dtmfCodec = (RTP_DataFrame::PayloadTypes)res->dtmfcodec;
-	dtmfMode = res->dtmfmode;
-
+	SetCallOptions(res, TRUE);
 
 	return H323Connection::OnReceivedSignalSetup(setupPDU);
 }
@@ -888,7 +909,6 @@
 BOOL MyH323Connection::OnSendSignalSetup(H323SignalPDU & setupPDU)
 {
 	call_details_t cd;
-	char *s, *s1;
 
 	if (h323debug) { 
 		cout << "	-- Sending SETUP message" << endl;
@@ -897,45 +917,14 @@
 	if (connectionState == ShuttingDownConnection)
 		return FALSE;
 
-	if (!ast_cid_num.IsEmpty()) {
+	if (!ast_cid_num.IsEmpty())
 		setupPDU.GetQ931().SetCallingPartyNumber(ast_cid_num);
-	}
-
-	if (!ast_cid_name.IsEmpty()) {
+	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 (progressSetup)
+		setupPDU.GetQ931().SetProgressIndicator(progressSetup);
 	
-    	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);
+	SetCallDetails(&cd, setupPDU, FALSE);
 
 	int res = on_outgoing_call(&cd);
 	if (!res) {
@@ -945,9 +934,6 @@
 		return FALSE;
 	}
 
-	if (progressSetup) {
-		setupPDU.GetQ931().SetProgressIndicator(progressSetup);
-	}
 	return H323Connection::OnSendSignalSetup(setupPDU);
 }
 

Modified: team/pcadach/chan_h323-live/channels/h323/ast_h323.h
URL: http://svn.digium.com/view/asterisk/team/pcadach/chan_h323-live/channels/h323/ast_h323.h?rev=42243&r1=42242&r2=42243&view=diff
==============================================================================
--- team/pcadach/chan_h323-live/channels/h323/ast_h323.h (original)
+++ team/pcadach/chan_h323-live/channels/h323/ast_h323.h Thu Sep  7 04:57:52 2006
@@ -172,7 +172,7 @@
 	void OnClosedLogicalChannel(H323Connection &, const H323Channel &);
 	void OnConnectionEstablished(H323Connection &, const PString &);
 	void OnConnectionCleared(H323Connection &, const PString &);
-	H323Connection * CreateConnection(unsigned, void *);
+	virtual H323Connection * CreateConnection(unsigned, void *, H323Transport *, H323SignalPDU *);
 	void SendUserTone(const PString &, char);
 	BOOL OnConnectionForwarded(H323Connection &, const PString &, const H323SignalPDU &);
 	BOOL ForwardConnection(H323Connection &, const PString &, const H323SignalPDU &);
@@ -215,6 +215,8 @@
 				     H245_TerminalCapabilitySetReject &);
 	void SetCause(int _cause) { cause = _cause; };
 	virtual BOOL StartControlChannel(const H225_TransportAddress & h245Address);
+	void SetCallOptions(void *opts, BOOL isIncoming);
+	void SetCallDetails(void *callDetails, const H323SignalPDU &setupPDU, BOOL isIncoming);
 
 	PString sourceAliases;
 	PString destAliases;



More information about the asterisk-commits mailing list