[Asterisk-code-review] res_http_media_cache.c: Compare unaltered MIME types. (asterisk[19])
Sean Bright
asteriskteam at digium.com
Thu Sep 16 12:40:49 CDT 2021
Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/16505 )
Change subject: res_http_media_cache.c: Compare unaltered MIME types.
......................................................................
res_http_media_cache.c: Compare unaltered MIME types.
Rather than stripping parameters from Content-Type headers before
comparison, first try to compare the whole string. If no match is
found, strip the parameters and try that way.
ASTERISK-29275 #close
Change-Id: I2963c8ecbb3a9605b78b6421c415108d77a66a0f
---
M res/res_http_media_cache.c
1 file changed, 30 insertions(+), 16 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/05/16505/1
diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c
index 9f560c7..c0363b1 100644
--- a/res/res_http_media_cache.c
+++ b/res/res_http_media_cache.c
@@ -176,8 +176,10 @@
* \brief Normalize the value of a Content-Type header
*
* This will trim off any optional parameters after the type/subtype.
+ *
+ * \return 0 if no normalization occurred, otherwise true (non-zero)
*/
-static void normalize_content_type_header(char *content_type)
+static int normalize_content_type_header(char *content_type)
{
char *params = strchr(content_type, ';');
@@ -186,7 +188,27 @@
while (params > content_type && (*params == ' ' || *params == '\t')) {
*params-- = 0;
}
+ return 1;
}
+
+ return 0;
+}
+
+static int derive_extension_from_mime_type(const char *mime_type, char *buffer, size_t capacity)
+{
+ int res = 0;
+
+ /* Compare the provided Content-Type directly, parameters and all */
+ res = ast_get_extension_for_mime_type(mime_type, buffer, sizeof(buffer));
+ if (!res) {
+ char *m = ast_strdupa(mime_type);
+ /* Strip MIME type parameters and then check */
+ if (normalize_content_type_header(m)) {
+ res = ast_get_extension_for_mime_type(m, buffer, sizeof(buffer));
+ }
+ }
+
+ return res;
}
static char *file_extension_from_content_type(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity)
@@ -198,28 +220,20 @@
* corresponding to the mime-type and use that to rename the file */
struct ast_bucket_metadata *header;
- char *mime_type;
header = ast_bucket_file_metadata_get(bucket_file, "content-type");
if (!header) {
return NULL;
}
- 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, buffer, sizeof(buffer))) {
- ast_debug(3, "Derived extension '%s' from MIME type %s\n",
- buffer,
- mime_type);
- ast_free(mime_type);
- ao2_ref(header, -1);
- return buffer;
- }
- }
+ if (derive_extension_from_mime_type(header->value, buffer, capacity)) {
+ ast_debug(3, "Derived extension '%s' from MIME type %s\n",
+ buffer,
+ header->value);
+ ao2_ref(header, -1);
+ return buffer;
}
- ast_free(mime_type);
+
ao2_ref(header, -1);
return NULL;
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16505
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 19
Gerrit-Change-Id: I2963c8ecbb3a9605b78b6421c415108d77a66a0f
Gerrit-Change-Number: 16505
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210916/2d5f96ff/attachment-0001.html>
More information about the asterisk-code-review
mailing list