From 376ef0ca478eaf16d641de019b8e2e87672c4a3a Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Fri, 30 Jan 2009 19:58:46 +0000 Subject: Make urldb_iterate_entries_path use iteration svn path=/trunk/netsurf/; revision=6304 --- content/urldb.c | 66 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 28 deletions(-) (limited to 'content') diff --git a/content/urldb.c b/content/urldb.c index 4eafc5e5e..d8a85d5ea 100644 --- a/content/urldb.c +++ b/content/urldb.c @@ -1406,39 +1406,49 @@ bool urldb_iterate_entries_path(const struct path_data *parent, bool (*cookie_callback)(const char *domain, const struct cookie_data *data)) { - const struct path_data *p; + const struct path_data *p = parent; - if (!parent->children) { - /* leaf node */ + do { + if (p->children != NULL) { + /* Drill down into children */ + p = p->children; + } else { + /* All leaf nodes in the path tree should have an URL or + * cookies attached to them. If this is not the case, it + * indicates that there's a bug in the file loader/URL + * insertion code. Therefore, assert this here. */ + assert(url_callback || cookie_callback); - /* All leaf nodes in the path tree should have an URL or - * cookies attached to them. If this is not the case, it - * indicates that there's a bug in the file loader/URL - * insertion code. Therefore, assert this here. */ - assert(url_callback || cookie_callback); + /** \todo handle fragments? */ + if (url_callback) { + const struct url_internal_data *u = &p->urld; - /** \todo handle fragments? */ - if (url_callback) { - const struct url_internal_data *u = &parent->urld; + assert(p->url); - assert(parent->url); - if (!url_callback(parent->url, - (const struct url_data *) u)) - return false; - } else { - if (parent->cookies && !cookie_callback( - parent->cookies->domain, - (const struct cookie_data *) - parent->cookies)) - return false; - } - } + if (!url_callback(p->url, + (const struct url_data *) u)) + return false; + } else { + if (p->cookies && !cookie_callback( + p->cookies->domain, + (const struct cookie_data *) + p->cookies)) + return false; + } - for (p = parent->children; p; p = p->next) { - if (!urldb_iterate_entries_path(p, - url_callback, cookie_callback)) - return false; - } + /* Now, find next node to process. */ + while (p != parent) { + if (p->next != NULL) { + /* Have a sibling, process that */ + p = p->next; + break; + } + + /* Ascend tree */ + p = p->parent; + } + } + } while (p != parent); return true; } -- cgit v1.2.3