[svn-commits] trunk r37362 - in /trunk: ./ channel.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Jul 10 14:07:48 MST 2006


Author: kpfleming
Date: Mon Jul 10 16:07:48 2006
New Revision: 37362

URL: http://svn.digium.com/view/asterisk?rev=37362&view=rev
Log:
Merged revisions 37361 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r37361 | kpfleming | 2006-07-10 16:01:35 -0500 (Mon, 10 Jul 2006) | 2 lines

do masquerade-behind-proxy checking with better control over locks

........

Modified:
    trunk/   (props changed)
    trunk/channel.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.2-merged' - no diff available.

Modified: trunk/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/channel.c?rev=37362&r1=37361&r2=37362&view=diff
==============================================================================
--- trunk/channel.c (original)
+++ trunk/channel.c Mon Jul 10 16:07:48 2006
@@ -2843,25 +2843,43 @@
 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone)
 {
 	int res = -1;
+	struct ast_channel *final_orig = original, *final_clone = clone;
+
+	ast_channel_lock(original);
+	while (ast_channel_trylock(clone)) {
+		ast_channel_unlock(original);
+		usleep(1);
+		ast_channel_lock(original);
+	}
 
 	/* 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;
+		final_orig = original->_bridge;
 
 	if (clone->_bridge && (clone->_bridge != ast_bridged_channel(clone)))
-		clone = clone->_bridge;
+		final_clone = clone->_bridge;
+
+	if ((final_orig != original) || (final_clone != clone)) {
+		ast_channel_lock(final_orig);
+		while (ast_channel_trylock(final_clone)) {
+			ast_channel_unlock(final_orig);
+			usleep(1);
+			ast_channel_lock(final_orig);
+		}
+		ast_channel_unlock(clone);
+		ast_channel_unlock(original);
+		original = final_orig;
+		clone = final_clone;
+	}
 
 	if (original == clone) {
 		ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name);
+		ast_channel_unlock(clone);
+		ast_channel_unlock(original);
 		return -1;
 	}
-	ast_channel_lock(original);
-	while(ast_channel_trylock(clone)) {
-		ast_channel_unlock(original);
-		usleep(1);
-		ast_channel_lock(original);
-	}
+
 	ast_log(LOG_DEBUG, "Planning to masquerade channel %s into the structure of %s\n",
 		clone->name, original->name);
 	if (original->masq) {
@@ -2878,8 +2896,10 @@
 		ast_log(LOG_DEBUG, "Done planning to masquerade channel %s into the structure of %s\n", clone->name, original->name);
 		res = 0;
 	}
+
 	ast_channel_unlock(clone);
 	ast_channel_unlock(original);
+
 	return res;
 }
 



More information about the svn-commits mailing list