[asterisk-commits] branch 1.2 r37361 - /branches/1.2/channel.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Jul 10 14:01:36 MST 2006


Author: kpfleming
Date: Mon Jul 10 16:01:35 2006
New Revision: 37361

URL: http://svn.digium.com/view/asterisk?rev=37361&view=rev
Log:
do masquerade-behind-proxy checking with better control over locks

Modified:
    branches/1.2/channel.c

Modified: branches/1.2/channel.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channel.c?rev=37361&r1=37360&r2=37361&view=diff
==============================================================================
--- branches/1.2/channel.c (original)
+++ branches/1.2/channel.c Mon Jul 10 16:01:35 2006
@@ -2748,25 +2748,43 @@
 {
 	struct ast_frame null = { AST_FRAME_NULL, };
 	int res = -1;
-
-	/* each of these channels may be sitting behind a channel proxy (i.e. chan_agent)
-	   and if so, we don't really want to masquerade it, but its proxy */
-	if (original->_bridge && (original->_bridge != ast_bridged_channel(original)))
-		original = original->_bridge;
-
-	if (clone->_bridge && (clone->_bridge != ast_bridged_channel(clone)))
-		clone = clone->_bridge;
-
-	if (original == clone) {
-		ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name);
-		return -1;
-	}
+	struct ast_channel *final_orig = original, *final_clone = clone;
+
 	ast_mutex_lock(&original->lock);
 	while(ast_mutex_trylock(&clone->lock)) {
 		ast_mutex_unlock(&original->lock);
 		usleep(1);
 		ast_mutex_lock(&original->lock);
 	}
+
+	/* each of these channels may be sitting behind a channel proxy (i.e. chan_agent)
+	   and if so, we don't really want to masquerade it, but its proxy */
+	if (original->_bridge && (original->_bridge != ast_bridged_channel(original)))
+		final_orig = original->_bridge;
+
+	if (clone->_bridge && (clone->_bridge != ast_bridged_channel(clone)))
+		final_clone = clone->_bridge;
+
+	if ((final_orig != original) || (final_clone != clone)) {
+		ast_mutex_lock(&final_orig->lock);
+		while(ast_mutex_trylock(&final_clone->lock)) {
+			ast_mutex_unlock(&final_orig->lock);
+			usleep(1);
+			ast_mutex_lock(&final_orig->lock);
+		}
+		ast_mutex_unlock(&clone->lock);
+		ast_mutex_unlock(&original->lock);
+		original = final_orig;
+		clone = final_clone;
+	}
+
+	if (original == clone) {
+		ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name);
+		ast_mutex_unlock(&clone->lock);
+		ast_mutex_unlock(&original->lock);
+		return -1;
+	}
+
 	ast_log(LOG_DEBUG, "Planning to masquerade channel %s into the structure of %s\n",
 		clone->name, original->name);
 	if (original->masq) {
@@ -2783,8 +2801,10 @@
 		ast_log(LOG_DEBUG, "Done planning to masquerade channel %s into the structure of %s\n", clone->name, original->name);
 		res = 0;
 	}
+
 	ast_mutex_unlock(&clone->lock);
 	ast_mutex_unlock(&original->lock);
+
 	return res;
 }
 



More information about the asterisk-commits mailing list