[project @ 2004-01-23 20:46:29 by bursa]

Add error pages for fetch failures.

svn path=/import/netsurf/; revision=498
This commit is contained in:
James Bursa 2004-01-23 20:46:29 +00:00
parent 9cf82c7fc4
commit 8755ceb0c8
5 changed files with 59 additions and 8 deletions

View File

@ -40,3 +40,5 @@ Not2xx:Server returned an error
cookiefile:Choices:WWW.NetSurf.Cookies
cookiejar:<Choices$Write>.WWW.NetSurf.Cookies
ErrorPage:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>Page error</title></head><body><h1>Sorry, NetSurf was unable to display this page</h1><p><strong>%s</strong></p></body></html>
InvalidURL:The address <em>%s</em> could not be understood.

View File

@ -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;
}

View File

@ -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.
*

View File

@ -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);

View File

@ -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 <unistd.h>