#include "asterisk.h"
#include <sys/ioctl.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/devicestate.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 , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } |
static char * | app = "ChanIsAvail" |
static 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 177 of file app_chanisavail.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 177 of file app_chanisavail.c.
static int chanavail_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 68 of file app_chanisavail.c.
References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_device_state(), ast_hangup(), ast_log(), ast_parse_device_state(), ast_request(), AST_STANDARD_APP_ARGS, ast_str_alloca, ast_str_append(), ast_strdupa, ast_strlen_zero(), chan, inuse, LOG_WARNING, ast_channel::name, ast_channel::nativeformats, pbx_builtin_setvar_helper(), status, ast_str::str, and ast_str::used.
Referenced by load_module().
00069 { 00070 int inuse=-1, option_state=0, string_compare=0, option_all_avail=0; 00071 int status; 00072 char *info, tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur; 00073 struct ast_str *tmp_availchan = ast_str_alloca(2048); 00074 struct ast_str *tmp_availorig = ast_str_alloca(2048); 00075 struct ast_str *tmp_availstat = ast_str_alloca(2048); 00076 struct ast_channel *tempchan; 00077 AST_DECLARE_APP_ARGS(args, 00078 AST_APP_ARG(reqchans); 00079 AST_APP_ARG(options); 00080 ); 00081 00082 if (ast_strlen_zero(data)) { 00083 ast_log(LOG_WARNING, "ChanIsAvail requires an argument (DAHDI/1&DAHDI/2)\n"); 00084 return -1; 00085 } 00086 00087 info = ast_strdupa(data); 00088 00089 AST_STANDARD_APP_ARGS(args, info); 00090 00091 if (args.options) { 00092 if (strchr(args.options, 'a')) { 00093 option_all_avail = 1; 00094 } 00095 if (strchr(args.options, 's')) { 00096 option_state = 1; 00097 } 00098 if (strchr(args.options, 't')) { 00099 string_compare = 1; 00100 } 00101 } 00102 peers = args.reqchans; 00103 if (peers) { 00104 cur = peers; 00105 do { 00106 /* remember where to start next time */ 00107 rest = strchr(cur, '&'); 00108 if (rest) { 00109 *rest = 0; 00110 rest++; 00111 } 00112 tech = cur; 00113 number = strchr(tech, '/'); 00114 if (!number) { 00115 ast_log(LOG_WARNING, "ChanIsAvail argument takes format ([technology]/[device])\n"); 00116 return -1; 00117 } 00118 *number = '\0'; 00119 number++; 00120 00121 if (string_compare) { 00122 /* ast_parse_device_state checks for "SIP/1234" as a channel name. 00123 ast_device_state will ask the SIP driver for the channel state. */ 00124 00125 snprintf(trychan, sizeof(trychan), "%s/%s",cur,number); 00126 status = inuse = ast_parse_device_state(trychan); 00127 } else if (option_state) { 00128 /* If the pbx says in use then don't bother trying further. 00129 This is to permit testing if someone's on a call, even if the 00130 channel can permit more calls (ie callwaiting, sip calls, etc). */ 00131 00132 snprintf(trychan, sizeof(trychan), "%s/%s",cur,number); 00133 status = inuse = ast_device_state(trychan); 00134 } 00135 if ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) { 00136 ast_str_append(&tmp_availchan, 0, "%s%s", tmp_availchan->used ? "&" : "", tempchan->name); 00137 00138 snprintf(tmp, sizeof(tmp), "%s/%s", tech, number); 00139 ast_str_append(&tmp_availorig, 0, "%s%s", tmp_availorig->used ? "&" : "", tmp); 00140 00141 snprintf(tmp, sizeof(tmp), "%d", status); 00142 ast_str_append(&tmp_availstat, 0, "%s%s", tmp_availstat->used ? "&" : "", tmp); 00143 00144 ast_hangup(tempchan); 00145 tempchan = NULL; 00146 00147 if (!option_all_avail) { 00148 break; 00149 } 00150 } else { 00151 snprintf(tmp, sizeof(tmp), "%d", status); 00152 ast_str_append(&tmp_availstat, 0, "%s%s", tmp_availstat->used ? "&" : "", tmp); 00153 } 00154 cur = rest; 00155 } while (cur); 00156 } 00157 00158 pbx_builtin_setvar_helper(chan, "AVAILCHAN", tmp_availchan->str); 00159 /* Store the originally used channel too */ 00160 pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", tmp_availorig->str); 00161 pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp_availstat->str); 00162 00163 return 0; 00164 }
static int load_module | ( | void | ) | [static] |
Definition at line 171 of file app_chanisavail.c.
References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_application, and chanavail_exec().
00172 { 00173 return ast_register_application(app, chanavail_exec, synopsis, descrip) ? 00174 AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS; 00175 }
static int unload_module | ( | void | ) | [static] |
Definition at line 166 of file app_chanisavail.c.
References ast_unregister_application().
00167 { 00168 return ast_unregister_application(app); 00169 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 177 of file app_chanisavail.c.
char* app = "ChanIsAvail" [static] |
Definition at line 44 of file app_chanisavail.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 177 of file app_chanisavail.c.
char* descrip [static] |
Definition at line 48 of file app_chanisavail.c.
char* synopsis = "Check channel availability" [static] |
Definition at line 46 of file app_chanisavail.c.