]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
ari: Allow variables to be set on channel create.
authorJoshua C. Colp <jcolp@sangoma.com>
Tue, 12 May 2020 23:15:41 +0000 (20:15 -0300)
committerJoshua Colp <jcolp@sangoma.com>
Fri, 15 May 2020 11:41:45 +0000 (06:41 -0500)
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

doc/CHANGES-staging/ari_create_with_variables.txt [new file with mode: 0644]
res/ari/resource_channels.c
res/ari/resource_channels.h
res/res_ari_channels.c
rest-api/api-docs/channels.json

diff --git a/doc/CHANGES-staging/ari_create_with_variables.txt b/doc/CHANGES-staging/ari_create_with_variables.txt
new file mode 100644 (file)
index 0000000..a9d28dd
--- /dev/null
@@ -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.
index eaff90fb8758f065601b3331e4e741d041c885a3..e59c74ffbb665c1a011eb40c9d09aaa7e9970079 100644 (file)
@@ -1779,6 +1779,7 @@ void ast_ari_channels_create(struct ast_variable *headers,
        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 @@ void ast_ari_channels_create(struct ast_variable *headers,
                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 @@ void ast_ari_channels_create(struct ast_variable *headers,
                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)) {
index d06e30b7da87868ae41e6070fb883c178a4c6c64..a16d9be31bc35d2cdd0705f1cca06c2f9cee15f6 100644 (file)
@@ -118,6 +118,8 @@ struct ast_ari_channels_create_args {
        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.
index 72e47f17a2e9aacc986c98440d645a16d987da59..a69be5138bd85a4109f942d20580c47b4eb5f789 100644 (file)
@@ -341,10 +341,7 @@ static void ast_ari_channels_create_cb(
                } 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;
index a20e9f2f6ae916c3c0e51b0569a0b97145393ce7..04d1577337f3213efd9e4ff82ff9d73e39566ec8 100644 (file)
                                                        "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": [