aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2006-07-10 21:01:35 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2006-07-10 21:01:35 +0000
commitaf45474d63e104f062fdaaf26d4df15e17502535 (patch)
tree55199ee2c2364509a55fd0b1659ebe8ec3ac5f20
parentfcb194b6cc180a4eabd162dc21b38911378f372b (diff)
do masquerade-behind-proxy checking with better control over locks
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.2@37361 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--channel.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/channel.c b/channel.c
index 1f5f59605..dc33e8a57 100644
--- a/channel.c
+++ b/channel.c
@@ -2748,25 +2748,43 @@ int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clo
{
struct ast_frame null = { AST_FRAME_NULL, };
int res = -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)))
- 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_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);
- return -1;
- }
- ast_mutex_lock(&original->lock);
- while(ast_mutex_trylock(&clone->lock)) {
+ ast_mutex_unlock(&clone->lock);
ast_mutex_unlock(&original->lock);
- usleep(1);
- ast_mutex_lock(&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 @@ int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clo
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;
}