From 83346830688525a287489cc791299cbc945d4fc4 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 2 Jan 2005 03:58:21 +0000 Subject: [project @ 2005-01-02 03:58:20 by jmb] xcalloc/xrealloc/xstrdup-purge - Lose remaining calls (and purge the relevant functions from utils.c) svn path=/import/netsurf/; revision=1419 --- content/content.c | 30 +++++++++++++++++++++++++++--- content/content.h | 2 +- content/fetchcache.c | 10 +++++++--- 3 files changed, 35 insertions(+), 7 deletions(-) (limited to 'content') diff --git a/content/content.c b/content/content.c index 052a35fe7..7dd85a668 100644 --- a/content/content.c +++ b/content/content.c @@ -392,7 +392,16 @@ bool content_set_type(struct content *c, content_type type, callback = c->user_list->next->next->callback; p1 = c->user_list->next->next->p1; p2 = c->user_list->next->next->p2; - content_add_user(clone, callback, p1, p2); + if (!content_add_user(clone, callback, p1, p2)) { + c->type = CONTENT_UNKNOWN; + c->status = CONTENT_STATUS_ERROR; + content_destroy(clone); + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, + msg_data); + warn_user("NoMemory", 0); + return false; + } content_remove_user(c, callback, p1, p2); content_broadcast(clone, CONTENT_MSG_NEWPTR, msg_data); fetchcache_go(clone, 0, callback, p1, p2, 0, 0, false); @@ -706,24 +715,39 @@ bool content_redraw(struct content *c, int x, int y, /** * Register a user for callbacks. * + * \param c The content to register + * \param callback The callback function + * \param p1, p2 Callback private data + * \return true on success, false otherwise and error broadcast to users + * * The callback will be called with p1 and p2 when content_broadcast() is * called with the content. */ -void content_add_user(struct content *c, +bool content_add_user(struct content *c, void (*callback)(content_msg msg, struct content *c, void *p1, void *p2, union content_msg_data data), void *p1, void *p2) { struct content_user *user; + union content_msg_data msg_data; + LOG(("content %s, user %p %p %p", c->url, callback, p1, p2)); - user = xcalloc(1, sizeof(*user)); + user = calloc(1, sizeof(*user)); + if (!user) { + c->status = CONTENT_STATUS_ERROR; + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; + } user->callback = callback; user->p1 = p1; user->p2 = p2; user->stop = false; user->next = c->user_list->next; c->user_list->next = user; + + return true; } diff --git a/content/content.h b/content/content.h index cb5d411e6..da565c711 100644 --- a/content/content.h +++ b/content/content.h @@ -276,7 +276,7 @@ bool content_redraw(struct content *c, int x, int y, int width, int height, int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale, unsigned long background_colour); -void content_add_user(struct content *c, +bool content_add_user(struct content *c, void (*callback)(content_msg msg, struct content *c, void *p1, void *p2, union content_msg_data data), void *p1, void *p2); diff --git a/content/fetchcache.c b/content/fetchcache.c index bdc04eb29..81c608b9e 100644 --- a/content/fetchcache.c +++ b/content/fetchcache.c @@ -84,8 +84,10 @@ struct content * fetchcache(const char *url, if (!post_urlenc && !post_multipart) { if ((c = content_get(url1)) != NULL) { free(url1); - content_add_user(c, callback, p1, p2); - return c; + if (!content_add_user(c, callback, p1, p2)) + return NULL; + else + return c; } } @@ -93,7 +95,9 @@ struct content * fetchcache(const char *url, free(url1); if (!c) return NULL; - content_add_user(c, callback, p1, p2); + if (!content_add_user(c, callback, p1, p2)) { + return NULL; + } if (!post_urlenc && !post_multipart) c->fresh = true; -- cgit v1.2.3