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