[Asterisk-code-review] res_http_media_cache.c: Compare unaltered MIME types. (asterisk[18])
Friendly Automation
asteriskteam at digium.com
Tue Sep 21 13:11:19 CDT 2021
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/16504 )
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(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Boris P. Korzun: Looks good to me, but someone else must approve
Friendly Automation: Approved for Submit
diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c
index 5410566..12e7aee 100644
--- a/res/res_http_media_cache.c
+++ b/res/res_http_media_cache.c
@@ -181,8 +181,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, ';');
@@ -191,7 +193,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)
@@ -203,28 +225,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/+/16504
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I2963c8ecbb3a9605b78b6421c415108d77a66a0f
Gerrit-Change-Number: 16504
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-Reviewer: Boris P. Korzun <drtr0jan at yandex.ru>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210921/87410dfc/attachment.html>
More information about the asterisk-code-review
mailing list