summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2003-02-09 12:58:15 +0000
committerJames Bursa <james@netsurf-browser.org>2003-02-09 12:58:15 +0000
commita4c5929a2fac1cb0c039b2d009d8093ac81a90d7 (patch)
tree710bf4247d92ec63df7c92815c5360ec907a4b66 /desktop
parent948dfeb1c2404e6bdad8c20c83a26f3eecb3764a (diff)
downloadnetsurf-a4c5929a2fac1cb0c039b2d009d8093ac81a90d7.tar.gz
netsurf-a4c5929a2fac1cb0c039b2d009d8093ac81a90d7.tar.bz2
[project @ 2003-02-09 12:58:14 by bursa]
Reorganization and rewrite of fetch, cache, and content handling. svn path=/import/netsurf/; revision=96
Diffstat (limited to 'desktop')
-rw-r--r--desktop/browser.c358
-rw-r--r--desktop/browser.h69
-rw-r--r--desktop/cache.c128
-rw-r--r--desktop/cache.h32
-rw-r--r--desktop/fetch.c211
-rw-r--r--desktop/fetch.h49
-rw-r--r--desktop/netsurf.c25
-rw-r--r--desktop/netsurf.h21
8 files changed, 52 insertions, 841 deletions
diff --git a/desktop/browser.c b/desktop/browser.c
index 270574901..f18ea38f4 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -1,15 +1,14 @@
/**
- * $Id: browser.c,v 1.22 2003/01/12 17:48:44 bursa Exp $
+ * $Id: browser.c,v 1.23 2003/02/09 12:58:14 bursa Exp $
*/
+#include "netsurf/content/cache.h"
+#include "netsurf/content/fetchcache.h"
+#include "netsurf/desktop/browser.h"
#include "netsurf/riscos/font.h"
#include "netsurf/render/box.h"
-#include "netsurf/render/layout.h"
-#include "netsurf/render/css.h"
-#include "netsurf/desktop/browser.h"
-#include "netsurf/render/utils.h"
-#include "netsurf/desktop/cache.h"
#include "netsurf/utils/log.h"
+#include "netsurf/utils/utils.h"
#include "libxml/uri.h"
#include "libxml/debugXML.h"
#include <string.h>
@@ -25,9 +24,11 @@ void browser_window_change_text_selection(struct browser_window* bw, struct box_
void browser_window_redraw_boxes(struct browser_window* bw, struct box_position* start, struct box_position* end);
void browser_window_follow_link(struct browser_window* bw,
int click_x, int click_y, int click_type);
-
+void browser_window_callback(fetchcache_msg msg, struct content *c,
+ struct browser_window* bw, char *error);
void box_under_area(struct box* box, int x, int y, int ox, int oy, struct box_selection** found, int* count, int* plot_index);
+
void browser_window_start_throbber(struct browser_window* bw)
{
bw->throbbing = 1;
@@ -41,180 +42,6 @@ void browser_window_stop_throbber(struct browser_window* bw)
gui_window_stop_throbber(bw->window);
}
-void content_destroy(struct content* c)
-{
- if (c == NULL)
- return;
-
- switch (c->type)
- {
- case CONTENT_HTML:
- /* free other memory here */
-// xmlFreeParserCtxt(c->data.html.parser);
- LOG(("free parser"));
-// htmlFreeParserCtxt(c->data.html.parser);
- LOG(("free sheet"));
-// xfree(c->data.html.stylesheet);
- LOG(("free style"));
-// xfree(c->data.html.style);
- if (c->data.html.layout != NULL)
- {
- LOG(("box_free box"));
-// box_free(c->data.html.layout);
- LOG(("free box"));
-// xfree(c->data.html.layout);
- }
- LOG(("free font"));
- font_free_set(c->data.html.fonts);
- break;
- default:
- break;
- }
-
- c->main_fetch = fetch_cancel(c->main_fetch);
- xfree(c);
-
- return;
-}
-
-size_t content_html_receive_data(struct content* c, void* data, size_t size, size_t nmemb)
-{
- size_t amount = nmemb;
- int offset = 0;
- size_t numInChunk = 2048 / size; /* process in 2k chunks */
-
- if (numInChunk > nmemb)
- numInChunk = nmemb;
- else if (numInChunk <= (size_t)0)
- numInChunk = 1;
-
- while (amount > 0)
- {
- htmlParseChunk(c->data.html.parser, (char*)data + (offset * size), numInChunk, 0);
- offset += numInChunk;
- amount -= numInChunk;
- if (amount < numInChunk)
- numInChunk = amount;
- gui_multitask();
- }
-
- return size * nmemb;
-}
-
-void set_content_html(struct content* c)
-{
- c->type = CONTENT_HTML;
- c->data.html.parser = htmlCreatePushParserCtxt(0, 0, "", 0, 0, XML_CHAR_ENCODING_8859_1);
- c->data.html.document = NULL;
- c->data.html.markup = NULL;
- c->data.html.layout = NULL;
- c->data.html.stylesheet = NULL;
- c->data.html.style = NULL;
- return;
-}
-
-
-void content_html_title(struct content *c)
-{
- xmlNode *node = c->data.html.markup;
-
- c->title = 0;
-
- while (node != 0) {
- if (node->type == XML_ELEMENT_NODE) {
- if (stricmp(node->name, "html") == 0) {
- node = node->children;
- continue;
- }
- if (stricmp(node->name, "head") == 0) {
- node = node->children;
- continue;
- }
- if (stricmp(node->name, "title") == 0) {
- c->title = xmlNodeGetContent(node);
- return;
- }
- }
- node = node->next;
- }
-}
-
-
-void content_html_reformat(struct content* c, int width)
-{
- char* file;
- struct css_selector* selector = xcalloc(1, sizeof(struct css_selector));
-
- LOG(("Starting stuff"));
-
- if (c->data.html.layout != NULL)
- {
- /* TODO: skip if width is unchanged */
- layout_document(c->data.html.layout->children, (unsigned long)width);
- return;
- }
-
- LOG(("Setting document to myDoc"));
- c->data.html.document = c->data.html.parser->myDoc;
- //xmlDebugDumpDocument(stderr, c->data.html.parser->myDoc);
-
- /* skip to start of html */
- LOG(("Skipping to html"));
- if (c->data.html.document == NULL)
- {
- LOG(("There is no document!"));
- return;
- }
- for (c->data.html.markup = c->data.html.document->children;
- c->data.html.markup != 0 &&
- c->data.html.markup->type != XML_ELEMENT_NODE;
- c->data.html.markup = c->data.html.markup->next)
- ;
-
- if (c->data.html.markup == 0)
- {
- LOG(("No markup"));
- return;
- }
- if (strcmp((const char *) c->data.html.markup->name, "html"))
- {
- LOG(("Not html"));
- return;
- }
-
-// xfree(c->data.html.stylesheet);
-// xfree(c->data.html.style);
-
- content_html_title(c);
-
- LOG(("Loading CSS"));
- file = load("<NetSurf$Dir>.Resources.CSS"); /*!!! not portable! !!!*/
- c->data.html.stylesheet = css_new_stylesheet();
- LOG(("Parsing stylesheet"));
- css_parse_stylesheet(c->data.html.stylesheet, file);
-
- LOG(("Copying base style"));
- c->data.html.style = xcalloc(1, sizeof(struct css_style));
- memcpy(c->data.html.style, &css_base_style, sizeof(struct css_style));
-
- LOG(("Creating box"));
- c->data.html.layout = xcalloc(1, sizeof(struct box));
- c->data.html.layout->type = BOX_BLOCK;
- c->data.html.layout->node = c->data.html.markup;
-
- c->data.html.fonts = font_new_set();
-
- LOG(("XML to box"));
- xml_to_box(c->data.html.markup, c->data.html.style, c->data.html.stylesheet, &selector, 0, c->data.html.layout, 0, 0, c->data.html.fonts, 0, 0, 0, 0, &c->data.html.elements);
- box_dump(c->data.html.layout->children, 0);
- LOG(("Layout document"));
- layout_document(c->data.html.layout->children, (unsigned long)width);
- box_dump(c->data.html.layout->children, 0);
-
- /* can tidy up memory here? */
-
- return;
-}
void browser_window_reformat(struct browser_window* bw)
{
@@ -222,8 +49,7 @@ void browser_window_reformat(struct browser_window* bw)
clock_t time0, time1;
LOG(("Entering..."));
- if (bw == NULL)
- return;
+ assert(bw != 0);
if (bw->current_content == NULL)
return;
@@ -231,34 +57,21 @@ void browser_window_reformat(struct browser_window* bw)
{
case CONTENT_HTML:
LOG(("HTML content."));
- browser_window_set_status(bw, "Formatting page...");
time0 = clock();
- content_html_reformat(bw->current_content, gui_window_get_width(bw->window));
- if (bw->current_content == 0)
+ if (bw->current_content->title == 0)
gui_window_set_title(bw->window, bw->url);
else
gui_window_set_title(bw->window, bw->current_content->title);
time1 = clock();
- LOG(("Content reformatted"));
- if (bw->current_content->data.html.layout != NULL)
- {
- LOG(("Setting extent"));
- gui_window_set_extent(bw->window, bw->current_content->data.html.layout->children->width, bw->current_content->data.html.layout->children->height);
- LOG(("Setting scroll"));
- gui_window_set_scroll(bw->window, 0, 0);
- LOG(("Redraw window"));
- gui_window_redraw_window(bw->window);
- LOG(("Complete"));
- sprintf(status, "Format complete (%gs).", ((float) time1 - time0) / CLOCKS_PER_SEC);
- browser_window_set_status(bw, status);
- }
- else
- {
- LOG(("This isn't html"));
- browser_window_set_status(bw, "This is not HTML!");
- cache_free(bw->current_content);
- bw->current_content = NULL;
- }
+ LOG(("Setting extent"));
+ gui_window_set_extent(bw->window, bw->current_content->data.html.layout->children->width, bw->current_content->data.html.layout->children->height);
+ LOG(("Setting scroll"));
+ gui_window_set_scroll(bw->window, 0, 0);
+ LOG(("Redraw window"));
+ gui_window_redraw_window(bw->window);
+ LOG(("Complete"));
+ sprintf(status, "Format complete (%gs).", ((float) time1 - time0) / CLOCKS_PER_SEC);
+ browser_window_set_status(bw, status);
break;
default:
LOG(("Unknown content type"));
@@ -346,7 +159,6 @@ struct browser_window* create_browser_window(int flags, int width, int height)
bw->scale.div = 1;
bw->current_content = NULL;
- bw->future_content = NULL;
bw->history = NULL;
bw->url = NULL;
@@ -370,8 +182,6 @@ void browser_window_destroy(struct browser_window* bw)
if (bw->current_content != NULL)
cache_free(bw->current_content);
- if (bw->future_content != NULL)
- cache_free(bw->future_content);
if (bw->history != NULL)
{
@@ -411,60 +221,9 @@ void browser_window_open_location_historical(struct browser_window* bw, char* ur
assert(bw != 0 && url != 0);
- if (bw->future_content != NULL)
- cache_free(bw->future_content);
-
- bw->future_content = cache_get(url);
- if (bw->future_content == 0)
- {
- /* not in cache: start fetch */
- struct fetch_request* req;
-
- LOG(("not in cache: starting fetch"));
-
- req = xcalloc(1, sizeof(struct fetch_request));
- req->type = REQUEST_FROM_BROWSER;
- req->requestor.browser = bw;
-
- bw->future_content = (struct content*) xcalloc(1, sizeof(struct content));
- bw->future_content->main_fetch = create_fetch(url, bw->url, 0, req);
-
- cache_put(url, bw->future_content, 1000);
-
- browser_window_start_throbber(bw);
- }
- else
- {
- /* in cache: reformat page and display */
- struct gui_message gmsg;
- gui_safety previous_safety;
-
- LOG(("in cache: reformatting"));
-
- browser_window_start_throbber(bw);
-
- /* TODO: factor out code shared with browser_window_message(), case msg_FETCH_FINISHED */
- if (url != bw->url) /* reload <=> url == bw->url */
- {
- if (bw->url != NULL)
- xfree(bw->url);
- bw->url = xstrdup(url);
- }
-
- gmsg.type = msg_SET_URL;
- gmsg.data.set_url.url = bw->url;
- gui_window_message(bw->window, &gmsg);
-
- previous_safety = gui_window_set_redraw_safety(bw->window, UNSAFE);
- if (bw->current_content != NULL)
- cache_free(bw->current_content);
- bw->current_content = bw->future_content;
- bw->future_content = NULL;
- browser_window_reformat(bw);
- gui_window_set_redraw_safety(bw->window, previous_safety);
- browser_window_stop_throbber(bw);
- }
-
+ browser_window_set_status(bw, "Opening page...");
+ fetchcache(url, 0, browser_window_callback, bw, gui_window_get_width(bw->window), 0);
+
LOG(("end"));
}
@@ -485,68 +244,25 @@ void browser_window_open_location(struct browser_window* bw, char* url)
LOG(("end"));
}
-int browser_window_message(struct browser_window* bw, struct browser_message* msg)
+void browser_window_callback(fetchcache_msg msg, struct content *c,
+ struct browser_window* bw, char *error)
{
gui_safety previous_safety;
- switch (msg->type)
+ switch (msg)
{
- case msg_FETCH_SENDING:
- browser_window_set_status(bw, "Sending request...");
- break;
-
- case msg_FETCH_WAITING:
- browser_window_set_status(bw, "Waiting for reply...");
- break;
-
- case msg_FETCH_FETCH_INFO:
- browser_window_set_status(bw, "Request received...");
- if (msg->f == bw->future_content->main_fetch)
- {
- switch (msg->data.fetch_info.type)
- {
- case type_HTML:
- set_content_html(bw->future_content);
- break;
- default:
- browser_window_stop_throbber(bw);
- return 1;
- }
- }
- break;
-
- case msg_FETCH_DATA:
- browser_window_set_status(bw, "Data received...");
- if (msg->f == bw->future_content->main_fetch)
- content_html_receive_data(bw->future_content, msg->data.fetch_data.block, sizeof(char), msg->data.fetch_data.block_size);
- break;
-
- case msg_FETCH_ABORT:
- browser_window_set_status(bw, "Request failed.");
- if (msg->f == bw->future_content->main_fetch)
- {
- browser_window_stop_throbber(bw);
- bw->future_content->main_fetch = NULL;
- cache_free(bw->future_content);
- bw->future_content = NULL;
- }
- break;
-
- case msg_FETCH_FINISHED:
+ case FETCHCACHE_OK:
browser_window_set_status(bw, "Request complete.");
- if (msg->f == bw->future_content->main_fetch)
{
struct gui_message gmsg;
- if (bw->future_content->main_fetch->location != NULL)
+ if (bw->url != 0)
xfree(bw->url);
- bw->url = xstrdup(bw->future_content->main_fetch->location);
+ bw->url = xstrdup(c->url);
gmsg.type = msg_SET_URL;
gmsg.data.set_url.url = bw->url;
gui_window_message(bw->window, &gmsg);
- htmlParseChunk(bw->future_content->data.html.parser, "", 0, 1);
- bw->future_content->main_fetch = NULL;
previous_safety = gui_window_set_redraw_safety(bw->window, UNSAFE);
if (bw->current_content != NULL)
{
@@ -557,20 +273,26 @@ int browser_window_message(struct browser_window* bw, struct browser_message* ms
}
cache_free(bw->current_content);
}
- bw->current_content = bw->future_content;
- bw->future_content = NULL;
+ bw->current_content = c;
browser_window_reformat(bw);
gui_window_set_redraw_safety(bw->window, previous_safety);
browser_window_stop_throbber(bw);
}
break;
- default:
- browser_window_set_status(bw, "???");
+ case FETCHCACHE_ERROR:
+ browser_window_set_status(bw, error);
+ browser_window_stop_throbber(bw);
break;
- }
- return 0;
+ case FETCHCACHE_BADTYPE:
+ browser_window_set_status(bw, "Unknown type");
+ browser_window_stop_throbber(bw);
+ break;
+
+ default:
+ assert(0);
+ }
}
void clear_radio_gadgets(struct browser_window* bw, struct box* box, struct gui_gadget* group)
diff --git a/desktop/browser.h b/desktop/browser.h
index 31275bde6..3271155b9 100644
--- a/desktop/browser.h
+++ b/desktop/browser.h
@@ -1,15 +1,13 @@
/**
- * $Id: browser.h,v 1.6 2003/01/12 17:48:44 bursa Exp $
+ * $Id: browser.h,v 1.7 2003/02/09 12:58:14 bursa Exp $
*/
#ifndef _NETSURF_DESKTOP_BROWSER_H_
#define _NETSURF_DESKTOP_BROWSER_H_
-#include "libxml/HTMLparser.h"
-#include "netsurf/render/css.h"
-#include "netsurf/render/box.h"
+#include "netsurf/content/content.h"
#include "netsurf/desktop/gui.h"
-#include "netsurf/desktop/fetch.h"
+#include "netsurf/render/box.h"
#include "netsurf/riscos/font.h"
typedef int browser_window_flags;
@@ -29,45 +27,6 @@ typedef int action_buttons;
-struct box_position
-{
- struct box* box;
- int actual_box_x;
- int actual_box_y;
- int plot_index;
- int pixel_offset;
- int char_offset;
-};
-
-struct content
-{
- enum {CONTENT_UNKNOWN, CONTENT_HTML, CONTENT_IMAGE} type;
-
- union
- {
- struct
- {
- htmlParserCtxt* parser;
- xmlDoc* document;
- xmlNode* markup;
- struct box* layout;
- struct css_stylesheet* stylesheet;
- struct css_style* style;
- struct {
- struct box_position start;
- struct box_position end;
- enum {alter_UNKNOWN, alter_START, alter_END} altering;
- int selected; /* 0 = unselected, 1 = selected */
- } text_selection;
- struct font_set* fonts;
- struct page_elements elements;
- } html;
- } data;
- struct fetch* main_fetch;
- unsigned int ref_count;
- char *title;
-};
-
struct history
{
@@ -88,7 +47,6 @@ struct browser_window
struct { int mult; int div; } scale;
struct content* current_content;
- struct content* future_content;
struct history* history;
char* url;
@@ -101,26 +59,6 @@ struct browser_window
};
-struct browser_message
-{
- enum { msg_UNKNOWN,
- msg_FETCH_SENDING, msg_FETCH_WAITING, msg_FETCH_ABORT,
- msg_FETCH_FETCH_INFO, msg_FETCH_DATA, msg_FETCH_FINISHED
- } type;
- struct fetch* f;
- union {
- struct {
- enum { type_UNKNOWN, type_HTML } type; /* should be a MIME type ? */
- int total_size; /* -1 == unknown size */
- } fetch_info;
- struct {
- char* block;
- int block_size;
- } fetch_data;
- } data;
-};
-
-
struct browser_action
{
enum { act_UNKNOWN,
@@ -156,7 +94,6 @@ struct browser_window* create_browser_window(int flags, int width, int height);
void browser_window_destroy(struct browser_window* bw);
void browser_window_open_location(struct browser_window* bw, char* url);
void browser_window_open_location_historical(struct browser_window* bw, char* url);
-int browser_window_message(struct browser_window* bw, struct browser_message* msg);
int browser_window_action(struct browser_window* bw, struct browser_action* act);
void browser_window_set_status(struct browser_window* bw, char* text);
diff --git a/desktop/cache.c b/desktop/cache.c
deleted file mode 100644
index 012683ebe..000000000
--- a/desktop/cache.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- * $Id: cache.c,v 1.1 2002/11/02 22:28:05 bursa Exp $
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "netsurf/desktop/cache.h"
-#include "netsurf/render/utils.h"
-#include "netsurf/utils/log.h"
-#include "curl/curl.h"
-#include "ubiqx/ubi_Cache.h"
-
-/**
- * internal structures and declarations
- */
-
-ubi_cacheRoot memcache;
-
-struct memcache_entry {
- ubi_cacheEntry Node;
- char * url;
- struct content * content;
-};
-
-static int memcache_compare(ubi_trItemPtr item, ubi_trNode * node);
-void memcache_free(ubi_trNode * node);
-
-
-/**
- * cache_init -- initialise the cache manager
- */
-
-void cache_init(void)
-{
- /* memory cache */
- ubi_cacheInit(&memcache, memcache_compare, memcache_free, 40, 100*1024);
-}
-
-
-/**
- * cache_quit -- terminate the cache manager
- */
-
-void cache_quit(void)
-{
- ubi_cacheClear(&memcache);
-}
-
-
-/**
- * cache_get -- retrieve url from memory cache or disc cache
- */
-
-struct content * cache_get(char * const url)
-{
- struct memcache_entry * entry;
-
- entry = (struct memcache_entry *) ubi_cacheGet(&memcache, url);
- if (entry != 0) {
- LOG(("url %s in cache, node %p", url, entry));
- entry->content->ref_count++;
- return entry->content;
- }
-
- LOG(("url %s not cached", url));
-
- /* TODO: check disc cache */
-
- return 0;
-}
-
-
-/**
- * cache_put -- place content in the memory cache
- */
-
-void cache_put(char * const url, struct content * content, unsigned long size)
-{
- struct memcache_entry * entry;
-
- entry = xcalloc(1, sizeof(struct memcache_entry));
- entry->url = xstrdup(url);
- entry->content = content;
- content->ref_count = 2; /* cache, caller */
- ubi_cachePut(&memcache, size,
- (ubi_cacheEntry *) entry, entry->url);
-}
-
-
-/**
- * cache_free -- free a cache object if it is no longer used
- */
-
-void cache_free(struct content * content)
-{
- LOG(("content %p, ref_count %u", content, content->ref_count));
- if (--content->ref_count == 0) {
- LOG(("ref count 0, freeing"));
- content_destroy(content);
- }
-}
-
-
-/**
- * memory cache
- */
-
-static int memcache_compare(ubi_trItemPtr item, ubi_trNode * node)
-{
- return strcmp((char *) item, ((struct memcache_entry *) node)->url);
-}
-
-
-void memcache_free(ubi_trNode * node)
-{
- struct memcache_entry * entry = (struct memcache_entry *) node;
-
- LOG(("node %p, node->url %s", node, entry->url));
-
- cache_free(entry->content);
- free(entry->url);
- free(entry);
-
- /* TODO: place the object in a disc cache */
-}
-
-
diff --git a/desktop/cache.h b/desktop/cache.h
deleted file mode 100644
index 90131d8c2..000000000
--- a/desktop/cache.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * $Id: cache.h,v 1.1 2002/11/02 22:28:05 bursa Exp $
- */
-
-/**
- * Using the cache:
- *
- * cache_init();
- * ...
- * c = cache_get(url);
- * if (c == 0) {
- * ... (create c) ...
- * cache_put(url, c, size);
- * }
- * ...
- * cache_free(c);
- * ...
- * cache_quit();
- *
- * cache_free informs the cache that the content is no longer being used, so
- * it can be deleted from the cache if necessary. There must be a call to
- * cache_free for each cache_get or cache_put.
- */
-
-#include "netsurf/desktop/browser.h"
-
-void cache_init(void);
-void cache_quit(void);
-struct content * cache_get(char * const url);
-void cache_put(char * const url, struct content * content, unsigned long size);
-void cache_free(struct content * content);
-
diff --git a/desktop/fetch.c b/desktop/fetch.c
deleted file mode 100644
index 3ff8dd09c..000000000
--- a/desktop/fetch.c
+++ /dev/null
@@ -1,211 +0,0 @@
-/**
- * $Id: fetch.c,v 1.7 2003/01/06 00:04:43 bursa Exp $
- */
-
-#include "libxml/HTMLparser.h"
-#include "netsurf/render/box.h"
-#include "netsurf/render/css.h"
-#include "netsurf/desktop/browser.h"
-#include "netsurf/desktop/netsurf.h"
-#include "netsurf/desktop/fetch.h"
-#include "netsurf/render/utils.h"
-#include "netsurf/utils/log.h"
-#include "curl/curl.h"
-#include <time.h>
-#include <string.h>
-#include <stdio.h>
-
-struct fetch* create_fetch(char* location, char* previous, fetch_flags f, struct fetch_request* r)
-{
- struct fetch* fetch = (struct fetch*) xcalloc(1, sizeof(struct fetch));
-
- if (fetch->location != NULL)
- free(fetch->location);
-
- fetch->location = xstrdup(location);
- fetch->type = fetch_CURL;
-
- fetch->flags = f;
-
- fetch->status = fetch_STATUS_WAIT;
- fetch->bytes_fetched = 0;
- fetch->bytes_total = -1;
-
- fetch->request = r;
-
- fetch->start_time = time(&fetch->start_time);
-
- fetch->next = netsurf_fetches;
- netsurf_fetches = fetch;
-
- return fetch;
-}
-
-void fetch_destroy(struct fetch* f)
-{
- if (f == NULL)
- return;
-
- if (netsurf_fetches == f)
- netsurf_fetches = f->next;
- else
- {
- struct fetch* ff = netsurf_fetches;
- while (ff->next != f && ff->next != NULL)
- ff = ff->next;
- if (ff->next == f)
- ff->next = f->next;
- }
-
- xfree(f->location);
- xfree(f->request);
- xfree(f);
-}
-
-struct fetch* fetch_cancel(struct fetch* f)
-{
- if (f == NULL)
- return NULL;
-
- /* may need to contact server here */
-
- f->status = fetch_DELETED;
- /* fetch may not necessarily be destroyed if the cancelling can't be done
- instantly */
- return f;
-}
-
-void fetch_receive(struct fetch* f, int amount, char* bytes)
-{
- struct browser_message msg;
-
- f->bytes_fetched = f->bytes_fetched + amount;
-
- switch (f->request->type)
- {
- case REQUEST_FROM_BROWSER:
- msg.type = msg_FETCH_DATA;
- msg.f = f;
- msg.data.fetch_data.block = bytes;
- msg.data.fetch_data.block_size = amount;
- if (browser_window_message(f->request->requestor.browser, &msg) != 0)
- {
- fetch_cancel(f);
- return;
- }
- break;
- default:
- break;
- }
-
- if (f->bytes_fetched >= f->bytes_total && f->bytes_total != -1)
- {
- msg.type = msg_FETCH_FINISHED;
- msg.f = f;
- browser_window_message(f->request->requestor.browser, &msg);
- fetch_destroy(f);
- }
-
- return;
-}
-
-size_t fetch_curl_data(void * data, size_t size, size_t nmemb, struct fetch* f)
-{
- struct browser_message msg;
- msg.type = msg_FETCH_DATA;
- msg.f = f;
- msg.data.fetch_data.block = data;
- msg.data.fetch_data.block_size = size * nmemb;
- LOG(("sending curl's FETCH_DATA to browser"));
- browser_window_message(f->request->requestor.browser, &msg);
- return size * nmemb;
-}
-
-struct fetch* fetch_poll(struct fetch* f)
-{
- struct fetch* ret = f;
-
-/* LOG(("polling...")); */
-
- if (f == NULL)
- {
-/* LOG(("null fetch; returning")); */
- return f;
- }
-
- if (f->status == fetch_DELETED)
- {
- ret = f->next;
- LOG(("deleting marked fetch"));
- fetch_destroy(f);
- LOG(("moving on..."));
- return fetch_poll(ret);
- }
- else if (f->type == fetch_CURL && f->status == fetch_STATUS_WAIT)
- {
- struct browser_message msg;
- CURL* curl;
-
- LOG(("init curl"));
- curl = curl_easy_init();
- LOG(("init curl returned"));
- if (curl != 0)
- {
- LOG(("init curl OK"));
- /* shouldn't assume this! somehow work it out instead. */
- msg.type = msg_FETCH_FETCH_INFO;
- msg.f = f;
- msg.data.fetch_info.type = type_HTML;
- msg.data.fetch_info.total_size = -1;
-
- if (browser_window_message(f->request->requestor.browser, &msg) == 0)
- {
- LOG(("about to set options"));
- curl_easy_setopt(curl, CURLOPT_URL, f->location);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fetch_curl_data);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, f);
- curl_easy_setopt(curl, CURLOPT_USERAGENT, "NetSurf/0.00 (alpha)");
- LOG(("about to perform"));
- curl_easy_perform(curl);
- LOG(("about to cleanup"));
- curl_easy_cleanup(curl);
-
- LOG(("cleanup finished"));
- msg.type = msg_FETCH_FINISHED;
- msg.f = f;
- LOG(("sending FETCH_FINISHED to browser"));
- browser_window_message(f->request->requestor.browser, &msg);
- LOG(("FETCH_FINISHED accepted"));
-
- ret = f->next;
- LOG(("Destroying f"));
- fetch_destroy(f);
- LOG(("Moving on..."));
- return fetch_poll(ret);
- }
- LOG(("about to cleanup since requestor went funny"));
- curl_easy_cleanup(curl);
-
- LOG(("Requesting browser didn't like something"));
- ret = f->next;
- LOG(("Cancelling fetch"));
- f = fetch_cancel(f);
- return fetch_poll(ret);
- }
-
- LOG(("we are aborting the mission"));
- msg.type = msg_FETCH_ABORT;
- msg.f = f;
- browser_window_message(f->request->requestor.browser, &msg);
- LOG(("ABORT message sent to browser"));
-
- ret = f->next;
- fetch_destroy(f);
- return fetch_poll(ret); /* carry on polling */
- }
-
- LOG(("Moving on (at end of function with f->next)"));
- f->next = fetch_poll(f->next);
- return f;
-}
-
diff --git a/desktop/fetch.h b/desktop/fetch.h
deleted file mode 100644
index f9366c8fa..000000000
--- a/desktop/fetch.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * $Id: fetch.h,v 1.2 2003/01/06 00:04:43 bursa Exp $
- */
-
-#ifndef _NETSURF_DESKTOP_FETCH_H_
-#define _NETSURF_DESKTOP_FETCH_H_
-
-#include "libxml/HTMLparser.h"
-#include "netsurf/render/box.h"
-#include "netsurf/render/css.h"
-#include "netsurf/desktop/browser.h"
-#include <time.h>
-
-typedef enum {fetch_CURL} fetch_type;
-typedef enum {fetch_STATUS_SEND, fetch_STATUS_WAIT, fetch_STATUS_FETCH, fetch_STATUS_FINISH, fetch_DELETED} fetch_status;
-
-typedef int fetch_flags;
-#define fetch_DO_NOT_CHECK_CACHE ((fetch_flags) 1);
-#define fetch_DO_NOT_STORE_IN_CACHE ((fetch_flags) 2);
-
-struct fetch_request {
- enum {REQUEST_FROM_BROWSER} type;
- union {struct browser_window* browser;} requestor;
-};
-
-struct fetch
-{
- char* location;
- fetch_type type;
- fetch_flags flags;
-
- fetch_status status;
- int bytes_fetched;
- int bytes_total;
-
- struct fetch_request* request;
-
- time_t start_time;
-
- struct fetch* next;
-};
-
-struct fetch* create_fetch(char* location, char* previous, fetch_flags f, struct fetch_request* r);
-void fetch_destroy(struct fetch* f);
-struct fetch* fetch_cancel(struct fetch* f);
-void fetch_receive(struct fetch* f, int amount, char* bytes);
-struct fetch* fetch_poll(struct fetch* f);
-
-#endif
diff --git a/desktop/netsurf.c b/desktop/netsurf.c
index 144d9fa7d..f8161c975 100644
--- a/desktop/netsurf.c
+++ b/desktop/netsurf.c
@@ -1,23 +1,23 @@
/**
- * $Id: netsurf.c,v 1.5 2002/12/29 22:27:35 monkeyson Exp $
+ * $Id: netsurf.c,v 1.6 2003/02/09 12:58:15 bursa Exp $
*/
#include "netsurf/desktop/netsurf.h"
-#include "netsurf/desktop/fetch.h"
#include "netsurf/desktop/browser.h"
#include "netsurf/desktop/gui.h"
-#include "netsurf/desktop/cache.h"
+#include "netsurf/content/cache.h"
+#include "netsurf/content/fetch.h"
+#include "netsurf/utils/log.h"
#include <stdlib.h>
int netsurf_quit = 0;
gui_window* netsurf_gui_windows = NULL;
-struct fetch* netsurf_fetches = NULL;
void netsurf_poll(void)
{
gui_poll();
- netsurf_fetches = fetch_poll(netsurf_fetches);
+ fetch_poll();
}
@@ -25,6 +25,7 @@ void netsurf_init(int argc, char** argv)
{
stdout = stderr;
gui_init(argc, argv);
+ fetch_init();
cache_init();
}
@@ -32,6 +33,7 @@ void netsurf_init(int argc, char** argv)
void netsurf_exit(void)
{
cache_quit();
+ fetch_quit();
}
@@ -42,21 +44,10 @@ int main(int argc, char** argv)
while (netsurf_quit == 0)
netsurf_poll();
- fprintf(stderr, "Netsurf quit!\n");
+ LOG(("Netsurf quit!"));
netsurf_exit();
return 0;
}
-void Log(char* func, char* msg)
-{
-#ifdef NETSURF_DUMP_MONKEYS
- FILE* logfile = NULL;
- logfile = fopen("logfile","a");
- if (logfile == NULL)
- die("can't open logfile");
- fprintf(logfile, "%s: %s\n", func, msg);
- fclose(logfile);
-#endif
-}
diff --git a/desktop/netsurf.h b/desktop/netsurf.h
index 1ebdf9d88..7acab2537 100644
--- a/desktop/netsurf.h
+++ b/desktop/netsurf.h
@@ -1,35 +1,16 @@
/**
- * $Id: netsurf.h,v 1.1 2002/09/11 14:24:02 monkeyson Exp $
+ * $Id: netsurf.h,v 1.2 2003/02/09 12:58:15 bursa Exp $
*/
#ifndef _NETSURF_DESKTOP_NETSURF_H_
#define _NETSURF_DESKTOP_NETSURF_H_
-#include "netsurf/desktop/fetch.h"
#include "netsurf/desktop/browser.h"
-extern struct fetch* netsurf_fetches;
extern gui_window* netsurf_gui_windows;
-
extern int netsurf_quit;
void netsurf_poll(void);
-void Log(char* func, char* msg);
#endif
-#ifndef _NETSURF_DESKTOP_NETSURF_H_
-#define _NETSURF_DESKTOP_NETSURF_H_
-
-#include "netsurf/desktop/fetch.h"
-#include "netsurf/desktop/browser.h"
-
-extern struct fetch* netsurf_fetches;
-extern gui_window* netsurf_gui_windows;
-
-extern int netsurf_quit;
-
-void netsurf_poll(void);
-void Log(char* func, char* msg);
-
-#endif