[Asterisk-cvs] asterisk/apps app_chanisavail.c,1.10,1.11

markster at lists.digium.com markster at lists.digium.com
Mon Nov 15 11:26:46 CST 2004


Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv9774/apps

Modified Files:
	app_chanisavail.c 
Log Message:
Channel availability updates (bug #2829 with mods)


Index: app_chanisavail.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_chanisavail.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- app_chanisavail.c	26 Oct 2004 22:25:43 -0000	1.10
+++ app_chanisavail.c	15 Nov 2004 16:27:28 -0000	1.11
@@ -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,16 @@
 			}
 			*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);




More information about the svn-commits mailing list