1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Use hash_table_iterate in cookie_jar_delete.

This commit is contained in:
hniksic 2005-08-27 06:25:47 -07:00
parent 8b7dabcdf8
commit ed8648d0c0

View File

@ -1482,40 +1482,25 @@ cookie_jar_save (struct cookie_jar *jar, const char *file)
DEBUGP (("Done saving cookies.\n")); DEBUGP (("Done saving cookies.\n"));
} }
/* Destroy all the elements in the chain and unhook it from the cookie /* Clean up cookie-related data. */
jar. This is written in the form of a callback to
hash_table_for_each and used by cookie_jar_delete to delete all the
cookies in a jar. */
static int void
nuke_cookie_chain (void *value, void *key, void *arg) cookie_jar_delete (struct cookie_jar *jar)
{ {
char *chain_key = (char *)value; /* Iterate over chains (indexed by domain) and free them. */
struct cookie *chain = (struct cookie *)key; hash_table_iterator iter;
struct cookie_jar *jar = (struct cookie_jar *)arg; for (hash_table_iterate (jar->chains, &iter); hash_table_iter_next (&iter); )
{
/* Remove the chain from the table and free the key. */ struct cookie *chain = iter.value;
hash_table_remove (jar->chains, chain_key); xfree (iter.key);
xfree (chain_key); /* Then all cookies in this chain. */
/* Then delete all the cookies in the chain. */
while (chain) while (chain)
{ {
struct cookie *next = chain->next; struct cookie *next = chain->next;
delete_cookie (chain); delete_cookie (chain);
chain = next; chain = next;
} }
/* Keep mapping. */
return 0;
} }
/* Clean up cookie-related data. */
void
cookie_jar_delete (struct cookie_jar *jar)
{
hash_table_for_each (jar->chains, nuke_cookie_chain, jar);
hash_table_destroy (jar->chains); hash_table_destroy (jar->chains);
xfree (jar); xfree (jar);
} }