#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 = "361d7bb937402d51e4658efb5b4d76e4" , .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 187 of file app_directed_pickup.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 187 of file app_directed_pickup.c.
static int can_pickup | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 86 of file app_directed_pickup.c.
References ast_channel::_state, AST_FLAG_ZOMBIE, AST_STATE_DOWN, AST_STATE_RING, AST_STATE_RINGING, ast_test_flag, ast_channel::masq, and ast_channel::pbx.
Referenced by pickup_by_exten(), and pickup_by_mark().
00087 { 00088 if (!chan->pbx && !chan->masq && 00089 !ast_test_flag(chan, AST_FLAG_ZOMBIE) && 00090 (chan->_state == AST_STATE_RINGING || 00091 chan->_state == AST_STATE_RING || 00092 chan->_state == AST_STATE_DOWN)) { 00093 return 1; 00094 } 00095 return 0; 00096 }
static int load_module | ( | void | ) | [static] |
Definition at line 182 of file app_directed_pickup.c.
References ast_register_application(), and pickup_exec().
00183 { 00184 return ast_register_application(app, pickup_exec, synopsis, descrip); 00185 }
static int pickup_by_exten | ( | struct ast_channel * | chan, | |
char * | exten, | |||
char * | context | |||
) | [static] |
Definition at line 99 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().
00100 { 00101 int res = -1; 00102 struct ast_channel *target = NULL; 00103 00104 while ((target = ast_channel_walk_locked(target))) { 00105 if ((!strcasecmp(target->macroexten, exten) || !strcasecmp(target->exten, exten)) && 00106 !strcasecmp(target->dialcontext, context) && 00107 (chan != target) && can_pickup(target)) { 00108 res = pickup_do(chan, target); 00109 ast_channel_unlock(target); 00110 break; 00111 } 00112 ast_channel_unlock(target); 00113 } 00114 00115 return res; 00116 }
static int pickup_by_mark | ( | struct ast_channel * | chan, | |
char * | mark | |||
) | [static] |
Definition at line 119 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().
00120 { 00121 int res = -1; 00122 const char *tmp = NULL; 00123 struct ast_channel *target = NULL; 00124 00125 while ((target = ast_channel_walk_locked(target))) { 00126 if ((tmp = pbx_builtin_getvar_helper(target, PICKUPMARK)) && 00127 !strcasecmp(tmp, mark) && 00128 can_pickup(target)) { 00129 res = pickup_do(chan, target); 00130 ast_channel_unlock(target); 00131 break; 00132 } 00133 ast_channel_unlock(target); 00134 } 00135 00136 return res; 00137 }
static int pickup_do | ( | struct ast_channel * | chan, | |
struct ast_channel * | target | |||
) | [static] |
Definition at line 62 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 ast_pickup_call(), pickup_by_exten(), and pickup_by_mark().
00063 { 00064 if (option_debug) 00065 ast_log(LOG_DEBUG, "Call pickup on '%s' by '%s'\n", target->name, chan->name); 00066 00067 if (ast_answer(chan)) { 00068 ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name); 00069 return -1; 00070 } 00071 00072 if (ast_queue_control(chan, AST_CONTROL_ANSWER)) { 00073 ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", chan->name); 00074 return -1; 00075 } 00076 00077 if (ast_channel_masquerade(target, chan)) { 00078 ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, target->name); 00079 return -1; 00080 } 00081 00082 return 0; 00083 }
static int pickup_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 140 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().
00141 { 00142 int res = 0; 00143 struct ast_module_user *u = NULL; 00144 char *tmp = ast_strdupa(data); 00145 char *exten = NULL, *context = NULL; 00146 00147 if (ast_strlen_zero(data)) { 00148 ast_log(LOG_WARNING, "Pickup requires an argument (extension)!\n"); 00149 return -1; 00150 } 00151 00152 u = ast_module_user_add(chan); 00153 00154 /* Parse extension (and context if there) */ 00155 while (!ast_strlen_zero(tmp) && (exten = strsep(&tmp, "&"))) { 00156 if ((context = strchr(exten, '@'))) 00157 *context++ = '\0'; 00158 if (context && !strcasecmp(context, PICKUPMARK)) { 00159 if (!pickup_by_mark(chan, exten)) 00160 break; 00161 } else { 00162 if (!pickup_by_exten(chan, exten, context ? context : chan->context)) 00163 break; 00164 } 00165 ast_log(LOG_NOTICE, "No target channel found for %s.\n", exten); 00166 } 00167 00168 ast_module_user_remove(u); 00169 00170 return res; 00171 }
static int unload_module | ( | void | ) | [static] |
Definition at line 173 of file app_directed_pickup.c.
References ast_unregister_application().
00174 { 00175 int res; 00176 00177 res = ast_unregister_application(app); 00178 00179 return res; 00180 }
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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 187 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 187 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.