Multiple revisions 420089-420090,420097
[asterisk/asterisk.git] / res / ari / resource_channels.c
index 3936092..d0a1be3 100644 (file)
@@ -42,6 +42,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/stasis_app_snoop.h"
 #include "asterisk/stasis_channels.h"
 #include "asterisk/causes.h"
+#include "asterisk/format_cache.h"
 #include "asterisk/core_local.h"
 #include "resource_channels.h"
 
@@ -722,36 +723,6 @@ void ast_ari_channels_list(struct ast_variable *headers,
        ast_ari_response_ok(response, ast_json_ref(json));
 }
 
-static int json_to_ast_variables(struct ast_json *json_variables, struct ast_variable **variables)
-{
-       struct ast_variable *current = NULL;
-       struct ast_json_iter *it_json_var;
-
-       for (it_json_var = ast_json_object_iter(json_variables); it_json_var;
-                it_json_var = ast_json_object_iter_next(json_variables, it_json_var)) {
-               struct ast_variable *new_var;
-
-               new_var = ast_variable_new(ast_json_object_iter_key(it_json_var),
-                                                                  ast_json_string_get(ast_json_object_iter_value(it_json_var)),
-                                                                  "");
-               if (!new_var) {
-                       ast_variables_destroy(*variables);
-                       *variables = NULL;
-                       return 1;
-               }
-
-               if (!current) {
-                       *variables = new_var;
-                       current = *variables;
-               } else {
-                       current->next = new_var;
-                       current = new_var;
-               }
-       }
-
-       return 0;
-}
-
 static void ari_channels_handle_originate_with_id(const char *args_endpoint,
        const char *args_extension,
        const char *args_context,
@@ -772,8 +743,7 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint,
        char *cid_name = NULL;
        int timeout = 30000;
        RAII_VAR(struct ast_format_cap *, cap,
-               ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK), ast_format_cap_destroy);
-       struct ast_format tmp_fmt;
+               ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup);
        char *stuff;
        struct ast_channel *chan;
        struct ast_channel *local_peer;
@@ -787,7 +757,7 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint,
                ast_ari_response_alloc_failed(response);
                return;
        }
-       ast_format_cap_add(cap, ast_format_set(&tmp_fmt, AST_FORMAT_SLINEAR, 0));
+       ast_format_cap_append(cap, ast_format_slin, 0);
 
        if ((assignedids.uniqueid && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid))
                || (assignedids.uniqueid2 && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid2))) {
@@ -894,7 +864,7 @@ void ast_ari_channels_originate_with_id(struct ast_variable *headers,
                ast_ari_channels_originate_with_id_parse_body(args->variables, args);
                json_variables = ast_json_object_get(args->variables, "variables");
                if (json_variables) {
-                       if (json_to_ast_variables(json_variables, &variables)) {
+                       if (ast_json_to_ast_variables(json_variables, &variables)) {
                                ast_log(AST_LOG_ERROR, "Unable to convert 'variables' in JSON body to channel variables\n");
                                ast_ari_response_alloc_failed(response);
                                return;
@@ -930,7 +900,7 @@ void ast_ari_channels_originate(struct ast_variable *headers,
                ast_ari_channels_originate_parse_body(args->variables, args);
                json_variables = ast_json_object_get(args->variables, "variables");
                if (json_variables) {
-                       if (json_to_ast_variables(json_variables, &variables)) {
+                       if (ast_json_to_ast_variables(json_variables, &variables)) {
                                ast_log(AST_LOG_ERROR, "Unable to convert 'variables' in JSON body to channel variables\n");
                                ast_ari_response_alloc_failed(response);
                                return;