mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-18 18:58:22 +00:00
do masquerade-behind-proxy checking with better control over locks
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@37361 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
44
channel.c
44
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;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
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 @@ 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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user