[svn-commits] qwell: branch qwell/agi_events r390502 - /team/qwell/agi_events/res/res_agi.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jun 5 11:15:28 CDT 2013


Author: qwell
Date: Wed Jun  5 11:15:27 2013
New Revision: 390502

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390502
Log:
Address review feedback.

Modified:
    team/qwell/agi_events/res/res_agi.c

Modified: team/qwell/agi_events/res/res_agi.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/agi_events/res/res_agi.c?view=diff&rev=390502&r1=390501&r2=390502
==============================================================================
--- team/qwell/agi_events/res/res_agi.c (original)
+++ team/qwell/agi_events/res/res_agi.c Wed Jun  5 11:15:27 2013
@@ -934,6 +934,7 @@
 		<managerEventInstance class="EVENT_FLAG_AGI">
 			<synopsis>Raised when a channel starts AsyncAGI command processing.</synopsis>
 			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
 				<parameter name="Env">
 					<para>URL encoded string read from the AsyncAGI server.</para>
 				</parameter>
@@ -943,12 +944,16 @@
 	<managerEvent language="en_US" name="AsyncAGIEnd">
 		<managerEventInstance class="EVENT_FLAG_AGI">
 			<synopsis>Raised when a channel stops AsyncAGI command processing.</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+			</syntax>
 		</managerEventInstance>
 	</managerEvent>
 	<managerEvent language="en_US" name="AsyncAGIExec">
 		<managerEventInstance class="EVENT_FLAG_AGI">
 			<synopsis>Raised when AsyncAGI completes an AGI command.</synopsis>
 			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
 				<parameter name="CommandID" required="false">
 					<para>Optional command ID sent by the AsyncAGI server to identify the command.</para>
 				</parameter>
@@ -962,6 +967,7 @@
 		<managerEventInstance class="EVENT_FLAG_AGI">
 			<synopsis>Raised when a received AGI command starts processing.</synopsis>
 			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
 				<parameter name="Command">
 					<para>The AGI command as received from the external source.</para>
 				</parameter>
@@ -975,8 +981,8 @@
 		<managerEventInstance class="EVENT_FLAG_AGI">
 			<synopsis>Raised when a received AGI command completes processing.</synopsis>
 			<syntax>
-				<xi:include xpointer="xpointer(/docs/managerEvent[@name='AGIExecStart']/managerEventInstance/syntax/parameter[@name='Command'])" />
-				<xi:include xpointer="xpointer(/docs/managerEvent[@name='AGIExecStart']/managerEventInstance/syntax/parameter[@name='CommandId'])" />
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='AGIExecStart']/managerEventInstance/syntax/parameter)" />
 				<parameter name="ResultCode">
 					<para>The numeric result code from AGI</para>
 				</parameter
@@ -1057,17 +1063,6 @@
 		"%s",
 		ast_str_buffer(channel_event_string),
 		ast_str_buffer(event_string));
-}
-
-static void agi_publish_channel_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
-{
-	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
-
-	msg = ast_channel_blob_create(chan, type, blob);
-	if (!msg) {
-		return;
-	}
-	stasis_publish(ast_channel_topic(chan), msg);
 }
 
 static agi_command *find_command(const char * const cmds[], int exact);
@@ -1458,7 +1453,7 @@
 	   to execute based on the setup info */
 	ast_uri_encode(agi_buffer, ami_buffer, AMI_BUF_SIZE, ast_uri_http);
 	startblob = ast_json_pack("{s: s}", "Env", ami_buffer);
-	agi_publish_channel_blob(chan, agi_async_start_type(), startblob);
+	ast_channel_publish_blob(chan, agi_async_start_type(), startblob);
 
 	hungup = ast_check_hangup(chan);
 	for (;;) {
@@ -1501,10 +1496,10 @@
 			ast_uri_encode(agi_buffer, ami_buffer, AMI_BUF_SIZE, ast_uri_http);
 
 			execblob = ast_json_pack("{s: s}", "Result", ami_buffer);
-			if (!ast_strlen_zero(cmd->cmd_id)) {
+			if (execblob && !ast_strlen_zero(cmd->cmd_id)) {
 				ast_json_object_set(execblob, "CommandId", ast_json_string_create(cmd->cmd_id));
 			}
-			agi_publish_channel_blob(chan, agi_async_exec_type(), execblob);
+			ast_channel_publish_blob(chan, agi_async_exec_type(), execblob);
 
 			free_agi_cmd(cmd);
 
@@ -1564,7 +1559,7 @@
 		ast_speech_destroy(async_agi.speech);
 	}
 	/* notify manager users this channel cannot be controlled anymore by Async AGI */
-	agi_publish_channel_blob(chan, agi_async_end_type(), NULL);
+	ast_channel_publish_blob(chan, agi_async_end_type(), NULL);
 
 async_agi_abort:
 	/* close the pipe */
@@ -3595,6 +3590,17 @@
 	return 0;
 }
 
+static void publish_async_exec_end(struct ast_channel *chan, int command_id, const char *command, int result_code, const char *result)
+{
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+	blob = ast_json_pack("{s: i, s: s, s: i, s: s}",
+			     "CommandId", command_id,
+			     "Command", command,
+			     "ResultCode", result_code,
+			     "Result", result);
+	ast_channel_publish_blob(chan, agi_exec_end_type(), blob);
+}
+
 static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int dead)
 {
 	const char *argv[MAX_ARGS];
@@ -3610,7 +3616,7 @@
 	startblob = ast_json_pack("{s: i, s: s}",
 			     "CommandId", command_id,
 			     "Command", ami_cmd);
-	agi_publish_channel_blob(chan, agi_exec_start_type(), startblob);
+	ast_channel_publish_blob(chan, agi_exec_start_type(), startblob);
 
 	parse_args(buf, &argc, argv);
 	c = find_command(argv, 0);
@@ -3631,24 +3637,9 @@
 		case RESULT_SHOWUSAGE:
 			ami_res = "Usage";
 			resultcode = 520;
-			break;
-		case RESULT_FAILURE:
-			ami_res = "Failure";
-			resultcode = -1;
-			break;
-		case ASYNC_AGI_BREAK:
-		case RESULT_SUCCESS:
-			ami_res = "Success";
-			resultcode = 200;
-			break;
-		default:
-			ami_res = "Unknown Result";
-			resultcode = 200;
-			break;
-		}
-
-		switch (res) {
-		case RESULT_SHOWUSAGE:
+
+			publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
 			if (ast_strlen_zero(c->usage)) {
 				ast_agi_send(agi->fd, chan, "520 Invalid command syntax.  Proper usage not available.\n");
 			} else {
@@ -3656,13 +3647,36 @@
 				ast_agi_send(agi->fd, chan, "%s", c->usage);
 				ast_agi_send(agi->fd, chan, "520 End of proper usage.\n");
 			}
+
 			break;
-		case ASYNC_AGI_BREAK:
-			return AGI_RESULT_SUCCESS_ASYNC;
 		case RESULT_FAILURE:
+			ami_res = "Failure";
+			resultcode = -1;
+
+			publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
 			/* The RESULT_FAILURE code is usually because the channel hungup. */
 			return AGI_RESULT_FAILURE;
+		case ASYNC_AGI_BREAK:
+			ami_res = "Success";
+			resultcode = 200;
+
+			publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
+			return AGI_RESULT_SUCCESS_ASYNC;
+		case RESULT_SUCCESS:
+			ami_res = "Success";
+			resultcode = 200;
+
+			publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
+			break;
 		default:
+			ami_res = "Unknown Result";
+			resultcode = 200;
+
+			publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
 			break;
 		}
 	} else if (c) {
@@ -3670,22 +3684,17 @@
 		resultcode = 511;
 
 		ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
+
+		publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
 	} else {
 		ami_res = "Invalid or unknown command";
 		resultcode = 510;
 
 		ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
-	}
-
-	if (resultcode != 0) {
-		RAII_VAR(struct ast_json *, endblob, NULL, ast_json_unref);
-		endblob = ast_json_pack("{s: i, s: s, s: i, s: s}",
-				     "CommandId", command_id,
-				     "Command", ami_cmd,
-				     "ResultCode", resultcode,
-				     "Result", ami_res);
-		agi_publish_channel_blob(chan, agi_exec_end_type(), endblob);
-	}
+
+		publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+	}
+
 	return AGI_RESULT_SUCCESS;
 }
 static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid, int *status, int dead, int argc, char *argv[])
@@ -4227,6 +4236,17 @@
 
 static int unload_module(void)
 {
+	struct stasis_message_router *message_router;
+
+	message_router = ast_manager_get_message_router();
+	if (message_router) {
+		stasis_message_router_remove(message_router, agi_exec_start_type());
+		stasis_message_router_remove(message_router, agi_exec_end_type());
+		stasis_message_router_remove(message_router, agi_async_start_type());
+		stasis_message_router_remove(message_router, agi_async_exec_type());
+		stasis_message_router_remove(message_router, agi_async_end_type());
+	}
+
 	STASIS_MESSAGE_TYPE_CLEANUP(agi_exec_start_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(agi_exec_end_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(agi_async_start_type);




More information about the svn-commits mailing list