Allow the user to delete cookies.

svn path=/trunk/netsurf/; revision=2770
This commit is contained in:
Richard Wilson 2006-07-16 21:42:37 +00:00
parent 81512fa939
commit 0309e937e6
13 changed files with 147 additions and 47 deletions

View File

@ -39,7 +39,6 @@ Quit:Beenden
# Iconbar -> Open menu # Iconbar -> Open menu
# #
OpenURL:Öffne URL OpenURL:Öffne URL
ShowCookies:Show cookies...
# Main menu # Main menu
# #
@ -134,6 +133,10 @@ HotlistShow:Hotlist zeigen... F6
HistLocal:History (lokal) zeigen... F7 HistLocal:History (lokal) zeigen... F7
HistGlobal:History (global) zeigen... ^F7 HistGlobal:History (global) zeigen... ^F7
# Main -> Utilities -> Cookies menu
ShowCookies:Show cookies...
DeleteCookies:Delete all cookies
# Main -> Utilities -> Window menu # Main -> Utilities -> Window menu
# #
WindowSave:aktuelle Fensterposition speichern WindowSave:aktuelle Fensterposition speichern

View File

@ -39,7 +39,6 @@ Quit:Quit
# Iconbar -> Open menu # Iconbar -> Open menu
# #
OpenURL:Open URL OpenURL:Open URL
ShowCookies:Show cookies...
# Main menu # Main menu
# #
@ -134,6 +133,10 @@ HotlistShow:Show hotlist... F6
HistLocal:Show local history... F7 HistLocal:Show local history... F7
HistGlobal:Show global history... ^F7 HistGlobal:Show global history... ^F7
# Main -> Utilities -> Cookies menu
ShowCookies:Show cookies...
DeleteCookies:Delete all cookies
# Main -> Utilities -> Window menu # Main -> Utilities -> Window menu
# #
WindowSave:Set as default position WindowSave:Set as default position

View File

@ -39,7 +39,6 @@ Quit:Quitter
# Iconbar -> Open menu # Iconbar -> Open menu
# #
OpenURL:Ouvrir l'URL... OpenURL:Ouvrir l'URL...
ShowCookies:Show cookies...
# Main menu # Main menu
# #
@ -134,6 +133,10 @@ HotlistShow:Montrer les favoris... F6
HistLocal:Montrer l'historique local... F7 HistLocal:Montrer l'historique local... F7
HistGlobal:Montrer l'historique global... ^F7 HistGlobal:Montrer l'historique global... ^F7
# Main -> Utilities -> Cookies menu
ShowCookies:Show cookies...
DeleteCookies:Delete all cookies
# Main -> Utilities -> Window menu # Main -> Utilities -> Window menu
# #
WindowSave:Définir comme position par défaut WindowSave:Définir comme position par défaut

View File

@ -39,7 +39,6 @@ Quit:Stop
# Iconbar -> Open menu # Iconbar -> Open menu
# #
OpenURL:Open URL OpenURL:Open URL
ShowCookies:Show cookies...
# Main menu # Main menu
# #
@ -141,6 +140,10 @@ WindowStagr:Nieuw venster verplaatsen
WindowSize:Copieer venster positie WindowSize:Copieer venster positie
WindowReset:Venster positie terugzetten WindowReset:Venster positie terugzetten
# Main -> Utilities -> Cookies menu
ShowCookies:Show cookies...
DeleteCookies:Delete all cookies
# Main -> Help menu # Main -> Help menu
# #
HelpContent:Inhoud F1 HelpContent:Inhoud F1

View File

@ -245,6 +245,8 @@ static bool urldb_insert_cookie(struct cookie_internal_data *c, const char *sche
static void urldb_free_cookie(struct cookie_internal_data *c); static void urldb_free_cookie(struct cookie_internal_data *c);
static bool urldb_concat_cookie(struct cookie_internal_data *c, int *used, static bool urldb_concat_cookie(struct cookie_internal_data *c, int *used,
int *alloc, char **buf); int *alloc, char **buf);
static void urldb_delete_cookie_hosts(const char *domain, const char *path, const char *name, struct host_part *parent);
static void urldb_delete_cookie_paths(const char *domain, const char *path, const char *name, struct path_data *parent);
static void urldb_save_cookie_hosts(FILE *fp, struct host_part *parent); static void urldb_save_cookie_hosts(FILE *fp, struct host_part *parent);
static void urldb_save_cookie_paths(FILE *fp, struct path_data *parent); static void urldb_save_cookie_paths(FILE *fp, struct path_data *parent);
@ -2372,6 +2374,7 @@ char *urldb_get_cookie(const char *url, const char *referer)
version = c->version; version = c->version;
c->last_used = now; c->last_used = now;
cookies_update(c->domain, (struct cookie_data *)c);
count++; count++;
} }
@ -2411,7 +2414,7 @@ char *urldb_get_cookie(const char *url, const char *referer)
version = c->version; version = c->version;
c->last_used = now; c->last_used = now;
cookies_update(c->domain, (struct cookie_data *)c);
count++; count++;
} }
} }
@ -2454,6 +2457,7 @@ char *urldb_get_cookie(const char *url, const char *referer)
version = c->version; version = c->version;
c->last_used = now; c->last_used = now;
cookies_update(c->domain, (struct cookie_data *)c);
count++; count++;
} }
@ -3189,6 +3193,54 @@ void urldb_load_cookies(const char *filename)
fclose(fp); fclose(fp);
} }
/**
* Delete a cookie
*
* \param domain The cookie's domain
* \param path The cookie's path
* \param name The cookie's name
*/
void urldb_delete_cookie(const char *domain, const char *path, const char *name)
{
urldb_delete_cookie_hosts(domain, path, name, &db_root);
}
void urldb_delete_cookie_hosts(const char *domain, const char *path, const char *name, struct host_part *parent)
{
assert(parent);
urldb_delete_cookie_paths(domain, path, name, &parent->paths);
for (struct host_part *h = parent->children; h; h = h->next)
urldb_delete_cookie_hosts(domain, path, name, h);
}
void urldb_delete_cookie_paths(const char *domain, const char *path, const char *name, struct path_data *parent)
{
struct cookie_internal_data *c;
assert(parent);
for (c = parent->cookies; c; c = c->next) {
if (!strcmp(c->domain, domain) && !strcmp(c->path, path) &&
!strcmp(c->name, name)) {
if (c->prev)
c->prev->next = c->next;
else
parent->cookies = c->next;
if (c->next)
c->next->prev = c->prev;
if (!parent->cookies)
cookies_update(domain, NULL);
urldb_free_cookie(c);
return;
}
}
for (struct path_data *p = parent->children; p; p = p->next)
urldb_delete_cookie_paths(domain, path, name, p);
}
/** /**
* Save persistent cookies to file * Save persistent cookies to file
* *

View File

@ -96,6 +96,7 @@ void urldb_dump(void);
/* Cookies */ /* Cookies */
bool urldb_set_cookie(const char *header, const char *url); bool urldb_set_cookie(const char *header, const char *url);
char *urldb_get_cookie(const char *url, const char *referer); char *urldb_get_cookie(const char *url, const char *referer);
void urldb_delete_cookie(const char *domain, const char *path, const char *name);
void urldb_load_cookies(const char *filename); void urldb_load_cookies(const char *filename);
void urldb_save_cookies(const char *filename); void urldb_save_cookies(const char *filename);

View File

@ -843,8 +843,11 @@ void tree_delink_node(struct node *node) {
node->parent->child = node->next; node->parent->child = node->next;
if (node->parent->last_child == node) if (node->parent->last_child == node)
node->parent->last_child = node->previous; node->parent->last_child = node->previous;
if (node->parent->child == NULL) if (node->parent->child == NULL) {
node->parent->expanded = false; /* don't contract top-level node */
if (node->parent->parent)
node->parent->expanded = false;
}
node->parent = NULL; node->parent = NULL;
} }
if (node->previous) if (node->previous)
@ -884,9 +887,7 @@ void tree_delete_selected_nodes(struct tree *tree, struct node *node) {
* \param siblings whether to delete all siblings * \param siblings whether to delete all siblings
*/ */
void tree_delete_node(struct tree *tree, struct node *node, bool siblings) { void tree_delete_node(struct tree *tree, struct node *node, bool siblings) {
tree_delete_node_internal(tree, node, siblings); tree_delete_node_internal(tree, node, siblings);
if (tree->root) if (tree->root)
tree_recalculate_node_positions(tree, tree->root); tree_recalculate_node_positions(tree, tree->root);
tree_redraw_area(tree, 0, 0, 16384, 16384); /* \todo correct area */ tree_redraw_area(tree, 0, 0, 16384, 16384); /* \todo correct area */
@ -902,51 +903,78 @@ void tree_delete_node(struct tree *tree, struct node *node, bool siblings) {
* \param siblings whether to delete all siblings * \param siblings whether to delete all siblings
*/ */
void tree_delete_node_internal(struct tree *tree, struct node *node, bool siblings) { void tree_delete_node_internal(struct tree *tree, struct node *node, bool siblings) {
struct node *next; struct node *next, *child;
struct node *parent; struct node_element *e, *f, *domain, *path;
struct node_element *e, *f; char *domain_t, *path_t, name_t;
char *space;
assert(node); assert(node);
if (tree->temp_selection == node) if (tree->temp_selection == node)
tree->temp_selection = NULL; tree->temp_selection = NULL;
if (tree->root == node) if (tree->root == node)
tree->root = NULL; tree->root = NULL;
next = node->next; next = node->next;
if (node->child)
tree_delete_node_internal(tree, node->child, true);
node->child = NULL;
parent = node->parent;
tree_delink_node(node); tree_delink_node(node);
child = node->child;
node->child = NULL;
if (child)
tree_delete_node_internal(tree, child, true);
if (!node->retain_in_memory) { if (!node->retain_in_memory) {
node->retain_in_memory = true;
for (e = &node->data; e; e = f) { for (e = &node->data; e; e = f) {
f = e->next;
if (e->text) { if (e->text) {
/* we don't free non-editable titles or URLs */ /* we don't free non-editable titles or URLs */
if ((node->editable) || (node->folder)) if ((node->editable) || (node->folder))
free(e->text); free(e->text);
else { else {
if (e->data == TREE_ELEMENT_URL) { /* only reset non-deleted items */
/* reset URL characteristics */
urldb_reset_url_visit_data(e->text);
}
/* if not already 'deleted' then delete cookie */
if (!node->deleted) { if (!node->deleted) {
/* todo: delete cookie data */ if (e->data == TREE_ELEMENT_URL) {
/* reset URL characteristics */
urldb_reset_url_visit_data(e->text);
} else if (e->data == TREE_ELEMENT_NAME) {
/* get the rest of the cookie data */
domain = tree_find_element(node,
TREE_ELEMENT_DOMAIN);
path = tree_find_element(node,
TREE_ELEMENT_PATH);
if (domain && path) {
domain_t = domain->text +
strlen(messages_get(
"TreeDomain")) - 4;
space = strchr(domain_t, ' ');
if (space)
*space = '\0';
path_t = path->text +
strlen(messages_get(
"TreePath")) - 4;
space = strchr(path_t, ' ');
if (space)
*space = '\0';
name_t = e->text;
urldb_delete_cookie(
domain_t,
path_t,
e->text);
}
}
} }
if (e->data != TREE_ELEMENT_TITLE && if (e->data != TREE_ELEMENT_TITLE &&
e->data != TREE_ELEMENT_URL) e->data != TREE_ELEMENT_URL) {
free(e->text); free(e->text);
e->text = NULL;
}
} }
} }
if (e->sprite) if (e->sprite) {
free(e->sprite); /* \todo platform specific bits */ free(e->sprite); /* \todo platform specific bits */
e->sprite = NULL;
}
f = e->next;
if (e != &node->data) if (e != &node->data)
free(e); free(e);
} }
@ -1002,7 +1030,7 @@ struct node *tree_create_leaf_node(struct node *parent, const char *title) {
node->folder = false; node->folder = false;
node->data.parent = node; node->data.parent = node;
node->data.type = NODE_ELEMENT_TEXT; node->data.type = NODE_ELEMENT_TEXT;
node->data.text = squash_whitespace(title); node->data.text = strdup(squash_whitespace(title));
node->data.data = TREE_ELEMENT_TITLE; node->data.data = TREE_ELEMENT_TITLE;
node->editable = true; node->editable = true;
if (parent) if (parent)
@ -1055,15 +1083,7 @@ struct node *tree_create_URL_node(struct node *parent,
assert(data); assert(data);
if (!title) { node = tree_create_leaf_node(parent, title ? title : url);
if (data->title)
title = strdup(data->title);
else
title = strdup(url);
if (!title)
return NULL;
}
node = tree_create_leaf_node(parent, title);
if (!node) if (!node)
return NULL; return NULL;
@ -1077,7 +1097,6 @@ struct node *tree_create_URL_node(struct node *parent,
element->text = strdup(url); element->text = strdup(url);
tree_update_URL_node(node, url, NULL); tree_update_URL_node(node, url, NULL);
return node; return node;
} }
@ -1119,7 +1138,6 @@ struct node *tree_create_URL_node_shared(struct node *parent,
element->text = url; element->text = url;
tree_update_URL_node(node, url, data); tree_update_URL_node(node, url, data);
return node; return node;
} }
@ -1201,7 +1219,6 @@ struct node *tree_create_cookie_node(struct node *parent,
element->text = strdup(buffer); element->text = strdup(buffer);
} }
if ((data->comment) && (strcmp(data->comment, ""))) { if ((data->comment) && (strcmp(data->comment, ""))) {
LOG(("Comment: '%s'", data->comment));
element = tree_create_node_element(node, TREE_ELEMENT_COMMENT); element = tree_create_node_element(node, TREE_ELEMENT_COMMENT);
if (element) { if (element) {
snprintf(buffer, 256, messages_get("TreeComment"), data->comment); snprintf(buffer, 256, messages_get("TreeComment"), data->comment);

View File

@ -97,6 +97,7 @@ struct tree {
int height; /* <-- Tree height */ int height; /* <-- Tree height */
int window_width; /* <-- Tree window width */ int window_width; /* <-- Tree window width */
int window_height; /* <-- Tree window height */ int window_height; /* <-- Tree window height */
bool no_drag; /* <-- Tree items can't be dragged out */
bool no_vscroll; /* <-- Tree has a vertical scroll only when needed */ bool no_vscroll; /* <-- Tree has a vertical scroll only when needed */
bool no_furniture; /* <-- Tree does not have connecting lines */ bool no_furniture; /* <-- Tree does not have connecting lines */
bool single_selection; /* <-- There can only be one item selected */ bool single_selection; /* <-- There can only be one item selected */

View File

@ -72,6 +72,7 @@ void ro_gui_cookies_initialise(void)
cookies_tree->root->expanded = true; cookies_tree->root->expanded = true;
cookies_tree->handle = (int)cookies_window; cookies_tree->handle = (int)cookies_window;
cookies_tree->movable = false; cookies_tree->movable = false;
cookies_tree->no_drag = true;
ro_gui_wimp_event_set_user_data(cookies_window, ro_gui_wimp_event_set_user_data(cookies_window,
cookies_tree); cookies_tree);
ro_gui_wimp_event_register_keypress(cookies_window, ro_gui_wimp_event_register_keypress(cookies_window,
@ -122,9 +123,10 @@ bool cookies_update(const char *domain, const struct cookie_data *data)
struct node *child; struct node *child;
struct node *add; struct node *add;
const struct cookie_data *cookie = NULL; const struct cookie_data *cookie = NULL;
bool expanded;
assert(domain); assert(domain);
/* check if we're a domain, and add get the first cookie */ /* check if we're a domain, and add get the first cookie */
if (data) if (data)
for (cookie = data; cookie->prev; cookie = cookie->prev); for (cookie = data; cookie->prev; cookie = cookie->prev);
@ -133,11 +135,14 @@ bool cookies_update(const char *domain, const struct cookie_data *data)
node = ro_gui_cookies_find(domain); node = ro_gui_cookies_find(domain);
if (node) { if (node) {
/* mark as deleted so we don't remove the cookies */ /* mark as deleted so we don't remove the cookies */
expanded = node->expanded;
for (child = node->child; child; child = child->next) for (child = node->child; child; child = child->next)
child->deleted = true; child->deleted = true;
if (node->child) if (node->child)
tree_delete_node(cookies_tree, node->child, tree_delete_node(cookies_tree, node->child,
true); true);
/* deleting will have contracted our node */
node->expanded = expanded;
} }
if (!data) { if (!data) {
if (!node) if (!node)
@ -148,7 +153,7 @@ bool cookies_update(const char *domain, const struct cookie_data *data)
return true; return true;
} }
} }
if (!node) { if (!node) {
for (parent = cookies_tree->root->child; parent; for (parent = cookies_tree->root->child; parent;
parent = parent->next) { parent = parent->next) {
@ -170,7 +175,7 @@ bool cookies_update(const char *domain, const struct cookie_data *data)
for (; cookie; cookie = cookie->next) { for (; cookie; cookie = cookie->next) {
add = tree_create_cookie_node(node, cookie); add = tree_create_cookie_node(node, cookie);
if (!cookies_init) if (add && !cookies_init)
tree_handle_node_changed(cookies_tree, add, tree_handle_node_changed(cookies_tree, add,
true, false); true, false);
} }

View File

@ -168,7 +168,7 @@ void ro_gui_menu_init(void)
(struct ns_menu *)&iconbar_definition); (struct ns_menu *)&iconbar_definition);
/* browser menu */ /* browser menu */
NS_MENU(68) browser_definition = { NS_MENU(69) browser_definition = {
"NetSurf", { "NetSurf", {
{ "Page", BROWSER_PAGE, 0 }, { "Page", BROWSER_PAGE, 0 },
{ "Page.PageInfo",BROWSER_PAGE_INFO, dialog_pageinfo }, { "Page.PageInfo",BROWSER_PAGE_INFO, dialog_pageinfo },
@ -225,6 +225,7 @@ void ro_gui_menu_init(void)
{ "Utilities.History.HistGlobal", HISTORY_SHOW_GLOBAL, 0 }, { "Utilities.History.HistGlobal", HISTORY_SHOW_GLOBAL, 0 },
{ "Utilities.Cookies", COOKIES_SHOW, 0 }, { "Utilities.Cookies", COOKIES_SHOW, 0 },
{ "Utilities.Cookies.ShowCookies", COOKIES_SHOW, 0 }, { "Utilities.Cookies.ShowCookies", COOKIES_SHOW, 0 },
{ "Utilities.Cookies.DeleteCookies", COOKIES_DELETE, 0 },
{ "Utilities.FindText", BROWSER_FIND_TEXT, dialog_search }, { "Utilities.FindText", BROWSER_FIND_TEXT, dialog_search },
{ "Utilities.Window", NO_ACTION, 0 }, { "Utilities.Window", NO_ACTION, 0 },
{ "Utilities.Window.WindowSave", BROWSER_WINDOW_DEFAULT, 0 }, { "Utilities.Window.WindowSave", BROWSER_WINDOW_DEFAULT, 0 },
@ -1470,6 +1471,11 @@ bool ro_gui_menu_handle_action(wimp_w owner, menu_action action,
ro_gui_tree_show(cookies_tree); ro_gui_tree_show(cookies_tree);
return true; return true;
case COOKIES_DELETE:
if (cookies_tree->root->child)
tree_delete_node(cookies_tree, cookies_tree->root->child, true);
return true;
/* page actions */ /* page actions */
case BROWSER_PAGE_INFO: case BROWSER_PAGE_INFO:
if (!c) if (!c)
@ -1832,6 +1838,10 @@ void ro_gui_menu_prepare_action(wimp_w owner, menu_action action,
ro_gui_menu_set_entry_shaded(current_menu, action, ro_gui_menu_set_entry_shaded(current_menu, action,
!cookies_tree); !cookies_tree);
break; break;
case COOKIES_DELETE:
ro_gui_menu_set_entry_shaded(current_menu, action,
!(cookies_tree && cookies_tree->root->child));
break;
/* page actions */ /* page actions */
case BROWSER_PAGE_INFO: case BROWSER_PAGE_INFO:

View File

@ -42,6 +42,7 @@ typedef enum {
/* cookie actions */ /* cookie actions */
COOKIES_SHOW, COOKIES_SHOW,
COOKIES_DELETE,
/* page actions */ /* page actions */
BROWSER_PAGE, BROWSER_PAGE,

View File

@ -197,6 +197,7 @@ void gui_cert_verify(struct browser_window *bw, struct content *c,
tree->root->expanded = true; tree->root->expanded = true;
tree->handle = (int)w; tree->handle = (int)w;
tree->movable = false; tree->movable = false;
tree->no_drag = true;
tree->no_vscroll = true; tree->no_vscroll = true;
tree->no_furniture = true; tree->no_furniture = true;
tree->single_selection = true; tree->single_selection = true;

View File

@ -851,7 +851,7 @@ bool ro_gui_tree_click(wimp_pointer *pointer, struct tree *tree) {
/* drag starts a drag operation */ /* drag starts a drag operation */
if ((!tree->editing) && ((pointer->buttons == (wimp_CLICK_SELECT << 4)) || if ((!tree->editing) && ((pointer->buttons == (wimp_CLICK_SELECT << 4)) ||
(pointer->buttons == (wimp_CLICK_ADJUST << 4)))) { (pointer->buttons == (wimp_CLICK_ADJUST << 4)))) {
if (tree->single_selection) if (tree->no_drag)
return true; return true;
if (!node->selected) { if (!node->selected) {