summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/content.c33
-rw-r--r--content/content.h4
-rw-r--r--content/fetchcache.c9
3 files changed, 35 insertions, 11 deletions
diff --git a/content/content.c b/content/content.c
index 39b1c7389..dacb46df8 100644
--- a/content/content.c
+++ b/content/content.c
@@ -627,6 +627,29 @@ void content_add_user(struct content *c,
/**
+ * Search the users of a content for the specified user.
+ *
+ * \return a content_user struct for the user, or 0 if not found
+ */
+
+struct content_user * content_find_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;
+
+ /* user_list starts with a sentinel */
+ for (user = c->user_list; user->next &&
+ !(user->next->callback == callback &&
+ user->next->p1 == p1 &&
+ user->next->p2 == p2); user = user->next)
+ ;
+ return user->next;
+}
+
+
+/**
* Remove a callback user.
*
* The callback function, p1, and p2 must be identical to those passed to
@@ -690,18 +713,12 @@ void content_stop(struct content *c,
assert(c->status == CONTENT_STATUS_READY);
- /* user_list starts with a sentinel */
- for (user = c->user_list; user->next != 0 &&
- !(user->next->callback == callback &&
- user->next->p1 == p1 &&
- user->next->p2 == p2); user = user->next)
- ;
- if (user->next == 0) {
+ user = content_find_user(c, callback, p1, p2);
+ if (!user) {
LOG(("user not found in list"));
assert(0);
return;
}
- user = user->next;
LOG(("%p %s: stop user %p %p %p", c, c->url, callback, p1, p2));
user->stop = true;
diff --git a/content/content.h b/content/content.h
index 1048df818..09d59be45 100644
--- a/content/content.h
+++ b/content/content.h
@@ -270,6 +270,10 @@ void 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 * content_find_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);
void content_remove_user(struct content *c,
void (*callback)(content_msg msg, struct content *c, void *p1,
void *p2, union content_msg_data data),
diff --git a/content/fetchcache.c b/content/fetchcache.c
index fb671ea50..8d3272c94 100644
--- a/content/fetchcache.c
+++ b/content/fetchcache.c
@@ -172,12 +172,15 @@ void fetchcache_go(struct content *content, char *referer,
} else if (content->status == CONTENT_STATUS_READY) {
callback(CONTENT_MSG_LOADING, content, p1, p2, msg_data);
- callback(CONTENT_MSG_READY, content, p1, p2, msg_data);
+ if (content_find_user(content, callback, p1, p2))
+ callback(CONTENT_MSG_READY, content, p1, p2, msg_data);
} else if (content->status == CONTENT_STATUS_DONE) {
callback(CONTENT_MSG_LOADING, content, p1, p2, msg_data);
- callback(CONTENT_MSG_READY, content, p1, p2, msg_data);
- callback(CONTENT_MSG_DONE, content, p1, p2, msg_data);
+ if (content_find_user(content, callback, p1, p2))
+ callback(CONTENT_MSG_READY, content, p1, p2, msg_data);
+ if (content_find_user(content, callback, p1, p2))
+ callback(CONTENT_MSG_DONE, content, p1, p2, msg_data);
} else if (content->status == CONTENT_STATUS_ERROR) {
/* shouldn't usually occur */