diff options
author | qwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-04-25 18:32:22 +0000 |
---|---|---|
committer | qwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-04-25 18:32:22 +0000 |
commit | 411be90034f6d561ee974e30565660def1e7860f (patch) | |
tree | 84c1b669425b35b608993d19a3682d499b0b1e04 /apps/app_directed_pickup.c | |
parent | db040bdbf49cfb03a7be046d9a361a2c6588f4d2 (diff) |
Merge app_pickupchan with app_directed_pickup, for AST-27.
Initially, this was to be a new feature, with a patch from Switchvox,
but after discussions, it was noted that this feature already existed in trunk.
The resulting discussions ended in a comment that was along the lines of
"the patch provided here is a lot smaller than what is already in trunk,
because it doesn't create a new application and duplicate existing code"
It was decided that these two applications could be easily merged to reduce
code duplication. SO, that's what this does.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@114660 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_directed_pickup.c')
-rw-r--r-- | apps/app_directed_pickup.c | 89 |
1 files changed, 87 insertions, 2 deletions
diff --git a/apps/app_directed_pickup.c b/apps/app_directed_pickup.c index e0de73d3a..1ead1d772 100644 --- a/apps/app_directed_pickup.c +++ b/apps/app_directed_pickup.c @@ -5,6 +5,9 @@ * * Joshua Colp <jcolp@digium.com> * + * Portions merged from app_pickupchan, which was + * Copyright (C) 2008, Gary Cook + * * See http://www.asterisk.org for more information about * the Asterisk project. Please do not directly contact * any of the maintainers of this project for assistance; @@ -21,6 +24,7 @@ * \brief Directed Call Pickup Support * * \author Joshua Colp <jcolp@digium.com> + * \author Gary Cook * * \ingroup applications */ @@ -51,6 +55,13 @@ static const char *descrip = "When no parameter is specified, the application will pickup a channel matching\n" "the pickup group of the active channel."; +static const char *app2 = "PickupChan"; +static const char *synopsis2 = "Pickup a ringing channel"; +static const char *descrip2 = +" PickupChan(channel[&channel...]): This application can pickup any ringing channel\n"; + +/*! \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) { @@ -85,6 +96,47 @@ static int can_pickup(struct ast_channel *chan) return 0; } +/*! \brief Helper Function to walk through ALL channels checking NAME and STATE */ +static struct ast_channel *my_ast_get_channel_by_name_locked(char *channame) +{ + struct ast_channel *chan; + char *chkchan = alloca(strlen(channame) + 2); + + /* need to append a '-' for the comparison so we check full channel name, + * i.e SIP/hgc- , use a temporary variable so original stays the same for + * debugging. + */ + strcpy(chkchan, channame); + strcat(chkchan, "-"); + + for (chan = ast_walk_channel_by_name_prefix_locked(NULL, channame, strlen(channame)); + chan; + chan = ast_walk_channel_by_name_prefix_locked(chan, channame, strlen(channame))) { + if (!strncasecmp(chan->name, chkchan, strlen(chkchan)) && can_pickup(chan)) + return chan; + ast_channel_unlock(chan); + } + return NULL; +} + +/*! \brief Attempt to pick up specified channel named , does not use context */ +static int pickup_by_channel(struct ast_channel *chan, char *pickup) +{ + int res = 0; + struct ast_channel *target; + + if (!(target = my_ast_get_channel_by_name_locked(pickup))) + 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); + } + + 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) { @@ -126,7 +178,7 @@ static int pickup_by_mark(struct ast_channel *chan, const char *mark) return res; } -/* Main application entry point */ +/* application entry point for Pickup() */ static int pickup_exec(struct ast_channel *chan, void *data) { int res = 0; @@ -155,18 +207,51 @@ static int pickup_exec(struct ast_channel *chan, void *data) return res; } +/* application entry point for PickupChan() */ +static int pickupchan_exec(struct ast_channel *chan, void *data) +{ + int res = 0; + char *tmp = ast_strdupa(data); + char *pickup = NULL; + + if (ast_strlen_zero(data)) { + ast_log(LOG_WARNING, "PickupChan requires an argument (channel)!\n"); + return -1; + } + + /* Parse channel */ + while (!ast_strlen_zero(tmp) && (pickup = strsep(&tmp, "&"))) { + 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)) { + break; + } + ast_log(LOG_NOTICE, "No target channel found for %s.\n", pickup); + } + } + + return res; +} + static int unload_module(void) { int res; res = ast_unregister_application(app); + res |= ast_unregister_application(app2); return res; } static int load_module(void) { - return ast_register_application(app, pickup_exec, synopsis, descrip); + int res; + + res = ast_register_application(app, pickup_exec, synopsis, descrip); + res |= ast_register_application(app2, pickupchan_exec, synopsis2, descrip2); + + return res; } AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Directed Call Pickup Application"); |