<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16505">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_http_media_cache.c: Compare unaltered MIME types.<br><br>Rather than stripping parameters from Content-Type headers before<br>comparison, first try to compare the whole string. If no match is<br>found, strip the parameters and try that way.<br><br>ASTERISK-29275 #close<br><br>Change-Id: I2963c8ecbb3a9605b78b6421c415108d77a66a0f<br>---<br>M res/res_http_media_cache.c<br>1 file changed, 30 insertions(+), 16 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/05/16505/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c</span><br><span>index 9f560c7..c0363b1 100644</span><br><span>--- a/res/res_http_media_cache.c</span><br><span>+++ b/res/res_http_media_cache.c</span><br><span>@@ -176,8 +176,10 @@</span><br><span> * \brief Normalize the value of a Content-Type header</span><br><span> *</span><br><span> * This will trim off any optional parameters after the type/subtype.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return 0 if no normalization occurred, otherwise true (non-zero)</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">-static void normalize_content_type_header(char *content_type)</span><br><span style="color: hsl(120, 100%, 40%);">+static int normalize_content_type_header(char *content_type)</span><br><span> {</span><br><span> char *params = strchr(content_type, ';');</span><br><span> </span><br><span>@@ -186,7 +188,27 @@</span><br><span> while (params > content_type && (*params == ' ' || *params == '\t')) {</span><br><span> *params-- = 0;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int derive_extension_from_mime_type(const char *mime_type, char *buffer, size_t capacity)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Compare the provided Content-Type directly, parameters and all */</span><br><span style="color: hsl(120, 100%, 40%);">+ res = ast_get_extension_for_mime_type(mime_type, buffer, sizeof(buffer));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!res) {</span><br><span style="color: hsl(120, 100%, 40%);">+ char *m = ast_strdupa(mime_type);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Strip MIME type parameters and then check */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (normalize_content_type_header(m)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ res = ast_get_extension_for_mime_type(m, buffer, sizeof(buffer));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return res;</span><br><span> }</span><br><span> </span><br><span> static char *file_extension_from_content_type(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity)</span><br><span>@@ -198,28 +220,20 @@</span><br><span> * corresponding to the mime-type and use that to rename the file */</span><br><span> </span><br><span> struct ast_bucket_metadata *header;</span><br><span style="color: hsl(0, 100%, 40%);">- char *mime_type;</span><br><span> </span><br><span> header = ast_bucket_file_metadata_get(bucket_file, "content-type");</span><br><span> if (!header) {</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- mime_type = ast_strdup(header->value);</span><br><span style="color: hsl(0, 100%, 40%);">- if (mime_type) {</span><br><span style="color: hsl(0, 100%, 40%);">- normalize_content_type_header(mime_type);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!ast_strlen_zero(mime_type)) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_get_extension_for_mime_type(mime_type, buffer, sizeof(buffer))) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(3, "Derived extension '%s' from MIME type %s\n",</span><br><span style="color: hsl(0, 100%, 40%);">- buffer,</span><br><span style="color: hsl(0, 100%, 40%);">- mime_type);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(mime_type);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(header, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- return buffer;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (derive_extension_from_mime_type(header->value, buffer, capacity)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(3, "Derived extension '%s' from MIME type %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ buffer,</span><br><span style="color: hsl(120, 100%, 40%);">+ header->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(header, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ return buffer;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(mime_type);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ao2_ref(header, -1);</span><br><span> </span><br><span> return NULL;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16505">change 16505</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16505"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 19 </div>
<div style="display:none"> Gerrit-Change-Id: I2963c8ecbb3a9605b78b6421c415108d77a66a0f </div>
<div style="display:none"> Gerrit-Change-Number: 16505 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>