]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Merged revisions 37361 via svnmerge from
authorKevin P. Fleming <kpfleming@digium.com>
Mon, 10 Jul 2006 21:07:48 +0000 (21:07 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Mon, 10 Jul 2006 21:07:48 +0000 (21:07 +0000)
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: https://origsvn.digium.com/svn/asterisk/trunk@37362 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channel.c

index e431bd112be04761f9c3f00ac89c8e1053ec10db..cf3680744edbb3aa98056a1e9036bf374ddc40eb 100644 (file)
--- 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;
 }