#include "asterisk.h"
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <pthread.h>
#include <asterisk/lock.h>
#include <asterisk/file.h>
#include <asterisk/logger.h>
#include <asterisk/channel.h>
#include <asterisk/pbx.h>
#include <asterisk/module.h>
#include <asterisk/features.h>
#include <asterisk/options.h>
Go to the source code of this file.
Functions | |
AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS,"PickUp/PickDown/Steal/PickupChan/StealChan",.load=load_module,.unload=unload_module,) | |
static int | load_module (void) |
static int | my_pickup_call (struct ast_channel *chan, unsigned int pickupgroup, int chanstate, int bridge) |
static int | my_pickup_channel (struct ast_channel *chan, void *data, int chanstate, int bridge) |
static int | pickdown_exec (struct ast_channel *chan, void *data) |
static int | pickup_exec (struct ast_channel *chan, void *data) |
static int | pickupchan_exec (struct ast_channel *chan, void *data) |
static int | steal_exec (struct ast_channel *chan, void *data) |
static int | stealchan_exec (struct ast_channel *chan, void *data) |
static int | unload_module (void) |
Variables | |
static char * | app = "PickUp" |
static char * | app2 = "Steal" |
static char * | app3 = "PickDown" |
static char * | app4 = "PickupChan" |
static char * | app5 = "StealChan" |
static char * | descrip |
static char * | descrip2 |
static char * | descrip3 |
static char * | descrip4 |
static char * | descrip5 |
static char * | synopsis = "Channel independent call pickup." |
static char * | synopsis2 = "Channel independent call stealing. Just like pickup but for answered channels." |
static char * | synopsis3 = "Channel independent call pickdown." |
static char * | synopsis4 = "Channel independent call pickup." |
static char * | synopsis5 = "Channel independent call stealing. Just like pickup but for answered channels." |
AST_MODULE_INFO | ( | ASTERISK_GPL_KEY | , | |
AST_MODFLAG_GLOBAL_SYMBOLS | , | |||
"PickUp/PickDown/Steal/PickupChan/StealChan" | , | |||
. | load = load_module , |
|||
. | unload = unload_module | |||
) |
static int load_module | ( | void | ) | [static] |
Definition at line 288 of file app_pickup.c.
References app, app2, app3, app4, app5, ast_register_application(), descrip, descrip2, descrip3, descrip4, descrip5, pickdown_exec(), pickup_exec(), pickupchan_exec(), steal_exec(), stealchan_exec(), synopsis, synopsis2, synopsis3, synopsis4, and synopsis5.
00289 { 00290 ast_register_application(app5, stealchan_exec, synopsis5, descrip5); 00291 ast_register_application(app4, pickupchan_exec, synopsis4, descrip4); 00292 ast_register_application(app3, pickdown_exec, synopsis3, descrip3); 00293 ast_register_application(app2, steal_exec, synopsis2, descrip2); 00294 return ast_register_application(app, pickup_exec, synopsis, descrip); 00295 }
static int my_pickup_call | ( | struct ast_channel * | chan, | |
unsigned int | pickupgroup, | |||
int | chanstate, | |||
int | bridge | |||
) | [static] |
Definition at line 73 of file app_pickup.c.
References ast_channel::_softhangup, ast_channel::_state, ast_answer(), ast_channel_masquerade(), ast_channel_walk_locked(), ast_log(), ast_mutex_unlock(), AST_SOFTHANGUP_DEV, AST_STATE_RINGING, AST_STATE_UP, ast_verbose(), ast_channel::callgroup, ast_channel::lock, LOG_ERROR, option_verbose, and VERBOSE_PREFIX_3.
Referenced by pickdown_exec(), pickup_exec(), and steal_exec().
00073 { 00074 struct ast_channel *cur; 00075 int res = -1; 00076 cur = ast_channel_walk_locked(NULL); 00077 while(cur) { 00078 if ((cur != chan) && 00079 (pickupgroup & cur->callgroup) && 00080 (cur->_state == chanstate)) { 00081 break; 00082 } 00083 ast_mutex_unlock(&cur->lock); 00084 cur = ast_channel_walk_locked(cur); 00085 } 00086 if (cur) { 00087 if(option_verbose > 2) { 00088 if (chanstate == AST_STATE_RINGING) { 00089 if (bridge == 1) { 00090 ast_verbose(VERBOSE_PREFIX_3 "Channel %s picked up ringing channel %s\n",chan->name,cur->name); 00091 } else { 00092 ast_verbose(VERBOSE_PREFIX_3 "Channel %s hung up ringing channel %s\n",chan->name,cur->name); 00093 } 00094 } else { 00095 ast_verbose(VERBOSE_PREFIX_3 "Channel %s stole channel %s\n",chan->name,cur->name); 00096 } 00097 } 00098 if (bridge == 1) { 00099 if (chan->_state != AST_STATE_UP) { 00100 ast_answer(chan); 00101 } 00102 if (ast_channel_masquerade(cur, chan)) { 00103 ast_log(LOG_ERROR, "unable to masquerade\n"); 00104 } 00105 ast_mutex_unlock(&cur->lock); 00106 ast_mutex_unlock(&chan->lock); 00107 } else { 00108 cur->_softhangup = AST_SOFTHANGUP_DEV; 00109 ast_mutex_unlock(&cur->lock); 00110 } 00111 } else { 00112 if(option_verbose > 2) { 00113 ast_verbose(VERBOSE_PREFIX_3 "No channel found %d.\n",pickupgroup); 00114 } 00115 } 00116 return res; 00117 }
static int my_pickup_channel | ( | struct ast_channel * | chan, | |
void * | data, | |||
int | chanstate, | |||
int | bridge | |||
) | [static] |
Definition at line 119 of file app_pickup.c.
References ast_channel::_softhangup, ast_channel::_state, ast_answer(), ast_channel_masquerade(), ast_channel_walk_locked(), ast_log(), ast_mutex_unlock(), AST_SOFTHANGUP_DEV, AST_STATE_RINGING, AST_STATE_UP, ast_verbose(), channels, ast_channel::lock, LOG_ERROR, option_verbose, VERBOSE_PREFIX_1, and VERBOSE_PREFIX_3.
Referenced by pickupchan_exec(), and stealchan_exec().
00119 { 00120 struct ast_channel *cur; 00121 char channels[256]; 00122 char evalchan[256]; 00123 char *endptr; 00124 int res = -1; 00125 cur = ast_channel_walk_locked(NULL); 00126 strncpy(channels, (char *)data, sizeof(channels) - 1); 00127 while(cur) { 00128 if ((cur != chan) && 00129 (cur->_state == chanstate)) { 00130 /* This call is a candidate (correct ringstate and not ourselves), now check if the channel is in our list */ 00131 strncpy(evalchan, (char *)cur->name, sizeof(evalchan) - 1); 00132 /* strip the subchannel tag */ 00133 endptr = strrchr(evalchan, '-'); 00134 if(endptr) { 00135 *endptr = '\0'; 00136 } 00137 /* check for each of the members if they match (probably a stristr will do ?) */ 00138 /* if we match the code, break */ 00139 if(strstr(channels, evalchan) != NULL) { 00140 ast_verbose(VERBOSE_PREFIX_1 "Nice channel, I'll take it: %s\n",evalchan); 00141 break; 00142 } 00143 } 00144 ast_mutex_unlock(&cur->lock); 00145 cur = ast_channel_walk_locked(cur); 00146 } 00147 if (cur) { 00148 if(option_verbose > 2) { 00149 if (chanstate == AST_STATE_RINGING) { 00150 if (bridge == 1) { 00151 ast_verbose(VERBOSE_PREFIX_3 "Channel %s picked up ringing channel %s\n",chan->name,cur->name); 00152 } else { 00153 ast_verbose(VERBOSE_PREFIX_3 "Channel %s hung up ringing channel %s\n",chan->name,cur->name); 00154 } 00155 } else { 00156 ast_verbose(VERBOSE_PREFIX_3 "Channel %s stole channel %s\n",chan->name,cur->name); 00157 } 00158 } 00159 if (bridge == 1) { 00160 if (chan->_state != AST_STATE_UP) { 00161 ast_answer(chan); 00162 } 00163 if (ast_channel_masquerade(cur, chan)) { 00164 ast_log(LOG_ERROR, "unable to masquerade\n"); 00165 } 00166 ast_mutex_unlock(&cur->lock); 00167 ast_mutex_unlock(&chan->lock); 00168 } else { 00169 cur->_softhangup = AST_SOFTHANGUP_DEV; 00170 ast_mutex_unlock(&cur->lock); 00171 } 00172 } else { 00173 if(option_verbose > 2) { 00174 ast_verbose(VERBOSE_PREFIX_3 "No channel found %s.\n",channels); 00175 } 00176 } 00177 return res; 00178 }
static int pickdown_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 221 of file app_pickup.c.
References ast_get_group(), ast_module_user_add, ast_module_user_remove, AST_STATE_RINGING, my_pickup_call(), and ast_channel::pickupgroup.
Referenced by load_module().
00222 { 00223 int res=0; 00224 unsigned int pickupgroup=0; 00225 struct ast_module_user *u; 00226 if (!data || !strlen(data)) { 00227 pickupgroup = chan->pickupgroup; 00228 } else { 00229 pickupgroup = ast_get_group(data); 00230 } 00231 u = ast_module_user_add(chan); 00232 if (!res) { 00233 res = my_pickup_call(chan, pickupgroup, AST_STATE_RINGING, 0); 00234 } 00235 if (res > 0) 00236 res = 0; 00237 ast_module_user_remove(u); 00238 return res; 00239 }
static int pickup_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 181 of file app_pickup.c.
References ast_get_group(), ast_module_user_add, ast_module_user_remove, AST_STATE_RINGING, my_pickup_call(), and ast_channel::pickupgroup.
00182 { 00183 int res=0; 00184 unsigned int pickupgroup=0; 00185 struct ast_module_user *u; 00186 if (!data || !strlen(data)) { 00187 pickupgroup = chan->pickupgroup; 00188 } else { 00189 pickupgroup = ast_get_group(data); 00190 } 00191 u = ast_module_user_add(chan); 00192 if (!res) { 00193 res = my_pickup_call(chan, pickupgroup, AST_STATE_RINGING, 1); 00194 } 00195 if (res > 0) 00196 res = 0; 00197 ast_module_user_remove(u); 00198 return res; 00199 }
static int pickupchan_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 241 of file app_pickup.c.
References ast_log(), ast_module_user_add, ast_module_user_remove, AST_STATE_RINGING, LOG_WARNING, and my_pickup_channel().
Referenced by load_module().
00241 { 00242 int res=0; 00243 struct ast_module_user *u; 00244 if (!data) { 00245 ast_log(LOG_WARNING, "PickupChan requires an argument (technology1/number1&technology2/number2...)\n"); 00246 return -1; 00247 } 00248 u = ast_module_user_add(chan); 00249 if (!res) { 00250 res = my_pickup_channel(chan, data, AST_STATE_RINGING, 1); 00251 } 00252 if (res > 0) 00253 res = 0; 00254 ast_module_user_remove(u); 00255 return res; 00256 }
static int steal_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 201 of file app_pickup.c.
References ast_get_group(), ast_module_user_add, ast_module_user_remove, AST_STATE_UP, my_pickup_call(), and ast_channel::pickupgroup.
Referenced by load_module().
00202 { 00203 int res=0; 00204 unsigned int pickupgroup=0; 00205 struct ast_module_user *u; 00206 if (!data || !strlen(data)) { 00207 pickupgroup = chan->pickupgroup; 00208 } else { 00209 pickupgroup = ast_get_group(data); 00210 } 00211 u = ast_module_user_add(chan); 00212 if (!res) { 00213 res = my_pickup_call(chan, pickupgroup, AST_STATE_UP, 1); 00214 } 00215 if (res > 0) 00216 res = 0; 00217 ast_module_user_remove(u); 00218 return res; 00219 }
static int stealchan_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 258 of file app_pickup.c.
References ast_log(), ast_module_user_add, ast_module_user_remove, AST_STATE_UP, LOG_WARNING, and my_pickup_channel().
Referenced by load_module().
00259 { 00260 int res=0; 00261 struct ast_module_user *u; 00262 if (!data) { 00263 ast_log(LOG_WARNING, "StealChan requires an argument (technology1/number1&technology2/number2...)\n"); 00264 return -1; 00265 } 00266 00267 u = ast_module_user_add(chan); 00268 if (!res) { 00269 res = my_pickup_channel(chan, data, AST_STATE_UP, 1); 00270 } 00271 if (res > 0) 00272 res = 0; 00273 ast_module_user_remove(u); 00274 return res; 00275 }
static int unload_module | ( | void | ) | [static] |
Definition at line 278 of file app_pickup.c.
References app, app2, app3, app4, app5, ast_module_user_hangup_all, and ast_unregister_application().
00279 { 00280 ast_module_user_hangup_all(); 00281 ast_unregister_application(app5); 00282 ast_unregister_application(app4); 00283 ast_unregister_application(app3); 00284 ast_unregister_application(app2); 00285 return ast_unregister_application(app); 00286 }
char* app = "PickUp" [static] |
Definition at line 34 of file app_pickup.c.
char* app2 = "Steal" [static] |
Definition at line 42 of file app_pickup.c.
char* app3 = "PickDown" [static] |
Definition at line 50 of file app_pickup.c.
char* app4 = "PickupChan" [static] |
Definition at line 58 of file app_pickup.c.
char* app5 = "StealChan" [static] |
char* descrip [static] |
Initial value:
" PickDown([group]): Tries to pickup the first ringing channel with callgroup == group.\n" " If called without the group argument, the pickupgroup of the channel will be used.\n"
Definition at line 38 of file app_pickup.c.
char* descrip2 [static] |
Initial value:
" Steal([group]): Tries to steal the first bridged channel with callgroup == group.\n" " If called without the group argument, the pickupgroup of the channel will be used.\n"
Definition at line 46 of file app_pickup.c.
char* descrip3 [static] |
Initial value:
" PickDown([group]): Tries to hangup the first ringing channel with callgroup == group.\n" " If called without the group argument, the pickupgroup of the channel will be used.\n"
Definition at line 54 of file app_pickup.c.
char* descrip4 [static] |
Initial value:
" PickupChan(Technology/resource[&Technology2/resource2...]): Tries to pickup the first ringing channel in the parameter list.\n"
Definition at line 62 of file app_pickup.c.
char* descrip5 [static] |
Initial value:
" StealChan(Technology/resource[&Technology2/resource2...]): Tries to steal the first ringing channel in the parameter list.\n"
Definition at line 69 of file app_pickup.c.
Referenced by load_module().
char* synopsis = "Channel independent call pickup." [static] |
Definition at line 36 of file app_pickup.c.
char* synopsis2 = "Channel independent call stealing. Just like pickup but for answered channels." [static] |
Definition at line 44 of file app_pickup.c.
char* synopsis3 = "Channel independent call pickdown." [static] |
Definition at line 52 of file app_pickup.c.
char* synopsis4 = "Channel independent call pickup." [static] |
Definition at line 60 of file app_pickup.c.
char* synopsis5 = "Channel independent call stealing. Just like pickup but for answered channels." [static] |