mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-29 18:19:30 +00:00
Add the ability to read the media file type from HTTP header for playback
How it works today: media_cache tries to parse out the extension of the media file to be played from the URI provided to Asterisk while caching the file. What's expected: Better will be to have Asterisk get extension from other ways too. One of the common ways is to get the type of content from the CONTENT-TYPE header in the HTTP response for fetching the media file using the URI provided. Steps to Reproduce: Provide a URL of the form: http://host/media/1234 to Asterisk for media playback. It fails to play and logs show the following error line: [Sep 15 15:48:05] WARNING [29148] [C-00000092] file.c: File http://host/media/1234 does not exist in any format Scenario this issue is blocking: In the case where the media files are stored in some cloud object store, following can block the media being played via Asterisk: Cloud storage generally needs authenticated access to the storage. The way to do that is by using signed URIs. With the signed URIs there's no way to preserve the name of the file. In most cases Cloud storage returns a key to access the object and preserving file name is also not a thing there ASTERISK-27286 Reporter: Gaurav Khurana Change-Id: I1b14692a49b2c1ac67688f58757184122e92ba89
This commit is contained in:
committed by
Sean Bright
parent
f633af89c1
commit
0827d5cc53
@@ -35,6 +35,7 @@
|
||||
#include "asterisk/bucket.h"
|
||||
#include "asterisk/astdb.h"
|
||||
#include "asterisk/cli.h"
|
||||
#include "asterisk/file.h"
|
||||
#include "asterisk/media_cache.h"
|
||||
|
||||
/*! The name of the AstDB family holding items in the cache. */
|
||||
@@ -123,6 +124,24 @@ static void media_cache_item_del_from_astdb(struct ast_bucket_file *bucket_file)
|
||||
ast_free(hash_value);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
* \brief Normalize the value of a Content-Type header
|
||||
*
|
||||
* This will trim off any optional parameters after the type/subtype.
|
||||
*/
|
||||
static void normalize_content_type_header(char *content_type)
|
||||
{
|
||||
char *params = strchr(content_type, ';');
|
||||
|
||||
if (params) {
|
||||
*params-- = 0;
|
||||
while (params > content_type && (*params == ' ' || *params == '\t')) {
|
||||
*params-- = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
* \brief Update the name of the file backing a \c bucket_file
|
||||
@@ -142,9 +161,32 @@ static void bucket_file_update_path(struct ast_bucket_file *bucket_file,
|
||||
} else if (!strchr(bucket_file->path, '.') && (ext = strrchr(ast_sorcery_object_get_id(bucket_file), '.'))) {
|
||||
/* If we don't have a file extension and were provided one in the URI, use it */
|
||||
char new_path[PATH_MAX];
|
||||
char found_ext[PATH_MAX];
|
||||
|
||||
ast_bucket_file_metadata_set(bucket_file, "ext", ext);
|
||||
|
||||
/* Don't pass '.' while checking for supported extension */
|
||||
if (!ast_get_format_for_file_ext(ext + 1)) {
|
||||
/* If the file extension passed in the URI isn't supported check for the
|
||||
* extension based on the MIME type passed in the Content-Type header before
|
||||
* giving up.
|
||||
* If a match is found then retrieve the extension from the supported list
|
||||
* corresponding to the mime-type and use that to rename the file */
|
||||
struct ast_bucket_metadata *header = ast_bucket_file_metadata_get(bucket_file, "content-type");
|
||||
if (header) {
|
||||
char *mime_type = ast_strdup(header->value);
|
||||
if (mime_type) {
|
||||
normalize_content_type_header(mime_type);
|
||||
if (!ast_strlen_zero(mime_type)) {
|
||||
if (ast_get_extension_for_mime_type(mime_type, found_ext, sizeof(found_ext))) {
|
||||
ext = found_ext;
|
||||
}
|
||||
}
|
||||
ast_free(mime_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(new_path, sizeof(new_path), "%s%s", bucket_file->path, ext);
|
||||
rename(bucket_file->path, new_path);
|
||||
ast_copy_string(bucket_file->path, new_path, sizeof(bucket_file->path));
|
||||
|
Reference in New Issue
Block a user