changeset 156:14f50d7607ed

- Added a_Capi_get_flags(). It requests a cache entry's status as flags.
author jcid
date Wed, 26 Mar 2008 15:46:46 +0100
parents fb8da086d7da
children 49d4a18c4928
files ChangeLog src/cache.c src/cache.h src/capi.c src/capi.h src/html.cc src/jpeg.c
diffstat 7 files changed, 102 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Mar 24 22:56:22 2008 +0100
+++ b/ChangeLog	Wed Mar 26 15:46:46 2008 +0100
@@ -91,6 +91,7 @@
  - Added shortcuts: PgDn=Spc, PgUp=b, Back=BackSpace, Forw=Shift+Backspace.
  - Made a cleanup in cache's parse header code.
  - Added support for "charset" in the META element.
+ - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
    Patch: place, Jorge Arellano Cid
 +- Fixed a va_list-related SEGFAULT on 64bit-arch in dStr_vsprintfa().
    Added const declarations in html parser.
--- a/src/cache.c	Mon Mar 24 22:56:22 2008 +0100
+++ b/src/cache.c	Wed Mar 26 15:46:46 2008 +0100
@@ -209,7 +209,7 @@
    NewEntry->ContentDecoder = NULL;
    NewEntry->ExpectedSize = 0;
    NewEntry->TransferSize = 0;
-   NewEntry->Flags = 0;
+   NewEntry->Flags = CA_IsEmpty;
 }
 
 /*
@@ -222,6 +222,30 @@
 }
 
 /*
+ * Given a URL, find its cache entry, following redirections.
+ */
+static CacheEntry_t *Cache_entry_search_with_redirect(const DilloUrl *Url)
+{
+   int i;
+   CacheEntry_t *entry;
+
+   for (i = 0; (entry = Cache_entry_search(Url)); ++i) {
+
+      /* Test for a redirection loop */
+      if (entry->Flags & CA_RedirectLoop || i == 3) {
+         _MSG_WARN("Redirect loop for URL: >%s<\n", URL_STR_(Url));
+         break;
+      }
+      /* Test for a working redirection */
+      if (entry && entry->Flags & CA_Redirect && entry->Location) {
+         Url = entry->Location;
+      } else
+         break;
+   }
+   return entry;
+}
+
+/*
  * Allocate and set a new entry in the cache list
  */
 static CacheEntry_t *Cache_entry_add(const DilloUrl *Url)
@@ -250,6 +274,8 @@
    if (!(entry = Cache_entry_search(Url)))
       entry = Cache_entry_add(Url);
    entry->Flags |= CA_GotData + CA_GotHeader + CA_GotLength + CA_InternalUrl;
+   if (data_ds->len)
+      entry->Flags &= ~CA_IsEmpty;
    dStr_truncate(entry->Data, 0);
    dStr_append_l(entry->Data, data_ds->str, data_ds->len);
    dStr_fit(entry->Data);
@@ -355,28 +381,21 @@
 }
 
 /*
+ * Get cache entry status
+ */
+uint_t a_Cache_get_flags(const DilloUrl *url)
+{
+   CacheEntry_t *entry = Cache_entry_search_with_redirect(url);
+   return (entry ? entry->Flags : 0);
+}
+
+/*
  * Get the pointer to the URL document, and its size, from the cache entry.
  * Return: 1 cached, 0 not cached.
  */
 int a_Cache_get_buf(const DilloUrl *Url, char **PBuf, int *BufSize)
 {
-   int i;
-   CacheEntry_t *entry;
-
-   for (i = 0; (entry = Cache_entry_search(Url)); ++i) {
-
-      /* Test for a redirection loop */
-      if (entry->Flags & CA_RedirectLoop || i == 3) {
-         _MSG_WARN("Redirect loop for URL: >%s<\n", URL_STR_(Url));
-         break;
-      }
-      /* Test for a working redirection */
-      if (entry && entry->Flags & CA_Redirect && entry->Location) {
-         Url = entry->Location;
-      } else
-         break;
-   }
-
+   CacheEntry_t *entry = Cache_entry_search_with_redirect(Url);
    *BufSize = (entry) ? entry->Data->len : 0;
    *PBuf = (entry) ? entry->Data->str : NULL;
    return (entry ? 1 : 0);
@@ -686,6 +705,8 @@
    }
 
    dStr_append_l(entry->Data, dbuf->str, dbuf->len);
+   if (entry->Data->len)
+      entry->Flags &= ~CA_IsEmpty;
    dStr_free(dbuf, 1);
 
    Cache_process_queue(entry);
--- a/src/cache.h	Mon Mar 24 22:56:22 2008 +0100
+++ b/src/cache.h	Wed Mar 26 15:46:46 2008 +0100
@@ -19,20 +19,20 @@
 /*
  * Flag Defines
  */
-#define CA_GotHeader       (1)  /* True after header is completely got */
-#define CA_GotContentType  (2)  /* True after Content-Type is known */
-#define CA_GotLength       (4)  /* True if Content-Length is known */
-#define CA_GotData         (8)  /* True if we have all Data in cache */
-#define CA_FreeData       (16)  /* Free the cache Data on close */
-#define CA_Redirect       (32)  /* Data actually points to a redirect */
-#define CA_ForceRedirect  (64)  /* Unconditional redirect */
-#define CA_TempRedirect  (128)  /* Temporary redirect */
-#define CA_NotFound      (256)  /* True if remote server didn't find the URL */
-#define CA_Stopped       (512)  /* True if the entry has been stopped */
-#define CA_MsgErased    (1024)  /* Used to erase the bw's status bar */
-#define CA_RedirectLoop (2048)  /* Redirect loop */
-#define CA_InternalUrl  (4096)  /* URL content is generated by dillo */
-#define CA_HugeFile     (8192)  /* URL content is too big */
+#define CA_GotHeader       0x1  /* True after header is completely got */
+#define CA_GotContentType  0x2  /* True after Content-Type is known */
+#define CA_GotLength       0x4  /* True if Content-Length is known */
+#define CA_GotData         0x8  /* True if we have all Data in cache */
+#define CA_Redirect       0x10  /* Data actually points to a redirect */
+#define CA_ForceRedirect  0x20  /* Unconditional redirect */
+#define CA_TempRedirect   0x40  /* Temporary redirect */
+#define CA_NotFound       0x80  /* True if remote server didn't find the URL */
+#define CA_Stopped       0x100  /* True if the entry has been stopped */
+#define CA_MsgErased     0x200  /* Used to erase the bw's status bar */
+#define CA_RedirectLoop  0x400  /* Redirect loop */
+#define CA_InternalUrl   0x800  /* URL content is generated by dillo */
+#define CA_HugeFile     0x1000  /* URL content is too big */
+#define CA_IsEmpty      0x2000  /* True until a byte of content arrives */
 
 /*
  * Callback type for cache clients
@@ -59,6 +59,7 @@
 void a_Cache_init(void);
 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);
+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);
 void a_Cache_entry_inject(const DilloUrl *Url, Dstr *data_ds);
--- a/src/capi.c	Mon Mar 24 22:56:22 2008 +0100
+++ b/src/capi.c	Wed Mar 26 15:46:46 2008 +0100
@@ -303,19 +303,19 @@
 int a_Capi_open_url(DilloWeb *web, CA_Callback_t Call, void *CbData)
 {
    capi_conn_t *conn;
-   int buf_size, reload;
-   char *cmd, *server, *buf;
+   int reload;
+   char *cmd, *server;
    const char *scheme = URL_SCHEME(web->url);
    int safe = 0, ret = 0, use_cache = 0;
 
    /* reload test */
-   reload = (!a_Capi_get_buf(web->url, &buf, &buf_size) ||
+   reload = (!(a_Capi_get_flags(web->url) & CAPI_IsCached) ||
              (URL_FLAGS(web->url) & URL_E2EReload));
 
    if (web->flags & WEB_Download) {
-     /* donwload request: if cached save from cache, else
+     /* download request: if cached save from cache, else
       * for http, ftp or https, use the downloads dpi */
-     if (a_Capi_get_buf(web->url, &buf, &buf_size)) {
+     if (a_Capi_get_flags(web->url) & CAPI_IsCached) {
         if (web->filename && (web->stream = fopen(web->filename, "w"))) {
            use_cache = 1;
         }
@@ -373,6 +373,28 @@
 }
 
 /*
+ * Return status information of an URL's content-transfer process.
+ */
+int a_Capi_get_flags(const DilloUrl *Url)
+{
+   int status = 0;
+   uint_t flags = a_Cache_get_flags(Url);
+
+   if (flags) {
+      status |= CAPI_IsCached;
+      if (flags & CA_IsEmpty)
+         status |= CAPI_IsEmpty;
+      if (flags & CA_GotData)
+         status |= CAPI_Completed;
+      else
+         status |= CAPI_InProgress;
+
+      /* CAPI_Aborted is not yet used/defined */
+   }
+   return status;
+}
+
+/*
  * Get the cache's buffer for the URL, and its size.
  * Return: 1 cached, 0 not cached.
  */
--- a/src/capi.h	Mon Mar 24 22:56:22 2008 +0100
+++ b/src/capi.h	Wed Mar 26 15:46:46 2008 +0100
@@ -10,11 +10,21 @@
 #include "web.hh"
 
 /*
+ * Flag defines
+ */
+#define CAPI_IsCached       (0x1)
+#define CAPI_IsEmpty        (0x2)
+#define CAPI_InProgress     (0x4)
+#define CAPI_Aborted        (0x8)
+#define CAPI_Completed     (0x10)
+
+/*
  * Function prototypes
  */
 void a_Capi_init(void);
 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);
+int a_Capi_get_flags(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	Mon Mar 24 22:56:22 2008 +0100
+++ b/src/html.cc	Wed Mar 26 15:46:46 2008 +0100
@@ -2423,13 +2423,12 @@
 static void Html_tag_open_frame (DilloHtml *html, const char *tag, int tagsize)
 {
    const char *attrbuf;
-   char *src, *buf;
+   char *src;
    DilloUrl *url;
    Textblock *textblock;
    StyleAttrs style_attrs;
    Style *link_style;
    Widget *bullet;
-   int buf_size;
 
    textblock = DW2TB(html->dw);
 
@@ -2443,7 +2442,7 @@
 
    style_attrs = *(S_TOP(html)->style);
 
-   if (a_Capi_get_buf(url, &buf, &buf_size)) { /* visited frame */
+   if (a_Capi_get_flags(url) & CAPI_IsCached) { /* visited frame */
       style_attrs.color =
          Color::createSimple (HT2LT(html), html->visited_color);
    } else {                                    /* unvisited frame */
@@ -2866,7 +2865,6 @@
    StyleAttrs style_attrs;
    const char *attrbuf;
    int border, load_now;
-   char *buf; int buf_size; /* solely for the sake of the cache test */
 
    /* This avoids loading images. Useful for viewing suspicious HTML email. */
    if (URL_FLAGS(html->base_url) & URL_SpamSafe)
@@ -2907,7 +2905,7 @@
     * we know Html_add_new_linkimage() will use size() as its next index */
    style_attrs.x_img = html->images->size();
 
-   load_now = (prefs.load_images || a_Capi_get_buf(url,&buf, &buf_size));
+   load_now = (prefs.load_images || (a_Capi_get_flags(url) & CAPI_IsCached));
    Image = Html_add_new_image(html, tag, tagsize, url, &style_attrs, TRUE);
    Html_add_new_linkimage(html, url, load_now ? NULL : Image);
    if (load_now)
@@ -3070,8 +3068,6 @@
    Style *old_style;
    DilloUrl *url;
    const char *attrbuf;
-   char *buf;
-   int buf_size;
 
    /* todo: add support for MAP with A HREF */
    Html_tag_open_area(html, tag, tagsize);
@@ -3087,7 +3083,7 @@
       old_style = S_TOP(html)->style;
       style_attrs = *old_style;
 
-      if (a_Capi_get_buf(url, &buf, &buf_size)) {
+      if (a_Capi_get_flags(url) & CAPI_IsCached) {
          html->InVisitedLink = TRUE;
          style_attrs.color = Color::createSimple (
             HT2LT(html),
--- a/src/jpeg.c	Mon Mar 24 22:56:22 2008 +0100
+++ b/src/jpeg.c	Wed Mar 26 15:46:46 2008 +0100
@@ -35,6 +35,7 @@
 #include "web.hh"
 #include "cache.h"
 #include "dicache.h"
+#include "capi.h"       /* get cache entry status */
 
 #define DEBUG_LEVEL 6
 #include "debug.h"
@@ -289,13 +290,13 @@
                       jpeg->cinfo.num_components);
 
          /*
-          * Display multiple-scan images progressively if the amount of data is
-          * small (it is likely coming over a network). If the source of a
-          * multiple-scan image is the cache or local filesystem, let libjpeg
-          * decode the entire image first and provide output in a single scan.
+          * If a multiple-scan image is not completely in cache,
+          * use progressive display, updating as it arrives.
           */
-         if ((BufSize < 2048) && jpeg_has_multiple_scans(&jpeg->cinfo))
+         if (jpeg_has_multiple_scans(&jpeg->cinfo) &&
+             !(a_Capi_get_flags(jpeg->url) & CAPI_Completed))
             jpeg->cinfo.buffered_image = TRUE;
+         printf("jpeg: %s\n", jpeg->cinfo.buffered_image ? "TRUE":"FALSE");
 
          a_Dicache_set_parms(jpeg->url, jpeg->version, jpeg->Image,
                              (uint_t)jpeg->cinfo.image_width,