Thu Jul 9 13:40:44 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 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 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 = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, }
static const char * app = "Pickup"
static const struct ast_module_infoast_module_info = &__mod_info
static const char * descrip
static const char * synopsis = "Directed Call Pickup"


Detailed Description

Directed Call Pickup Support.

Author:
Joshua Colp <jcolp@digium.com>

Definition in file app_directed_pickup.c.


Define Documentation

#define PICKUPMARK   "PICKUPMARK"

Definition at line 40 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 172 of file app_directed_pickup.c.

static void __unreg_module ( void   )  [static]

Definition at line 172 of file app_directed_pickup.c.

static int can_pickup ( struct ast_channel chan  )  [static]

Definition at line 80 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().

00081 {
00082    if (!chan->pbx && (chan->_state == AST_STATE_RINGING || chan->_state == AST_STATE_RING || chan->_state == AST_STATE_DOWN))
00083       return 1;
00084    else
00085       return 0;
00086 }

static int load_module ( void   )  [static]

Definition at line 167 of file app_directed_pickup.c.

References ast_register_application, and pickup_exec().

00168 {
00169    return ast_register_application(app, pickup_exec, synopsis, descrip);
00170 }

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

Definition at line 89 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().

00090 {
00091    int res = -1;
00092    struct ast_channel *target = NULL;
00093 
00094    while ((target = ast_channel_walk_locked(target))) {
00095       if ((!strcasecmp(target->macroexten, exten) || !strcasecmp(target->exten, exten)) &&
00096          !strcasecmp(target->dialcontext, context) &&
00097          can_pickup(target)) {
00098          res = pickup_do(chan, target);
00099          ast_channel_unlock(target);
00100          break;
00101       }
00102       ast_channel_unlock(target);
00103    }
00104 
00105    return res;
00106 }

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

Definition at line 109 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().

00110 {
00111    int res = -1;
00112    const char *tmp = NULL;
00113    struct ast_channel *target = NULL;
00114 
00115    while ((target = ast_channel_walk_locked(target))) {
00116       if ((tmp = pbx_builtin_getvar_helper(target, PICKUPMARK)) &&
00117          !strcasecmp(tmp, mark) &&
00118          can_pickup(target)) {
00119          res = pickup_do(chan, target);
00120          ast_channel_unlock(target);
00121          break;
00122       }
00123       ast_channel_unlock(target);
00124    }
00125 
00126    return res;
00127 }

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

Definition at line 55 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().

00056 {
00057    int res = 0;
00058 
00059    ast_debug(1, "Call pickup on '%s' by '%s'\n", target->name, chan->name);
00060 
00061    if ((res = ast_answer(chan))) {
00062       ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
00063       return -1;
00064    }
00065 
00066    if ((res = ast_queue_control(chan, AST_CONTROL_ANSWER))) {
00067       ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", chan->name);
00068       return -1;
00069    }
00070 
00071    if ((res = ast_channel_masquerade(target, chan))) {
00072       ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, target->name);
00073       return -1;
00074    }
00075 
00076    return res;
00077 }

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

Definition at line 130 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().

00131 {
00132    int res = 0;
00133    char *tmp = ast_strdupa(data);
00134    char *exten = NULL, *context = NULL;
00135 
00136    if (ast_strlen_zero(data)) {
00137       res = ast_pickup_call(chan);
00138       return res;
00139    }
00140    
00141    /* Parse extension (and context if there) */
00142    while (!ast_strlen_zero(tmp) && (exten = strsep(&tmp, "&"))) {
00143       if ((context = strchr(exten, '@')))
00144          *context++ = '\0';
00145       if (!ast_strlen_zero(context) && !strcasecmp(context, PICKUPMARK)) {
00146          if (!pickup_by_mark(chan, exten))
00147             break;
00148       } else {
00149          if (!pickup_by_exten(chan, exten, !ast_strlen_zero(context) ? context : chan->context))
00150             break;
00151       }
00152       ast_log(LOG_NOTICE, "No target channel found for %s.\n", exten);
00153    }
00154 
00155    return res;
00156 }

static int unload_module ( void   )  [static]

Definition at line 158 of file app_directed_pickup.c.

References ast_unregister_application().

00159 {
00160    int res;
00161 
00162    res = ast_unregister_application(app);
00163 
00164    return res;
00165 }


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 = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } [static]

Definition at line 172 of file app_directed_pickup.c.

const char* app = "Pickup" [static]

Definition at line 42 of file app_directed_pickup.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 172 of file app_directed_pickup.c.

const char* descrip [static]

Definition at line 44 of file app_directed_pickup.c.

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

Definition at line 43 of file app_directed_pickup.c.


Generated on Thu Jul 9 13:40:44 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7