diff options
author | John Tytgat <joty@netsurf-browser.org> | 2004-06-05 15:03:59 +0000 |
---|---|---|
committer | John Tytgat <joty@netsurf-browser.org> | 2004-06-05 15:03:59 +0000 |
commit | dc65374aa6ccd54fd4b61cacb7bd57b7d756043d (patch) | |
tree | 2164e073695b9d506f3bb9e0a3327d117749b0d5 /content | |
parent | ea2cc2312770769604fb14569408f039eaa4c266 (diff) | |
download | netsurf-dc65374aa6ccd54fd4b61cacb7bd57b7d756043d.tar.gz netsurf-dc65374aa6ccd54fd4b61cacb7bd57b7d756043d.tar.bz2 |
[project @ 2004-06-05 15:03:59 by joty]
Created content_set_status() : one centralised place where status_message
in the content struct is updated in a fail safe way.
svn path=/import/netsurf/; revision=928
Diffstat (limited to 'content')
-rw-r--r-- | content/content.c | 26 | ||||
-rw-r--r-- | content/content.h | 1 | ||||
-rw-r--r-- | content/fetchcache.c | 8 |
3 files changed, 29 insertions, 6 deletions
diff --git a/content/content.c b/content/content.c index be4331884..a002c04fd 100644 --- a/content/content.c +++ b/content/content.c @@ -13,8 +13,10 @@ */ #include <assert.h> -#include <string.h> +#include <stdarg.h> +#include <stdio.h> #include <stdlib.h> +#include <string.h> #include "netsurf/utils/config.h" #include "netsurf/content/content.h" #include "netsurf/css/css.h" @@ -183,7 +185,7 @@ struct content * content_create(char *url) c->source_data = 0; c->source_size = 0; c->mime_type = 0; - strcpy(c->status_message, messages_get("Loading")); + content_set_status(c, messages_get("Loading")); user_sentinel = xcalloc(1, sizeof(*user_sentinel)); user_sentinel->callback = 0; user_sentinel->p1 = user_sentinel->p2 = 0; @@ -230,6 +232,26 @@ void content_set_type(struct content *c, content_type type, /** + * Updates content with new status. + * + * The textual status contained in the content is updated with given string. + * + * \param status_message new textual status + */ +void content_set_status(struct content *c, const char *status_message, ...) +{ + va_list ap; + int len; + + va_start(ap, status_message); + if ((len = vsnprintf(c->status_message, sizeof(c->status_message), status_message, ap)) < 0 + || len >= sizeof(c->status_message)) + c->status_message[sizeof(c->status_message) - 1] = '\0'; + va_end(ap); +} + + +/** * Process a block of source data. * * Calls the process_data function for the content. diff --git a/content/content.h b/content/content.h index 5c36559da..13c4092ce 100644 --- a/content/content.h +++ b/content/content.h @@ -169,6 +169,7 @@ content_type content_lookup(const char *mime_type); struct content * content_create(char *url); void content_set_type(struct content *c, content_type type, const char *mime_type, const char *params[]); +void content_set_status(struct content *c, const char *status_message, ...); void content_process_data(struct content *c, char *data, unsigned long size); void content_convert(struct content *c, unsigned long width, unsigned long height); void content_revive(struct content *c, unsigned long width, unsigned long height); diff --git a/content/fetchcache.c b/content/fetchcache.c index a56da83f9..ed958882e 100644 --- a/content/fetchcache.c +++ b/content/fetchcache.c @@ -171,13 +171,13 @@ void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size) case FETCH_DATA: LOG(("FETCH_DATA")); if (c->total_size) - sprintf(c->status_message, + content_set_status(c, messages_get("RecPercent"), human_friendly_bytesize(c->source_size + size), human_friendly_bytesize(c->total_size), (unsigned int) ((c->source_size + size) * 100.0 / c->total_size)); else - sprintf(c->status_message, + content_set_status(c, messages_get("Received"), human_friendly_bytesize(c->source_size + size)); content_broadcast(c, CONTENT_MSG_STATUS, msg_data); @@ -186,9 +186,9 @@ void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size) case FETCH_FINISHED: LOG(("FETCH_FINISHED")); - sprintf(c->status_message, messages_get("Converting"), - c->source_size); c->fetch = 0; + content_set_status(c, messages_get("Converting"), + c->source_size); content_broadcast(c, CONTENT_MSG_STATUS, msg_data); content_convert(c, c->width, c->height); break; |