Merged revisions 84018 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r84018 | dhubbard | 2007-09-27 18:12:25 -0500 (Thu, 27 Sep 2007) | 1 line

if an Agent is redirected, the base channel should actually be redirected.  This was causing multiple issues, especially issue 7706 and BE-160
........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@84019 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Dwayne M. Hubbard
2007-09-27 23:18:09 +00:00
parent 077cd17212
commit bd5b6cea68
3 changed files with 58 additions and 1 deletions

View File

@@ -231,6 +231,8 @@ static int agent_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
static struct ast_channel *agent_bridgedchannel(struct ast_channel *chan, struct ast_channel *bridge); static struct ast_channel *agent_bridgedchannel(struct ast_channel *chan, struct ast_channel *bridge);
static void set_agentbycallerid(const char *callerid, const char *agent); static void set_agentbycallerid(const char *callerid, const char *agent);
static char *complete_agent_logoff_cmd(const char *line, const char *word, int pos, int state); static char *complete_agent_logoff_cmd(const char *line, const char *word, int pos, int state);
static struct ast_channel* agent_get_base_channel(struct ast_channel *chan);
static int agent_set_base_channel(struct ast_channel *chan, struct ast_channel *base);
/*! \brief Channel interface description for PBX integration */ /*! \brief Channel interface description for PBX integration */
static const struct ast_channel_tech agent_tech = { static const struct ast_channel_tech agent_tech = {
@@ -253,6 +255,8 @@ static const struct ast_channel_tech agent_tech = {
.indicate = agent_indicate, .indicate = agent_indicate,
.fixup = agent_fixup, .fixup = agent_fixup,
.bridged_channel = agent_bridgedchannel, .bridged_channel = agent_bridgedchannel,
.get_base_channel = agent_get_base_channel,
.set_base_channel = agent_set_base_channel,
}; };
/*! /*!
@@ -698,6 +702,37 @@ static void set_agentbycallerid(const char *callerid, const char *agent)
pbx_builtin_setvar_helper(NULL, buf, agent); pbx_builtin_setvar_helper(NULL, buf, agent);
} }
struct ast_channel* agent_get_base_channel(struct ast_channel *chan)
{
struct agent_pvt *p = NULL;
struct ast_channel *base = NULL;
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 base;
}
int agent_set_base_channel(struct ast_channel *chan, struct ast_channel *base)
{
struct agent_pvt *p = NULL;
if (!chan || !base) {
ast_log(LOG_ERROR, "whoa, you need a channel (0x%ld) and a base channel (0x%ld) for setting.\n", (long)chan, (long)base);
return -1;
}
p = chan->tech_pvt;
if (!p) {
ast_log(LOG_ERROR, "whoa, channel %s is missing his tech_pvt structure!!.\n", chan->name);
return -1;
}
p->chan = base;
return 0;
}
static int agent_hangup(struct ast_channel *ast) static int agent_hangup(struct ast_channel *ast)
{ {
struct agent_pvt *p = ast->tech_pvt; struct agent_pvt *p = ast->tech_pvt;

View File

@@ -314,6 +314,12 @@ struct ast_channel_tech {
/*! \brief Provide additional write items for CHANNEL() dialplan function */ /*! \brief Provide additional write items for CHANNEL() dialplan function */
int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value); int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);
/*! \brief Retrieve base channel (agent and local) */
struct ast_channel* (* get_base_channel)(struct ast_channel *chan);
/*! \brief Set base channel (agent and local) */
int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base);
}; };
struct ast_epoll_data; struct ast_epoll_data;

View File

@@ -1787,7 +1787,7 @@ static int action_redirect(struct mansession *s, const struct message *m)
const char *exten = astman_get_header(m, "Exten"); const char *exten = astman_get_header(m, "Exten");
const char *context = astman_get_header(m, "Context"); const char *context = astman_get_header(m, "Context");
const char *priority = astman_get_header(m, "Priority"); const char *priority = astman_get_header(m, "Priority");
struct ast_channel *chan, *chan2 = NULL; struct ast_channel *base, *chan, *chan2 = NULL;
int pi = 0; int pi = 0;
int res; int res;
@@ -1809,6 +1809,14 @@ static int action_redirect(struct mansession *s, const struct message *m)
astman_send_error(s, m, buf); astman_send_error(s, m, buf);
return 0; 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)) { if (ast_check_hangup(chan)) {
astman_send_error(s, m, "Redirect failed, channel not up.\n"); astman_send_error(s, m, "Redirect failed, channel not up.\n");
ast_channel_unlock(chan); ast_channel_unlock(chan);
@@ -1822,6 +1830,14 @@ static int action_redirect(struct mansession *s, const struct message *m)
ast_channel_unlock(chan2); ast_channel_unlock(chan2);
return 0; 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); res = ast_async_goto(chan, context, exten, pi);
if (!res) { if (!res) {
if (!ast_strlen_zero(name2)) { if (!ast_strlen_zero(name2)) {