[svn-commits] oej: trunk r128240 - in /trunk: include/asterisk/ main/ pbx/ res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Jul 5 15:54:31 CDT 2008


Author: oej
Date: Sat Jul  5 15:54:30 2008
New Revision: 128240

URL: http://svn.digium.com/view/asterisk?view=rev&rev=128240
Log:
Implement flags for AGI in the channel structure so taht "show channels" and
AMI commands can display that a channel is under control of an AGI.

Work inspired by work at customer site, but paid for by Edvina AB

Modified:
    trunk/include/asterisk/channel.h
    trunk/include/asterisk/pbx.h
    trunk/main/cli.c
    trunk/main/manager.c
    trunk/main/pbx.c
    trunk/pbx/pbx_realtime.c
    trunk/res/res_agi.c

Modified: trunk/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/channel.h?view=diff&rev=128240&r1=128239&r2=128240
==============================================================================
--- trunk/include/asterisk/channel.h (original)
+++ trunk/include/asterisk/channel.h Sat Jul  5 15:54:30 2008
@@ -582,6 +582,12 @@
 	/*! This flag indicates that on a masquerade, an active stream should not
 	 *  be carried over */
 	AST_FLAG_MASQ_NOSTREAM = (1 << 16),
+	/*! If the flag is controlled by AGI (not FastAGI) */
+	AST_FLAG_AGI =           (1 << 17),
+	/*! If the flag is controlled by FastAGI  */
+	AST_FLAG_FASTAGI =       (1 << 18),
+	/*! If the flag is controlled by AsyncAGI  */
+	AST_FLAG_ASYNCAGI =      (1 << 19),
 };
 
 /*! \brief ast_bridge_config flags */

Modified: trunk/include/asterisk/pbx.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/pbx.h?view=diff&rev=128240&r1=128239&r2=128240
==============================================================================
--- trunk/include/asterisk/pbx.h (original)
+++ trunk/include/asterisk/pbx.h Sat Jul  5 15:54:30 2008
@@ -998,6 +998,9 @@
 									 const char *context, const char *exten, int priority,
 									 const char *label, const char *callerid, enum ext_match_t action);
 
+/*! \brief Function in pbx.c that propably should be somewhere else, but not in res_agi, since it's a loadable module */
+const char *agi_state(struct ast_channel *chan);
+
 
 /* every time a write lock is obtained for contexts,
    a counter is incremented. You can check this via the

Modified: trunk/main/cli.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cli.c?view=diff&rev=128240&r1=128239&r2=128240
==============================================================================
--- trunk/main/cli.c (original)
+++ trunk/main/cli.c Sat Jul  5 15:54:30 2008
@@ -626,6 +626,20 @@
 	}
 
 	return RESULT_SUCCESS;
+}
+
+/*! \brief Add a marker before the app if the channel is controlled by AGI/FastAGI or AsyncAGI 
+	Used for "show channels"
+*/
+static const char *agi_flag(struct ast_channel *chan)
+{
+	if (ast_test_flag(chan, AST_FLAG_AGI))
+		return "[AGI]  ";
+	if (ast_test_flag(chan, AST_FLAG_FASTAGI))
+		return "[FAGI] ";
+	if (ast_test_flag(chan, AST_FLAG_ASYNCAGI))
+		return "[AAGI] ";
+	return "";
 }
 
 static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
@@ -723,7 +737,7 @@
 				if (!ast_strlen_zero(c->context) && !ast_strlen_zero(c->exten)) 
 					snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority);
 				if (c->appl)
-					snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, S_OR(c->data, ""));
+					snprintf(appdata, sizeof(appdata), "%s%s(%s)", agi_flag(c), c->appl, S_OR(c->data, ""));
 				ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata);
 			}
 		}

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?view=diff&rev=128240&r1=128239&r2=128240
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Sat Jul  5 15:54:30 2008
@@ -2718,9 +2718,13 @@
 			"AccountCode: %s\r\n"
 			"BridgedChannel: %s\r\n"
 			"BridgedUniqueID: %s\r\n"
-			"\r\n", c->name, c->uniqueid, c->context, c->exten, c->priority, c->_state, ast_state2str(c->_state),
+			"AGIstate: %s\r\n"
+			"\r\n",
+			c->name, c->uniqueid, c->context, c->exten, c->priority, c->_state, ast_state2str(c->_state),
 			c->appl ? c->appl : "", c->data ? S_OR(c->data, ""): "",
-			S_OR(c->cid.cid_num, ""), durbuf, S_OR(c->accountcode, ""), bc ? bc->name : "", bc ? bc->uniqueid : "");
+			S_OR(c->cid.cid_num, ""), durbuf, S_OR(c->accountcode, ""), bc ? bc->name : "", bc ? bc->uniqueid : "",
+			agi_state(c)
+			);
 		ast_channel_unlock(c);
 		numchans++;
 	}

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=128240&r1=128239&r2=128240
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Sat Jul  5 15:54:30 2008
@@ -2901,6 +2901,18 @@
 	pbx_substitute_variables_helper(c, e->data, passdata, datalen - 1);
 }
 
+/*! \brief report AGI state for channel */
+const char *agi_state(struct ast_channel *chan)
+{
+	if (ast_test_flag(chan, AST_FLAG_AGI))
+		return "AGI";
+	if (ast_test_flag(chan, AST_FLAG_FASTAGI))
+		return "FASTAGI";
+	if (ast_test_flag(chan, AST_FLAG_ASYNCAGI))
+		return "ASYNCAGI";
+	return "";
+}
+
 /*! 
  * \brief The return value depends on the action:
  *
@@ -2981,8 +2993,9 @@
 					"Priority: %d\r\n"
 					"Application: %s\r\n"
 					"AppData: %s\r\n"
-					"Uniqueid: %s\r\n",
-					c->name, c->context, c->exten, c->priority, app->name, passdata, c->uniqueid);
+					"Uniqueid: %s\r\n"
+					"AGIstate: %s\r\n",
+					c->name, c->context, c->exten, c->priority, app->name, passdata, c->uniqueid, agi_state(c));
 			return pbx_exec(c, app, passdata);	/* 0 on success, -1 on failure */
 		}
 	} else if (q.swo) {	/* not found here, but in another switch */

Modified: trunk/pbx/pbx_realtime.c
URL: http://svn.digium.com/view/asterisk/trunk/pbx/pbx_realtime.c?view=diff&rev=128240&r1=128239&r2=128240
==============================================================================
--- trunk/pbx/pbx_realtime.c (original)
+++ trunk/pbx/pbx_realtime.c Sat Jul  5 15:54:30 2008
@@ -226,8 +226,9 @@
 							  "Priority: %d\r\n"
 							  "Application: %s\r\n"
 							  "AppData: %s\r\n"
-							  "Uniqueid: %s\r\n",
-							  chan->name, chan->context, chan->exten, chan->priority, app, !ast_strlen_zero(appdata) ? appdata : "(NULL)", chan->uniqueid);
+							  "Uniqueid: %s\r\n"
+                                        		  "AGIstate: %s\r\n",
+							  chan->name, chan->context, chan->exten, chan->priority, app, !ast_strlen_zero(appdata) ? appdata : "(NULL)", chan->uniqueid, agi_state(chan));
 				
 				res = pbx_exec(chan, a, appdata);
 			} else

Modified: trunk/res/res_agi.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_agi.c?view=diff&rev=128240&r1=128239&r2=128240
==============================================================================
--- trunk/res/res_agi.c (original)
+++ trunk/res/res_agi.c Sat Jul  5 15:54:30 2008
@@ -204,7 +204,7 @@
 	return cmd;
 }
 
-/* channel is locked when calling this one either from the CLI or manager thread */
+/*! \brief channel is locked when calling this one either from the CLI or manager thread */
 static int add_agi_cmd(struct ast_channel *chan, const char *cmd_buff, const char *cmd_id)
 {
 	struct ast_datastore *store;
@@ -424,6 +424,8 @@
 		returnstatus = AGI_RESULT_FAILURE;
 		goto quit;
 	}
+	ast_set_flag(chan, AST_FLAG_ASYNCAGI);
+
 	agi_buffer[res] = '\0';
 	/* encode it and send it thru the manager so whoever is going to take
 	   care of AGI commands on this channel can decide which AGI commands
@@ -606,8 +608,10 @@
 	int pid, toast[2], fromast[2], audio[2], res;
 	struct stat st;
 
-	if (!strncasecmp(script, "agi://", 6))
+	if (!strncasecmp(script, "agi://", 6)) {
+		ast_set_flag(chan, AST_FLAG_FASTAGI);
 		return launch_netscript(script, argv, fds, efd, opid);
+	}
 	if (!strncasecmp(script, "agi:async", sizeof("agi:async")-1))
 		return launch_asyncagi(chan, argv, efd);
 
@@ -711,6 +715,7 @@
 		close(audio[0]);
 
 	*opid = pid;
+	ast_set_flag(chan, AST_FLAG_AGI);
 	return AGI_RESULT_SUCCESS;
 }
 
@@ -2919,6 +2924,9 @@
 			close(efd);
 	}
 	ast_safe_fork_cleanup();
+	ast_clear_flag(chan, AST_FLAG_AGI);
+	ast_clear_flag(chan, AST_FLAG_FASTAGI);
+	ast_clear_flag(chan, AST_FLAG_ASYNCAGI);
 
 	switch (res) {
 	case AGI_RESULT_SUCCESS:




More information about the svn-commits mailing list