--- ../clean/asterisk-1.6.2.17-rc2/apps/app_directed_pickup.c 2010-10-05 21:54:50.000000000 +0200 +++ apps/app_directed_pickup.c 2011-02-17 19:48:37.000000000 +0200 @@ -48,14 +48,15 @@ Directed extension call pickup. - - - - + + + + If you wish to check multiple targets enter them as + extension2@context2&..... + - - - + + @@ -67,6 +68,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 @@ -74,11 +77,20 @@ 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 ***/ @@ -88,9 +100,10 @@ /*! \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_channel *bridge; ast_debug(1, "Call pickup on '%s' by '%s'\n", target->name, chan->name); @@ -109,13 +122,21 @@ return -1; } + ast_channel_unlock(target); + if (!ast_strlen_zero(grpcat)) { + while (target && !(bridge = ast_bridged_channel(target))) + usleep(1000); + if (bridge) + 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 || chan->_state == AST_STATE_DOWN)) return 1; else return 0; @@ -160,7 +181,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; @@ -169,10 +190,8 @@ return -1; /* Just check that we are not picking up the SAME as target */ - if (chan->name != target->name && chan != target) { - res = pickup_do(chan, target); - } - ast_channel_unlock(target); + if (chan->name != target->name && chan != target) + res = pickup_do(chan, target, grpcat); return res; } @@ -193,7 +212,7 @@ } /* 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 pickup_criteria search = { @@ -204,12 +223,8 @@ target = ast_channel_search_locked(find_by_exten, &search); - if (target) { - int res = pickup_do(chan, target); - ast_channel_unlock(target); - target = NULL; - return res; - } + if (target) + return pickup_do(chan, target, grpcat); return -1; } @@ -225,16 +240,27 @@ } /* 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 = ast_channel_search_locked(find_by_mark, (char *) mark); - if (target) { - int res = pickup_do(chan, target); + if (target) + return pickup_do(chan, target, grpcat); + + return -1; +} + +static int pickup_by_group(struct ast_channel *chan, const char *grpcat) +{ + struct ast_channel *target; + + while ((target = ast_channel_walk_locked(target))) { + if (can_pickup(target) && (target != chan) && (chan->pickupgroup & target->callgroup)) + break; ast_channel_unlock(target); - target = NULL; - return res; } + if (target) + return pickup_do(chan, target, grpcat); return -1; } @@ -245,21 +271,32 @@ 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); @@ -274,18 +311,29 @@ int res = 0; char *tmp = ast_strdupa(data); char *pickup = NULL; + char grpcat[81]; if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "PickupChan requires an argument (channel)!\n"); return -1; } + 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); + /* Parse channel */ - while (!ast_strlen_zero(tmp) && (pickup = strsep(&tmp, "&"))) { + while (!ast_strlen_zero(args.target) && (pickup = strsep(&args.target, "&"))) { if (!strncasecmp(chan->name, pickup, strlen(pickup))) { ast_log(LOG_NOTICE, "Cannot pickup your own channel %s.\n", pickup); } else { - if (!pickup_by_channel(chan, pickup)) { + if (!pickup_by_channel(chan, pickup, grpcat)) { break; } ast_log(LOG_NOTICE, "No target channel found for %s.\n", pickup);