<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14424">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Benjamin Keith Ford: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Joshua Colp: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">ari: Allow variables to be set on channel create.<br><br>This change adds the same variable functionality that<br>is available for originating a channel to the create<br>call. Now when creating a channel you can specify<br>dialplan variables to set instead of having to do another<br>API call.<br><br>ASTERISK-28896<br><br>Change-Id: If13997ba818136d7c070585504fc4164378aa992<br>---<br>A doc/CHANGES-staging/ari_create_with_variables.txt<br>M res/ari/resource_channels.c<br>M res/ari/resource_channels.h<br>M res/res_ari_channels.c<br>M rest-api/api-docs/channels.json<br>5 files changed, 33 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/ari_create_with_variables.txt b/doc/CHANGES-staging/ari_create_with_variables.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..a9d28dd</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/ari_create_with_variables.txt</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_ari_channels</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+When creating a channel in ARI using the create call</span><br><span style="color: hsl(120, 100%, 40%);">+you can now specify dialplan variables to be set as part</span><br><span style="color: hsl(120, 100%, 40%);">+of the same operation.</span><br><span>diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c</span><br><span>index eaff90f..e59c74f 100644</span><br><span>--- a/res/ari/resource_channels.c</span><br><span>+++ b/res/ari/resource_channels.c</span><br><span>@@ -1779,6 +1779,7 @@</span><br><span> struct ast_ari_channels_create_args *args,</span><br><span> struct ast_ari_response *response)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *variables = NULL;</span><br><span> struct ast_assigned_ids assignedids = {</span><br><span> .uniqueid = args->channel_id,</span><br><span> .uniqueid2 = args->other_channel_id,</span><br><span>@@ -1805,6 +1806,18 @@</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Parse any query parameters out of the body parameter */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (args->variables) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_json *json_variables;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_ari_channels_create_parse_body(args->variables, args);</span><br><span style="color: hsl(120, 100%, 40%);">+ json_variables = ast_json_object_get(args->variables, "variables");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (json_variables</span><br><span style="color: hsl(120, 100%, 40%);">+ && json_to_ast_variables(response, json_variables, &variables)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> chan_data = ast_calloc(1, sizeof(*chan_data));</span><br><span> if (!chan_data) {</span><br><span> ast_ari_response_alloc_failed(response);</span><br><span>@@ -1899,6 +1912,10 @@</span><br><span> stasis_app_subscribe_channel(args->app, chan_data->chan);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (variables) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_set_variables(chan_data->chan, variables);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ast_channel_cleanup(originator);</span><br><span> </span><br><span> if (save_dialstring(chan_data->chan, stuff)) {</span><br><span>diff --git a/res/ari/resource_channels.h b/res/ari/resource_channels.h</span><br><span>index d06e30b..a16d9be 100644</span><br><span>--- a/res/ari/resource_channels.h</span><br><span>+++ b/res/ari/resource_channels.h</span><br><span>@@ -118,6 +118,8 @@</span><br><span> const char *originator;</span><br><span> /*! The format name capability list to use if originator is not specified. Ex. "ulaw,slin16". Format names can be found with "core show codecs". */</span><br><span> const char *formats;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! 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" } } */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_json *variables;</span><br><span> };</span><br><span> /*!</span><br><span> * \brief Body parsing function for /channels/create.</span><br><span>diff --git a/res/res_ari_channels.c b/res/res_ari_channels.c</span><br><span>index 72e47f1..a69be51 100644</span><br><span>--- a/res/res_ari_channels.c</span><br><span>+++ b/res/res_ari_channels.c</span><br><span>@@ -341,10 +341,7 @@</span><br><span> } else</span><br><span> {}</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_ari_channels_create_parse_body(body, &args)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_ari_response_alloc_failed(response);</span><br><span style="color: hsl(0, 100%, 40%);">- goto fin;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ args.variables = body;</span><br><span> ast_ari_channels_create(headers, &args, response);</span><br><span> #if defined(AST_DEVMODE)</span><br><span> code = response->response_code;</span><br><span>diff --git a/rest-api/api-docs/channels.json b/rest-api/api-docs/channels.json</span><br><span>index a20e9f2..04d1577 100644</span><br><span>--- a/rest-api/api-docs/channels.json</span><br><span>+++ b/rest-api/api-docs/channels.json</span><br><span>@@ -222,6 +222,14 @@</span><br><span> "required": false,</span><br><span> "allowMultiple": false,</span><br><span> "dataType": "string"</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ "name": "variables",</span><br><span style="color: hsl(120, 100%, 40%);">+ "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\" } }",</span><br><span style="color: hsl(120, 100%, 40%);">+ "paramType": "body",</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "dataType": "containers",</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowMultiple": false</span><br><span> }</span><br><span> ],</span><br><span> "errorResponses": [</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14424">change 14424</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/14424"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: If13997ba818136d7c070585504fc4164378aa992 </div>
<div style="display:none"> Gerrit-Change-Number: 14424 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>