--- ../clean/asterisk-trunk/apps/app_directed_pickup.c 2011-02-18 10:42:04.000000000 +0200
+++ ./apps/app_directed_pickup.c 2011-02-18 12:09:51.000000000 +0200
@@ -51,14 +51,15 @@
Directed extension call pickup.
-
-
-
-
+
+
+
+ If you wish to check multiple targets enter them as
+ extension2@context2&.....
+
-
-
-
+
+
@@ -70,6 +71,8 @@
channel variable with the same value as extension
(in this example, 10). When no parameter is specified, the application
will pickup a channel matching the pickup group of the active channel.
+ When the optional group category is added the channel group variable assosiated on the target
+ will be unset allowing group counts to work for call limiting
@@ -77,8 +80,12 @@
Pickup a ringing channel.
-
-
+
+
+ If you need more then one enter them as
+ Channel&.....
+
+
+
+
+
This will pickup a specified channel if ringing.
+ When the optional group category is added the channel group variable assosiated on the target
+ will be unset allowing group counts to work for call limiting
***/
@@ -98,10 +110,11 @@
/*! \todo This application should return a result code, like PICKUPRESULT */
/* Perform actual pickup between two channels */
-static int pickup_do(struct ast_channel *chan, struct ast_channel *target)
+static int pickup_do(struct ast_channel *chan, struct ast_channel *target, const char *grpcat)
{
int res = 0;
struct ast_party_connected_line connected_caller;
+ struct ast_channel *bridge;
struct ast_channel *chans[2] = { chan, target };
ast_debug(1, "Call pickup on '%s' by '%s'\n", target->name, chan->name);
@@ -124,16 +137,19 @@
if ((res = ast_answer(chan))) {
ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
+ ast_channel_unlock(chan);
return -1;
}
if ((res = ast_queue_control(chan, AST_CONTROL_ANSWER))) {
ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", chan->name);
+ ast_channel_unlock(chan);
return -1;
}
if ((res = ast_channel_masquerade(target, chan))) {
ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, target->name);
+ ast_channel_unlock(chan);
return -1;
}
@@ -141,13 +157,21 @@
ast_manager_event_multichan(EVENT_FLAG_CALL, "Pickup", 2, chans,
"Channel: %s\r\nTargetChannel: %s\r\n", chan->name, target->name);
+ ast_channel_unlock(target);
+ if (!ast_strlen_zero(grpcat)) {
+ while (target && !(bridge = ast_bridged_channel(target)))
+ usleep(1000);
+ if (bridge && !ast_strlen_zero(grpcat))
+ ast_app_group_set_channel(bridge,grpcat);
+ }
+
return res;
}
/* Helper function that determines whether a channel is capable of being picked up */
static int can_pickup(struct ast_channel *chan)
{
- if (!chan->pbx && (chan->_state == AST_STATE_RINGING || chan->_state == AST_STATE_RING || chan->_state == AST_STATE_DOWN))
+ if (!chan->pbx && !chan->masq && (chan->_state == AST_STATE_RINGING || chan->_state == AST_STATE_RING))
return 1;
else
return 0;
@@ -202,7 +226,7 @@
}
/*! \brief Attempt to pick up specified channel named , does not use context */
-static int pickup_by_channel(struct ast_channel *chan, char *pickup)
+static int pickup_by_channel(struct ast_channel *chan, char *pickup, const char *grpcat)
{
int res = 0;
struct ast_channel *target;
@@ -213,17 +237,16 @@
/* Just check that we are not picking up the SAME as target */
if (chan != target) {
- res = pickup_do(chan, target);
+ res = pickup_do(chan, target, grpcat);
}
- ast_channel_unlock(target);
target = ast_channel_unref(target);
return res;
}
/* Attempt to pick up specified extension with context */
-static int pickup_by_exten(struct ast_channel *chan, const char *exten, const char *context)
+static int pickup_by_exten(struct ast_channel *chan, const char *exten, const char *context, const char *grpcat)
{
struct ast_channel *target = NULL;
struct ast_channel_iterator *iter;
@@ -238,15 +261,13 @@
if ((chan != target) && can_pickup(target)) {
break;
}
- ast_channel_unlock(target);
target = ast_channel_unref(target);
}
ast_channel_iterator_destroy(iter);
if (target) {
- res = pickup_do(chan, target);
- ast_channel_unlock(target);
+ res = pickup_do(chan, target, grpcat);
target = ast_channel_unref(target);
}
@@ -272,42 +293,75 @@
}
/* Attempt to pick up specified mark */
-static int pickup_by_mark(struct ast_channel *chan, const char *mark)
+static int pickup_by_mark(struct ast_channel *chan, const char *mark, const char *grpcat)
{
struct ast_channel *target;
int res = -1;
if ((target = ast_channel_callback(find_by_mark, NULL, (char *) mark, 0))) {
ast_channel_lock(target);
- res = pickup_do(chan, target);
- ast_channel_unlock(target);
+ res = pickup_do(chan, target, grpcat);
target = ast_channel_unref(target);
}
return res;
}
+static int find_channel_by_group(void *obj, void *arg, void *data, int flags)
+{
+ struct ast_channel *chan = obj;
+ struct ast_channel *c = data;
+
+ int i = (can_pickup(chan) && (c != chan) && (c->pickupgroup & chan->callgroup));
+
+ return i ? CMP_MATCH | CMP_STOP : 0;
+}
+
+static int pickup_by_group(struct ast_channel *chan, const char *grpcat)
+{
+ struct ast_channel *target=NULL;
+ int res=-1;
+
+ if ((target = ast_channel_callback(find_channel_by_group, NULL, chan, 0))) {
+ ast_channel_lock(target);
+ res=pickup_do(chan, target, grpcat);
+ target = ast_channel_unref(target);
+ }
+ return res;
+}
+
/* application entry point for Pickup() */
static int pickup_exec(struct ast_channel *chan, const char *data)
{
int res = 0;
char *tmp = ast_strdupa(data);
char *exten = NULL, *context = NULL;
+ char grpcat[81];
- if (ast_strlen_zero(data)) {
- res = ast_pickup_call(chan);
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(target);
+ AST_APP_ARG(category);
+ );
+
+ AST_STANDARD_APP_ARGS(args, tmp);
+
+ if (!ast_strlen_zero(args.category))
+ sprintf(grpcat,"@%s",args.category);
+
+ if (ast_strlen_zero(args.target)) {
+ pickup_by_group(chan,grpcat);
return res;
}
-
+
/* Parse extension (and context if there) */
- while (!ast_strlen_zero(tmp) && (exten = strsep(&tmp, "&"))) {
+ while (!ast_strlen_zero(args.target) && (exten = strsep(&args.target, "&"))) {
if ((context = strchr(exten, '@')))
*context++ = '\0';
if (!ast_strlen_zero(context) && !strcasecmp(context, PICKUPMARK)) {
- if (!pickup_by_mark(chan, exten))
+ if (!pickup_by_mark(chan, exten, grpcat))
break;
} else {
- if (!pickup_by_exten(chan, exten, !ast_strlen_zero(context) ? context : chan->context))
+ if (!pickup_by_exten(chan, exten, !ast_strlen_zero(context) ? context : chan->context, grpcat))
break;
}
ast_log(LOG_NOTICE, "No target channel found for %s.\n", exten);
@@ -334,15 +388,14 @@
}
/* Attempt to pick up specified by partial channel name */
-static int pickup_by_part(struct ast_channel *chan, const char *part)
+static int pickup_by_part(struct ast_channel *chan, const char *part, const char *grpcat)
{
struct ast_channel *target;
int res = -1;
if ((target = ast_channel_callback(find_by_part, NULL, (char *) part, 0))) {
ast_channel_lock(target);
- res = pickup_do(chan, target);
- ast_channel_unlock(target);
+ res = pickup_do(chan, target, grpcat);
target = ast_channel_unref(target);
}
@@ -356,9 +409,12 @@
int partial_pickup = 0;
char *pickup = NULL;
char *parse = ast_strdupa(data);
+ char grpcat[81];
+
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(channel);
AST_APP_ARG(options);
+ AST_APP_ARG(category);
);
AST_STANDARD_APP_ARGS(args, parse);
@@ -371,16 +427,19 @@
partial_pickup = 1;
}
+ if (!ast_strlen_zero(args.category))
+ sprintf(grpcat,"@%s",args.category);
+
/* Parse channel */
while (!ast_strlen_zero(args.channel) && (pickup = strsep(&args.channel, "&"))) {
if (!strncasecmp(chan->name, pickup, strlen(pickup))) {
ast_log(LOG_NOTICE, "Cannot pickup your own channel %s.\n", pickup);
} else {
if (partial_pickup) {
- if (!pickup_by_part(chan, pickup)) {
+ if (!pickup_by_part(chan, pickup, grpcat)) {
break;
}
- } else if (!pickup_by_channel(chan, pickup)) {
+ } else if (!pickup_by_channel(chan, pickup, grpcat)) {
break;
}
ast_log(LOG_NOTICE, "No target channel found for %s.\n", pickup);