#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.
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, char *exten, char *context) |
static int | pickup_by_mark (struct ast_channel *chan, 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 | AST_MODFLAG_BUILDSUM, .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 = "6989f2ec67f8497e38c12890500c525b" , .load = load_module, .unload = unload_module, } |
static const char * | app = "Pickup" |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static const char * | descrip |
static const char * | synopsis = "Directed Call Pickup" |
Definition in file app_directed_pickup.c.
#define PICKUPMARK "PICKUPMARK" |
Definition at line 46 of file app_directed_pickup.c.
Referenced by pickup_by_mark(), and pickup_exec().
static void __reg_module | ( | void | ) | [static] |
Definition at line 181 of file app_directed_pickup.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 181 of file app_directed_pickup.c.
static int can_pickup | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 84 of file app_directed_pickup.c.
References ast_channel::_state, AST_STATE_DOWN, AST_STATE_RING, AST_STATE_RINGING, and ast_channel::pbx.
Referenced by pickup_by_exten(), and pickup_by_mark().
00085 { 00086 if (!chan->pbx && (chan->_state == AST_STATE_RINGING || chan->_state == AST_STATE_RING || chan->_state == AST_STATE_DOWN)) 00087 return 1; 00088 else 00089 return 0; 00090 }
static int load_module | ( | void | ) | [static] |
Definition at line 176 of file app_directed_pickup.c.
References ast_register_application(), and pickup_exec().
00177 { 00178 return ast_register_application(app, pickup_exec, synopsis, descrip); 00179 }
static int pickup_by_exten | ( | struct ast_channel * | chan, | |
char * | exten, | |||
char * | context | |||
) | [static] |
Definition at line 93 of file app_directed_pickup.c.
References ast_channel_unlock, ast_channel_walk_locked(), can_pickup(), ast_channel::dialcontext, ast_channel::exten, ast_channel::macroexten, and pickup_do().
Referenced by pickup_exec().
00094 { 00095 int res = -1; 00096 struct ast_channel *target = NULL; 00097 00098 while ((target = ast_channel_walk_locked(target))) { 00099 if ((!strcasecmp(target->macroexten, exten) || !strcasecmp(target->exten, exten)) && 00100 !strcasecmp(target->dialcontext, context) && 00101 (chan != target) && can_pickup(target)) { 00102 res = pickup_do(chan, target); 00103 ast_channel_unlock(target); 00104 break; 00105 } 00106 ast_channel_unlock(target); 00107 } 00108 00109 return res; 00110 }
static int pickup_by_mark | ( | struct ast_channel * | chan, | |
char * | mark | |||
) | [static] |
Definition at line 113 of file app_directed_pickup.c.
References ast_channel_unlock, ast_channel_walk_locked(), can_pickup(), pbx_builtin_getvar_helper(), pickup_do(), and PICKUPMARK.
Referenced by pickup_exec().
00114 { 00115 int res = -1; 00116 const char *tmp = NULL; 00117 struct ast_channel *target = NULL; 00118 00119 while ((target = ast_channel_walk_locked(target))) { 00120 if ((tmp = pbx_builtin_getvar_helper(target, PICKUPMARK)) && 00121 !strcasecmp(tmp, mark) && 00122 can_pickup(target)) { 00123 res = pickup_do(chan, target); 00124 ast_channel_unlock(target); 00125 break; 00126 } 00127 ast_channel_unlock(target); 00128 } 00129 00130 return res; 00131 }
static int pickup_do | ( | struct ast_channel * | chan, | |
struct ast_channel * | target | |||
) | [static] |
Definition at line 58 of file app_directed_pickup.c.
References ast_answer(), ast_channel_masquerade(), AST_CONTROL_ANSWER, ast_log(), ast_queue_control(), LOG_DEBUG, LOG_WARNING, ast_channel::name, and option_debug.
Referenced by pickup_by_exten(), and pickup_by_mark().
00059 { 00060 int res = 0; 00061 00062 if (option_debug) 00063 ast_log(LOG_DEBUG, "Call pickup on '%s' by '%s'\n", target->name, chan->name); 00064 00065 if ((res = ast_answer(chan))) { 00066 ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name); 00067 return -1; 00068 } 00069 00070 if ((res = ast_queue_control(chan, AST_CONTROL_ANSWER))) { 00071 ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", chan->name); 00072 return -1; 00073 } 00074 00075 if ((res = ast_channel_masquerade(target, chan))) { 00076 ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, target->name); 00077 return -1; 00078 } 00079 00080 return res; 00081 }
static int pickup_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 134 of file app_directed_pickup.c.
References ast_log(), ast_module_user_add, ast_module_user_remove, ast_strdupa, ast_strlen_zero(), ast_module_user::chan, ast_channel::context, context, exten, LOG_NOTICE, LOG_WARNING, pickup_by_exten(), pickup_by_mark(), and PICKUPMARK.
Referenced by load_module().
00135 { 00136 int res = 0; 00137 struct ast_module_user *u = NULL; 00138 char *tmp = ast_strdupa(data); 00139 char *exten = NULL, *context = NULL; 00140 00141 if (ast_strlen_zero(data)) { 00142 ast_log(LOG_WARNING, "Pickup requires an argument (extension)!\n"); 00143 return -1; 00144 } 00145 00146 u = ast_module_user_add(chan); 00147 00148 /* Parse extension (and context if there) */ 00149 while (!ast_strlen_zero(tmp) && (exten = strsep(&tmp, "&"))) { 00150 if ((context = strchr(exten, '@'))) 00151 *context++ = '\0'; 00152 if (context && !strcasecmp(context, PICKUPMARK)) { 00153 if (!pickup_by_mark(chan, exten)) 00154 break; 00155 } else { 00156 if (!pickup_by_exten(chan, exten, context ? context : chan->context)) 00157 break; 00158 } 00159 ast_log(LOG_NOTICE, "No target channel found for %s.\n", exten); 00160 } 00161 00162 ast_module_user_remove(u); 00163 00164 return res; 00165 }
static int unload_module | ( | void | ) | [static] |
Definition at line 167 of file app_directed_pickup.c.
References ast_unregister_application().
00168 { 00169 int res; 00170 00171 res = ast_unregister_application(app); 00172 00173 return res; 00174 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "6989f2ec67f8497e38c12890500c525b" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 181 of file app_directed_pickup.c.
const char* app = "Pickup" [static] |
Definition at line 48 of file app_directed_pickup.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 181 of file app_directed_pickup.c.
const char* descrip [static] |
Definition at line 50 of file app_directed_pickup.c.
const char* synopsis = "Directed Call Pickup" [static] |
Definition at line 49 of file app_directed_pickup.c.