[asterisk-commits] qwell: trunk r393326 - in /trunk: include/asterisk/ res/ res/stasis/ res/stas...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 1 13:19:20 CDT 2013


Author: qwell
Date: Mon Jul  1 13:19:15 2013
New Revision: 393326

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393326
Log:
ARI: Implement channel dial.

This creates a new outbound channel, and bridges it to a channel already in
the Stasis application.

(closes issue ASTERISK-21620)

Review: https://reviewboard.asterisk.org/r/2634/

Modified:
    trunk/include/asterisk/stasis_app.h
    trunk/res/res_stasis_http_channels.c
    trunk/res/stasis/control.c
    trunk/res/stasis_http/resource_channels.c
    trunk/res/stasis_http/resource_channels.h
    trunk/rest-api/api-docs/channels.json

Modified: trunk/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/stasis_app.h?view=diff&rev=393326&r1=393325&r2=393326
==============================================================================
--- trunk/include/asterisk/stasis_app.h (original)
+++ trunk/include/asterisk/stasis_app.h Mon Jul  1 13:19:15 2013
@@ -137,6 +137,20 @@
 	const struct stasis_app_control *control);
 
 /*!
+ * \brief Dial an endpoint and bridge it to a channel in \c res_stasis
+ *
+ * If the channel is no longer in \c res_stasis, this function does nothing.
+ *
+ * \param control Control for \c res_stasis
+ * \param endpoint The endpoint to dial.
+ * \param timeout The amount of time to wait for answer, before giving up.
+ *
+ * \return 0 for success
+ * \return -1 for error.
+ */
+int stasis_app_control_dial(struct stasis_app_control *control, const char *endpoint, int timeout);
+
+/*!
  * \brief Exit \c res_stasis and continue execution in the dialplan.
  *
  * If the channel is no longer in \c res_stasis, this function does nothing.

Modified: trunk/res/res_stasis_http_channels.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_stasis_http_channels.c?view=diff&rev=393326&r1=393325&r2=393326
==============================================================================
--- trunk/res/res_stasis_http_channels.c (original)
+++ trunk/res/res_stasis_http_channels.c Mon Jul  1 13:19:15 2013
@@ -170,6 +170,9 @@
 		if (strcmp(i->name, "context") == 0) {
 			args.context = (i->value);
 		} else
+		if (strcmp(i->name, "timeout") == 0) {
+			args.timeout = atoi(i->value);
+		} else
 		{}
 	}
 	for (i = path_vars; i; i = i->next) {

Modified: trunk/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/stasis/control.c?view=diff&rev=393326&r1=393325&r2=393326
==============================================================================
--- trunk/res/stasis/control.c (original)
+++ trunk/res/stasis/control.c Mon Jul  1 13:19:15 2013
@@ -31,7 +31,9 @@
 
 #include "command.h"
 #include "control.h"
+#include "asterisk/dial.h"
 #include "asterisk/bridging.h"
+#include "asterisk/bridging_basic.h"
 #include "asterisk/bridging_features.h"
 #include "asterisk/pbx.h"
 
@@ -86,6 +88,80 @@
 	return command;
 }
 
+struct stasis_app_control_dial_data {
+	char endpoint[AST_CHANNEL_NAME];
+	int timeout;
+};
+
+static void *app_control_dial(struct stasis_app_control *control,
+	struct ast_channel *chan, void *data)
+{
+	RAII_VAR(struct ast_dial *, dial, ast_dial_create(), ast_dial_destroy);
+	RAII_VAR(struct stasis_app_control_dial_data *, dial_data, data, ast_free);
+	enum ast_dial_result res;
+	char *tech, *resource;
+
+	struct ast_channel *new_chan;
+	struct ast_bridge *bridge;
+
+	tech = dial_data->endpoint;
+	if (!(resource = strchr(tech, '/'))) {
+		return NULL;
+	}
+	*resource++ = '\0';
+
+	if (!dial) {
+		ast_log(LOG_ERROR, "Failed to create dialing structure.\n");
+		return NULL;
+	}
+
+	if (ast_dial_append(dial, tech, resource) < 0) {
+		ast_log(LOG_ERROR, "Failed to add %s/%s to dialing structure.\n", tech, resource);
+		return NULL;
+	}
+
+	ast_dial_set_global_timeout(dial, dial_data->timeout);
+
+	res = ast_dial_run(dial, NULL, 0);
+
+	if (res != AST_DIAL_RESULT_ANSWERED || !(new_chan = ast_dial_answered_steal(dial))) {
+		return NULL;
+	}
+
+	if (!(bridge = ast_bridge_basic_new())) {
+		ast_log(LOG_ERROR, "Failed to create basic bridge.\n");
+		return NULL;
+	}
+
+	ast_bridge_impart(bridge, new_chan, NULL, NULL, 1);
+	stasis_app_control_add_channel_to_bridge(control, bridge);
+
+	return NULL;
+}
+
+int stasis_app_control_dial(struct stasis_app_control *control, const char *endpoint, int timeout)
+{
+	struct stasis_app_control_dial_data *dial_data;
+
+	if (!(dial_data = ast_calloc(1, sizeof(*dial_data)))) {
+		return -1;
+	}
+
+	ast_copy_string(dial_data->endpoint, endpoint, sizeof(dial_data->endpoint));
+
+	if (timeout > 0) {
+		dial_data->timeout = timeout * 1000;
+	} else if (timeout == -1) {
+		dial_data->timeout = -1;
+	} else {
+		dial_data->timeout = 30000;
+	}
+
+	stasis_app_send_command_async(control, app_control_dial, dial_data);
+
+	return 0;
+}
+
 int control_is_done(struct stasis_app_control *control)
 {
 	/* Called from stasis_app_exec thread; no lock needed */

Modified: trunk/res/stasis_http/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/stasis_http/resource_channels.c?view=diff&rev=393326&r1=393325&r2=393326
==============================================================================
--- trunk/res/stasis_http/resource_channels.c (original)
+++ trunk/res/stasis_http/resource_channels.c Mon Jul  1 13:19:15 2013
@@ -34,6 +34,8 @@
 
 #include "asterisk/file.h"
 #include "asterisk/pbx.h"
+#include "asterisk/dial.h"
+#include "asterisk/bridging.h"
 #include "asterisk/callerid.h"
 #include "asterisk/stasis_app.h"
 #include "asterisk/stasis_app_playback.h"
@@ -80,7 +82,19 @@
 
 void stasis_http_dial(struct ast_variable *headers, struct ast_dial_args *args, struct stasis_http_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: stasis_http_dial\n");
+	struct stasis_app_control *control;
+
+	control = find_control(response, args->channel_id);
+	if (control == NULL) {
+		return;
+	}
+
+	if (stasis_app_control_dial(control, args->endpoint, args->timeout)) {
+		stasis_http_response_alloc_failed(response);
+		return;
+	}
+
+	stasis_http_response_no_content(response);
 }
 
 void stasis_http_continue_in_dialplan(

Modified: trunk/res/stasis_http/resource_channels.h
URL: http://svnview.digium.com/svn/asterisk/trunk/res/stasis_http/resource_channels.h?view=diff&rev=393326&r1=393325&r2=393326
==============================================================================
--- trunk/res/stasis_http/resource_channels.h (original)
+++ trunk/res/stasis_http/resource_channels.h Mon Jul  1 13:19:15 2013
@@ -113,6 +113,8 @@
 	const char *extension;
 	/*! \brief When routing via dialplan, the context use. If omitted, uses 'default' */
 	const char *context;
+	/*! \brief Timeout (in seconds) before giving up dialing, or -1 for no timeout. */
+	int timeout;
 };
 /*!
  * \brief Create a new channel (originate) and bridge to this channel.

Modified: trunk/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/trunk/rest-api/api-docs/channels.json?view=diff&rev=393326&r1=393325&r2=393326
==============================================================================
--- trunk/rest-api/api-docs/channels.json (original)
+++ trunk/rest-api/api-docs/channels.json Mon Jul  1 13:19:15 2013
@@ -183,6 +183,15 @@
 							"required": false,
 							"allowMultiple": false,
 							"dataType": "string"
+						},
+						{
+							"name": "timeout",
+							"description": "Timeout (in seconds) before giving up dialing, or -1 for no timeout.",
+							"paramType": "query",
+							"required": false,
+							"allowMultiple": false,
+							"dataType": "int",
+							"defaultValue": 30
 						}
 					],
 					"errorResponses": [




More information about the asterisk-commits mailing list