Extent cookie_update API to allow notification of deleted domains. Fix nodes not being re-calculated.

svn path=/trunk/netsurf/; revision=2765
This commit is contained in:
Richard Wilson 2006-07-16 16:10:43 +00:00
parent 7f75f86661
commit 9294938976
4 changed files with 35 additions and 20 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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 */
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);