mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-11-03 20:38:59 +00:00 
			
		
		
		
	Channel availability updates (bug #2829 with mods)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4257 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
		@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user