[asterisk-commits] trunk r20424 - in /trunk: channel.c channels/chan_sip.c include/asterisk/lock.h

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun Apr 16 05:57:20 MST 2006


Author: oej
Date: Sun Apr 16 07:57:15 2006
New Revision: 20424

URL: http://svn.digium.com/view/asterisk?rev=20424&view=rev
Log:
- Fixes to ast_channel_lock functions
- New get_sip_pvt_byid function (not really used correctly yet...)

Modified:
    trunk/channel.c
    trunk/channels/chan_sip.c
    trunk/include/asterisk/lock.h

Modified: trunk/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/channel.c?rev=20424&r1=20423&r2=20424&view=diff
==============================================================================
--- trunk/channel.c (original)
+++ trunk/channel.c Sun Apr 16 07:57:15 2006
@@ -4217,7 +4217,7 @@
 
 /*! \brief Lock AST channel (and print debugging output)
 \note	You need to enable DEBUG_CHANNEL_LOCKS for this function */
-int __ast_channel_trylock(struct ast_channel *chan)
+int ast_channel_trylock(struct ast_channel *chan)
 {
 	int res;
 

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=20424&r1=20423&r2=20424&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Sun Apr 16 07:57:15 2006
@@ -6807,17 +6807,44 @@
 	return -1;
 }
 
-/*! \brief Lock interface lock and find matching pvt lock  */
-static struct sip_pvt *get_sip_pvt_byid_locked(char *callid) 
+/*! \brief Lock interface lock and find matching pvt lock  
+	- Their tag is fromtag, our tag is to-tag
+	- This means that in some transactions, totag needs to be their tag :-)
+	  depending upon the direction
+*/
+static struct sip_pvt *get_sip_pvt_byid_locked(char *callid, char *totag, char *fromtag) 
 {
 	struct sip_pvt *sip_pvt_ptr = NULL;
 	
 	/* Search interfaces and find the match */
 	ast_mutex_lock(&iflock);
-	for (sip_pvt_ptr = iflist; sip_pvt_ptr ; sip_pvt_ptr = sip_pvt_ptr->next) {
+
+	if (option_debug > 3 && totag)
+		ast_log(LOG_DEBUG, "Looking for callid %s (fromtag %s totag %s)\n", callid, fromtag ? fromtag : "<no fromtag>", totag ? totag : "<no totag>");
+
+	for (sip_pvt_ptr = iflist; sip_pvt_ptr; sip_pvt_ptr = sip_pvt_ptr->next) {
 		if (!strcmp(sip_pvt_ptr->callid, callid)) {
+			int match = 1;
+			char *ourtag = sip_pvt_ptr->tag;
+
 			/* Go ahead and lock it (and its owner) before returning */
 			ast_mutex_lock(&sip_pvt_ptr->lock);
+
+			/* Check if tags match. If not, this is not the call we want
+			   (With a forking SIP proxy, several call legs share the
+			   call id, but have different tags)
+			*/
+			if (pedanticsipchecking && (strcmp(fromtag, sip_pvt_ptr->theirtag) || strcmp(totag, ourtag)))
+				match = 0;
+
+			if (!match) {
+				ast_mutex_unlock(&sip_pvt_ptr->lock);
+				break;
+			}
+
+			if (option_debug > 3 && totag)				 
+				ast_log(LOG_DEBUG, "Matched %s call - their tag is %s Our tag is %s\n", ast_test_flag(&sip_pvt_ptr->flags[0], SIP_OUTGOING) ? "OUTGOING": "INCOMING", sip_pvt_ptr->theirtag, sip_pvt_ptr->tag);
+
 			if (sip_pvt_ptr->owner) {
 				while(ast_channel_trylock(sip_pvt_ptr->owner)) {
 					ast_mutex_unlock(&sip_pvt_ptr->lock);
@@ -6831,6 +6858,8 @@
 		}
 	}
 	ast_mutex_unlock(&iflock);
+	if (option_debug > 3 && !sip_pvt_ptr)
+		ast_log(LOG_DEBUG, "Found no match for callid %s to-tag %s from-tag %s\n", callid, totag, fromtag);
 	return sip_pvt_ptr;
 }
 
@@ -6921,13 +6950,13 @@
 	}
 	if (!ast_strlen_zero(replace_callid)) {	
 		/* This is a supervised transfer */
-		ast_log(LOG_DEBUG,"Assigning Replace-Call-ID Info %s to REPLACE_CALL_ID\n",replace_callid);
+		ast_log(LOG_DEBUG,"Assigning Replace-Call-ID Info %s to REPLACE_CALL_ID\n", replace_callid);
 		
 		ast_string_field_free(sip_pvt, refer_to);
 		ast_string_field_free(sip_pvt, referred_by);
 		ast_string_field_free(sip_pvt, refer_contact);
 		sip_pvt->refer_call = NULL;
-		if ((sip_pvt_ptr = get_sip_pvt_byid_locked(replace_callid))) {
+		if ((sip_pvt_ptr = get_sip_pvt_byid_locked(replace_callid, NULL, NULL))) {
 			sip_pvt->refer_call = sip_pvt_ptr;
 			if (sip_pvt->refer_call == sip_pvt) {
 				ast_log(LOG_NOTICE, "Supervised transfer attempted to transfer into same call id (%s == %s)!\n", replace_callid, sip_pvt->callid);

Modified: trunk/include/asterisk/lock.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/lock.h?rev=20424&r1=20423&r2=20424&view=diff
==============================================================================
--- trunk/include/asterisk/lock.h (original)
+++ trunk/include/asterisk/lock.h Sun Apr 16 07:57:15 2006
@@ -784,7 +784,7 @@
 
 /*! \brief Lock AST channel (and print debugging output)
 \note   You need to enable DEBUG_CHANNEL_LOCKS for this function */
-int __ast_channel_trylock(struct ast_channel *chan);
+int ast_channel_trylock(struct ast_channel *chan);
 #endif
 
 #endif /* _ASTERISK_LOCK_H */



More information about the asterisk-commits mailing list