aboutsummaryrefslogtreecommitdiffstats
path: root/channel.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2006-07-10 21:07:48 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2006-07-10 21:07:48 +0000
commitb25b437be66981ccca8348be7cbd4cb6ff13f659 (patch)
treeb7238f0b3136b61245ab4b2a77ded338690c4041 /channel.c
parentcfb66bf49ddf3801568d94f8abd596bd64c4fe27 (diff)
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 ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@37362 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channel.c')
-rw-r--r--channel.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/channel.c b/channel.c
index e431bd112..cf3680744 100644
--- a/channel.c
+++ b/channel.c
@@ -2843,25 +2843,43 @@ int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *pe
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);
- return -1;
- }
- ast_channel_lock(original);
- while(ast_channel_trylock(clone)) {
+ ast_channel_unlock(clone);
ast_channel_unlock(original);
- usleep(1);
- ast_channel_lock(original);
+ return -1;
}
+
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 @@ 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_channel_unlock(clone);
ast_channel_unlock(original);
+
return res;
}