Use proper case for checking if digest authentication is used.
[asterisk/asterisk.git] / res / res_ari_recordings.c
index 01ad49a..56fb9ec 100644 (file)
@@ -58,17 +58,19 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  * \param headers HTTP headers.
  * \param[out] response Response to the HTTP request.
  */
-static void ast_ari_get_stored_recordings_cb(
+static void ast_ari_recordings_list_stored_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_get_stored_recordings_args args = {};
+       struct ast_ari_recordings_list_stored_args args = {};
+       RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
 #if defined(AST_DEVMODE)
        int is_valid;
        int code;
 #endif /* AST_DEVMODE */
 
-       ast_ari_get_stored_recordings(headers, &args, response);
+       ast_ari_recordings_list_stored(headers, &args, response);
 #if defined(AST_DEVMODE)
        code = response->response_code;
 
@@ -107,12 +109,14 @@ fin: __attribute__((unused))
  * \param headers HTTP headers.
  * \param[out] response Response to the HTTP request.
  */
-static void ast_ari_get_stored_recording_cb(
+static void ast_ari_recordings_get_stored_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_get_stored_recording_args args = {};
+       struct ast_ari_recordings_get_stored_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;
@@ -124,7 +128,7 @@ static void ast_ari_get_stored_recording_cb(
                } else
                {}
        }
-       ast_ari_get_stored_recording(headers, &args, response);
+       ast_ari_recordings_get_stored(headers, &args, response);
 #if defined(AST_DEVMODE)
        code = response->response_code;
 
@@ -134,6 +138,7 @@ static void ast_ari_get_stored_recording_cb(
                break;
        case 500: /* Internal Server Error */
        case 501: /* Not Implemented */
+       case 404: /* Recording not found */
                is_valid = 1;
                break;
        default:
@@ -163,12 +168,14 @@ fin: __attribute__((unused))
  * \param headers HTTP headers.
  * \param[out] response Response to the HTTP request.
  */
-static void ast_ari_delete_stored_recording_cb(
+static void ast_ari_recordings_delete_stored_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_delete_stored_recording_args args = {};
+       struct ast_ari_recordings_delete_stored_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;
@@ -180,7 +187,7 @@ static void ast_ari_delete_stored_recording_cb(
                } else
                {}
        }
-       ast_ari_delete_stored_recording(headers, &args, response);
+       ast_ari_recordings_delete_stored(headers, &args, response);
 #if defined(AST_DEVMODE)
        code = response->response_code;
 
@@ -190,6 +197,7 @@ static void ast_ari_delete_stored_recording_cb(
                break;
        case 500: /* Internal Server Error */
        case 501: /* Not Implemented */
+       case 404: /* Recording not found */
                is_valid = 1;
                break;
        default:
@@ -213,67 +221,20 @@ fin: __attribute__((unused))
        return;
 }
 /*!
- * \brief Parameter parsing callback for /recordings/live.
- * \param get_params GET parameters in the HTTP request.
- * \param path_vars Path variables extracted from the request.
- * \param headers HTTP headers.
- * \param[out] response Response to the HTTP request.
- */
-static void ast_ari_get_live_recordings_cb(
-       struct ast_variable *get_params, struct ast_variable *path_vars,
-       struct ast_variable *headers, struct ast_ari_response *response)
-{
-       struct ast_get_live_recordings_args args = {};
-#if defined(AST_DEVMODE)
-       int is_valid;
-       int code;
-#endif /* AST_DEVMODE */
-
-       ast_ari_get_live_recordings(headers, &args, response);
-#if defined(AST_DEVMODE)
-       code = response->response_code;
-
-       switch (code) {
-       case 0: /* Implementation is still a stub, or the code wasn't set */
-               is_valid = response->message == NULL;
-               break;
-       case 500: /* Internal Server Error */
-       case 501: /* Not Implemented */
-               is_valid = 1;
-               break;
-       default:
-               if (200 <= code && code <= 299) {
-                       is_valid = ast_ari_validate_list(response->message,
-                               ast_ari_validate_live_recording_fn());
-               } else {
-                       ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live\n", code);
-                       is_valid = 0;
-               }
-       }
-
-       if (!is_valid) {
-               ast_log(LOG_ERROR, "Response validation failed for /recordings/live\n");
-               ast_ari_response_error(response, 500,
-                       "Internal Server Error", "Response validation failed");
-       }
-#endif /* AST_DEVMODE */
-
-fin: __attribute__((unused))
-       return;
-}
-/*!
  * \brief Parameter parsing callback for /recordings/live/{recordingName}.
  * \param get_params GET parameters in the HTTP request.
  * \param path_vars Path variables extracted from the request.
  * \param headers HTTP headers.
  * \param[out] response Response to the HTTP request.
  */
-static void ast_ari_get_live_recording_cb(
+static void ast_ari_recordings_get_live_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_get_live_recording_args args = {};
+       struct ast_ari_recordings_get_live_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;
@@ -285,7 +246,7 @@ static void ast_ari_get_live_recording_cb(
                } else
                {}
        }
-       ast_ari_get_live_recording(headers, &args, response);
+       ast_ari_recordings_get_live(headers, &args, response);
 #if defined(AST_DEVMODE)
        code = response->response_code;
 
@@ -295,6 +256,7 @@ static void ast_ari_get_live_recording_cb(
                break;
        case 500: /* Internal Server Error */
        case 501: /* Not Implemented */
+       case 404: /* Recording not found */
                is_valid = 1;
                break;
        default:
@@ -324,12 +286,14 @@ fin: __attribute__((unused))
  * \param headers HTTP headers.
  * \param[out] response Response to the HTTP request.
  */
-static void ast_ari_cancel_recording_cb(
+static void ast_ari_recordings_cancel_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_cancel_recording_args args = {};
+       struct ast_ari_recordings_cancel_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;
@@ -341,7 +305,7 @@ static void ast_ari_cancel_recording_cb(
                } else
                {}
        }
-       ast_ari_cancel_recording(headers, &args, response);
+       ast_ari_recordings_cancel(headers, &args, response);
 #if defined(AST_DEVMODE)
        code = response->response_code;
 
@@ -351,6 +315,7 @@ static void ast_ari_cancel_recording_cb(
                break;
        case 500: /* Internal Server Error */
        case 501: /* Not Implemented */
+       case 404: /* Recording not found */
                is_valid = 1;
                break;
        default:
@@ -380,12 +345,14 @@ fin: __attribute__((unused))
  * \param headers HTTP headers.
  * \param[out] response Response to the HTTP request.
  */
-static void ast_ari_stop_recording_cb(
+static void ast_ari_recordings_stop_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_stop_recording_args args = {};
+       struct ast_ari_recordings_stop_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;
@@ -397,7 +364,7 @@ static void ast_ari_stop_recording_cb(
                } else
                {}
        }
-       ast_ari_stop_recording(headers, &args, response);
+       ast_ari_recordings_stop(headers, &args, response);
 #if defined(AST_DEVMODE)
        code = response->response_code;
 
@@ -407,6 +374,7 @@ static void ast_ari_stop_recording_cb(
                break;
        case 500: /* Internal Server Error */
        case 501: /* Not Implemented */
+       case 404: /* Recording not found */
                is_valid = 1;
                break;
        default:
@@ -436,12 +404,14 @@ fin: __attribute__((unused))
  * \param headers HTTP headers.
  * \param[out] response Response to the HTTP request.
  */
-static void ast_ari_pause_recording_cb(
+static void ast_ari_recordings_pause_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_pause_recording_args args = {};
+       struct ast_ari_recordings_pause_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;
@@ -453,7 +423,7 @@ static void ast_ari_pause_recording_cb(
                } else
                {}
        }
-       ast_ari_pause_recording(headers, &args, response);
+       ast_ari_recordings_pause(headers, &args, response);
 #if defined(AST_DEVMODE)
        code = response->response_code;
 
@@ -463,6 +433,8 @@ static void ast_ari_pause_recording_cb(
                break;
        case 500: /* Internal Server Error */
        case 501: /* Not Implemented */
+       case 404: /* Recording not found */
+       case 409: /* Recording not in session */
                is_valid = 1;
                break;
        default:
@@ -486,18 +458,20 @@ fin: __attribute__((unused))
        return;
 }
 /*!
- * \brief Parameter parsing callback for /recordings/live/{recordingName}/unpause.
+ * \brief Parameter parsing callback for /recordings/live/{recordingName}/pause.
  * \param get_params GET parameters in the HTTP request.
  * \param path_vars Path variables extracted from the request.
  * \param headers HTTP headers.
  * \param[out] response Response to the HTTP request.
  */
-static void ast_ari_unpause_recording_cb(
+static void ast_ari_recordings_unpause_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_unpause_recording_args args = {};
+       struct ast_ari_recordings_unpause_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;
@@ -509,7 +483,7 @@ static void ast_ari_unpause_recording_cb(
                } else
                {}
        }
-       ast_ari_unpause_recording(headers, &args, response);
+       ast_ari_recordings_unpause(headers, &args, response);
 #if defined(AST_DEVMODE)
        code = response->response_code;
 
@@ -519,6 +493,8 @@ static void ast_ari_unpause_recording_cb(
                break;
        case 500: /* Internal Server Error */
        case 501: /* Not Implemented */
+       case 404: /* Recording not found */
+       case 409: /* Recording not in session */
                is_valid = 1;
                break;
        default:
@@ -526,13 +502,13 @@ static void ast_ari_unpause_recording_cb(
                        is_valid = ast_ari_validate_void(
                                response->message);
                } else {
-                       ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live/{recordingName}/unpause\n", code);
+                       ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live/{recordingName}/pause\n", code);
                        is_valid = 0;
                }
        }
 
        if (!is_valid) {
-               ast_log(LOG_ERROR, "Response validation failed for /recordings/live/{recordingName}/unpause\n");
+               ast_log(LOG_ERROR, "Response validation failed for /recordings/live/{recordingName}/pause\n");
                ast_ari_response_error(response, 500,
                        "Internal Server Error", "Response validation failed");
        }
@@ -548,12 +524,14 @@ fin: __attribute__((unused))
  * \param headers HTTP headers.
  * \param[out] response Response to the HTTP request.
  */
-static void ast_ari_mute_recording_cb(
+static void ast_ari_recordings_mute_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_mute_recording_args args = {};
+       struct ast_ari_recordings_mute_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;
@@ -565,7 +543,7 @@ static void ast_ari_mute_recording_cb(
                } else
                {}
        }
-       ast_ari_mute_recording(headers, &args, response);
+       ast_ari_recordings_mute(headers, &args, response);
 #if defined(AST_DEVMODE)
        code = response->response_code;
 
@@ -575,6 +553,8 @@ static void ast_ari_mute_recording_cb(
                break;
        case 500: /* Internal Server Error */
        case 501: /* Not Implemented */
+       case 404: /* Recording not found */
+       case 409: /* Recording not in session */
                is_valid = 1;
                break;
        default:
@@ -598,18 +578,20 @@ fin: __attribute__((unused))
        return;
 }
 /*!
- * \brief Parameter parsing callback for /recordings/live/{recordingName}/unmute.
+ * \brief Parameter parsing callback for /recordings/live/{recordingName}/mute.
  * \param get_params GET parameters in the HTTP request.
  * \param path_vars Path variables extracted from the request.
  * \param headers HTTP headers.
  * \param[out] response Response to the HTTP request.
  */
-static void ast_ari_unmute_recording_cb(
+static void ast_ari_recordings_unmute_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_unmute_recording_args args = {};
+       struct ast_ari_recordings_unmute_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;
@@ -621,7 +603,7 @@ static void ast_ari_unmute_recording_cb(
                } else
                {}
        }
-       ast_ari_unmute_recording(headers, &args, response);
+       ast_ari_recordings_unmute(headers, &args, response);
 #if defined(AST_DEVMODE)
        code = response->response_code;
 
@@ -631,6 +613,8 @@ static void ast_ari_unmute_recording_cb(
                break;
        case 500: /* Internal Server Error */
        case 501: /* Not Implemented */
+       case 404: /* Recording not found */
+       case 409: /* Recording not in session */
                is_valid = 1;
                break;
        default:
@@ -638,13 +622,13 @@ static void ast_ari_unmute_recording_cb(
                        is_valid = ast_ari_validate_void(
                                response->message);
                } else {
-                       ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live/{recordingName}/unmute\n", code);
+                       ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live/{recordingName}/mute\n", code);
                        is_valid = 0;
                }
        }
 
        if (!is_valid) {
-               ast_log(LOG_ERROR, "Response validation failed for /recordings/live/{recordingName}/unmute\n");
+               ast_log(LOG_ERROR, "Response validation failed for /recordings/live/{recordingName}/mute\n");
                ast_ari_response_error(response, 500,
                        "Internal Server Error", "Response validation failed");
        }
@@ -659,8 +643,8 @@ static struct stasis_rest_handlers recordings_stored_recordingName = {
        .path_segment = "recordingName",
        .is_wildcard = 1,
        .callbacks = {
-               [AST_HTTP_GET] = ast_ari_get_stored_recording_cb,
-               [AST_HTTP_DELETE] = ast_ari_delete_stored_recording_cb,
+               [AST_HTTP_GET] = ast_ari_recordings_get_stored_cb,
+               [AST_HTTP_DELETE] = ast_ari_recordings_delete_stored_cb,
        },
        .num_children = 0,
        .children = {  }
@@ -669,7 +653,7 @@ static struct stasis_rest_handlers recordings_stored_recordingName = {
 static struct stasis_rest_handlers recordings_stored = {
        .path_segment = "stored",
        .callbacks = {
-               [AST_HTTP_GET] = ast_ari_get_stored_recordings_cb,
+               [AST_HTTP_GET] = ast_ari_recordings_list_stored_cb,
        },
        .num_children = 1,
        .children = { &recordings_stored_recordingName, }
@@ -678,7 +662,7 @@ static struct stasis_rest_handlers recordings_stored = {
 static struct stasis_rest_handlers recordings_live_recordingName_stop = {
        .path_segment = "stop",
        .callbacks = {
-               [AST_HTTP_POST] = ast_ari_stop_recording_cb,
+               [AST_HTTP_POST] = ast_ari_recordings_stop_cb,
        },
        .num_children = 0,
        .children = {  }
@@ -687,16 +671,8 @@ static struct stasis_rest_handlers recordings_live_recordingName_stop = {
 static struct stasis_rest_handlers recordings_live_recordingName_pause = {
        .path_segment = "pause",
        .callbacks = {
-               [AST_HTTP_POST] = ast_ari_pause_recording_cb,
-       },
-       .num_children = 0,
-       .children = {  }
-};
-/*! \brief REST handler for /api-docs/recordings.{format} */
-static struct stasis_rest_handlers recordings_live_recordingName_unpause = {
-       .path_segment = "unpause",
-       .callbacks = {
-               [AST_HTTP_POST] = ast_ari_unpause_recording_cb,
+               [AST_HTTP_POST] = ast_ari_recordings_pause_cb,
+               [AST_HTTP_DELETE] = ast_ari_recordings_unpause_cb,
        },
        .num_children = 0,
        .children = {  }
@@ -705,16 +681,8 @@ static struct stasis_rest_handlers recordings_live_recordingName_unpause = {
 static struct stasis_rest_handlers recordings_live_recordingName_mute = {
        .path_segment = "mute",
        .callbacks = {
-               [AST_HTTP_POST] = ast_ari_mute_recording_cb,
-       },
-       .num_children = 0,
-       .children = {  }
-};
-/*! \brief REST handler for /api-docs/recordings.{format} */
-static struct stasis_rest_handlers recordings_live_recordingName_unmute = {
-       .path_segment = "unmute",
-       .callbacks = {
-               [AST_HTTP_POST] = ast_ari_unmute_recording_cb,
+               [AST_HTTP_POST] = ast_ari_recordings_mute_cb,
+               [AST_HTTP_DELETE] = ast_ari_recordings_unmute_cb,
        },
        .num_children = 0,
        .children = {  }
@@ -724,17 +692,16 @@ static struct stasis_rest_handlers recordings_live_recordingName = {
        .path_segment = "recordingName",
        .is_wildcard = 1,
        .callbacks = {
-               [AST_HTTP_GET] = ast_ari_get_live_recording_cb,
-               [AST_HTTP_DELETE] = ast_ari_cancel_recording_cb,
+               [AST_HTTP_GET] = ast_ari_recordings_get_live_cb,
+               [AST_HTTP_DELETE] = ast_ari_recordings_cancel_cb,
        },
-       .num_children = 5,
-       .children = { &recordings_live_recordingName_stop,&recordings_live_recordingName_pause,&recordings_live_recordingName_unpause,&recordings_live_recordingName_mute,&recordings_live_recordingName_unmute, }
+       .num_children = 3,
+       .children = { &recordings_live_recordingName_stop,&recordings_live_recordingName_pause,&recordings_live_recordingName_mute, }
 };
 /*! \brief REST handler for /api-docs/recordings.{format} */
 static struct stasis_rest_handlers recordings_live = {
        .path_segment = "live",
        .callbacks = {
-               [AST_HTTP_GET] = ast_ari_get_live_recordings_cb,
        },
        .num_children = 1,
        .children = { &recordings_live_recordingName, }