Fri Jul 24 00:41:08 2009

Asterisk developer's documentation


app_directed_pickup.c File Reference

Directed Call Pickup Support. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/features.h"

Go to the source code of this file.

Defines

#define PICKUPMARK   "PICKUPMARK"

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int can_pickup (struct ast_channel *chan)
static int load_module (void)
static struct ast_channelmy_ast_get_channel_by_name_locked (char *channame)
 Helper Function to walk through ALL channels checking NAME and STATE.
static int pickup_by_channel (struct ast_channel *chan, char *pickup)
 Attempt to pick up specified channel named , does not use context.
static int pickup_by_exten (struct ast_channel *chan, const char *exten, const char *context)
static int pickup_by_mark (struct ast_channel *chan, const char *mark)
static int pickup_do (struct ast_channel *chan, struct ast_channel *target)
static int pickup_exec (struct ast_channel *chan, void *data)
static int pickupchan_exec (struct ast_channel *chan, void *data)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Directed Call Pickup Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, }
static const char * app = "Pickup"
static const char * app2 = "PickupChan"
static struct ast_module_infoast_module_info = &__mod_info
static const char * descrip
static const char * descrip2
static const char * synopsis = "Directed Call Pickup"
static const char * synopsis2 = "Pickup a ringing channel"


Detailed Description

Directed Call Pickup Support.

Author:
Joshua Colp <jcolp@digium.com>

Gary Cook

Definition in file app_directed_pickup.c.


Define Documentation

#define PICKUPMARK   "PICKUPMARK"

Definition at line 44 of file app_directed_pickup.c.

Referenced by pickup_by_mark(), and pickup_exec().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 257 of file app_directed_pickup.c.

static void __unreg_module ( void   )  [static]

Definition at line 257 of file app_directed_pickup.c.

static int can_pickup ( struct ast_channel chan  )  [static]

Definition at line 91 of file app_directed_pickup.c.

References ast_channel::_state, AST_STATE_DOWN, AST_STATE_RING, AST_STATE_RINGING, chan, and ast_channel::pbx.

Referenced by my_ast_get_channel_by_name_locked(), pickup_by_exten(), and pickup_by_mark().

00092 {
00093    if (!chan->pbx && (chan->_state == AST_STATE_RINGING || chan->_state == AST_STATE_RING || chan->_state == AST_STATE_DOWN))
00094       return 1;
00095    else
00096       return 0;
00097 }

static int load_module ( void   )  [static]

Definition at line 247 of file app_directed_pickup.c.

References ast_register_application, pickup_exec(), and pickupchan_exec().

00248 {
00249    int res;
00250 
00251    res = ast_register_application(app, pickup_exec, synopsis, descrip);
00252    res |= ast_register_application(app2, pickupchan_exec, synopsis2, descrip2);
00253 
00254    return res;
00255 }

static struct ast_channel* my_ast_get_channel_by_name_locked ( char *  channame  )  [static]

Helper Function to walk through ALL channels checking NAME and STATE.

Definition at line 100 of file app_directed_pickup.c.

References ast_channel_unlock, ast_walk_channel_by_name_prefix_locked(), can_pickup(), chan, and ast_channel::name.

Referenced by pickup_by_channel().

00101 {
00102    struct ast_channel *chan;
00103    char *chkchan = alloca(strlen(channame) + 2);
00104 
00105    /* need to append a '-' for the comparison so we check full channel name,
00106     * i.e SIP/hgc- , use a temporary variable so original stays the same for
00107     * debugging.
00108     */
00109    strcpy(chkchan, channame);
00110    strcat(chkchan, "-");
00111 
00112    for (chan = ast_walk_channel_by_name_prefix_locked(NULL, channame, strlen(channame));
00113        chan;
00114        chan = ast_walk_channel_by_name_prefix_locked(chan, channame, strlen(channame))) {
00115       if (!strncasecmp(chan->name, chkchan, strlen(chkchan)) && can_pickup(chan))
00116          return chan;
00117       ast_channel_unlock(chan);
00118    }
00119    return NULL;
00120 }

static int pickup_by_channel ( struct ast_channel chan,
char *  pickup 
) [static]

Attempt to pick up specified channel named , does not use context.

Definition at line 123 of file app_directed_pickup.c.

References ast_channel_unlock, chan, my_ast_get_channel_by_name_locked(), ast_channel::name, and pickup_do().

Referenced by pickupchan_exec().

00124 {
00125    int res = 0;
00126    struct ast_channel *target;
00127 
00128    if (!(target = my_ast_get_channel_by_name_locked(pickup)))
00129       return -1;
00130 
00131    /* Just check that we are not picking up the SAME as target */
00132    if (chan->name != target->name && chan != target) {
00133       res = pickup_do(chan, target);
00134    }
00135    ast_channel_unlock(target);
00136 
00137    return res;
00138 }

static int pickup_by_exten ( struct ast_channel chan,
const char *  exten,
const char *  context 
) [static]

Definition at line 141 of file app_directed_pickup.c.

References ast_channel_unlock, ast_channel_walk_locked(), can_pickup(), chan, ast_channel::dialcontext, ast_channel::exten, ast_channel::macroexten, and pickup_do().

Referenced by pickup_exec().

00142 {
00143    int res = -1;
00144    struct ast_channel *target = NULL;
00145 
00146    while ((target = ast_channel_walk_locked(target))) {
00147       if ((!strcasecmp(target->macroexten, exten) || !strcasecmp(target->exten, exten)) &&
00148          !strcasecmp(target->dialcontext, context) &&
00149          can_pickup(target)) {
00150          res = pickup_do(chan, target);
00151          ast_channel_unlock(target);
00152          break;
00153       }
00154       ast_channel_unlock(target);
00155    }
00156 
00157    return res;
00158 }

static int pickup_by_mark ( struct ast_channel chan,
const char *  mark 
) [static]

Definition at line 161 of file app_directed_pickup.c.

References ast_channel_unlock, ast_channel_walk_locked(), can_pickup(), chan, pbx_builtin_getvar_helper(), pickup_do(), and PICKUPMARK.

Referenced by pickup_exec().

00162 {
00163    int res = -1;
00164    const char *tmp = NULL;
00165    struct ast_channel *target = NULL;
00166 
00167    while ((target = ast_channel_walk_locked(target))) {
00168       if ((tmp = pbx_builtin_getvar_helper(target, PICKUPMARK)) &&
00169          !strcasecmp(tmp, mark) &&
00170          can_pickup(target)) {
00171          res = pickup_do(chan, target);
00172          ast_channel_unlock(target);
00173          break;
00174       }
00175       ast_channel_unlock(target);
00176    }
00177 
00178    return res;
00179 }

static int pickup_do ( struct ast_channel chan,
struct ast_channel target 
) [static]

Todo:
This application should return a result code, like PICKUPRESULT

Definition at line 66 of file app_directed_pickup.c.

References ast_answer(), ast_channel_masquerade(), AST_CONTROL_ANSWER, ast_debug, ast_log(), ast_queue_control(), chan, LOG_WARNING, and ast_channel::name.

Referenced by pickup_by_channel(), pickup_by_exten(), and pickup_by_mark().

00067 {
00068    int res = 0;
00069 
00070    ast_debug(1, "Call pickup on '%s' by '%s'\n", target->name, chan->name);
00071 
00072    if ((res = ast_answer(chan))) {
00073       ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
00074       return -1;
00075    }
00076 
00077    if ((res = ast_queue_control(chan, AST_CONTROL_ANSWER))) {
00078       ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", chan->name);
00079       return -1;
00080    }
00081 
00082    if ((res = ast_channel_masquerade(target, chan))) {
00083       ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, target->name);
00084       return -1;
00085    }
00086 
00087    return res;
00088 }

static int pickup_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 182 of file app_directed_pickup.c.

References ast_log(), ast_pickup_call(), ast_strdupa, ast_strlen_zero(), chan, ast_channel::context, context, exten, LOG_NOTICE, pickup_by_exten(), pickup_by_mark(), PICKUPMARK, and strsep().

Referenced by load_module().

00183 {
00184    int res = 0;
00185    char *tmp = ast_strdupa(data);
00186    char *exten = NULL, *context = NULL;
00187 
00188    if (ast_strlen_zero(data)) {
00189       res = ast_pickup_call(chan);
00190       return res;
00191    }
00192    
00193    /* Parse extension (and context if there) */
00194    while (!ast_strlen_zero(tmp) && (exten = strsep(&tmp, "&"))) {
00195       if ((context = strchr(exten, '@')))
00196          *context++ = '\0';
00197       if (!ast_strlen_zero(context) && !strcasecmp(context, PICKUPMARK)) {
00198          if (!pickup_by_mark(chan, exten))
00199             break;
00200       } else {
00201          if (!pickup_by_exten(chan, exten, !ast_strlen_zero(context) ? context : chan->context))
00202             break;
00203       }
00204       ast_log(LOG_NOTICE, "No target channel found for %s.\n", exten);
00205    }
00206 
00207    return res;
00208 }

static int pickupchan_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 211 of file app_directed_pickup.c.

References ast_log(), ast_strdupa, ast_strlen_zero(), chan, LOG_NOTICE, LOG_WARNING, ast_channel::name, pickup_by_channel(), and strsep().

Referenced by load_module().

00212 {
00213    int res = 0;
00214    char *tmp = ast_strdupa(data);
00215    char *pickup = NULL;
00216 
00217    if (ast_strlen_zero(data)) {
00218       ast_log(LOG_WARNING, "PickupChan requires an argument (channel)!\n");
00219       return -1;  
00220    }
00221 
00222    /* Parse channel */
00223    while (!ast_strlen_zero(tmp) && (pickup = strsep(&tmp, "&"))) {
00224       if (!strncasecmp(chan->name, pickup, strlen(pickup))) {
00225          ast_log(LOG_NOTICE, "Cannot pickup your own channel %s.\n", pickup);
00226       } else {
00227          if (!pickup_by_channel(chan, pickup)) {
00228             break;
00229          }
00230          ast_log(LOG_NOTICE, "No target channel found for %s.\n", pickup);
00231       }
00232    }
00233 
00234    return res;
00235 }

static int unload_module ( void   )  [static]

Definition at line 237 of file app_directed_pickup.c.

References ast_unregister_application().

00238 {
00239    int res;
00240 
00241    res = ast_unregister_application(app);
00242    res |= ast_unregister_application(app2);
00243 
00244    return res;
00245 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Directed Call Pickup Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static]

Definition at line 257 of file app_directed_pickup.c.

const char* app = "Pickup" [static]

Definition at line 46 of file app_directed_pickup.c.

const char* app2 = "PickupChan" [static]

Definition at line 58 of file app_directed_pickup.c.

Referenced by _macro_exec().

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 257 of file app_directed_pickup.c.

const char* descrip [static]

Definition at line 48 of file app_directed_pickup.c.

const char* descrip2 [static]

Initial value:

"  PickupChan(channel[&channel...]): This application can pickup any ringing channel\n"

Definition at line 60 of file app_directed_pickup.c.

const char* synopsis = "Directed Call Pickup" [static]

Definition at line 47 of file app_directed_pickup.c.

const char* synopsis2 = "Pickup a ringing channel" [static]

Definition at line 59 of file app_directed_pickup.c.


Generated on Fri Jul 24 00:41:08 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7