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 *synopsis = "Check if channel is available";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static char *descrip = 
 | 
					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"
 | 
					"Checks is any of the requested channels are available.  If none\n"
 | 
				
			||||||
"of the requested channels are available the new priority will be\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"
 | 
					"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"
 | 
					"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"
 | 
					"${AVAILCHAN} will be set to the name of the available channel and\n"
 | 
				
			||||||
"the ChanIsAvail app will return 0.  ${AVAILORIGCHAN} is\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;
 | 
					STANDARD_LOCAL_USER;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -50,10 +52,10 @@ LOCAL_USER_DECL;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static int chanavail_exec(struct ast_channel *chan, void *data)
 | 
					static int chanavail_exec(struct ast_channel *chan, void *data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int res=-1;
 | 
						int res=-1, inuse=-1, option_state=0;
 | 
				
			||||||
	int status;
 | 
						int status;
 | 
				
			||||||
	struct localuser *u;
 | 
						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;
 | 
						struct ast_channel *tempchan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!data) {
 | 
						if (!data) {
 | 
				
			||||||
@@ -63,6 +65,11 @@ static int chanavail_exec(struct ast_channel *chan, void *data)
 | 
				
			|||||||
	LOCAL_USER_ADD(u);
 | 
						LOCAL_USER_ADD(u);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	strncpy(info, (char *)data, sizeof(info)-1);
 | 
						strncpy(info, (char *)data, sizeof(info)-1);
 | 
				
			||||||
 | 
						stringp = info;
 | 
				
			||||||
 | 
						strsep(&stringp, "|");
 | 
				
			||||||
 | 
						options = strsep(&stringp, "|");
 | 
				
			||||||
 | 
						if (options && *options == 's');
 | 
				
			||||||
 | 
							option_state = 1;
 | 
				
			||||||
	peers = info;
 | 
						peers = info;
 | 
				
			||||||
	if (peers) {
 | 
						if (peers) {
 | 
				
			||||||
		cur = peers;
 | 
							cur = peers;
 | 
				
			||||||
@@ -81,7 +88,16 @@ static int chanavail_exec(struct ast_channel *chan, void *data)
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			*number = '\0';
 | 
								*number = '\0';
 | 
				
			||||||
			number++;
 | 
								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);
 | 
										pbx_builtin_setvar_helper(chan, "AVAILCHAN", tempchan->name);
 | 
				
			||||||
					/* Store the originally used channel too */
 | 
										/* Store the originally used channel too */
 | 
				
			||||||
					snprintf(tmp, sizeof(tmp), "%s/%s", tech, number);
 | 
										snprintf(tmp, sizeof(tmp), "%s/%s", tech, number);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user