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
This commit is contained in:
Matt Jordan
2016-05-18 06:19:58 -05:00
parent d4b77dad1b
commit e773e3a9bb
12 changed files with 235 additions and 5 deletions

View File

@@ -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)

View File

@@ -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 */