changeset 1077:17688e07a8b7

separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
author corvid, Jorge Arellano Cid
date Wed, 06 May 2009 23:43:52 +0000
parents 0dc447948944
children fdcb2ef163c0
files src/cache.c src/cache.h src/capi.c src/capi.h src/html.cc
diffstat 5 files changed, 42 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/cache.c	Wed May 06 22:23:40 2009 +0000
+++ b/src/cache.c	Wed May 06 23:43:52 2009 +0000
@@ -414,6 +414,15 @@
  */
 uint_t a_Cache_get_flags(const DilloUrl *url)
 {
+   CacheEntry_t *entry = Cache_entry_search(url);
+   return (entry ? entry->Flags : 0);
+}
+
+/*
+ * Get cache entry status (following redirections).
+ */
+uint_t a_Cache_get_flags_with_redirection(const DilloUrl *url)
+{
    CacheEntry_t *entry = Cache_entry_search_with_redirect(url);
    return (entry ? entry->Flags : 0);
 }
--- a/src/cache.h	Wed May 06 22:23:40 2009 +0000
+++ b/src/cache.h	Wed May 06 23:43:52 2009 +0000
@@ -65,6 +65,7 @@
 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);
+uint_t a_Cache_get_flags_with_redirection(const DilloUrl *url);
 void a_Cache_process_dbuf(int Op, const char *buf, size_t buf_size,
                           const DilloUrl *Url);
 void a_Cache_entry_inject(const DilloUrl *Url, Dstr *data_ds);
--- a/src/capi.c	Wed May 06 22:23:40 2009 +0000
+++ b/src/capi.c	Wed May 06 23:43:52 2009 +0000
@@ -314,7 +314,7 @@
    if (web->flags & WEB_Download) {
      /* download request: if cached save from cache, else
       * for http, ftp or https, use the downloads dpi */
-     if (a_Capi_get_flags(web->url) & CAPI_IsCached) {
+     if (a_Capi_get_flags_with_redirection(web->url) & CAPI_IsCached) {
         if (web->filename) {
            if ((web->stream = fopen(web->filename, "w"))) {
               use_cache = 1;
@@ -376,12 +376,11 @@
 }
 
 /*
- * Return status information of an URL's content-transfer process.
+ * Convert cache-defined flags to Capi ones.
  */
-int a_Capi_get_flags(const DilloUrl *Url)
+static int Capi_map_cache_flags(uint_t flags)
 {
    int status = 0;
-   uint_t flags = a_Cache_get_flags(Url);
 
    if (flags) {
       status |= CAPI_IsCached;
@@ -398,6 +397,26 @@
 }
 
 /*
+ * Return status information of an URL's content-transfer process.
+ */
+int a_Capi_get_flags(const DilloUrl *Url)
+{
+   uint_t flags = a_Cache_get_flags(Url);
+   int status = flags ? Capi_map_cache_flags(flags) : 0;
+   return status;
+}
+
+/*
+ * Same as a_Capi_get_flags() but following redirections.
+ */
+int a_Capi_get_flags_with_redirection(const DilloUrl *Url)
+{
+   uint_t flags = a_Cache_get_flags_with_redirection(Url);
+   int status = flags ? Capi_map_cache_flags(flags) : 0;
+   return status;
+}
+
+/*
  * Get the cache's buffer for the URL, and its size.
  * Return: 1 cached, 0 not cached.
  */
--- a/src/capi.h	Wed May 06 22:23:40 2009 +0000
+++ b/src/capi.h	Wed May 06 23:43:52 2009 +0000
@@ -29,6 +29,7 @@
 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_get_flags_with_redirection(const DilloUrl *Url);
 int a_Capi_dpi_send_cmd(DilloUrl *url, void *bw, char *cmd, char *server,
                          int flags);
 void a_Capi_stop_client(int Key, int force);
--- a/src/html.cc	Wed May 06 22:23:40 2009 +0000
+++ b/src/html.cc	Wed May 06 23:43:52 2009 +0000
@@ -1805,9 +1805,11 @@
 
    src = dStrdup(attrbuf);
 
-   if (a_Capi_get_flags(url) & CAPI_IsCached) { /* visited frame */
+   if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
+      /* visited frame */
       html->styleEngine->setPseudoVisited ();
-   } else {                                    /* unvisited frame */
+   } else {
+      /* unvisited frame */
       html->styleEngine->setPseudoLink ();
    }
 
@@ -2067,7 +2069,7 @@
       Image->bg_color = DW2TB(html->dw)->getBgColor()->getColor();
 
    load_now = prefs.load_images ||
-              (a_Capi_get_flags(url) & CAPI_IsCached);
+              (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached);
    Html_add_new_linkimage(html, &url, load_now ? NULL : Image);
    if (load_now)
       Html_load_image(html->bw, url, Image);
@@ -2312,7 +2314,7 @@
                            URL_STR(base_url), (base_url != NULL));
       dReturn_if_fail ( url != NULL );
 
-      if (a_Capi_get_flags(url) & CAPI_IsCached) {
+      if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
          html->styleEngine->setPseudoVisited ();
       } else {
          html->styleEngine->setPseudoLink ();
@@ -2389,7 +2391,7 @@
       url = a_Html_url_new(html, attrbuf, NULL, 0);
       dReturn_if_fail ( url != NULL );
 
-      if (a_Capi_get_flags(url) & CAPI_IsCached) {
+      if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
          html->InVisitedLink = true;
          html->styleEngine->setPseudoVisited ();
          if (html->non_css_visited_color != -1)
@@ -2883,7 +2885,7 @@
    _MSG("Html_load_stylesheet: ");
    if (a_Capi_get_buf(url, &data, &len)) {
       _MSG("cached URL=%s len=%d", URL_STR(url), len);
-      if (a_Capi_get_flags(url) & CAPI_Completed)
+      if (a_Capi_get_flags_with_redirection(url) & CAPI_Completed)
          html->styleEngine->parse(html, url, data, len, CSS_ORIGIN_AUTHOR);
       a_Capi_unref_buf(url);
    } else {