From b34502af8247606ae3b5693cd3046566b16a3e6d Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Fri, 8 Jul 2011 08:38:17 +0000 Subject: Refactor http utilities svn path=/trunk/netsurf/; revision=12595 --- content/content_factory.c | 46 +++++++++++----------------------------------- content/content_factory.h | 2 +- content/hlcache.c | 11 ++++------- 3 files changed, 16 insertions(+), 43 deletions(-) (limited to 'content') diff --git a/content/content_factory.c b/content/content_factory.c index ae226a4d1..0b9d44b7d 100644 --- a/content/content_factory.c +++ b/content/content_factory.c @@ -128,24 +128,16 @@ static const content_handler *content_lookup(lwc_string *mime_type) * \param mime_type MIME type to consider * \return Generic content type */ -content_type content_factory_type_from_mime_type(const char *mime_type) +content_type content_factory_type_from_mime_type(lwc_string *mime_type) { const content_handler *handler; - lwc_string *imime_type; - lwc_error lerror; content_type type = CONTENT_NONE; - lerror = lwc_intern_string(mime_type, strlen(mime_type), &imime_type); - if (lerror != lwc_error_ok) - return CONTENT_NONE; - - handler = content_lookup(imime_type); + handler = content_lookup(mime_type); if (handler != NULL) { - type = handler->type(imime_type); + type = handler->type(mime_type); } - lwc_string_unref(imime_type); - return type; } @@ -163,10 +155,7 @@ struct content *content_factory_create_content(llcache_handle *llcache, struct content *c; const char *content_type_header; const content_handler *handler; - char *mime_type; - http_parameter *params; - lwc_string *imime_type; - lwc_error lerr; + http_content_type *ct; nserror error; content_type_header = @@ -174,39 +163,26 @@ struct content *content_factory_create_content(llcache_handle *llcache, if (content_type_header == NULL) content_type_header = "text/plain"; - error = http_parse_content_type(content_type_header, &mime_type, - ¶ms); + error = http_parse_content_type(content_type_header, &ct); if (error != NSERROR_OK) return NULL; - lerr = lwc_intern_string(mime_type, strlen(mime_type), &imime_type); - if (lerr != lwc_error_ok) { - http_parameter_list_destroy(params); - free(mime_type); - return NULL; - } - - free(mime_type); - - handler = content_lookup(imime_type); + handler = content_lookup(ct->media_type); if (handler == NULL) { - lwc_string_unref(imime_type); - http_parameter_list_destroy(params); + http_content_type_destroy(ct); return NULL; } assert(handler->create != NULL); - error = handler->create(handler, imime_type, params, llcache, - fallback_charset, quirks, &c); + error = handler->create(handler, ct->media_type, ct->parameters, + llcache, fallback_charset, quirks, &c); if (error != NSERROR_OK) { - lwc_string_unref(imime_type); - http_parameter_list_destroy(params); + http_content_type_destroy(ct); return NULL; } - lwc_string_unref(imime_type); - http_parameter_list_destroy(params); + http_content_type_destroy(ct); return c; } diff --git a/content/content_factory.h b/content/content_factory.h index aff7a64ac..f6ea3ce49 100644 --- a/content/content_factory.h +++ b/content/content_factory.h @@ -39,6 +39,6 @@ nserror content_factory_register_handler(lwc_string *mime_type, struct content *content_factory_create_content(struct llcache_handle *llcache, const char *fallback_charset, bool quirks); -content_type content_factory_type_from_mime_type(const char *mime_type); +content_type content_factory_type_from_mime_type(lwc_string *mime_type); #endif diff --git a/content/hlcache.c b/content/hlcache.c index b684ed01c..40b6486c9 100644 --- a/content/hlcache.c +++ b/content/hlcache.c @@ -541,8 +541,7 @@ bool hlcache_type_is_acceptable(llcache_handle *llcache, content_type accepted_types, content_type *computed_type) { const char *content_type_header; - char *mime_type; - http_parameter *params; + http_content_type *ct; content_type type; nserror error; @@ -551,15 +550,13 @@ bool hlcache_type_is_acceptable(llcache_handle *llcache, if (content_type_header == NULL) content_type_header = "text/plain"; - error = http_parse_content_type(content_type_header, &mime_type, - ¶ms); + error = http_parse_content_type(content_type_header, &ct); if (error != NSERROR_OK) return false; - type = content_factory_type_from_mime_type(mime_type); + type = content_factory_type_from_mime_type(ct->media_type); - free(mime_type); - http_parameter_list_destroy(params); + http_content_type_destroy(ct); *computed_type = type; -- cgit v1.2.3