From c7520629b0d655bde1db9cbe0012f91502265b5d Mon Sep 17 00:00:00 2001 From: James Bursa Date: Wed, 16 Jul 2003 17:38:46 +0000 Subject: [project @ 2003-07-16 17:38:46 by bursa] Make fetchcache return 0 on failure to parse URL. svn path=/import/netsurf/; revision=225 --- content/content.c | 12 +++++++++--- content/fetch.c | 5 ++++- content/fetchcache.c | 6 ++++++ css/css.c | 8 ++++++-- debug/netsurfd.c | 12 ++++++++---- desktop/browser.c | 4 ++++ render/html.c | 23 +++++++++++++++-------- 7 files changed, 52 insertions(+), 18 deletions(-) diff --git a/content/content.c b/content/content.c index 2c7f5d00e..253caea16 100644 --- a/content/content.c +++ b/content/content.c @@ -121,6 +121,7 @@ struct content * content_create(char *url) c->url = xstrdup(url); c->type = CONTENT_UNKNOWN; c->status = CONTENT_STATUS_TYPE_UNKNOWN; + c->cache = 0; c->size = sizeof(struct content); c->fetch = 0; strcpy(c->status_message, "Loading"); @@ -178,6 +179,8 @@ void content_convert(struct content *c, unsigned long width, unsigned long heigh if (handler_map[c->type].convert(c, width, height)) { /* convert failed, destroy content */ content_broadcast(c, CONTENT_MSG_ERROR, "Conversion failed"); + if (c->cache) + cache_destroy(c); content_destroy(c); return; } @@ -305,10 +308,13 @@ void content_remove_user(struct content *c, if (c->fetch != 0) fetch_abort(c->fetch); if (c->status < CONTENT_STATUS_READY) { - cache_destroy(c); + if (c->cache) + cache_destroy(c); content_destroy(c); - } else - cache_freeable(c); + } else { + if (c->cache) + cache_freeable(c); + } } } diff --git a/content/fetch.c b/content/fetch.c index 3b057c266..330f68d3b 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -119,7 +119,10 @@ struct fetch * fetch_start(char *url, char *referer, LOG(("fetch %p, url '%s'", fetch, url)); uri = xmlParseURI(url); - assert(uri != 0); + if (uri == 0) { + LOG(("warning: failed to parse url")); + return 0; + } /* construct a new fetch structure */ fetch->start_time = time(0); diff --git a/content/fetchcache.c b/content/fetchcache.c index 844111376..99686efe0 100644 --- a/content/fetchcache.c +++ b/content/fetchcache.c @@ -46,6 +46,12 @@ struct content * fetchcache(const char *url0, char *referer, c->width = width; c->height = height; c->fetch = fetch_start(url, referer, fetchcache_callback, c); + if (c->fetch == 0) { + LOG(("warning: fetch_start failed")); + cache_destroy(c); + content_destroy(c); + return 0; + } return c; } diff --git a/css/css.c b/css/css.c index 8a29abb85..c894f6678 100644 --- a/css/css.c +++ b/css/css.c @@ -147,6 +147,8 @@ void css_revive(struct content *c, unsigned int width, unsigned int height) c->data.css.import_url[i], c->url, css_atimport_callback, c, i, c->width, c->height); + if (c->data.css.import_content[i] == 0) + continue; if (c->data.css.import_content[i]->status != CONTENT_STATUS_DONE) c->active++; } @@ -296,7 +298,8 @@ void css_atimport(struct content *c, struct node *node) c->data.css.import_content[i] = fetchcache( c->data.css.import_url[i], c->url, css_atimport_callback, c, i, c->width, c->height); - if (c->data.css.import_content[i]->status != CONTENT_STATUS_DONE) + if (c->data.css.import_content[i] && + c->data.css.import_content[i]->status != CONTENT_STATUS_DONE) c->active++; free(url); @@ -343,7 +346,8 @@ void css_atimport_callback(content_msg msg, struct content *css, c->data.css.import_content[i] = fetchcache( c->data.css.import_url[i], c->url, css_atimport_callback, c, i, css->width, css->height); - if (c->data.css.import_content[i]->status != CONTENT_STATUS_DONE) + if (c->data.css.import_content[i] && + c->data.css.import_content[i]->status != CONTENT_STATUS_DONE) c->active++; break; diff --git a/debug/netsurfd.c b/debug/netsurfd.c index c5ad28e9d..f73e44954 100644 --- a/debug/netsurfd.c +++ b/debug/netsurfd.c @@ -40,10 +40,14 @@ int main(int argc, char *argv[]) puts("=== URL:"); gets(url); c = fetchcache(url, 0, callback, 0, 0, 100, 1000); - done = c->status == CONTENT_STATUS_DONE; - while (!done) - fetch_poll(); - puts("=== SUCCESS, dumping cache"); + if (c) { + done = c->status == CONTENT_STATUS_DONE; + while (!done) + fetch_poll(); + puts("=== SUCCESS, dumping cache"); + } else { + puts("=== FAILURE, dumping cache"); + } cache_dump(); content_remove_user(c, callback, 0, 0); } diff --git a/desktop/browser.c b/desktop/browser.c index 4f9fcc362..ad29e6f38 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -230,6 +230,10 @@ void browser_window_open_location_historical(struct browser_window* bw, const ch bw->time0 = clock(); bw->loading_content = fetchcache(url, 0, browser_window_callback, bw, 0, gui_window_get_width(bw->window), 0); + if (bw->loading_content == 0) { + browser_window_set_status(bw, "Unable to fetch document"); + return; + } if (bw->loading_content->status == CONTENT_STATUS_READY) browser_window_callback(CONTENT_MSG_READY, bw->loading_content, bw, 0, 0); else if (bw->loading_content->status == CONTENT_STATUS_DONE) diff --git a/render/html.c b/render/html.c index 440b8fd0c..be0044fce 100644 --- a/render/html.c +++ b/render/html.c @@ -176,7 +176,8 @@ void html_convert_css_callback(content_msg msg, struct content *css, c->data.html.stylesheet_content[i] = fetchcache( error, c->url, html_convert_css_callback, c, i, css->width, css->height); - if (c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE) + if (c->data.html.stylesheet_content[i] != 0 && + c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE) c->active++; break; @@ -228,6 +229,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head) c->url, html_convert_css_callback, c, 0, c->width, c->height); + assert(c->data.html.stylesheet_content[0] != 0); if (c->data.html.stylesheet_content[0]->status != CONTENT_STATUS_DONE) c->active++; @@ -278,7 +280,8 @@ void html_find_stylesheets(struct content *c, xmlNode *head) c->data.html.stylesheet_content[i] = fetchcache(url, c->url, html_convert_css_callback, c, i, c->width, c->height); - if (c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE) + if (c->data.html.stylesheet_content[i] && + c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE) c->active++; free(url); i++; @@ -362,10 +365,12 @@ void html_fetch_object(struct content *c, char *url, struct box *box) c->width, c->height); /* we don't know the object's dimensions yet; use parent's as an estimate */ - c->active++; - if (c->data.html.object[i].content->status == CONTENT_STATUS_DONE) - html_object_callback(CONTENT_MSG_DONE, - c->data.html.object[i].content, c, i, 0); + if (c->data.html.object[i].content) { + c->active++; + if (c->data.html.object[i].content->status == CONTENT_STATUS_DONE) + html_object_callback(CONTENT_MSG_DONE, + c->data.html.object[i].content, c, i, 0); + } c->data.html.object_count++; } @@ -453,7 +458,8 @@ void html_object_callback(content_msg msg, struct content *object, c->data.html.object[i].content = fetchcache( error, c->url, html_object_callback, c, i, 0, 0); - if (c->data.html.object[i].content->status != CONTENT_STATUS_DONE) + if (c->data.html.object[i].content && + c->data.html.object[i].content->status != CONTENT_STATUS_DONE) c->active++; break; @@ -519,7 +525,8 @@ void html_revive(struct content *c, unsigned int width, unsigned int height) c->data.html.object[i].url, c->url, html_object_callback, c, i, 0, 0); - if (c->data.html.object[i].content->status != CONTENT_STATUS_DONE) + if (c->data.html.object[i].content && + c->data.html.object[i].content->status != CONTENT_STATUS_DONE) c->active++; } } -- cgit v1.2.3