aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjcid <devnull@localhost>2008-03-26 15:46:46 +0100
committerjcid <devnull@localhost>2008-03-26 15:46:46 +0100
commit072933308a1128555e6e56f519fdc9603d060d0f (patch)
tree2dddc7686d2209ad5392691dfcd362f494178735 /src
parent5763bad3e2a95553ed799e73ffd640dfaf441ac0 (diff)
- Added a_Capi_get_flags(). It requests a cache entry's status as flags.
Diffstat (limited to 'src')
-rw-r--r--src/cache.c57
-rw-r--r--src/cache.h29
-rw-r--r--src/capi.c32
-rw-r--r--src/capi.h10
-rw-r--r--src/html.cc12
-rw-r--r--src/jpeg.c11
6 files changed, 101 insertions, 50 deletions
diff --git a/src/cache.c b/src/cache.c
index 13a56127..185c7846 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -209,7 +209,7 @@ static void Cache_entry_init(CacheEntry_t *NewEntry, const DilloUrl *Url)
NewEntry->ContentDecoder = NULL;
NewEntry->ExpectedSize = 0;
NewEntry->TransferSize = 0;
- NewEntry->Flags = 0;
+ NewEntry->Flags = CA_IsEmpty;
}
/*
@@ -222,6 +222,30 @@ static CacheEntry_t *Cache_entry_search(const DilloUrl *Url)
}
/*
+ * 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 @@ void a_Cache_entry_inject(const DilloUrl *Url, Dstr *data_ds)
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 @@ int a_Cache_open_url(void *web, CA_Callback_t Call, void *CbData)
}
/*
+ * 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 @@ void a_Cache_process_dbuf(int Op, const char *buf, size_t buf_size,
}
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);
diff --git a/src/cache.h b/src/cache.h
index f6a831ea..5dee12c1 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -19,20 +19,20 @@ extern "C" {
/*
* 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 @@ struct _CacheClient {
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);
diff --git a/src/capi.c b/src/capi.c
index 38947b17..40e35b57 100644
--- a/src/capi.c
+++ b/src/capi.c
@@ -303,19 +303,19 @@ static char *Capi_dpi_build_cmd(DilloWeb *web, char *server)
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 @@ int a_Capi_open_url(DilloWeb *web, CA_Callback_t Call, void *CbData)
}
/*
+ * 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.
*/
diff --git a/src/capi.h b/src/capi.h
index e61d815b..120eb3c1 100644
--- a/src/capi.h
+++ b/src/capi.h
@@ -10,11 +10,21 @@ extern "C" {
#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);
diff --git a/src/html.cc b/src/html.cc
index a388b9a5..f635e1fd 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -2423,13 +2423,12 @@ static void Html_tag_open_tr(DilloHtml *html, const char *tag, int tagsize)
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 @@ static void Html_tag_open_frame (DilloHtml *html, const char *tag, int tagsize)
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 @@ static void Html_tag_open_img(DilloHtml *html, const char *tag, int tagsize)
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 @@ static void Html_tag_open_img(DilloHtml *html, const char *tag, int tagsize)
* 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 @@ static void Html_tag_open_a(DilloHtml *html, const char *tag, int tagsize)
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 @@ static void Html_tag_open_a(DilloHtml *html, const char *tag, int tagsize)
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),
diff --git a/src/jpeg.c b/src/jpeg.c
index def53c55..812a458e 100644
--- a/src/jpeg.c
+++ b/src/jpeg.c
@@ -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 @@ static void Jpeg_write(DilloJpeg *jpeg, void *Buf, uint_t BufSize)
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,