[asterisk-commits] qwell: branch qwell/ari_channel_dial r392345 - in /team/qwell/ari_channel_dia...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 20 12:50:36 CDT 2013


Author: qwell
Date: Thu Jun 20 12:50:34 2013
New Revision: 392345

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392345
Log:
Add a timeout for the dial operation.

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

Modified: team/qwell/ari_channel_dial/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_dial/include/asterisk/stasis_app.h?view=diff&rev=392345&r1=392344&r2=392345
==============================================================================
--- team/qwell/ari_channel_dial/include/asterisk/stasis_app.h (original)
+++ team/qwell/ari_channel_dial/include/asterisk/stasis_app.h Thu Jun 20 12:50:34 2013
@@ -136,6 +136,11 @@
 const char *stasis_app_control_get_channel_id(
 	const struct stasis_app_control *control);
 
+struct stasis_app_dial {
+	char endpoint[AST_CHANNEL_NAME];
+	int timeout;
+};
+
 /*!
  * \brief Dial an endpoint and bridge it to a channel in \c res_stasis
  *
@@ -144,7 +149,7 @@
  * \param control Control for \c res_stasis
  * \param endpoint The endpoint to dial.
  */
-void stasis_app_control_dial(struct stasis_app_control *control, const char *endpoint);
+void stasis_app_control_dial(struct stasis_app_control *control, struct stasis_app_dial *dial_data);
 
 /*!
  * \brief Exit \c res_stasis and continue execution in the dialplan.

Modified: team/qwell/ari_channel_dial/res/res_stasis_http_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_dial/res/res_stasis_http_channels.c?view=diff&rev=392345&r1=392344&r2=392345
==============================================================================
--- team/qwell/ari_channel_dial/res/res_stasis_http_channels.c (original)
+++ team/qwell/ari_channel_dial/res/res_stasis_http_channels.c Thu Jun 20 12:50:34 2013
@@ -167,6 +167,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: team/qwell/ari_channel_dial/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_dial/res/stasis/control.c?view=diff&rev=392345&r1=392344&r2=392345
==============================================================================
--- team/qwell/ari_channel_dial/res/stasis/control.c (original)
+++ team/qwell/ari_channel_dial/res/stasis/control.c Thu Jun 20 12:50:34 2013
@@ -91,14 +91,14 @@
 	struct ast_channel *chan, void *data)
 {
 	RAII_VAR(struct ast_dial *, dial, ast_dial_create(), ast_dial_destroy);
-	const char *endpoint = data;
+	RAII_VAR(struct stasis_app_dial *, dial_data, data, ast_free);
 	enum ast_dial_result res;
 	char *tech, *resource;
 
 	struct ast_channel *new_chan;
 	struct ast_bridge *bridge;
 
-	tech = ast_strdupa(endpoint);
+	tech = dial_data->endpoint;
 	if (!(resource = strchr(tech, '/'))) {
 		return NULL;
 	}
@@ -113,7 +113,10 @@
 		ast_log(LOG_ERROR, "Failed to add %s/%s to dialing structure.\n", tech, resource);
 		return NULL;
 	}
-	res = ast_dial_run(dial, chan, 0);
+
+	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;
@@ -130,9 +133,9 @@
 	return NULL;
 }
 
-void stasis_app_control_dial(struct stasis_app_control *control, const char *endpoint)
-{
-	stasis_app_send_command_async(control, app_control_dial, (void *)endpoint);
+void stasis_app_control_dial(struct stasis_app_control *control, struct stasis_app_dial *dial_data)
+{
+	stasis_app_send_command_async(control, app_control_dial, dial_data);
 }
 
 int control_is_done(struct stasis_app_control *control)

Modified: team/qwell/ari_channel_dial/res/stasis_http/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_dial/res/stasis_http/resource_channels.c?view=diff&rev=392345&r1=392344&r2=392345
==============================================================================
--- team/qwell/ari_channel_dial/res/stasis_http/resource_channels.c (original)
+++ team/qwell/ari_channel_dial/res/stasis_http/resource_channels.c Thu Jun 20 12:50:34 2013
@@ -83,13 +83,26 @@
 void stasis_http_dial(struct ast_variable *headers, struct ast_dial_args *args, struct stasis_http_response *response)
 {
 	struct stasis_app_control *control;
+	struct stasis_app_dial *dial_data;
+	int timeout = 30000;
 
 	control = find_control(response, args->channel_id);
 	if (control == NULL) {
 		return;
 	}
 
-	stasis_app_control_dial(control, args->endpoint);
+	dial_data = ast_calloc(1, sizeof(*dial_data));
+
+	ast_copy_string(dial_data->endpoint, args->endpoint, sizeof(dial_data->endpoint));
+
+	if (args->timeout > 0) {
+		timeout = args->timeout * 1000;
+	} else if (args->timeout == -1) {
+		timeout = -1;
+	}
+	dial_data->timeout = timeout;
+
+	stasis_app_control_dial(control, dial_data);
 
 	stasis_http_response_no_content(response);
 }

Modified: team/qwell/ari_channel_dial/res/stasis_http/resource_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_dial/res/stasis_http/resource_channels.h?view=diff&rev=392345&r1=392344&r2=392345
==============================================================================
--- team/qwell/ari_channel_dial/res/stasis_http/resource_channels.h (original)
+++ team/qwell/ari_channel_dial/res/stasis_http/resource_channels.h Thu Jun 20 12:50:34 2013
@@ -111,6 +111,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: team/qwell/ari_channel_dial/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_dial/rest-api/api-docs/channels.json?view=diff&rev=392345&r1=392344&r2=392345
==============================================================================
--- team/qwell/ari_channel_dial/rest-api/api-docs/channels.json (original)
+++ team/qwell/ari_channel_dial/rest-api/api-docs/channels.json Thu Jun 20 12:50:34 2013
@@ -175,6 +175,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