ARI: REST over Websocket

This commit adds the ability to make ARI REST requests over the same
websocket used to receive events.

For full details on how to use the new capability, visit...

https://docs.asterisk.org/Configuration/Interfaces/Asterisk-REST-Interface-ARI/ARI-REST-over-WebSocket/

Changes:

* Added utilities to http.c:
  * ast_get_http_method_from_string().
  * ast_http_parse_post_form().
* Added utilities to json.c:
  * ast_json_nvp_array_to_ast_variables().
  * ast_variables_to_json_nvp_array().
* Added definitions for new events to carry REST responses.
* Created res/ari/ari_websocket_requests.c to house the new request handlers.
* Moved non-event specific code out of res/ari/resource_events.c into
  res/ari/ari_websockets.c
* Refactored res/res_ari.c to move non-http code out of ast_ari_callback()
  (which is http specific) and into ast_ari_invoke() so it can be shared
  between both the http and websocket transports.

UpgradeNote: This commit adds the ability to make ARI REST requests over the same
websocket used to receive events.
See https://docs.asterisk.org/Configuration/Interfaces/Asterisk-REST-Interface-ARI/ARI-REST-over-WebSocket/

(cherry picked from commit 4e07d3d50f)
This commit is contained in:
George Joseph
2025-03-12 15:58:51 -06:00
committed by Asterisk Development Team
parent d6a1b044a8
commit 8d69af73d6
20 changed files with 2154 additions and 1300 deletions

View File

@@ -345,7 +345,7 @@ AST_TEST_DEFINE(invoke_get)
"head2", "head-two",
"path_vars");
ast_ari_invoke(NULL, "foo", AST_HTTP_GET, get_params, headers,
ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo", AST_HTTP_GET, get_params, headers,
ast_json_null(), response);
ast_test_validate(test, 1 == invocation_count);
@@ -383,7 +383,7 @@ AST_TEST_DEFINE(invoke_wildcard)
"path_vars",
"bam", "foshizzle");
ast_ari_invoke(NULL, "foo/foshizzle", AST_HTTP_GET, get_params, headers,
ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo/foshizzle", AST_HTTP_GET, get_params, headers,
ast_json_null(), response);
ast_test_validate(test, 1 == invocation_count);
@@ -421,7 +421,7 @@ AST_TEST_DEFINE(invoke_delete)
"path_vars",
"bam", "foshizzle");
ast_ari_invoke(NULL, "foo/foshizzle/bang", AST_HTTP_DELETE, get_params, headers,
ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo/foshizzle/bang", AST_HTTP_DELETE, get_params, headers,
ast_json_null(), response);
ast_test_validate(test, 1 == invocation_count);
@@ -472,7 +472,7 @@ AST_TEST_DEFINE(invoke_post)
"head2", "head-two",
"path_vars");
ast_ari_invoke(NULL, "foo/bar", AST_HTTP_POST, get_params, headers,
ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo/bar", AST_HTTP_POST, get_params, headers,
ast_json_null(), response);
ast_test_validate(test, 1 == invocation_count);
@@ -502,7 +502,7 @@ AST_TEST_DEFINE(invoke_bad_post)
fixture = setup_invocation_test();
response = response_alloc();
ast_ari_invoke(NULL, "foo", AST_HTTP_POST, get_params, headers,
ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo", AST_HTTP_POST, get_params, headers,
ast_json_null(), response);
ast_test_validate(test, 0 == invocation_count);
@@ -531,7 +531,7 @@ AST_TEST_DEFINE(invoke_not_found)
fixture = setup_invocation_test();
response = response_alloc();
ast_ari_invoke(NULL, "foo/fizzle/i-am-not-a-resource", AST_HTTP_GET, get_params, headers,
ast_ari_invoke(NULL, ARI_INVOKE_SOURCE_TEST, NULL, "foo/fizzle/i-am-not-a-resource", AST_HTTP_GET, get_params, headers,
ast_json_null(), response);
ast_test_validate(test, 0 == invocation_count);