Thu Jul 9 13:40:47 2009

Asterisk developer's documentation


app_pickupchan.c File Reference

Pickup a ringing channel. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/options.h"

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int can_pickup (struct ast_channel *chan)
 Helper function that determines whether a channel is capable of being picked up.
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_do (struct ast_channel *chan, struct ast_channel *target)
 Perform actual pickup between two channels.
static int pickupchan_exec (struct ast_channel *chan, void *data)
 Main application entry point.
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Channel 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 = "PickupChan"
static const struct ast_module_infoast_module_info = &__mod_info
static const char * descrip
static const char * synopsis = "Pickup a ringing channel"


Detailed Description

Pickup a ringing channel.

Author:
Gary Cook

Definition in file app_pickupchan.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 174 of file app_pickupchan.c.

static void __unreg_module ( void   )  [static]

Definition at line 174 of file app_pickupchan.c.

static int can_pickup ( struct ast_channel chan  )  [static]

Helper function that determines whether a channel is capable of being picked up.

Definition at line 52 of file app_pickupchan.c.

References ast_channel::_state, ast_debug, ast_state2str(), AST_STATE_RING, AST_STATE_RINGING, chan, ast_channel::name, and ast_channel::pbx.

00053 {
00054    ast_debug(3, "Checking Pickup '%s' state '%s ( %d )'\n", chan->name, ast_state2str(chan->_state), chan->_state);
00055 
00056    if (!chan->pbx && (chan->_state == AST_STATE_RINGING || chan->_state == AST_STATE_RING)) {
00057       return 1;
00058    } else {
00059       return 0;
00060    }
00061 }

static int load_module ( void   )  [static]

Definition at line 169 of file app_pickupchan.c.

References ast_register_application, and pickupchan_exec().

00170 {
00171    return ast_register_application(app, pickupchan_exec, synopsis, descrip);
00172 }

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 64 of file app_pickupchan.c.

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

Referenced by pickup_by_channel().

00065 {
00066    struct ast_channel *chan;
00067    char *chkchan = alloca(strlen(channame) + 2);
00068 
00069    /* need to append a '-' for the comparison so we check full channel name,
00070     * i.e SIP/hgc- , use a temporary variable so original stays the same for
00071     * debugging.
00072     */
00073    strcpy(chkchan, channame);
00074    strcat(chkchan, "-");
00075 
00076    for (chan = ast_walk_channel_by_name_prefix_locked(NULL, channame, strlen(channame));
00077        chan;
00078        chan = ast_walk_channel_by_name_prefix_locked(chan, channame, strlen(channame))) {
00079       if (!strncasecmp(chan->name, chkchan, strlen(chkchan)) && can_pickup(chan))
00080          return chan;
00081       ast_channel_unlock(chan);
00082    }
00083    return NULL;
00084 }

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 112 of file app_pickupchan.c.

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

Referenced by pickupchan_exec().

00113 {
00114    int res = 0;
00115    struct ast_channel *target;
00116 
00117    if (!(target = my_ast_get_channel_by_name_locked(pickup)))
00118       return -1;
00119 
00120    /* Just check that we are not picking up the SAME as target */
00121    if (chan->name != target->name && chan != target) {
00122       res = pickup_do(chan, target);
00123       ast_channel_unlock(target);
00124    }
00125 
00126    return res;
00127 }

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

Perform actual pickup between two channels.

Definition at line 87 of file app_pickupchan.c.

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

00088 {
00089    int res = 0;
00090 
00091    ast_debug(3, "Call pickup on '%s' by '%s'\n", target->name, chan->name);
00092 
00093    if ((res = ast_answer(chan))) {
00094       ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
00095       return -1;
00096    }
00097 
00098    if ((res = ast_queue_control(chan, AST_CONTROL_ANSWER))) {
00099       ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", chan->name);
00100       return -1;
00101    }
00102 
00103    if ((res = ast_channel_masquerade(target, chan))) {
00104       ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, target->name);
00105       return -1;
00106    }
00107 
00108    return res;
00109 }

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

Main application entry point.

Definition at line 130 of file app_pickupchan.c.

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

Referenced by load_module().

00131 {
00132    int res = 0;
00133    struct ast_module_user *u = NULL;
00134    char *tmp = ast_strdupa(data);
00135    char *pickup = NULL, *context = NULL;
00136 
00137    if (ast_strlen_zero(data)) {
00138       ast_log(LOG_WARNING, "Pickup requires an argument (channel)!\n");
00139       return -1;  
00140    }
00141 
00142    u = ast_module_user_add(chan);
00143 
00144    /* Parse channel (and ignore context if there) */
00145    while (!ast_strlen_zero(tmp) && (pickup = strsep(&tmp, "&"))) {
00146       if ((context = strchr(pickup , '@'))) {
00147          *context++ = '\0';
00148       }
00149       if (!strncasecmp(chan->name, pickup , strlen(pickup))) {
00150          ast_log(LOG_NOTICE, "Cannot pickup your own channel %s.\n", pickup);
00151       } else {
00152          if (!pickup_by_channel(chan, pickup)) {
00153             break;
00154          }
00155          ast_log(LOG_NOTICE, "No target channel found for %s.\n", pickup);
00156       }
00157    }
00158 
00159    ast_module_user_remove(u);
00160 
00161    return res;
00162 }

static int unload_module ( void   )  [static]

Definition at line 164 of file app_pickupchan.c.

References ast_unregister_application().

00165 {
00166    return ast_unregister_application(app);
00167 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Channel 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 174 of file app_pickupchan.c.

const char* app = "PickupChan" [static]

Definition at line 44 of file app_pickupchan.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 174 of file app_pickupchan.c.

const char* descrip [static]

Initial value:

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

Definition at line 46 of file app_pickupchan.c.

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

Definition at line 45 of file app_pickupchan.c.


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