summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2007-01-13 00:21:15 +0000
committerJames Bursa <james@netsurf-browser.org>2007-01-13 00:21:15 +0000
commitbda01b31353e60fe4ad40d765de8ea1c396509bc (patch)
tree252891fdd2159e82e1f6287a92a8f14e6192a2da /content
parente76140557d804016563be73d8220c46a9c42ca7a (diff)
downloadnetsurf-bda01b31353e60fe4ad40d765de8ea1c396509bc.tar.gz
netsurf-bda01b31353e60fe4ad40d765de8ea1c396509bc.tar.bz2
Fix parsing error when an empty HTML data is returned. Add HTTP status and other information to status bar.
svn path=/trunk/netsurf/; revision=3140
Diffstat (limited to 'content')
-rw-r--r--content/content.c60
-rw-r--r--content/content.h11
-rw-r--r--content/fetchcache.c1
3 files changed, 64 insertions, 8 deletions
diff --git a/content/content.c b/content/content.c
index 0f23d25cc..d211bb109 100644
--- a/content/content.c
+++ b/content/content.c
@@ -2,7 +2,7 @@
* This file is part of NetSurf, http://netsurf-browser.org/
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
- * Copyright 2005 James Bursa <bursa@users.sourceforge.net>
+ * Copyright 2005-2007 James Bursa <bursa@users.sourceforge.net>
*/
/** \file
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include "netsurf/utils/config.h"
#include "netsurf/content/content.h"
#include "netsurf/content/fetch.h"
@@ -304,6 +305,7 @@ static const struct handler_entry handler_map[] = {
#define HANDLER_MAP_COUNT (sizeof(handler_map) / sizeof(handler_map[0]))
+static void content_update_status(struct content *c);
static void content_destroy(struct content *c);
static void content_stop_check(struct content *c);
@@ -373,6 +375,7 @@ struct content * content_create(const char *url)
c->refresh = 0;
c->bitmap = 0;
c->fresh = false;
+ c->time = clock();
c->size = 0;
c->title = 0;
c->active = 0;
@@ -380,13 +383,14 @@ struct content * content_create(const char *url)
user_sentinel->p1 = user_sentinel->p2 = 0;
user_sentinel->next = 0;
c->user_list = user_sentinel;
- content_set_status(c, messages_get("Loading"));
+ c->sub_status[0] = 0;
c->locked = false;
c->fetch = 0;
c->source_data = 0;
c->source_size = 0;
c->source_allocated = 0;
c->total_size = 0;
+ c->http_code = 0;
c->no_error_pages = false;
c->download = false;
c->error_count = 0;
@@ -400,6 +404,8 @@ struct content * content_create(const char *url)
c->cache_data->etag = 0;
c->cache_data->last_modified = 0;
+ content_set_status(c, messages_get("Loading"));
+
c->prev = 0;
c->next = content_list;
if (content_list)
@@ -592,11 +598,38 @@ void content_set_status(struct content *c, const char *status_message, ...)
int len;
va_start(ap, status_message);
- if ((len = vsnprintf(c->status_message, sizeof (c->status_message),
+ if ((len = vsnprintf(c->sub_status, sizeof (c->sub_status),
status_message, ap)) < 0 ||
- (int)sizeof (c->status_message) <= len)
- c->status_message[sizeof (c->status_message) - 1] = '\0';
+ (int)sizeof (c->sub_status) <= len)
+ c->sub_status[sizeof (c->sub_status) - 1] = '\0';
va_end(ap);
+
+ content_update_status(c);
+}
+
+
+void content_update_status(struct content *c)
+{
+ char token[20];
+ const char *status;
+ clock_t time;
+
+ snprintf(token, sizeof token, "HTTP%li", c->http_code);
+ status = messages_get(token);
+ if (status == token)
+ status = token + 4;
+
+ if (c->status == CONTENT_STATUS_TYPE_UNKNOWN ||
+ c->status == CONTENT_STATUS_LOADING ||
+ c->status == CONTENT_STATUS_READY)
+ time = clock() - c->time;
+ else
+ time = c->time;
+
+ snprintf(c->status_message, sizeof (c->status_message),
+ "%s (%.1fs) %s", status,
+ (float) time / CLOCKS_PER_SEC, c->sub_status);
+ /* LOG(("%s", c->status_message)); */
}
@@ -704,7 +737,22 @@ void content_convert(struct content *c, int width, int height)
c->status == CONTENT_STATUS_DONE);
content_broadcast(c, CONTENT_MSG_READY, msg_data);
if (c->status == CONTENT_STATUS_DONE)
- content_broadcast(c, CONTENT_MSG_DONE, msg_data);
+ content_set_done(c);
+}
+
+
+/**
+ * Put a content in status CONTENT_STATUS_DONE.
+ */
+
+void content_set_done(struct content *c)
+{
+ union content_msg_data msg_data;
+
+ c->status = CONTENT_STATUS_DONE;
+ c->time = clock() - c->time;
+ content_update_status(c);
+ content_broadcast(c, CONTENT_MSG_DONE, msg_data);
}
diff --git a/content/content.h b/content/content.h
index 123733ba9..268ba31a1 100644
--- a/content/content.h
+++ b/content/content.h
@@ -2,7 +2,7 @@
* This file is part of NetSurf, http://netsurf-browser.org/
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
- * Copyright 2005 James Bursa <bursa@users.sourceforge.net>
+ * Copyright 2005-2007 James Bursa <bursa@users.sourceforge.net>
* Copyright 2003 Philip Pemberton <philpem@users.sourceforge.net>
*/
@@ -16,6 +16,7 @@
#define _NETSURF_DESKTOP_CONTENT_H_
#include <stdint.h>
+#include <time.h>
#include "netsurf/utils/config.h"
#include "netsurf/content/content_type.h"
#include "netsurf/css/css.h"
@@ -178,6 +179,9 @@ struct content {
* shared between users. */
bool fresh;
struct cache_data *cache_data; /**< Cache control data */
+ clock_t time; /**< Creation time, if TYPE_UNKNOWN,
+ LOADING or READY,
+ otherwise total time. */
unsigned int size; /**< Estimated size of all data
associated with this content, except
@@ -186,7 +190,8 @@ struct content {
unsigned int active; /**< Number of child fetches or
conversions currently in progress. */
struct content_user *user_list; /**< List of users. */
- char status_message[80]; /**< Text for status bar. */
+ char status_message[120]; /**< Full text for status bar. */
+ char sub_status[80]; /**< Status of content. */
/** Content is being processed: data structures may be inconsistent
* and content must not be redrawn or modified. */
bool locked;
@@ -196,6 +201,7 @@ struct content {
unsigned long source_size; /**< Amount of data fetched so far. */
unsigned long source_allocated; /**< Amount of space allocated so far. */
unsigned long total_size; /**< Total data size, 0 if unknown. */
+ long http_code; /**< HTTP status code, 0 if not HTTP. */
bool no_error_pages; /**< Used by fetchcache(). */
bool download; /**< Used by fetchcache(). */
@@ -226,6 +232,7 @@ void content_set_status(struct content *c, const char *status_message, ...);
bool content_process_data(struct content *c, const char *data,
unsigned int size);
void content_convert(struct content *c, int width, int height);
+void content_set_done(struct content *c);
void content_reformat(struct content *c, int width, int height);
void content_clean(void);
void content_reset(struct content *c);
diff --git a/content/fetchcache.c b/content/fetchcache.c
index 220359df0..0a630661b 100644
--- a/content/fetchcache.c
+++ b/content/fetchcache.c
@@ -376,6 +376,7 @@ void fetchcache_callback(fetch_msg msg, void *p, const void *data,
switch (msg) {
case FETCH_TYPE:
c->total_size = size;
+ c->http_code = fetch_http_code(c->fetch);
mime_type = fetchcache_parse_type(data, &params);
if (!mime_type) {
msg_data.error = messages_get("NoMemory");