allow app_directed_pickup to try to pickup

multiple channels at the same time. however it
does not work in cases where dial was called
with multiple devices.  bug 5694.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8057 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Matt O'Gorman
2006-01-13 17:02:15 +00:00
parent 34ba77e702
commit 2aaffe48e4

View File

@@ -46,7 +46,7 @@ static const char *tdesc = "Directed Call Pickup Application";
static const char *app = "Pickup"; static const char *app = "Pickup";
static const char *synopsis = "Directed Call Pickup"; static const char *synopsis = "Directed Call Pickup";
static const char *descrip = static const char *descrip =
" Pickup(extension[@context]): This application can pickup any ringing channel\n" " Pickup(extension[@context][&extension2@context...]): This application can pickup any ringing channel\n"
"that is calling the specified extension. If no context is specified, the current\n" "that is calling the specified extension. If no context is specified, the current\n"
"context will be used.\n"; "context will be used.\n";
@@ -59,7 +59,7 @@ static int pickup_exec(struct ast_channel *chan, void *data)
int res = 0; int res = 0;
struct localuser *u = NULL; struct localuser *u = NULL;
struct ast_channel *origin = NULL, *target = NULL; struct ast_channel *origin = NULL, *target = NULL;
char *tmp = NULL, *exten = NULL, *context = NULL; char *tmp = NULL, *exten = NULL, *context = NULL, *rest=data;
char workspace[256] = ""; char workspace[256] = "";
if (ast_strlen_zero(data)) { if (ast_strlen_zero(data)) {
@@ -69,64 +69,65 @@ static int pickup_exec(struct ast_channel *chan, void *data)
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
/* Get the extension and context if present */ while (!target && (exten = rest) ) {
exten = data; res = 0;
context = strchr(data, '@'); rest = strchr(exten, '&');
if (context) { if (rest)
*context = '\0'; *rest++ = 0;
context++;
}
/* Find a channel to pickup */ /* Get the extension and context if present */
origin = ast_get_channel_by_exten_locked(exten, context); context = strchr(exten, '@');
if (origin && origin->cdr) { if (context)
ast_cdr_getvar(origin->cdr, "dstchannel", &tmp, workspace, *context++ = '\0';
sizeof(workspace), 0);
if (tmp) { /* Find a channel to pickup */
/* We have a possible channel... now we need to find it! */ origin = ast_get_channel_by_exten_locked(exten, context);
target = ast_get_channel_by_name_locked(tmp); if (origin) {
} else { ast_cdr_getvar(origin->cdr, "dstchannel", &tmp, workspace,
ast_log(LOG_DEBUG, "No target channel found.\n"); sizeof(workspace), 0);
res = -1; if (tmp) {
} /* We have a possible channel... now we need to find it! */
ast_mutex_unlock(&origin->lock); target = ast_get_channel_by_name_locked(tmp);
} else { } else {
if (origin) ast_log(LOG_NOTICE, "No target channel found for %s.\n", exten);
res = -1;
}
ast_mutex_unlock(&origin->lock); ast_mutex_unlock(&origin->lock);
ast_log(LOG_DEBUG, "No originating channel found.\n");
}
if (res)
goto out;
if (target && (!target->pbx) && ((target->_state == AST_STATE_RINGING) || (target->_state == AST_STATE_RING))) { } else {
ast_log(LOG_DEBUG, "Call pickup on chan '%s' by '%s'\n", target->name, ast_log(LOG_DEBUG, "No originating channel found.\n");
chan->name);
res = ast_answer(chan);
if (res) {
ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
res = -1;
goto out;
} }
res = ast_queue_control(chan, AST_CONTROL_ANSWER);
if (res) { if (res)
ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", continue;
chan->name);
if (target && (!target->pbx) && ((target->_state == AST_STATE_RINGING) || (target->_state == AST_STATE_RING) ) ) {
ast_log(LOG_DEBUG, "Call pickup on chan '%s' by '%s'\n", target->name,
chan->name);
res = ast_answer(chan);
if (res) {
ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
res = -1;
break;
}
res = ast_queue_control(chan, AST_CONTROL_ANSWER);
if (res) {
ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n",
chan->name);
res = -1;
break;
}
res = ast_channel_masquerade(target, chan);
if (res) {
ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, target->name);
res = -1;
break;
}
} else {
ast_log(LOG_NOTICE, "No call pickup possible for %s...\n", exten);
res = -1; res = -1;
goto out;
} }
res = ast_channel_masquerade(target, chan);
if (res) {
ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, target->name);
res = -1;
goto out;
}
} else {
ast_log(LOG_DEBUG, "No call pickup possible...\n");
res = -1;
} }
/* Done */
out:
if (target) if (target)
ast_mutex_unlock(&target->lock); ast_mutex_unlock(&target->lock);