diff options
author | Jorge Arellano Cid <jcid@dillo.org> | 2009-01-23 16:53:57 -0300 |
---|---|---|
committer | Jorge Arellano Cid <jcid@dillo.org> | 2009-01-23 16:53:57 -0300 |
commit | 37e9c1e7d1dbf66ee78189c2775922f8360c0e60 (patch) | |
tree | 863a464788c939466a7b561eeaaa42759fe958db | |
parent | 9df15efd4e1e782f406f1f045361c50cd615759e (diff) |
Cleanup and logic change in a_Cache_set_content_type().
-rw-r--r-- | src/cache.c | 35 | ||||
-rw-r--r-- | src/cache.h | 3 | ||||
-rw-r--r-- | src/capi.c | 5 | ||||
-rw-r--r-- | src/capi.h | 3 | ||||
-rw-r--r-- | src/html.cc | 2 |
5 files changed, 27 insertions, 21 deletions
diff --git a/src/cache.c b/src/cache.c index 8fd9f524..7c16807b 100644 --- a/src/cache.c +++ b/src/cache.c @@ -483,9 +483,11 @@ static Dstr *Cache_data(CacheEntry_t *entry) /* * Change Content-Type for cache entry found by url. + * from = { "http" | "meta" } * Return new content type. */ -const char *a_Cache_set_content_type(const DilloUrl *url, const char *ctype) +const char *a_Cache_set_content_type(const DilloUrl *url, const char *ctype, + const char *from) { char *charset; const char *curr; @@ -496,11 +498,11 @@ const char *a_Cache_set_content_type(const DilloUrl *url, const char *ctype) _MSG("a_Cache_set_content_type {%s} {%s}\n", ctype, URL_STR(url)); curr = Cache_current_content_type(entry); - if (entry->TypeMeta) { - /* Type is already been set. Do nothing. META overrides TypeHdr. - * Multiple META elements? */ + if (entry->TypeMeta || (*from == 'h' && entry->TypeHdr) ) { + /* Type is already been set. Do nothing. + * BTW, META overrides TypeHdr */ } else { - if (!entry->TypeHdr) { + if (*from == 'h') { /* Content-Type from HTTP header */ entry->TypeHdr = dStrdup(ctype); } else { @@ -509,17 +511,18 @@ const char *a_Cache_set_content_type(const DilloUrl *url, const char *ctype) } if (a_Misc_content_type_cmp(curr, ctype)) { /* ctype gives one different from current */ - if (entry->CharsetDecoder) - a_Decode_free(entry->CharsetDecoder); a_Misc_parse_content_type(ctype, NULL, NULL, &charset); - entry->CharsetDecoder = a_Decode_charset_init(charset); - dFree(charset); - curr = Cache_current_content_type(entry); - - /* Invalidate UTF8Data */ - dStr_free(entry->UTF8Data, 1); - entry->UTF8Data = NULL; - + if (charset) { + if (entry->CharsetDecoder) + a_Decode_free(entry->CharsetDecoder); + entry->CharsetDecoder = a_Decode_charset_init(charset); + dFree(charset); + curr = Cache_current_content_type(entry); + + /* Invalidate UTF8Data */ + dStr_free(entry->UTF8Data, 1); + entry->UTF8Data = NULL; + } } } return curr; @@ -757,7 +760,7 @@ static void Cache_parse_header(CacheEntry_t *entry) } else { /* This HTTP Content-Type is not trusted. It's checked against real data * in Cache_process_queue(); only then CA_GotContentType becomes true. */ - a_Cache_set_content_type(entry->Url, Type); + a_Cache_set_content_type(entry->Url, Type, "http"); _MSG("TypeHdr {%s} {%s}\n", Type, URL_STR(entry->Url)); _MSG("TypeMeta {%s}\n", entry->TypeMeta); dFree(Type); diff --git a/src/cache.h b/src/cache.h index 81b9c1ec..bbcb9a22 100644 --- a/src/cache.h +++ b/src/cache.h @@ -62,7 +62,8 @@ int a_Cache_open_url(void *Web, CA_Callback_t Call, void *CbData); int a_Cache_get_buf(const DilloUrl *Url, char **PBuf, int *BufSize); void a_Cache_unref_buf(const DilloUrl *Url); const char *a_Cache_get_content_type(const DilloUrl *url); -const char *a_Cache_set_content_type(const DilloUrl *url, const char *ctype); +const char *a_Cache_set_content_type(const DilloUrl *url, const char *ctype, + const char *from); uint_t a_Cache_get_flags(const DilloUrl *url); void a_Cache_process_dbuf(int Op, const char *buf, size_t buf_size, const DilloUrl *Url); @@ -421,9 +421,10 @@ const char *a_Capi_get_content_type(const DilloUrl *url) /* * Set the Content-Type for the URL. */ -const char *a_Capi_set_content_type(const DilloUrl *url, const char *ctype) +const char *a_Capi_set_content_type(const DilloUrl *url, const char *ctype, + const char *from) { - return a_Cache_set_content_type(url, ctype); + return a_Cache_set_content_type(url, ctype, from); } /* @@ -26,7 +26,8 @@ int a_Capi_open_url(DilloWeb *web, CA_Callback_t Call, void *CbData); int a_Capi_get_buf(const DilloUrl *Url, char **PBuf, int *BufSize); void a_Capi_unref_buf(const DilloUrl *Url); const char *a_Capi_get_content_type(const DilloUrl *url); -const char *a_Capi_set_content_type(const DilloUrl *url, const char *ctype); +const char *a_Capi_set_content_type(const DilloUrl *url, const char *ctype, + const char *from); int a_Capi_get_flags(const DilloUrl *Url); int a_Capi_dpi_send_cmd(DilloUrl *url, void *bw, char *cmd, char *server, int flags); diff --git a/src/html.cc b/src/html.cc index a8d10a47..0007ea9f 100644 --- a/src/html.cc +++ b/src/html.cc @@ -2778,7 +2778,7 @@ static void Html_tag_open_meta(DilloHtml *html, const char *tag, int tagsize) /* Cannot ask cache whether the content type was changed, as * this code in another bw might have already changed it for us. */ - new_content = a_Capi_set_content_type(html->page_url, content); + new_content = a_Capi_set_content_type(html->page_url,content,"meta"); if (a_Misc_content_type_cmp(html->content_type, new_content)) { html->stop_parser = true; /* Avoid a race condition */ html->repush_after_head = true; |