From 0866314d9675c09b4b3d0db9e777f132b7c0aae7 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 19 Mar 2017 22:29:23 +0000 Subject: [PATCH] reduce hlcache handle api usage in mimesniff --- content/content_factory.c | 6 ++++-- content/hlcache.c | 6 +++--- content/mimesniff.c | 9 +++------ content/mimesniff.h | 4 ++-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/content/content_factory.c b/content/content_factory.c index 224220796..935354a5d 100644 --- a/content/content_factory.c +++ b/content/content_factory.c @@ -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; } diff --git a/content/hlcache.c b/content/hlcache.c index 95edd2120..731c0bbb7 100644 --- a/content/hlcache.c +++ b/content/hlcache.c @@ -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); diff --git a/content/mimesniff.c b/content/mimesniff.c index 832320086..68f3fbd8e 100644 --- a/content/mimesniff.c +++ b/content/mimesniff.c @@ -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); diff --git a/content/mimesniff.h b/content/mimesniff.h index 474f7b87f..faecab865 100644 --- a/content/mimesniff.h +++ b/content/mimesniff.h @@ -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);