Index: channels/chan_h323.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_h323.c,v
retrieving revision 1.72
diff -u -r1.72 chan_h323.c
--- channels/chan_h323.c	8 Aug 2004 17:15:02 -0000	1.72
+++ channels/chan_h323.c	13 Aug 2004 13:06:46 -0000
@@ -821,7 +821,7 @@
 	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;
 
@@ -830,14 +830,23 @@
 
         while(p) {
                 if ((signed int)p->cd.call_reference == call_reference) {
-                        /* Found the call */						
-						ast_mutex_unlock(&iflock);
-						return p;
+                        /* Found the call */
+                         
+                        
+                        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; 
         }
         ast_mutex_unlock(&iflock);
-		return NULL;
+	return NULL;
         
 }
 
@@ -979,13 +988,14 @@
   * 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 ast_frame f;
 
 	ast_log(LOG_DEBUG, "Recieved Digit: %c\n", digit);
-	p = find_call(call_reference);
+        
+	p = find_call(call_reference, token); 
 	
 	if (!p) {
 		ast_log(LOG_ERROR, "Private structure not found in send_digit.\n");
@@ -1009,12 +1019,13 @@
   *
   * 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 sockaddr_in us;
 	struct sockaddr_in them;
 	struct rtp_info *info;
+        
 	/* XXX This is sooooo bugus.  inet_ntoa is not reentrant
 	   but this function wants to return a static variable so
 	   the only way to do this will be to declare iabuf within
@@ -1023,7 +1034,7 @@
 
 	info = (struct rtp_info *) malloc(sizeof(struct rtp_info));
 
-	p = find_call(call_reference);
+	p = find_call(call_reference, token); 
 
 	if (!p) {
 		ast_log(LOG_ERROR, "Unable to allocate private structure, this is very bad.\n");
@@ -1180,13 +1191,13 @@
  *
  * 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 ast_channel *c = NULL;
-	
+
 	/* 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) {
 		ast_log(LOG_ERROR, "Something is wrong: answer_call\n");
@@ -1229,13 +1240,13 @@
   *
   * 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 sockaddr_in them;
 
 	/* 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) {
 		ast_log(LOG_ERROR, "Something is wrong: rtp\n");
@@ -1254,12 +1265,12 @@
   *	Call-back function to signal asterisk that the channel has been answered 
   * Returns nothing
   */
-void connection_made(unsigned call_reference)
+void connection_made(unsigned call_reference, const char *token)
 {
 	struct ast_channel *c = NULL;
 	struct oh323_pvt *p = NULL;
 	
-	p = find_call(call_reference);
+	p = find_call(call_reference, token); 
 	
 	if (!p) {
 		ast_log(LOG_ERROR, "Something is wrong: connection\n");
@@ -1281,12 +1292,12 @@
   *  Call-back function to signal asterisk that the channel is ringing
   *  Returns nothing
   */
-void chan_ringing(unsigned call_reference)
+void chan_ringing(unsigned call_reference, const char *token)
 {
         struct ast_channel *c = NULL;
         struct oh323_pvt *p = NULL;
 
-        p = find_call(call_reference);
+        p = find_call(call_reference, token); 
 
         if (!p) {
                 ast_log(LOG_ERROR, "Something is wrong: ringing\n");
@@ -1339,7 +1350,7 @@
 	struct oh323_user *user = NULL;
 	struct ast_rtp *rtp = NULL;
 	
-	p = find_call(cd.call_reference);
+	p = find_call(cd.call_reference, cd.call_token); 
 
 	if (!p) {
 		return;
Index: channels/h323/ast_h323.cpp
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/h323/ast_h323.cpp,v
retrieving revision 1.57
diff -u -r1.57 ast_h323.cpp
--- channels/h323/ast_h323.cpp	22 Jul 2004 04:24:50 -0000	1.57
+++ channels/h323/ast_h323.cpp	13 Aug 2004 13:06:47 -0000
@@ -359,7 +359,7 @@
 	if (h323debug) {
 		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
@@ -493,6 +493,7 @@
 	if (h323debug) {
 		cout << "	== New H.323 Connection created." << endl;
 	}
+
 	return;
 }
 
@@ -508,7 +509,9 @@
 																   const H323SignalPDU & /*setupPDU*/,
 																   H323SignalPDU & /*connectPDU*/)
 {
-	if (!on_answer_call(GetCallReference()))
+
+	
+	if (!on_answer_call(GetCallReference(), (const char *)GetCallToken()))
 		return H323Connection::AnswerCallDenied;
 
 	/* The call will be answered later with "AnsweringCall()" function.
@@ -522,7 +525,7 @@
 	if (h323debug) {
 		cout << "	-- Ringing phone for \"" << username << "\"" << endl;
 	}
-	on_chan_ringing(GetCallReference());
+	on_chan_ringing(GetCallReference(), (const char *)GetCallToken());
 	return TRUE;
 }
 
@@ -712,7 +715,7 @@
 	WORD 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) {
 		return NULL;
@@ -720,7 +723,7 @@
 
 	GetControlChannel().GetLocalAddress().GetIpAndPort(externalIpAddress, port);
 	externalPort = info->port;
-	
+
 	if (h323debug) {
 		cout << "	=*= In CreateRealTimeLogicalChannel for call " << GetCallReference() << endl;
 		cout << "		-- externalIpAddress: " << externalIpAddress << endl;
@@ -728,6 +731,7 @@
 		cout << "		-- SessionID: " << sessionID << endl;
 		cout << "		-- Direction: " << dir << endl;
 	}
+
 	return new MyH323_ExternalRTPChannel(*this, capability, dir, sessionID, externalIpAddress, externalPort);
 }
 
@@ -793,7 +797,8 @@
         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);
+               on_start_logical_channel(connection.GetCallReference(), (const char *)remoteIpAddress.AsString(), remotePort, 
+                                         (const char *)connection.GetCallToken() );
                 return TRUE;
         }
         return FALSE;
Index: channels/h323/ast_h323.h
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/h323/ast_h323.h,v
retrieving revision 1.24
diff -u -r1.24 ast_h323.h
--- channels/h323/ast_h323.h	26 Jun 2004 03:50:14 -0000	1.24
+++ channels/h323/ast_h323.h	13 Aug 2004 13:06:48 -0000
@@ -241,6 +241,7 @@
 	WORD externalPort;
 	WORD sessionId;
 	BOOL bridging;			
+        
 };
 
 class MyH323_ExternalRTPChannel : public H323_ExternalRTPChannel {
Index: channels/h323/chan_h323.h
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/h323/chan_h323.h,v
retrieving revision 1.25
diff -u -r1.25 chan_h323.h
--- channels/h323/chan_h323.h	22 Jul 2004 04:24:50 -0000	1.25
+++ channels/h323/chan_h323.h	13 Aug 2004 13:06:48 -0000
@@ -119,7 +119,7 @@
 
 /* This is a callback prototype function, called to collect
    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; 
 
 /* This is a callback prototype function, called upon
@@ -134,17 +134,17 @@
 
 /* This is a callback prototype function, called when the openh323 
    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; 
 
 /* This is a callback prototype function, called when openh323
    OnAlerting is invoked */
-typedef void (*chan_ringing_cb)(unsigned);
+typedef void (*chan_ringing_cb)(unsigned, const char *);
 extern chan_ringing_cb		on_chan_ringing;
 
 /* This is a callback protoype function, called when the openh323
    OnConnectionEstablished is inovked */
-typedef void (*con_established_cb)(unsigned);
+typedef void (*con_established_cb)(unsigned, const char *);
 extern con_established_cb		on_connection_established;
 
 /* This is a callback prototype function, called when the openH323
@@ -152,7 +152,7 @@
 typedef void (*clear_con_cb)(call_details_t);
 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;
 
 /* debug flag */
