aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_chanisavail.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-11-15 16:27:28 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-11-15 16:27:28 +0000
commit1d3503b73ab761222affb97ea48f4ddf1a96d619 (patch)
treef72f5cc4eebc09947d614010ea9aa65bd0ce6bcc /apps/app_chanisavail.c
parent149e739dc53c5722436ddc7049969cfba6ea47b2 (diff)
Channel availability updates (bug #2829 with mods)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4257 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_chanisavail.c')
-rwxr-xr-xapps/app_chanisavail.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/apps/app_chanisavail.c b/apps/app_chanisavail.c
index 91bf838b2..9590dac0a 100755
--- a/apps/app_chanisavail.c
+++ b/apps/app_chanisavail.c
@@ -34,7 +34,7 @@ static char *app = "ChanIsAvail";
static char *synopsis = "Check if channel is available";
static char *descrip =
-" ChanIsAvail(Technology/resource[&Technology2/resource2...]): \n"
+" ChanIsAvail(Technology/resource[&Technology2/resource2...][|option]): \n"
"Checks is any of the requested channels are available. If none\n"
"of the requested channels are available the new priority will be\n"
"n+101 (unless such a priority does not exist or on error, in which\n"
@@ -42,7 +42,9 @@ static char *descrip =
"are available, the next priority will be n+1, the channel variable\n"
"${AVAILCHAN} will be set to the name of the available channel and\n"
"the ChanIsAvail app will return 0. ${AVAILORIGCHAN} is\n"
-"the canonical channel name that was used to create the channel.\n";
+"the canonical channel name that was used to create the channel.\n"
+"If the option 's' is specified (state), will consider channel unavailable\n"
+"when the channel is in use at all, even if it can take another call.\n";
STANDARD_LOCAL_USER;
@@ -50,10 +52,10 @@ LOCAL_USER_DECL;
static int chanavail_exec(struct ast_channel *chan, void *data)
{
- int res=-1;
+ int res=-1, inuse=-1, option_state=0;
int status;
struct localuser *u;
- char info[512], tmp[512], *peers, *tech, *number, *rest, *cur;
+ char info[512], tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur, *options, *stringp;
struct ast_channel *tempchan;
if (!data) {
@@ -63,6 +65,11 @@ static int chanavail_exec(struct ast_channel *chan, void *data)
LOCAL_USER_ADD(u);
strncpy(info, (char *)data, sizeof(info)-1);
+ stringp = info;
+ strsep(&stringp, "|");
+ options = strsep(&stringp, "|");
+ if (options && *options == 's');
+ option_state = 1;
peers = info;
if (peers) {
cur = peers;
@@ -81,7 +88,16 @@ static int chanavail_exec(struct ast_channel *chan, void *data)
}
*number = '\0';
number++;
- if ((tempchan = ast_request(tech, chan->nativeformats, number, &status))) {
+
+ if (option_state) {
+ /* If the pbx says in use then don't bother trying further.
+ This is to permit testing if someone's on a call, even if the
+ channel can permit more calls (ie callwaiting, sip calls, etc). */
+
+ snprintf(trychan, sizeof(trychan), "%s/%s",cur,number);
+ status = inuse = ast_device_state(trychan);
+ }
+ if ((inuse < 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) {
pbx_builtin_setvar_helper(chan, "AVAILCHAN", tempchan->name);
/* Store the originally used channel too */
snprintf(tmp, sizeof(tmp), "%s/%s", tech, number);