From bda01b31353e60fe4ad40d765de8ea1c396509bc Mon Sep 17 00:00:00 2001 From: James Bursa Date: Sat, 13 Jan 2007 00:21:15 +0000 Subject: 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 --- content/content.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++------ content/content.h | 11 ++++++++-- content/fetchcache.c | 1 + 3 files changed, 64 insertions(+), 8 deletions(-) (limited to 'content') 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 + * Copyright 2005-2007 James Bursa */ /** \file @@ -18,6 +18,7 @@ #include #include #include +#include #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 + * Copyright 2005-2007 James Bursa * Copyright 2003 Philip Pemberton */ @@ -16,6 +16,7 @@ #define _NETSURF_DESKTOP_CONTENT_H_ #include +#include #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, ¶ms); if (!mime_type) { msg_data.error = messages_get("NoMemory"); -- cgit v1.2.3