diff options
author | Matt Jordan <mjordan@digium.com> | 2016-05-18 06:19:58 -0500 |
---|---|---|
committer | Matt Jordan <mjordan@digium.com> | 2016-05-20 09:06:12 -0500 |
commit | e773e3a9bbaf378d53647e4bac3ffcd61afb4ae6 (patch) | |
tree | 23e75dcdaf9b8c72a23387bfabdd42f643e5c480 /res/ari/resource_recordings.c | |
parent | d4b77dad1b0154eb3b89133d941dd8d624deda54 (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/resource_recordings.c')
-rw-r--r-- | res/ari/resource_recordings.c | 44 |
1 files changed, 44 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) |