summaryrefslogtreecommitdiff
path: root/res/res_stasis_http_playback.c
diff options
context:
space:
mode:
Diffstat (limited to 'res/res_stasis_http_playback.c')
-rw-r--r--res/res_stasis_http_playback.c102
1 files changed, 96 insertions, 6 deletions
diff --git a/res/res_stasis_http_playback.c b/res/res_stasis_http_playback.c
index 4608686bc..0e56e6229 100644
--- a/res/res_stasis_http_playback.c
+++ b/res/res_stasis_http_playback.c
@@ -44,6 +44,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/module.h"
#include "asterisk/stasis_app.h"
#include "stasis_http/resource_playback.h"
+#if defined(AST_DEVMODE)
+#include "stasis_http/ari_model_validators.h"
+#endif
/*!
* \brief Parameter parsing callback for /playback/{playbackId}.
@@ -53,9 +56,14 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
* \param[out] response Response to the HTTP request.
*/
static void stasis_http_get_playback_cb(
- struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct stasis_http_response *response)
+ struct ast_variable *get_params, struct ast_variable *path_vars,
+ struct ast_variable *headers, struct stasis_http_response *response)
{
+#if defined(AST_DEVMODE)
+ int is_valid;
+ int code;
+#endif /* AST_DEVMODE */
+
struct ast_get_playback_args args = {};
struct ast_variable *i;
@@ -66,6 +74,29 @@ static void stasis_http_get_playback_cb(
{}
}
stasis_http_get_playback(headers, &args, response);
+#if defined(AST_DEVMODE)
+ code = response->response_code;
+
+ switch (code) {
+ case 500: /* Internal server error */
+ is_valid = 1;
+ break;
+ default:
+ if (200 <= code && code <= 299) {
+ is_valid = ari_validate_playback(
+ response->message);
+ } else {
+ ast_log(LOG_ERROR, "Invalid error response %d for /playback/{playbackId}\n", code);
+ is_valid = 0;
+ }
+ }
+
+ if (!is_valid) {
+ ast_log(LOG_ERROR, "Response validation failed for /playback/{playbackId}\n");
+ stasis_http_response_error(response, 500,
+ "Internal Server Error", "Response validation failed");
+ }
+#endif /* AST_DEVMODE */
}
/*!
* \brief Parameter parsing callback for /playback/{playbackId}.
@@ -75,9 +106,14 @@ static void stasis_http_get_playback_cb(
* \param[out] response Response to the HTTP request.
*/
static void stasis_http_stop_playback_cb(
- struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct stasis_http_response *response)
+ struct ast_variable *get_params, struct ast_variable *path_vars,
+ struct ast_variable *headers, struct stasis_http_response *response)
{
+#if defined(AST_DEVMODE)
+ int is_valid;
+ int code;
+#endif /* AST_DEVMODE */
+
struct ast_stop_playback_args args = {};
struct ast_variable *i;
@@ -88,6 +124,29 @@ static void stasis_http_stop_playback_cb(
{}
}
stasis_http_stop_playback(headers, &args, response);
+#if defined(AST_DEVMODE)
+ code = response->response_code;
+
+ switch (code) {
+ case 500: /* Internal server error */
+ is_valid = 1;
+ break;
+ default:
+ if (200 <= code && code <= 299) {
+ is_valid = ari_validate_playback(
+ response->message);
+ } else {
+ ast_log(LOG_ERROR, "Invalid error response %d for /playback/{playbackId}\n", code);
+ is_valid = 0;
+ }
+ }
+
+ if (!is_valid) {
+ ast_log(LOG_ERROR, "Response validation failed for /playback/{playbackId}\n");
+ stasis_http_response_error(response, 500,
+ "Internal Server Error", "Response validation failed");
+ }
+#endif /* AST_DEVMODE */
}
/*!
* \brief Parameter parsing callback for /playback/{playbackId}/control.
@@ -97,9 +156,14 @@ static void stasis_http_stop_playback_cb(
* \param[out] response Response to the HTTP request.
*/
static void stasis_http_control_playback_cb(
- struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct stasis_http_response *response)
+ struct ast_variable *get_params, struct ast_variable *path_vars,
+ struct ast_variable *headers, struct stasis_http_response *response)
{
+#if defined(AST_DEVMODE)
+ int is_valid;
+ int code;
+#endif /* AST_DEVMODE */
+
struct ast_control_playback_args args = {};
struct ast_variable *i;
@@ -116,6 +180,32 @@ static void stasis_http_control_playback_cb(
{}
}
stasis_http_control_playback(headers, &args, response);
+#if defined(AST_DEVMODE)
+ code = response->response_code;
+
+ switch (code) {
+ case 500: /* Internal server error */
+ case 400: /* The provided operation parameter was invalid */
+ case 404: /* The playback cannot be found */
+ case 409: /* The operation cannot be performed in the playback's current state */
+ is_valid = 1;
+ break;
+ default:
+ if (200 <= code && code <= 299) {
+ is_valid = ari_validate_playback(
+ response->message);
+ } else {
+ ast_log(LOG_ERROR, "Invalid error response %d for /playback/{playbackId}/control\n", code);
+ is_valid = 0;
+ }
+ }
+
+ if (!is_valid) {
+ ast_log(LOG_ERROR, "Response validation failed for /playback/{playbackId}/control\n");
+ stasis_http_response_error(response, 500,
+ "Internal Server Error", "Response validation failed");
+ }
+#endif /* AST_DEVMODE */
}
/*! \brief REST handler for /api-docs/playback.{format} */