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