[asterisk-commits] file: branch file/stasis-tweaking r400621 - in /team/file/stasis-tweaking: ma...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Oct 5 22:20:44 CDT 2013


Author: file
Date: Sat Oct  5 22:20:41 2013
New Revision: 400621

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=400621
Log:
When originating a call using ARI return a channel snapshot instead of nothing.

This also adds the ability to optionally subscribe a Stasis application to the originated channel.

Modified:
    team/file/stasis-tweaking/main/pbx.c
    team/file/stasis-tweaking/res/ari/resource_channels.c
    team/file/stasis-tweaking/res/ari/resource_channels.h
    team/file/stasis-tweaking/res/res_ari_channels.c
    team/file/stasis-tweaking/rest-api/api-docs/channels.json

Modified: team/file/stasis-tweaking/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis-tweaking/main/pbx.c?view=diff&rev=400621&r1=400620&r2=400621
==============================================================================
--- team/file/stasis-tweaking/main/pbx.c (original)
+++ team/file/stasis-tweaking/main/pbx.c Sat Oct  5 22:20:41 2013
@@ -10115,7 +10115,7 @@
 	}
 
 	/* Wait for dialing to complete */
-	if (channel || synchronous) {
+	if (synchronous) {
 		if (channel && *channel) {
 			ast_channel_unlock(*channel);
 		}

Modified: team/file/stasis-tweaking/res/ari/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis-tweaking/res/ari/resource_channels.c?view=diff&rev=400621&r1=400620&r2=400621
==============================================================================
--- team/file/stasis-tweaking/res/ari/resource_channels.c (original)
+++ team/file/stasis-tweaking/res/ari/resource_channels.c Sat Oct  5 22:20:41 2013
@@ -585,6 +585,8 @@
 	int timeout = 30000;
 
 	char *stuff;
+	struct ast_channel *chan;
+	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
 
 	if (ast_strlen_zero(args->endpoint)) {
 		ast_ari_response_error(response, 400, "Bad Request",
@@ -635,13 +637,13 @@
 		}
 
 		/* originate a channel, putting it into an application */
-		if (ast_pbx_outgoing_app(dialtech, NULL, dialdevice, timeout, app, ast_str_buffer(appdata), NULL, 0, cid_num, cid_name, NULL, NULL, NULL)) {
+		if (ast_pbx_outgoing_app(dialtech, NULL, dialdevice, timeout, app, ast_str_buffer(appdata), NULL, 0, cid_num, cid_name, NULL, NULL, &chan)) {
 			ast_ari_response_alloc_failed(response);
 			return;
 		}
 	} else if (!ast_strlen_zero(args->extension)) {
 		/* originate a channel, sending it to an extension */
-		if (ast_pbx_outgoing_exten(dialtech, NULL, dialdevice, timeout, S_OR(args->context, "default"), args->extension, args->priority ? args->priority : 1, NULL, 0, cid_num, cid_name, NULL, NULL, NULL, 0)) {
+		if (ast_pbx_outgoing_exten(dialtech, NULL, dialdevice, timeout, S_OR(args->context, "default"), args->extension, args->priority ? args->priority : 1, NULL, 0, cid_num, cid_name, NULL, NULL, &chan, 0)) {
 			ast_ari_response_alloc_failed(response);
 			return;
 		}
@@ -651,7 +653,19 @@
 		return;
 	}
 
-	ast_ari_response_no_content(response);
+	if (!ast_strlen_zero(args->subscribe_app)) {
+		char uri[9 + strlen(ast_channel_uniqueid(chan))];
+		const char *uris[1] = { uri, };
+
+		snprintf(uri, sizeof(uri), "channel:%s", ast_channel_uniqueid(chan));
+		stasis_app_subscribe(args->subscribe_app, uris, 1, NULL);
+	}
+
+	snapshot = ast_channel_snapshot_create(chan);
+	ast_ari_response_ok(response, ast_channel_snapshot_to_json(snapshot));
+
+	ast_channel_unlock(chan);
+	ast_channel_unref(chan);
 }
 
 void ast_ari_get_channel_var(struct ast_variable *headers, struct ast_get_channel_var_args *args, struct ast_ari_response *response)

Modified: team/file/stasis-tweaking/res/ari/resource_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis-tweaking/res/ari/resource_channels.h?view=diff&rev=400621&r1=400620&r2=400621
==============================================================================
--- team/file/stasis-tweaking/res/ari/resource_channels.h (original)
+++ team/file/stasis-tweaking/res/ari/resource_channels.h Sat Oct  5 22:20:41 2013
@@ -64,6 +64,8 @@
 	const char *app;
 	/*! \brief The application arguments to pass to the Stasis application. */
 	const char *app_args;
+	/*! \brief The Stasis application to subscribe to the originated channel. */
+	const char *subscribe_app;
 	/*! \brief CallerID to use when dialing the endpoint or extension. */
 	const char *caller_id;
 	/*! \brief Timeout (in seconds) before giving up dialing, or -1 for no timeout. */

Modified: team/file/stasis-tweaking/res/res_ari_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis-tweaking/res/res_ari_channels.c?view=diff&rev=400621&r1=400620&r2=400621
==============================================================================
--- team/file/stasis-tweaking/res/res_ari_channels.c (original)
+++ team/file/stasis-tweaking/res/res_ari_channels.c Sat Oct  5 22:20:41 2013
@@ -137,6 +137,9 @@
 		if (strcmp(i->name, "appArgs") == 0) {
 			args.app_args = (i->value);
 		} else
+		if (strcmp(i->name, "subscribeApp") == 0) {
+			args.subscribe_app = (i->value);
+		} else
 		if (strcmp(i->name, "callerId") == 0) {
 			args.caller_id = (i->value);
 		} else
@@ -160,7 +163,7 @@
 		break;
 	default:
 		if (200 <= code && code <= 299) {
-			is_valid = ast_ari_validate_void(
+			is_valid = ast_ari_validate_channel(
 				response->message);
 		} else {
 			ast_log(LOG_ERROR, "Invalid error response %d for /channels\n", code);

Modified: team/file/stasis-tweaking/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis-tweaking/rest-api/api-docs/channels.json?view=diff&rev=400621&r1=400620&r2=400621
==============================================================================
--- team/file/stasis-tweaking/rest-api/api-docs/channels.json (original)
+++ team/file/stasis-tweaking/rest-api/api-docs/channels.json Sat Oct  5 22:20:41 2013
@@ -22,7 +22,7 @@
 					"summary": "Create a new channel (originate).",
 					"notes": "The new channel is not created until the dialed party picks up. Not wanting to block this request indefinitely, this request returns immediately with a 204 No Content. When the channel is created, a StasisStart event is sent with the provided app and appArgs. In the event of a failure (timeout, busy, etc.), an OriginationFailed event is sent.",
 					"nickname": "originate",
-					"responseClass": "void",
+					"responseClass": "channel",
 					"parameters": [
 						{
 							"name": "endpoint",
@@ -67,6 +67,14 @@
 						{
 							"name": "appArgs",
 							"description": "The application arguments to pass to the Stasis application.",
+							"paramType": "query",
+							"required": false,
+							"allowMultiple": false,
+							"dataType": "string"
+						},
+						{
+							"name": "subscribeApp",
+							"description": "The Stasis application to subscribe to the originated channel.",
 							"paramType": "query",
 							"required": false,
 							"allowMultiple": false,




More information about the asterisk-commits mailing list