Mercurial > dillo_port1.3
changeset 814:3e06388a0bc3
Cleanup and logic change in a_Cache_set_content_type().
author | Jorge Arellano Cid <jcid@dillo.org> |
---|---|
date | Fri, 23 Jan 2009 16:53:57 -0300 |
parents | 7437a4d4928d |
children | e8d905aef58f |
files | src/cache.c src/cache.h src/capi.c src/capi.h src/html.cc |
diffstat | 5 files changed, 27 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cache.c Fri Jan 23 16:50:20 2009 -0300 +++ b/src/cache.c Fri Jan 23 16:53:57 2009 -0300 @@ -483,9 +483,11 @@ /* * 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 @@ _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 @@ } 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 @@ } 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);
--- a/src/cache.h Fri Jan 23 16:50:20 2009 -0300 +++ b/src/cache.h Fri Jan 23 16:53:57 2009 -0300 @@ -62,7 +62,8 @@ 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);
--- a/src/capi.c Fri Jan 23 16:50:20 2009 -0300 +++ b/src/capi.c Fri Jan 23 16:53:57 2009 -0300 @@ -421,9 +421,10 @@ /* * 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); } /*
--- a/src/capi.h Fri Jan 23 16:50:20 2009 -0300 +++ b/src/capi.h Fri Jan 23 16:53:57 2009 -0300 @@ -26,7 +26,8 @@ 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);
--- a/src/html.cc Fri Jan 23 16:50:20 2009 -0300 +++ b/src/html.cc Fri Jan 23 16:53:57 2009 -0300 @@ -2778,7 +2778,7 @@ /* 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;