diff --git a/content/urldb.c b/content/urldb.c index 6d51c932d..11cfe2ca8 100644 --- a/content/urldb.c +++ b/content/urldb.c @@ -188,10 +188,10 @@ static bool urldb_iterate_partial_path(const struct path_data *parent, const struct url_data *data)); static bool urldb_iterate_entries_host(struct search_node *parent, bool (*url_callback)(const char *url, const struct url_data *data), - bool (*cookie_callback)(const struct cookie_data *data)); + bool (*cookie_callback)(const char *domain, const struct cookie_data *data)); static bool urldb_iterate_entries_path(const struct path_data *parent, bool (*url_callback)(const char *url, const struct url_data *data), - bool (*cookie_callback)(const struct cookie_data *data)); + bool (*cookie_callback)(const char *domain, const struct cookie_data *data)); /* Insertion */ static struct host_part *urldb_add_host_node(const char *part, @@ -1309,7 +1309,7 @@ void urldb_iterate_entries(bool (*callback)(const char *url, * * \param callback Function to callback for each entry */ -void urldb_iterate_cookies(bool (*callback)(const struct cookie_data *data)) +void urldb_iterate_cookies(bool (*callback)(const char *domain, const struct cookie_data *data)) { int i; @@ -1332,7 +1332,7 @@ void urldb_iterate_cookies(bool (*callback)(const struct cookie_data *data)) */ bool urldb_iterate_entries_host(struct search_node *parent, bool (*url_callback)(const char *url, const struct url_data *data), - bool (*cookie_callback)(const struct cookie_data *data)) + bool (*cookie_callback)(const char *domain, const struct cookie_data *data)) { if (parent == &empty) return true; @@ -1364,7 +1364,7 @@ bool urldb_iterate_entries_host(struct search_node *parent, */ bool urldb_iterate_entries_path(const struct path_data *parent, bool (*url_callback)(const char *url, const struct url_data *data), - bool (*cookie_callback)(const struct cookie_data *data)) + bool (*cookie_callback)(const char *domain, const struct cookie_data *data)) { const struct path_data *p; @@ -1384,7 +1384,7 @@ bool urldb_iterate_entries_path(const struct path_data *parent, (const struct url_data *) &parent->urld)) return false; } else { - if (parent->cookies && !cookie_callback( + if (parent->cookies && !cookie_callback(parent->cookies->domain, (const struct cookie_data *) parent->cookies)) return false; } @@ -2619,7 +2619,7 @@ bool urldb_set_cookie(const char *header, const char *url) /* Now insert into database */ if (!urldb_insert_cookie(c, scheme, urlt)) goto error; - cookies_update((struct cookie_data *)c); + cookies_update(c->domain, (struct cookie_data *)c); } while (cur < end); free(host); diff --git a/content/urldb.h b/content/urldb.h index ec08bb2b1..699c89674 100644 --- a/content/urldb.h +++ b/content/urldb.h @@ -87,7 +87,8 @@ void urldb_iterate_partial(const char *prefix, /* Iteration */ void urldb_iterate_entries(bool (*callback)(const char *url, const struct url_data *data)); -void urldb_iterate_cookies(bool (*callback)(const struct cookie_data *cookie)); +void urldb_iterate_cookies(bool (*callback)(const char *domain, + const struct cookie_data *cookie)); /* Debug */ void urldb_dump(void); diff --git a/desktop/cookies.h b/desktop/cookies.h index 94d74dd50..4e2753037 100644 --- a/desktop/cookies.h +++ b/desktop/cookies.h @@ -16,6 +16,6 @@ struct cookie_data; -bool cookies_update(const struct cookie_data *data); +bool cookies_update(const char *domain, const struct cookie_data *data); #endif diff --git a/riscos/cookies.c b/riscos/cookies.c index 2830e1ec8..173f73d69 100644 --- a/riscos/cookies.c +++ b/riscos/cookies.c @@ -112,23 +112,25 @@ bool ro_gui_cookies_click(wimp_pointer *pointer) /** * Perform cookie addition * - * \param data Cookie data for a domain + * \param data Cookie data for a domain, or NULL * \return true (for urldb_iterate_entries) */ -bool cookies_update(const struct cookie_data *data) +bool cookies_update(const char *domain, const struct cookie_data *data) { struct node *parent; struct node *node = NULL; struct node *child; - const struct cookie_data *cookie; + struct node *add; + const struct cookie_data *cookie = NULL; - assert(data); + assert(domain); /* check if we're a domain, and add get the first cookie */ - for (cookie = data; cookie->prev; cookie = cookie->prev); + if (data) + for (cookie = data; cookie->prev; cookie = cookie->prev); if (!cookies_init) { - node = ro_gui_cookies_find(data->domain); + node = ro_gui_cookies_find(domain); if (node) { /* mark as deleted so we don't remove the cookies */ for (child = node->child; child; child = child->next) @@ -137,19 +139,27 @@ bool cookies_update(const struct cookie_data *data) tree_delete_node(cookies_tree, node->child, true); } + if (!data) { + if (!node) + return true; + tree_delete_node(cookies_tree, node, false); + tree_handle_node_changed(cookies_tree, + cookies_tree->root, true, false); + return true; + } } if (!node) { for (parent = cookies_tree->root->child; parent; parent = parent->next) { - if (strcmp(cookie->domain, parent->data.text) < 0) + if (strcmp(domain, parent->data.text) < 0) break; } if (!parent) { node = tree_create_folder_node(cookies_tree->root, - cookie->domain); + domain); } else { - node = tree_create_folder_node(NULL, data->domain); + node = tree_create_folder_node(NULL, domain); if (node) tree_link_node(parent, node, true); } @@ -158,8 +168,12 @@ bool cookies_update(const struct cookie_data *data) return true; node->editable = false; - for (; cookie; cookie = cookie->next) - tree_create_cookie_node(node, cookie); + for (; cookie; cookie = cookie->next) { + add = tree_create_cookie_node(node, cookie); + if (!cookies_init) + tree_handle_node_changed(cookies_tree, add, + true, false); + } if (!cookies_init) { tree_handle_node_changed(cookies_tree, node, true, false);