[Asterisk-code-review] ari: Allow variables to be set on channel create. (asterisk[17])

Friendly Automation asteriskteam at digium.com
Mon May 18 10:46:39 CDT 2020


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14423 )

Change subject: ari: Allow variables to be set on channel create.
......................................................................

ari: Allow variables to be set on channel create.

This change adds the same variable functionality that
is available for originating a channel to the create
call. Now when creating a channel you can specify
dialplan variables to set instead of having to do another
API call.

ASTERISK-28896

Change-Id: If13997ba818136d7c070585504fc4164378aa992
---
A doc/CHANGES-staging/ari_create_with_variables.txt
M res/ari/resource_channels.c
M res/ari/resource_channels.h
M res/res_ari_channels.c
M rest-api/api-docs/channels.json
5 files changed, 33 insertions(+), 4 deletions(-)

Approvals:
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/doc/CHANGES-staging/ari_create_with_variables.txt b/doc/CHANGES-staging/ari_create_with_variables.txt
new file mode 100644
index 0000000..a9d28dd
--- /dev/null
+++ b/doc/CHANGES-staging/ari_create_with_variables.txt
@@ -0,0 +1,5 @@
+Subject: res_ari_channels
+
+When creating a channel in ARI using the create call
+you can now specify dialplan variables to be set as part
+of the same operation.
diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c
index 6003a38..3603dee 100644
--- a/res/ari/resource_channels.c
+++ b/res/ari/resource_channels.c
@@ -1779,6 +1779,7 @@
 	struct ast_ari_channels_create_args *args,
 	struct ast_ari_response *response)
 {
+	struct ast_variable *variables = NULL;
 	struct ast_assigned_ids assignedids = {
 		.uniqueid = args->channel_id,
 		.uniqueid2 = args->other_channel_id,
@@ -1805,6 +1806,18 @@
 		return;
 	}
 
+	/* Parse any query parameters out of the body parameter */
+	if (args->variables) {
+		struct ast_json *json_variables;
+
+		ast_ari_channels_create_parse_body(args->variables, args);
+		json_variables = ast_json_object_get(args->variables, "variables");
+		if (json_variables
+			&& json_to_ast_variables(response, json_variables, &variables)) {
+			return;
+		}
+	}
+
 	chan_data = ast_calloc(1, sizeof(*chan_data));
 	if (!chan_data) {
 		ast_ari_response_alloc_failed(response);
@@ -1899,6 +1912,10 @@
 		stasis_app_subscribe_channel(args->app, chan_data->chan);
 	}
 
+	if (variables) {
+		ast_set_variables(chan_data->chan, variables);
+	}
+
 	ast_channel_cleanup(originator);
 
 	if (save_dialstring(chan_data->chan, stuff)) {
diff --git a/res/ari/resource_channels.h b/res/ari/resource_channels.h
index 49a3882..a8ff052 100644
--- a/res/ari/resource_channels.h
+++ b/res/ari/resource_channels.h
@@ -118,6 +118,8 @@
 	const char *originator;
 	/*! The format name capability list to use if originator is not specified. Ex. "ulaw,slin16".  Format names can be found with "core show codecs". */
 	const char *formats;
+	/*! The "variables" key in the body object holds variable key/value pairs to set on the channel on creation. Other keys in the body object are interpreted as query parameters. Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } } */
+	struct ast_json *variables;
 };
 /*!
  * \brief Body parsing function for /channels/create.
diff --git a/res/res_ari_channels.c b/res/res_ari_channels.c
index f938e14..e40cf4b 100644
--- a/res/res_ari_channels.c
+++ b/res/res_ari_channels.c
@@ -341,10 +341,7 @@
 		} else
 		{}
 	}
-	if (ast_ari_channels_create_parse_body(body, &args)) {
-		ast_ari_response_alloc_failed(response);
-		goto fin;
-	}
+	args.variables = body;
 	ast_ari_channels_create(headers, &args, response);
 #if defined(AST_DEVMODE)
 	code = response->response_code;
diff --git a/rest-api/api-docs/channels.json b/rest-api/api-docs/channels.json
index 94afb27..2e01523 100644
--- a/rest-api/api-docs/channels.json
+++ b/rest-api/api-docs/channels.json
@@ -222,6 +222,14 @@
 							"required": false,
 							"allowMultiple": false,
 							"dataType": "string"
+						},
+						{
+							"name": "variables",
+							"description": "The \"variables\" key in the body object holds variable key/value pairs to set on the channel on creation. Other keys in the body object are interpreted as query parameters. Ex. { \"endpoint\": \"SIP/Alice\", \"variables\": { \"CALLERID(name)\": \"Alice\" } }",
+							"paramType": "body",
+							"required": false,
+							"dataType": "containers",
+							"allowMultiple": false
 						}
 					],
 					"errorResponses": [

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14423
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 17
Gerrit-Change-Id: If13997ba818136d7c070585504fc4164378aa992
Gerrit-Change-Number: 14423
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200518/b74b068d/attachment-0001.html>


More information about the asterisk-code-review mailing list