summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2004-01-23 20:46:29 +0000
committerJames Bursa <james@netsurf-browser.org>2004-01-23 20:46:29 +0000
commit8755ceb0c809cde60b44acf74d55044315fd22e3 (patch)
treea24d6da09a0a4e8470f9313cf24d1a997453926b /content
parent9cf82c7fc4820e4fecc24d4e4fdd0926eefaa98e (diff)
downloadnetsurf-8755ceb0c809cde60b44acf74d55044315fd22e3.tar.gz
netsurf-8755ceb0c809cde60b44acf74d55044315fd22e3.tar.bz2
[project @ 2004-01-23 20:46:29 by bursa]
Add error pages for fetch failures. svn path=/import/netsurf/; revision=498
Diffstat (limited to 'content')
-rw-r--r--content/cache.c1
-rw-r--r--content/content.c21
-rw-r--r--content/content.h1
-rw-r--r--content/fetchcache.c42
4 files changed, 57 insertions, 8 deletions
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
@@ -343,6 +343,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.
*
* Calls the redraw function for the content, if it exists.
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 <unistd.h>