#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.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/app.h"
#include "asterisk/devicestate.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 | chanavail_exec (struct ast_channel *chan, void *data) |
static int | load_module (void) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Check channel availability" , .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 = "f450f61f60e761b3aa089ebed76ca8a5" , .load = load_module, .unload = unload_module, } |
static char * | app = "ChanIsAvail" |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static char * | descrip |
static char * | synopsis = "Check channel availability" |
James Golovich <james@gnuinter.net>
Definition in file app_chanisavail.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 173 of file app_chanisavail.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 173 of file app_chanisavail.c.
static int chanavail_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 67 of file app_chanisavail.c.
References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_device_state(), ast_goto_if_exists(), ast_hangup(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_opt_priority_jumping, ast_request(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_channel::context, inuse, LOG_WARNING, ast_channel::name, ast_channel::nativeformats, and pbx_builtin_setvar_helper().
Referenced by load_module().
00068 { 00069 int res=-1, inuse=-1, option_state=0, priority_jump=0; 00070 int status; 00071 struct ast_module_user *u; 00072 char *info, tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur; 00073 struct ast_channel *tempchan; 00074 AST_DECLARE_APP_ARGS(args, 00075 AST_APP_ARG(reqchans); 00076 AST_APP_ARG(options); 00077 ); 00078 00079 if (ast_strlen_zero(data)) { 00080 ast_log(LOG_WARNING, "ChanIsAvail requires an argument (Zap/1&Zap/2)\n"); 00081 return -1; 00082 } 00083 00084 u = ast_module_user_add(chan); 00085 00086 info = ast_strdupa(data); 00087 00088 AST_STANDARD_APP_ARGS(args, info); 00089 00090 if (args.options) { 00091 if (strchr(args.options, 's')) 00092 option_state = 1; 00093 if (strchr(args.options, 'j')) 00094 priority_jump = 1; 00095 } 00096 peers = args.reqchans; 00097 if (peers) { 00098 cur = peers; 00099 do { 00100 /* remember where to start next time */ 00101 rest = strchr(cur, '&'); 00102 if (rest) { 00103 *rest = 0; 00104 rest++; 00105 } 00106 tech = cur; 00107 number = strchr(tech, '/'); 00108 if (!number) { 00109 ast_log(LOG_WARNING, "ChanIsAvail argument takes format ([technology]/[device])\n"); 00110 ast_module_user_remove(u); 00111 return -1; 00112 } 00113 *number = '\0'; 00114 number++; 00115 00116 if (option_state) { 00117 /* If the pbx says in use then don't bother trying further. 00118 This is to permit testing if someone's on a call, even if the 00119 channel can permit more calls (ie callwaiting, sip calls, etc). */ 00120 00121 snprintf(trychan, sizeof(trychan), "%s/%s",cur,number); 00122 status = inuse = ast_device_state(trychan); 00123 } 00124 if ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) { 00125 pbx_builtin_setvar_helper(chan, "AVAILCHAN", tempchan->name); 00126 /* Store the originally used channel too */ 00127 snprintf(tmp, sizeof(tmp), "%s/%s", tech, number); 00128 pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", tmp); 00129 snprintf(tmp, sizeof(tmp), "%d", status); 00130 pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp); 00131 ast_hangup(tempchan); 00132 tempchan = NULL; 00133 res = 1; 00134 break; 00135 } else { 00136 snprintf(tmp, sizeof(tmp), "%d", status); 00137 pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp); 00138 } 00139 cur = rest; 00140 } while (cur); 00141 } 00142 if (res < 1) { 00143 pbx_builtin_setvar_helper(chan, "AVAILCHAN", ""); 00144 pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", ""); 00145 if (priority_jump || ast_opt_priority_jumping) { 00146 if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) { 00147 ast_module_user_remove(u); 00148 return -1; 00149 } 00150 } 00151 } 00152 00153 ast_module_user_remove(u); 00154 return 0; 00155 }
static int load_module | ( | void | ) | [static] |
Definition at line 168 of file app_chanisavail.c.
References ast_register_application(), and chanavail_exec().
00169 { 00170 return ast_register_application(app, chanavail_exec, synopsis, descrip); 00171 }
static int unload_module | ( | void | ) | [static] |
Definition at line 157 of file app_chanisavail.c.
References ast_module_user_hangup_all, and ast_unregister_application().
00158 { 00159 int res = 0; 00160 00161 res = ast_unregister_application(app); 00162 00163 ast_module_user_hangup_all(); 00164 00165 return res; 00166 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Check channel availability" , .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 = "f450f61f60e761b3aa089ebed76ca8a5" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 173 of file app_chanisavail.c.
char* app = "ChanIsAvail" [static] |
Definition at line 51 of file app_chanisavail.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 173 of file app_chanisavail.c.
char* descrip [static] |
Definition at line 55 of file app_chanisavail.c.
char* synopsis = "Check channel availability" [static] |
Definition at line 53 of file app_chanisavail.c.