reduce hlcache handle api usage in mimesniff

This commit is contained in:
Vincent Sanders 2017-03-19 22:29:23 +00:00
parent 93e2b4855b
commit 0866314d96
4 changed files with 12 additions and 13 deletions

View File

@ -125,12 +125,14 @@ static const content_handler *content_lookup(lwc_string *mime_type)
for (entry = content_handlers; entry != NULL; entry = entry->next) {
if (lwc_string_caseless_isequal(mime_type, entry->mime_type,
&match) == lwc_error_ok && match)
&match) == lwc_error_ok && match) {
break;
}
}
if (entry != NULL)
if (entry != NULL) {
return entry->handler;
}
return NULL;
}

View File

@ -421,7 +421,7 @@ static nserror hlcache_llcache_callback(llcache_handle *handle,
switch (event->type) {
case LLCACHE_EVENT_HAD_HEADERS:
error = mimesniff_compute_effective_type(handle, NULL, 0,
error = mimesniff_compute_effective_type(llcache_handle_get_header(handle, "Content-Type"), NULL, 0,
ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE,
ctx->accepted_types == CONTENT_IMAGE,
&effective_type);
@ -444,7 +444,7 @@ static nserror hlcache_llcache_callback(llcache_handle *handle,
break;
case LLCACHE_EVENT_HAD_DATA:
error = mimesniff_compute_effective_type(handle,
error = mimesniff_compute_effective_type(llcache_handle_get_header(handle, "Content-Type"),
event->data.data.buf, event->data.data.len,
ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE,
ctx->accepted_types == CONTENT_IMAGE,
@ -463,7 +463,7 @@ static nserror hlcache_llcache_callback(llcache_handle *handle,
case LLCACHE_EVENT_DONE:
/* DONE event before we could determine the effective MIME type.
*/
error = mimesniff_compute_effective_type(handle,
error = mimesniff_compute_effective_type(llcache_handle_get_header(handle, "Content-Type"),
NULL, 0, false, false, &effective_type);
if (error == NSERROR_OK || error == NSERROR_NOT_FOUND) {
error = hlcache_migrate_ctx(ctx, effective_type);

View File

@ -31,7 +31,6 @@
#include "utils/corestrings.h"
#include "content/content_factory.h"
#include "content/llcache.h"
#include "content/mimesniff.h"
struct map_s {
@ -547,7 +546,7 @@ static nserror mimesniff__compute_feed_or_html(const uint8_t *data,
}
/* See mimesniff.h for documentation */
nserror mimesniff_compute_effective_type(llcache_handle *handle,
nserror mimesniff_compute_effective_type(const char *content_type_header,
const uint8_t *data, size_t len, bool sniff_allowed,
bool image_only, lwc_string **effective_type)
{
@ -564,18 +563,16 @@ nserror mimesniff_compute_effective_type(llcache_handle *handle,
};
#undef S
const char *content_type_header;
size_t content_type_header_len;
http_content_type *ct;
const struct tt_s *tt;
bool match;
nserror error;
content_type_header =
llcache_handle_get_header(handle, "Content-Type");
if (content_type_header == NULL) {
if (sniff_allowed == false)
if (sniff_allowed == false) {
return NSERROR_NOT_FOUND;
}
/* No official type => unknown */
return mimesniff__compute_unknown(data, len, effective_type);

View File

@ -37,7 +37,7 @@ struct llcache_handle;
* The implementation uses the sniffing algorithm described in
* http://mimesniff.spec.whatwg.org/
*
* \param handle Source data handle to sniff
* \param content_type_header Source content type header
* \param data First data chunk, or NULL
* \param len Length of \a data, in bytes
* \param sniff_allowed Whether MIME type sniffing is allowed
@ -48,7 +48,7 @@ struct llcache_handle;
* NSERROR_NOT_FOUND if sniffing is prohibited and no
* Content-Type header was found
*/
nserror mimesniff_compute_effective_type(struct llcache_handle *handle,
nserror mimesniff_compute_effective_type(const char *content_type_header,
const uint8_t *data, size_t len, bool sniff_allowed,
bool image_only, lwc_string **effective_type);