From 8755ceb0c809cde60b44acf74d55044315fd22e3 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Fri, 23 Jan 2004 20:46:29 +0000 Subject: [project @ 2004-01-23 20:46:29 by bursa] Add error pages for fetch failures. svn path=/import/netsurf/; revision=498 --- content/cache.c | 1 + content/content.c | 21 +++++++++++++++++++++ content/content.h | 1 + content/fetchcache.c | 42 ++++++++++++++++++++++++++++++++++-------- 4 files changed, 57 insertions(+), 8 deletions(-) (limited to 'content') diff --git a/content/cache.c b/content/cache.c index 7fab30352..5e95f4c6e 100644 --- a/content/cache.c +++ b/content/cache.c @@ -194,6 +194,7 @@ void cache_destroy(struct content * content) e->prev->next = e->next; e->next->prev = e->prev; xfree(e); + content->cache = 0; } diff --git a/content/content.c b/content/content.c index 91481ff48..61b8cd1c9 100644 --- a/content/content.c +++ b/content/content.c @@ -342,6 +342,27 @@ void content_destroy(struct content *c) } +/** + * Reset a content. + * + * Calls the destroy function for the content, but does not free + * the structure. + */ + +void content_reset(struct content *c) +{ + assert(c != 0); + LOG(("content %p %s", c, c->url)); + if (c->type < HANDLER_MAP_COUNT) + handler_map[c->type].destroy(c); + c->type = CONTENT_UNKNOWN; + c->status = CONTENT_STATUS_TYPE_UNKNOWN; + c->size = sizeof(struct content); + free(c->mime_type); + c->mime_type = 0; +} + + /** * Display content on screen. * diff --git a/content/content.h b/content/content.h index ffd73ab06..d5adf1a6f 100644 --- a/content/content.h +++ b/content/content.h @@ -185,6 +185,7 @@ void content_convert(struct content *c, unsigned long width, unsigned long heigh void content_revive(struct content *c, unsigned long width, unsigned long height); void content_reformat(struct content *c, unsigned long width, unsigned long height); void content_destroy(struct content *c); +void content_reset(struct content *c); void content_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, long clip_x0, long clip_y0, long clip_x1, long clip_y1); diff --git a/content/fetchcache.c b/content/fetchcache.c index 4cec561dc..e7e8f2b3a 100644 --- a/content/fetchcache.c +++ b/content/fetchcache.c @@ -23,12 +23,15 @@ #include "netsurf/content/fetchcache.h" #include "netsurf/content/fetch.h" #include "netsurf/utils/log.h" +#include "netsurf/utils/messages.h" #include "netsurf/utils/utils.h" +static char error_page[1000]; static regex_t re_content_type; static void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size); static char *fetchcache_parse_type(char *s, char **params[]); +static void fetchcache_error_page(struct content *c, const char *error); /** @@ -60,6 +63,8 @@ struct content * fetchcache(const char *url0, char *referer, struct content *c; char *url = xstrdup(url0); char *hash = strchr(url, '#'); + const char *params[] = { 0 }; + char error_message[500]; /* strip fragment identifier */ if (hash != 0) @@ -68,7 +73,9 @@ struct content * fetchcache(const char *url0, char *referer, LOG(("url %s", url)); #ifdef WITH_POST - if (!post_urlenc && !post_multipart) { + if (!post_urlenc && !post_multipart) +#endif + { c = cache_get(url); if (c != 0) { free(url); @@ -76,15 +83,15 @@ struct content * fetchcache(const char *url0, char *referer, return c; } } -#endif c = content_create(url); content_add_user(c, callback, p1, p2); #ifdef WITH_POST if (!post_urlenc && !post_multipart) - cache_put(c); #endif + cache_put(c); + c->fetch_size = 0; c->width = width; c->height = height; @@ -96,14 +103,15 @@ struct content * fetchcache(const char *url0, char *referer, ,cookies #endif ); - free(url); if (c->fetch == 0) { LOG(("warning: fetch_start failed")); if (c->cache) cache_destroy(c); - content_destroy(c); - return 0; + snprintf(error_message, sizeof error_message, + messages_get("InvalidURL"), url); + fetchcache_error_page(c, error_message); } + free(url); return c; } @@ -159,10 +167,11 @@ void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size) case FETCH_ERROR: LOG(("FETCH_ERROR, '%s'", data)); c->fetch = 0; - content_broadcast(c, CONTENT_MSG_ERROR, data); +/* content_broadcast(c, CONTENT_MSG_ERROR, data); */ if (c->cache) cache_destroy(c); - content_destroy(c); + content_reset(c); + fetchcache_error_page(c, data); break; case FETCH_REDIRECT: @@ -252,6 +261,23 @@ char *fetchcache_parse_type(char *s, char **params[]) } +/** + * Generate an error page. + * + * \param c empty content to generate the page in + * \param error message to display + */ + +void fetchcache_error_page(struct content *c, const char *error) +{ + const char *params[] = { 0 }; + snprintf(error_page, sizeof error_page, messages_get("ErrorPage"), error); + content_set_type(c, CONTENT_HTML, "text/html", params); + content_process_data(c, error_page, strlen(error_page)); + content_convert(c, c->width, c->height); +} + + #ifdef TEST #include -- cgit v1.2.3