#include <asterisk.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <pthread.h>
#include <asterisk/file.h>
#include <asterisk/logger.h>
#include <asterisk/channel.h>
#include <asterisk/pbx.h>
#include <asterisk/module.h>
#include <asterisk/adsi.h>
#include <asterisk/musiconhold.h>
#include <asterisk/features.h>
#include <asterisk/options.h>
#include <asterisk/utils.h>
#include <asterisk/lock.h>
Include dependency graph for app_pickup2.c:
Go to the source code of this file.
Defines | |
#define | AST_MODULE "app_pickup2" |
Functions | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"PickUp2/PickDown2/Steal2 version 0.1") | |
static struct ast_channel * | find_matching_channel (struct ast_channel *chan, void *pattern, int chanstate) |
static int | load_module (void) |
static int | pickdown_channel (struct ast_channel *chan, void *pattern) |
static int | pickup_channel (struct ast_channel *chan, void *pattern) |
static int | steal_channel (struct ast_channel *chan, void *pattern) |
static int | unload_module (void) |
Variables | |
static char * | app = "PickUp2" |
static char * | app2 = "PickDown2" |
static char * | app3 = "Steal2" |
static char * | descrip |
static char * | descrip2 |
static char * | descrip3 |
static char * | synopsis = "PickUp ringing channel." |
static char * | synopsis2 = "Hangup ringing channel." |
static char * | synopsis3 = "Steal a connected channel." |
#define AST_MODULE "app_pickup2" |
Definition at line 36 of file app_pickup2.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"PickUp2/PickDown2/Steal2 version 0.1" | ||||
) |
static struct ast_channel* find_matching_channel | ( | struct ast_channel * | chan, | |
void * | pattern, | |||
int | chanstate | |||
) | [static] |
Definition at line 70 of file app_pickup2.c.
References ast_channel::_state, ast_channel_walk_locked(), ast_mutex_unlock(), ast_verbose(), ast_channel::lock, and VERBOSE_PREFIX_4.
Referenced by pickdown_channel(), pickup_channel(), and steal_channel().
00071 { 00072 struct ast_channel *cur; 00073 char *pat = NULL; 00074 char *next_pat = NULL; 00075 00076 /* copy original pattern or use empty pattern if no pattern has been given */ 00077 if (pattern) { 00078 pat = alloca(strlen(pattern) + 1); 00079 strcpy(pat, pattern); 00080 } else { 00081 pat = ""; 00082 } 00083 ast_verbose(VERBOSE_PREFIX_4 "find_matching_channel: pattern='%s' state=%d\n", (char *) pattern, chanstate); 00084 00085 /* Iterate over each part of the pattern */ 00086 while (pat) { 00087 /* find pattern for next iteration, terminate current pattern */ 00088 for (next_pat = pat; *next_pat && *next_pat != '&'; next_pat++); 00089 if (*next_pat == '&') { 00090 *next_pat = 0; 00091 next_pat++; 00092 } else 00093 next_pat = NULL; 00094 /* Iterate over all channels */ 00095 cur = ast_channel_walk_locked(NULL); 00096 while (cur) { 00097 ast_verbose(VERBOSE_PREFIX_4 "find_matching_channel: trying channel='%s' " "state=%d pattern='%s'\n", cur->name, cur->_state, pat); 00098 if ((cur != chan) && (cur->_state == chanstate) && !strncmp(pat, cur->name, strlen(pat))) { 00099 ast_verbose(VERBOSE_PREFIX_4 "find_matching_channel: " "found channel='%s'\n", cur->name); 00100 return (cur); 00101 } 00102 ast_mutex_unlock(&cur->lock); 00103 cur = ast_channel_walk_locked(cur); 00104 } 00105 pat = next_pat; 00106 } 00107 return (NULL); 00108 }
static int load_module | ( | void | ) | [static] |
Definition at line 196 of file app_pickup2.c.
References app, app2, app3, ast_register_application(), descrip, descrip2, descrip3, pickdown_channel(), pickup_channel(), steal_channel(), synopsis, synopsis2, and synopsis3.
00197 { 00198 ast_register_application(app3, steal_channel, synopsis3, descrip3); 00199 ast_register_application(app2, pickdown_channel, synopsis2, descrip2); 00200 return ast_register_application(app, pickup_channel, synopsis, descrip); 00201 }
static int pickdown_channel | ( | struct ast_channel * | chan, | |
void * | pattern | |||
) | [static] |
Definition at line 136 of file app_pickup2.c.
References ast_module_user_add, ast_module_user_remove, ast_mutex_unlock(), AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), AST_STATE_RINGING, ast_verbose(), find_matching_channel(), ast_channel::lock, pbx_builtin_setvar_helper(), and VERBOSE_PREFIX_3.
Referenced by load_module().
00137 { 00138 int ret = 0; 00139 struct ast_module_user *u; 00140 struct ast_channel *cur; 00141 u = ast_module_user_add(chan); 00142 cur = find_matching_channel(chan, pattern, AST_STATE_RINGING); 00143 if (cur) { 00144 ast_verbose(VERBOSE_PREFIX_3 "Channel %s hung up ringing channel %s\n", chan->name, cur->name); 00145 pbx_builtin_setvar_helper(chan, "PICKDOWN_CHANNEL", cur->name); 00146 ast_softhangup_nolock(cur, AST_SOFTHANGUP_DEV); 00147 ast_mutex_unlock(&cur->lock); 00148 } else 00149 pbx_builtin_setvar_helper(chan, "PICKDOWN_CHANNEL", ""); 00150 ast_module_user_remove(u); 00151 return (ret); 00152 }
static int pickup_channel | ( | struct ast_channel * | chan, | |
void * | pattern | |||
) | [static] |
Definition at line 110 of file app_pickup2.c.
References ast_channel::_state, ast_answer(), ast_channel_masquerade(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_mutex_unlock(), AST_STATE_RINGING, AST_STATE_UP, ast_verbose(), find_matching_channel(), ast_channel::lock, LOG_ERROR, pbx_builtin_setvar_helper(), and VERBOSE_PREFIX_3.
Referenced by load_module().
00111 { 00112 int ret = 0; 00113 struct ast_module_user *u; 00114 struct ast_channel *cur; 00115 u = ast_module_user_add(chan); 00116 cur = find_matching_channel(chan, pattern, AST_STATE_RINGING); 00117 if (cur) { 00118 ast_verbose(VERBOSE_PREFIX_3 "Channel %s picked up ringing channel %s\n", chan->name, cur->name); 00119 pbx_builtin_setvar_helper(chan, "PICKUP_CHANNEL", cur->name); 00120 if (chan->_state != AST_STATE_UP) { 00121 ast_answer(chan); 00122 } 00123 if (ast_channel_masquerade(cur, chan)) { 00124 ast_log(LOG_ERROR, "unable to masquerade\n"); 00125 ret = -1; 00126 } 00127 ast_mutex_unlock(&cur->lock); 00128 ast_mutex_unlock(&chan->lock); 00129 } else { 00130 pbx_builtin_setvar_helper(chan, "PICKUP_CHANNEL", ""); 00131 } 00132 ast_module_user_remove(u); 00133 return (ret); 00134 }
static int steal_channel | ( | struct ast_channel * | chan, | |
void * | pattern | |||
) | [static] |
Definition at line 154 of file app_pickup2.c.
References ast_channel::_bridge, ast_channel::_state, ast_answer(), ast_channel_masquerade(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_moh_stop(), ast_mutex_lock(), ast_mutex_unlock(), AST_STATE_UP, ast_verbose(), find_matching_channel(), ast_channel::lock, LOG_ERROR, pbx_builtin_setvar_helper(), and VERBOSE_PREFIX_3.
Referenced by load_module().
00155 { 00156 int ret = 0; 00157 struct ast_module_user *u; 00158 struct ast_channel *cur; 00159 u = ast_module_user_add(chan); 00160 cur = find_matching_channel(chan, pattern, AST_STATE_UP); 00161 if (cur) { 00162 ast_verbose(VERBOSE_PREFIX_3 "Channel %s stole channel %s\n", chan->name, cur->name); 00163 pbx_builtin_setvar_helper(chan, "STEAL_CHANNEL", cur->name); 00164 if (chan->_state != AST_STATE_UP) { 00165 ast_answer(chan); 00166 } 00167 if (cur->_bridge) { 00168 if (!ast_mutex_lock(&cur->_bridge->lock)) { 00169 ast_moh_stop(cur->_bridge); 00170 ast_mutex_unlock(&cur->_bridge->lock); 00171 } 00172 } 00173 00174 if (ast_channel_masquerade(cur, chan)) { 00175 ast_log(LOG_ERROR, "unable to masquerade\n"); 00176 ret = -1; 00177 } 00178 ast_mutex_unlock(&cur->lock); 00179 ast_mutex_unlock(&chan->lock); 00180 } else 00181 pbx_builtin_setvar_helper(chan, "STEAL_CHANNEL", ""); 00182 ast_module_user_remove(u); 00183 return (ret); 00184 }
static int unload_module | ( | void | ) | [static] |
Definition at line 186 of file app_pickup2.c.
References app, app2, app3, ast_module_user_hangup_all, and ast_unregister_application().
00187 { 00188 int res; 00189 ast_module_user_hangup_all(); 00190 res |= ast_unregister_application(app3); 00191 res |= ast_unregister_application(app2); 00192 res = ast_unregister_application(app); 00193 return res; 00194 }
char* app = "PickUp2" [static] |
Definition at line 38 of file app_pickup2.c.
char* app2 = "PickDown2" [static] |
Definition at line 47 of file app_pickup2.c.
char* app3 = "Steal2" [static] |
Definition at line 56 of file app_pickup2.c.
char* descrip [static] |
Definition at line 40 of file app_pickup2.c.
char* descrip2 [static] |
Definition at line 49 of file app_pickup2.c.
char* descrip3 [static] |
Definition at line 59 of file app_pickup2.c.
char* synopsis = "PickUp ringing channel." [static] |
Definition at line 39 of file app_pickup2.c.
char* synopsis2 = "Hangup ringing channel." [static] |
Definition at line 48 of file app_pickup2.c.
Definition at line 57 of file app_pickup2.c.