2 * Asterisk -- A telephony toolkit for Linux.
4 * Check if Channel is Available
6 * Copyright (C) 2003, Digium
8 * Mark Spencer <markster@digium.com>
9 * James Golovich <james@gnuinter.net>
11 * This program is free software, distributed under the terms of
12 * the GNU General Public License
16 #include <asterisk/lock.h>
17 #include <asterisk/file.h>
18 #include <asterisk/logger.h>
19 #include <asterisk/channel.h>
20 #include <asterisk/pbx.h>
21 #include <asterisk/module.h>
22 #include <asterisk/app.h>
28 #include <sys/ioctl.h>
32 static char *tdesc = "Check if channel is available";
34 static char *app = "ChanIsAvail";
36 static char *synopsis = "Check if channel is available";
38 static char *descrip =
39 " ChanIsAvail(Technology/resource[&Technology2/resource2...]): \n"
40 "Checks is any of the requested channels are available. If none\n"
41 "of the requested channels are available the new priority will\n"
42 "be n+101 (unless such a priority does not exist, in which case\n"
43 "ChanIsAvail will return -1. If any of the requested channels\n"
44 "are available, the next priority will be n+1, the channel variable\n"
45 "${AVAILCHAN} will be set to the name of the available channel and\n"
46 "the ChanIsAvail app will return 0.\n";
52 static int chanavail_exec(struct ast_channel *chan, void *data)
56 char info[256], *peers, *tech, *number, *rest, *cur;
57 struct ast_channel *tempchan;
60 ast_log(LOG_WARNING, "ChanIsAvail requires an argument (Zap/1&Zap/2)\n");
65 strncpy(info, (char *)data, strlen((char *)data) + AST_MAX_EXTENSION-1);
70 /* remember where to start next time */
71 rest = strchr(cur, '&');
77 number = strchr(tech, '/');
79 ast_log(LOG_WARNING, "ChanIsAvail argument takes format ([technology]/[device])\n");
84 if ((tempchan = ast_request(tech, chan->nativeformats, number))) {
85 pbx_builtin_setvar_helper(chan, "AVAILCHAN", tempchan->name);
96 pbx_builtin_setvar_helper(chan, "AVAILCHAN", "");
97 if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
103 LOCAL_USER_REMOVE(u);
107 int unload_module(void)
109 STANDARD_HANGUP_LOCALUSERS;
110 return ast_unregister_application(app);
113 int load_module(void)
115 return ast_register_application(app, chanavail_exec, synopsis, descrip);
118 char *description(void)
126 STANDARD_USECOUNT(res);
132 return ASTERISK_GPL_KEY;