summaryrefslogtreecommitdiff
path: root/res/ari
diff options
context:
space:
mode:
authorMatt Jordan <mjordan@digium.com>2016-05-18 06:19:58 -0500
committerMatt Jordan <mjordan@digium.com>2016-05-20 09:06:12 -0500
commite773e3a9bbaf378d53647e4bac3ffcd61afb4ae6 (patch)
tree23e75dcdaf9b8c72a23387bfabdd42f643e5c480 /res/ari
parentd4b77dad1b0154eb3b89133d941dd8d624deda54 (diff)
ARI: Add the ability to download the media associated with a stored recording
This patch adds a new feature to ARI that allows a client to download the media associated with a stored recording. The new route is /recordings/stored/{name}/file, and transmits the underlying binary file using Asterisk's HTTP server's underlying file transfer facilities. Because this REST route returns non-JSON, a few small enhancements had to be made to the Python Swagger generation code, as well as the mustache templates that generate the ARI bindings. ASTERISK-26042 #close Change-Id: I49ec5c4afdec30bb665d9c977ab423b5387e0181
Diffstat (limited to 'res/ari')
-rw-r--r--res/ari/resource_recordings.c44
-rw-r--r--res/ari/resource_recordings.h14
2 files changed, 58 insertions, 0 deletions
diff --git a/res/ari/resource_recordings.c b/res/ari/resource_recordings.c
index a49c3b12e..5661d608d 100644
--- a/res/ari/resource_recordings.c
+++ b/res/ari/resource_recordings.c
@@ -101,6 +101,50 @@ void ast_ari_recordings_get_stored(struct ast_variable *headers,
ast_ari_response_ok(response, json);
}
+void ast_ari_recordings_get_stored_file(struct ast_tcptls_session_instance *ser,
+ struct ast_variable *headers, struct ast_ari_recordings_get_stored_file_args *args,
+ struct ast_ari_response *response)
+{
+ RAII_VAR(struct stasis_app_stored_recording *, recording,
+ stasis_app_stored_recording_find_by_name(args->recording_name),
+ ao2_cleanup);
+ static const char *format_type_names[AST_MEDIA_TYPE_TEXT + 1] = {
+ [AST_MEDIA_TYPE_UNKNOWN] = "binary",
+ [AST_MEDIA_TYPE_AUDIO] = "audio",
+ [AST_MEDIA_TYPE_VIDEO] = "video",
+ [AST_MEDIA_TYPE_IMAGE] = "image",
+ [AST_MEDIA_TYPE_TEXT] = "text",
+ };
+ struct ast_format *format;
+
+ response->message = ast_json_null();
+
+ if (!recording) {
+ ast_ari_response_error(response, 404, "Not Found",
+ "Recording not found");
+ return;
+ }
+
+ format = ast_get_format_for_file_ext(stasis_app_stored_recording_get_extension(recording));
+ if (!format) {
+ ast_ari_response_error(response, 500, "Internal Server Error",
+ "Format specified by recording not available or loaded");
+ return;
+ }
+
+ response->fd = open(stasis_app_stored_recording_get_filename(recording), O_RDONLY);
+ if (response->fd < 0) {
+ ast_ari_response_error(response, 403, "Forbidden",
+ "Recording could not be opened");
+ return;
+ }
+
+ ast_str_append(&response->headers, 0, "Content-Type: %s/%s\r\n",
+ format_type_names[ast_format_get_type(format)],
+ stasis_app_stored_recording_get_extension(recording));
+ ast_ari_response_ok(response, ast_json_null());
+}
+
void ast_ari_recordings_copy_stored(struct ast_variable *headers,
struct ast_ari_recordings_copy_stored_args *args,
struct ast_ari_response *response)
diff --git a/res/ari/resource_recordings.h b/res/ari/resource_recordings.h
index 196122f44..1bc93c527 100644
--- a/res/ari/resource_recordings.h
+++ b/res/ari/resource_recordings.h
@@ -76,6 +76,20 @@ struct ast_ari_recordings_delete_stored_args {
* \param[out] response HTTP response
*/
void ast_ari_recordings_delete_stored(struct ast_variable *headers, struct ast_ari_recordings_delete_stored_args *args, struct ast_ari_response *response);
+/*! Argument struct for ast_ari_recordings_get_stored_file() */
+struct ast_ari_recordings_get_stored_file_args {
+ /*! The name of the recording */
+ const char *recording_name;
+};
+/*!
+ * \brief Get the file associated with the stored recording.
+ *
+ * \param ser TCP/TLS session instance
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void ast_ari_recordings_get_stored_file(struct ast_tcptls_session_instance *ser, struct ast_variable *headers, struct ast_ari_recordings_get_stored_file_args *args, struct ast_ari_response *response);
/*! Argument struct for ast_ari_recordings_copy_stored() */
struct ast_ari_recordings_copy_stored_args {
/*! The name of the recording to copy */