--- asterisk/apps/app_chanisavail.c 2004-11-12 10:30:23.000000000 -0700 +++ asterisk.new/apps/app_chanisavail.c 2004-11-12 10:29:20.000000000 -0700 @@ -34,7 +34,7 @@ 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 @@ "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 @@ 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 @@ 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,17 @@ } *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). */ + + sprintf(trychan,"%s/%s",cur,number); + if (ast_parse_device_state(trychan) == AST_DEVICE_INUSE); + inuse = 1; + } + if (inuse != 1 && (tempchan = ast_request(tech, chan->nativeformats, number))) { pbx_builtin_setvar_helper(chan, "AVAILCHAN", tempchan->name); /* Store the originally used channel too */ snprintf(tmp, sizeof(tmp), "%s/%s", tech, number);