[asterisk-commits] dlee: branch dlee/record r394775 - in /team/dlee/record: include/asterisk/ re...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jul 18 16:59:28 CDT 2013


Author: dlee
Date: Thu Jul 18 16:59:26 2013
New Revision: 394775

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394775
Log:
Stored recordings REST layer

Modified:
    team/dlee/record/include/asterisk/stasis_app_recording.h
    team/dlee/record/res/res_stasis_http_recordings.c
    team/dlee/record/res/stasis_http/resource_recordings.c
    team/dlee/record/res/stasis_http/resource_recordings.h
    team/dlee/record/rest-api/api-docs/recordings.json

Modified: team/dlee/record/include/asterisk/stasis_app_recording.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/include/asterisk/stasis_app_recording.h?view=diff&rev=394775&r1=394774&r2=394775
==============================================================================
--- team/dlee/record/include/asterisk/stasis_app_recording.h (original)
+++ team/dlee/record/include/asterisk/stasis_app_recording.h Thu Jul 18 16:59:26 2013
@@ -30,6 +30,24 @@
 
 #include "asterisk/app.h"
 #include "asterisk/stasis_app.h"
+
+/*! @{ */
+
+struct stasis_app_stored_recording;
+
+struct ast_json *stasis_app_stored_recording_to_json(
+	struct stasis_app_stored_recording *recording);
+
+struct ao2_container *stasis_app_stored_recording_find_all(void);
+
+struct stasis_app_stored_recording *stasis_app_stored_recording_find_by_name(
+	const char *name);
+
+int stasis_app_stored_recording_delete(
+	struct stasis_app_stored_recording *recording);
+/*! @} */
+
+/*! @{ */
 
 /*! Opaque struct for handling the recording of media to a file. */
 struct stasis_app_recording;
@@ -200,4 +218,6 @@
  */
 struct stasis_message_type *stasis_app_recording_snapshot_type(void);
 
+/*! @} */
+
 #endif /* _ASTERISK_STASIS_APP_RECORDING_H */

Modified: team/dlee/record/res/res_stasis_http_recordings.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/res_stasis_http_recordings.c?view=diff&rev=394775&r1=394774&r2=394775
==============================================================================
--- team/dlee/record/res/res_stasis_http_recordings.c (original)
+++ team/dlee/record/res/res_stasis_http_recordings.c Thu Jul 18 16:59:26 2013
@@ -203,52 +203,6 @@
 #endif /* AST_DEVMODE */
 }
 /*!
- * \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 stasis_http_get_live_recordings_cb(
-	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_live_recordings_args args = {};
-	stasis_http_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 = ari_validate_list(response->message,
-				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");
-		stasis_http_response_error(response, 500,
-			"Internal Server Error", "Response validation failed");
-	}
-#endif /* AST_DEVMODE */
-}
-/*!
  * \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.
@@ -707,7 +661,6 @@
 static struct stasis_rest_handlers recordings_live = {
 	.path_segment = "live",
 	.callbacks = {
-		[AST_HTTP_GET] = stasis_http_get_live_recordings_cb,
 	},
 	.num_children = 1,
 	.children = { &recordings_live_recordingName, }

Modified: team/dlee/record/res/stasis_http/resource_recordings.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/stasis_http/resource_recordings.c?view=diff&rev=394775&r1=394774&r2=394775
==============================================================================
--- team/dlee/record/res/stasis_http/resource_recordings.c (original)
+++ team/dlee/record/res/stasis_http/resource_recordings.c Thu Jul 18 16:59:26 2013
@@ -30,21 +30,111 @@
 #include "asterisk/stasis_app_recording.h"
 #include "resource_recordings.h"
 
-void stasis_http_get_stored_recordings(struct ast_variable *headers, struct ast_get_stored_recordings_args *args, struct stasis_http_response *response)
+void stasis_http_get_stored_recordings(struct ast_variable *headers,
+	struct ast_get_stored_recordings_args *args,
+	struct stasis_http_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: stasis_http_get_stored_recordings\n");
+	RAII_VAR(struct ao2_container *, recordings, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+	struct ao2_iterator i;
+	void *obj;
+
+	recordings = stasis_app_stored_recording_find_all();
+
+	if (!recordings) {
+		stasis_http_response_alloc_failed(response);
+		return;
+	}
+
+	json = ast_json_array_create();
+	if (!json) {
+		stasis_http_response_alloc_failed(response);
+		return;
+	}
+
+	i = ao2_iterator_init(recordings, 0);
+	while ((obj = ao2_iterator_next(&i))) {
+		RAII_VAR(struct stasis_app_stored_recording *, recording, obj,
+			ao2_cleanup);
+
+		int r = ast_json_array_append(
+			json, stasis_app_stored_recording_to_json(recording));
+		if (r != 0) {
+			stasis_http_response_alloc_failed(response);
+			return;
+		}
+	}
+	ao2_iterator_destroy(&i);
+
+	stasis_http_response_ok(response, ast_json_ref(json));
 }
-void stasis_http_get_stored_recording(struct ast_variable *headers, struct ast_get_stored_recording_args *args, struct stasis_http_response *response)
+
+void stasis_http_get_stored_recording(struct ast_variable *headers,
+	struct ast_get_stored_recording_args *args,
+	struct stasis_http_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: stasis_http_get_stored_recording\n");
+	RAII_VAR(struct stasis_app_stored_recording *, recording, NULL,
+		ao2_cleanup);
+	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+
+	recording = stasis_app_stored_recording_find_by_name(
+		args->recording_name);
+	if (recording == NULL) {
+		stasis_http_response_error(response, 404, "Not Found",
+			"Recording not found");
+		return;
+	}
+
+	json = stasis_app_stored_recording_to_json(recording);
+
+	if (json == NULL) {
+		stasis_http_response_error(response, 500,
+			"Internal Server Error", "Error building response");
+		return;
+	}
+
+	stasis_http_response_ok(response, ast_json_ref(json));
 }
-void stasis_http_delete_stored_recording(struct ast_variable *headers, struct ast_delete_stored_recording_args *args, struct stasis_http_response *response)
+
+void stasis_http_delete_stored_recording(struct ast_variable *headers,
+	struct ast_delete_stored_recording_args *args,
+	struct stasis_http_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: stasis_http_delete_stored_recording\n");
-}
-void stasis_http_get_live_recordings(struct ast_variable *headers, struct ast_get_live_recordings_args *args, struct stasis_http_response *response)
-{
-	ast_log(LOG_ERROR, "TODO: stasis_http_get_live_recordings\n");
+	RAII_VAR(struct stasis_app_stored_recording *, recording, NULL,
+		ao2_cleanup);
+	int res;
+
+	recording = stasis_app_stored_recording_find_by_name(
+		args->recording_name);
+	if (recording == NULL) {
+		stasis_http_response_error(response, 404, "Not Found",
+			"Recording not found");
+		return;
+	}
+
+	res = stasis_app_stored_recording_delete(recording);
+
+	if (res != 0) {
+		switch (errno) {
+		case EACCES:
+		case EPERM:
+			stasis_http_response_error(response, 500,
+				"Internal Server Error",
+				"Delete failed");
+			break;
+		case ENOENT:
+			/* Treat does not exist errors as success */
+			stasis_http_response_no_content(response);
+			break;
+		default:
+			ast_log(LOG_WARNING,
+				"Unexpected error deleting recording %s: %s\n",
+				args->recording_name, strerror(errno));
+		}
+		return;
+	}
+
+	stasis_http_response_no_content(response);
 }
 
 void stasis_http_get_live_recording(struct ast_variable *headers,

Modified: team/dlee/record/res/stasis_http/resource_recordings.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/stasis_http/resource_recordings.h?view=diff&rev=394775&r1=394774&r2=394775
==============================================================================
--- team/dlee/record/res/stasis_http/resource_recordings.h (original)
+++ team/dlee/record/res/stasis_http/resource_recordings.h Thu Jul 18 16:59:26 2013
@@ -76,17 +76,6 @@
  * \param[out] response HTTP response
  */
 void stasis_http_delete_stored_recording(struct ast_variable *headers, struct ast_delete_stored_recording_args *args, struct stasis_http_response *response);
-/*! \brief Argument struct for stasis_http_get_live_recordings() */
-struct ast_get_live_recordings_args {
-};
-/*!
- * \brief List libe recordings.
- *
- * \param headers HTTP headers
- * \param args Swagger parameters
- * \param[out] response HTTP response
- */
-void stasis_http_get_live_recordings(struct ast_variable *headers, struct ast_get_live_recordings_args *args, struct stasis_http_response *response);
 /*! \brief Argument struct for stasis_http_get_live_recording() */
 struct ast_get_live_recording_args {
 	/*! \brief The name of the recording */

Modified: team/dlee/record/rest-api/api-docs/recordings.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/rest-api/api-docs/recordings.json?view=diff&rev=394775&r1=394774&r2=394775
==============================================================================
--- team/dlee/record/rest-api/api-docs/recordings.json (original)
+++ team/dlee/record/rest-api/api-docs/recordings.json Thu Jul 18 16:59:26 2013
@@ -54,18 +54,6 @@
 							"dataType": "string"
 						}
 					]
-				}
-			]
-		},
-		{
-			"path": "/recordings/live",
-			"description": "Recordings that are in progress",
-			"operations": [
-				{
-					"httpMethod": "GET",
-					"summary": "List libe recordings.",
-					"nickname": "getLiveRecordings",
-					"responseClass": "List[LiveRecording]"
 				}
 			]
 		},




More information about the asterisk-commits mailing list