aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordhubbard <dhubbard@f38db490-d61c-443f-a65b-d21fe96a405b>2007-10-01 21:25:37 +0000
committerdhubbard <dhubbard@f38db490-d61c-443f-a65b-d21fe96a405b>2007-10-01 21:25:37 +0000
commit6c41fcab5e61440e473a08ab15244982cb54e02c (patch)
tree35df600fab2ed11dd4550dde270ebe1d32230a1a
parentb0a268d26d87642ea59f7539d8503b37b86df6e3 (diff)
moved get_base_channel() code from action_redirect to ast_channel_masquerade() for issue 7706 and BE-160
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@84274 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--channels/chan_agent.c13
-rw-r--r--main/channel.c6
-rw-r--r--main/manager.c18
3 files changed, 14 insertions, 23 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c
index a83eb66b0..883de716f 100644
--- a/channels/chan_agent.c
+++ b/channels/chan_agent.c
@@ -730,17 +730,20 @@ static void set_agentbycallerid(const char *callerid, const char *agent)
pbx_builtin_setvar_helper(NULL, buf, agent);
}
+/*! \brief return the channel or base channel if one exists. This function assumes the channel it is called on is already locked */
struct ast_channel* agent_get_base_channel(struct ast_channel *chan)
{
struct agent_pvt *p = NULL;
- struct ast_channel *base = NULL;
-
+ struct ast_channel *base = chan;
+
+ /* chan is locked by the calling function */
if (!chan || !chan->tech_pvt) {
ast_log(LOG_ERROR, "whoa, you need a channel (0x%ld) with a tech_pvt (0x%ld) to get a base channel.\n", (long)chan, (chan)?(long)chan->tech_pvt:(long)NULL);
- } else {
- p = chan->tech_pvt;
- base = p->chan;
+ return NULL;
}
+ p = chan->tech_pvt;
+ if (p->chan)
+ base = p->chan;
return base;
}
diff --git a/main/channel.c b/main/channel.c
index 0ae9af4b0..0b7fe4027 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -3410,7 +3410,7 @@ 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, *final_clone;
+ struct ast_channel *final_orig, *final_clone, *base;
retrymasq:
final_orig = original;
@@ -3430,6 +3430,10 @@ retrymasq:
if (clone->_bridge && (clone->_bridge != ast_bridged_channel(clone)) && (clone->_bridge->_bridge != clone))
final_clone = clone->_bridge;
+
+ if (final_clone->tech->get_base_channel && (base = final_clone->tech->get_base_channel(final_clone))) {
+ final_clone = base;
+ }
if ((final_orig != original) || (final_clone != clone)) {
/* Lots and lots of deadlock avoidance. The main one we're competing with
diff --git a/main/manager.c b/main/manager.c
index 6a6deb643..d39de8061 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -1550,7 +1550,7 @@ static int action_redirect(struct mansession *s, const struct message *m)
const char *exten = astman_get_header(m, "Exten");
const char *context = astman_get_header(m, "Context");
const char *priority = astman_get_header(m, "Priority");
- struct ast_channel *base, *chan, *chan2 = NULL;
+ struct ast_channel *chan, *chan2 = NULL;
int pi = 0;
int res;
@@ -1572,14 +1572,6 @@ static int action_redirect(struct mansession *s, const struct message *m)
astman_send_error(s, m, buf);
return 0;
}
- if (chan->tech->get_base_channel) {
- base = chan->tech->get_base_channel(chan);
- if (base) {
- ast_mutex_unlock(&chan->lock);
- chan = base;
- ast_mutex_lock(&chan->lock);
- }
- }
if (ast_check_hangup(chan)) {
astman_send_error(s, m, "Redirect failed, channel not up.\n");
ast_channel_unlock(chan);
@@ -1593,14 +1585,6 @@ static int action_redirect(struct mansession *s, const struct message *m)
ast_channel_unlock(chan2);
return 0;
}
- if (chan2 && chan2->tech->get_base_channel) {
- base = chan2->tech->get_base_channel(chan2);
- if (base) {
- ast_mutex_unlock(&chan2->lock);
- chan2 = base;
- ast_mutex_lock(&chan2->lock);
- }
- }
res = ast_async_goto(chan, context, exten, pi);
if (!res) {
if (!ast_strlen_zero(name2)) {