summaryrefslogtreecommitdiff
path: root/res/res_ari_bridges.c
diff options
context:
space:
mode:
authorGeorge Joseph <gjoseph@digium.com>2017-01-19 08:05:36 -0700
committerGeorge Joseph <gjoseph@digium.com>2017-01-23 10:25:58 -0700
commit66916067236dc2f5cf54fadee33a5203d8716148 (patch)
tree963dec954768e5eb279af597ea3fc62d9b43af59 /res/res_ari_bridges.c
parente2da0021b99ace55a36ad5d1a497159a2d077025 (diff)
ari: Implement 'debug all' and request/response logging
The 'ari set debug' command has been enhanced to accept 'all' as an application name. This allows dumping of all apps even if an app hasn't registered yet. To accomplish this, a new global_debug global variable was added to res/stasis/app.c and new APIs were added to set and query the value. 'ari set debug' now displays requests and responses as well as events. This required refactoring the existing debug code. * The implementation for 'ari set debug' was moved from stasis/cli.{c,h} to ari/cli.{c,h}, and stasis/cli.{c,h} were deleted. * In order to print the body of incoming requests even if a request failed, the consumption of the body was moved from the ari stubs to ast_ari_callback in res_ari.c and the moustache templates were then regenerated. The body is now passed to ast_ari_invoke and then on to the handlers. This results in code savings since that template was inserted multiple times into all the stubs. An additional change was made to the ao2_str_container implementation to add partial key searching and a sort function. The existing cli code assumed it was already there when it wasn't so the tab completion was never working. Change-Id: Ief936f747ce47f1fb14035fbe61152cf766406bf (cherry picked from commit 1d890874f39a5a81b20da44358143ed9b54ab0fe)
Diffstat (limited to 'res/res_ari_bridges.c')
-rw-r--r--res/res_ari_bridges.c162
1 files changed, 14 insertions, 148 deletions
diff --git a/res/res_ari_bridges.c b/res/res_ari_bridges.c
index 0b370c299..e61865e31 100644
--- a/res/res_ari_bridges.c
+++ b/res/res_ari_bridges.c
@@ -60,10 +60,9 @@
static void ast_ari_bridges_list_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_list_args args = {};
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -132,11 +131,10 @@ int ast_ari_bridges_create_parse_body(
static void ast_ari_bridges_create_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_create_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -154,21 +152,6 @@ static void ast_ari_bridges_create_cb(
} else
{}
}
- /* Look for a JSON request entity */
- body = ast_http_get_json(ser, headers);
- if (!body) {
- switch (errno) {
- case EFBIG:
- ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
- goto fin;
- case ENOMEM:
- ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
- goto fin;
- case EIO:
- ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
- goto fin;
- }
- }
if (ast_ari_bridges_create_parse_body(body, &args)) {
ast_ari_response_alloc_failed(response);
goto fin;
@@ -232,11 +215,10 @@ int ast_ari_bridges_create_with_id_parse_body(
static void ast_ari_bridges_create_with_id_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_create_with_id_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -257,21 +239,6 @@ static void ast_ari_bridges_create_with_id_cb(
} else
{}
}
- /* Look for a JSON request entity */
- body = ast_http_get_json(ser, headers);
- if (!body) {
- switch (errno) {
- case EFBIG:
- ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
- goto fin;
- case ENOMEM:
- ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
- goto fin;
- case EIO:
- ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
- goto fin;
- }
- }
if (ast_ari_bridges_create_with_id_parse_body(body, &args)) {
ast_ari_response_alloc_failed(response);
goto fin;
@@ -318,11 +285,10 @@ fin: __attribute__((unused))
static void ast_ari_bridges_get_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_get_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -377,11 +343,10 @@ fin: __attribute__((unused))
static void ast_ari_bridges_destroy_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_destroy_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -478,11 +443,10 @@ int ast_ari_bridges_add_channel_parse_body(
static void ast_ari_bridges_add_channel_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_add_channel_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -543,21 +507,6 @@ static void ast_ari_bridges_add_channel_cb(
} else
{}
}
- /* Look for a JSON request entity */
- body = ast_http_get_json(ser, headers);
- if (!body) {
- switch (errno) {
- case EFBIG:
- ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
- goto fin;
- case ENOMEM:
- ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
- goto fin;
- case EIO:
- ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
- goto fin;
- }
- }
if (ast_ari_bridges_add_channel_parse_body(body, &args)) {
ast_ari_response_alloc_failed(response);
goto fin;
@@ -648,11 +597,10 @@ int ast_ari_bridges_remove_channel_parse_body(
static void ast_ari_bridges_remove_channel_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_remove_channel_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -710,21 +658,6 @@ static void ast_ari_bridges_remove_channel_cb(
} else
{}
}
- /* Look for a JSON request entity */
- body = ast_http_get_json(ser, headers);
- if (!body) {
- switch (errno) {
- case EFBIG:
- ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
- goto fin;
- case ENOMEM:
- ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
- goto fin;
- case EIO:
- ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
- goto fin;
- }
- }
if (ast_ari_bridges_remove_channel_parse_body(body, &args)) {
ast_ari_response_alloc_failed(response);
goto fin;
@@ -777,11 +710,10 @@ fin: __attribute__((unused))
static void ast_ari_bridges_set_video_source_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_set_video_source_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -841,11 +773,10 @@ fin: __attribute__((unused))
static void ast_ari_bridges_clear_video_source_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_clear_video_source_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -913,11 +844,10 @@ int ast_ari_bridges_start_moh_parse_body(
static void ast_ari_bridges_start_moh_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_start_moh_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -935,21 +865,6 @@ static void ast_ari_bridges_start_moh_cb(
} else
{}
}
- /* Look for a JSON request entity */
- body = ast_http_get_json(ser, headers);
- if (!body) {
- switch (errno) {
- case EFBIG:
- ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
- goto fin;
- case ENOMEM:
- ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
- goto fin;
- case EIO:
- ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
- goto fin;
- }
- }
if (ast_ari_bridges_start_moh_parse_body(body, &args)) {
ast_ari_response_alloc_failed(response);
goto fin;
@@ -998,11 +913,10 @@ fin: __attribute__((unused))
static void ast_ari_bridges_stop_moh_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_stop_moh_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -1112,11 +1026,10 @@ int ast_ari_bridges_play_parse_body(
static void ast_ari_bridges_play_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_play_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -1186,21 +1099,6 @@ static void ast_ari_bridges_play_cb(
} else
{}
}
- /* Look for a JSON request entity */
- body = ast_http_get_json(ser, headers);
- if (!body) {
- switch (errno) {
- case EFBIG:
- ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
- goto fin;
- case ENOMEM:
- ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
- goto fin;
- case EIO:
- ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
- goto fin;
- }
- }
if (ast_ari_bridges_play_parse_body(body, &args)) {
ast_ari_response_alloc_failed(response);
goto fin;
@@ -1301,11 +1199,10 @@ int ast_ari_bridges_play_with_id_parse_body(
static void ast_ari_bridges_play_with_id_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_play_with_id_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -1375,21 +1272,6 @@ static void ast_ari_bridges_play_with_id_cb(
} else
{}
}
- /* Look for a JSON request entity */
- body = ast_http_get_json(ser, headers);
- if (!body) {
- switch (errno) {
- case EFBIG:
- ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
- goto fin;
- case ENOMEM:
- ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
- goto fin;
- case EIO:
- ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
- goto fin;
- }
- }
if (ast_ari_bridges_play_with_id_parse_body(body, &args)) {
ast_ari_response_alloc_failed(response);
goto fin;
@@ -1477,11 +1359,10 @@ int ast_ari_bridges_record_parse_body(
static void ast_ari_bridges_record_cb(
struct ast_tcptls_session_instance *ser,
struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
+ struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
{
struct ast_ari_bridges_record_args args = {};
struct ast_variable *i;
- RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -1517,21 +1398,6 @@ static void ast_ari_bridges_record_cb(
} else
{}
}
- /* Look for a JSON request entity */
- body = ast_http_get_json(ser, headers);
- if (!body) {
- switch (errno) {
- case EFBIG:
- ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
- goto fin;
- case ENOMEM:
- ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
- goto fin;
- case EIO:
- ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
- goto fin;
- }
- }
if (ast_ari_bridges_record_parse_body(body, &args)) {
ast_ari_response_alloc_failed(response);
goto fin;