the cookies. */
struct cookie_jar {
- /* Mapping between domains and their corresponding cookies. */
- struct hash_table *chains_by_domain;
+ /* Cookie chains indexed by domain. */
+ struct hash_table *chains;
int cookie_count; /* number of cookies in the jar. */
};
struct cookie_jar *
cookie_jar_new (void)
{
- struct cookie_jar *jar = xmalloc (sizeof (struct cookie_jar));
- jar->chains_by_domain = make_nocase_string_hash_table (0);
+ struct cookie_jar *jar = xnew (struct cookie_jar);
+ jar->chains = make_nocase_string_hash_table (0);
jar->cookie_count = 0;
return jar;
}
char *attr; /* cookie attribute name */
char *value; /* cookie attribute value */
- struct cookie_jar *jar; /* pointer back to the cookie jar, for
- convenience. */
struct cookie *next; /* used for chaining of cookies in the
same domain. */
};
static struct cookie *
cookie_new (void)
{
- struct cookie *cookie = xmalloc (sizeof (struct cookie));
- memset (cookie, '\0', sizeof (struct cookie));
+ struct cookie *cookie = xnew0 (struct cookie);
/* Both cookie->permanent and cookie->expiry_time are now 0. By
default, we assume that the cookie is non-permanent and valid
\f
/* Functions for storing cookies.
- All cookies can be reached beginning with jar->chains_by_domain.
- The key in that table is the domain name, and the value is a linked
- list of all cookies from that domain. Every new cookie is placed
- on the head of the list. */
+ All cookies can be reached beginning with jar->chains. The key in
+ that table is the domain name, and the value is a linked list of
+ all cookies from that domain. Every new cookie is placed on the
+ head of the list. */
/* Find and return a cookie in JAR whose domain, path, and attribute
name correspond to COOKIE. If found, PREVPTR will point to the
{
struct cookie *chain, *prev;
- chain = hash_table_get (jar->chains_by_domain, cookie->domain);
+ chain = hash_table_get (jar->chains, cookie->domain);
if (!chain)
goto nomatch;
struct cookie *chain_head;
char *chain_key;
- if (hash_table_get_pair (jar->chains_by_domain, cookie->domain,
+ if (hash_table_get_pair (jar->chains, cookie->domain,
&chain_key, &chain_head))
{
/* A chain of cookies in this domain already exists. Check for
chain_key = xstrdup (cookie->domain);
}
- hash_table_put (jar->chains_by_domain, chain_key, cookie);
+ hash_table_put (jar->chains, chain_key, cookie);
++jar->cookie_count;
DEBUGP (("\nStored cookie %s %d%s %s %s %d %s %s %s\n",
{
struct cookie *prev, *victim;
- if (!hash_table_count (jar->chains_by_domain))
+ if (!hash_table_count (jar->chains))
/* No elements == nothing to discard. */
return;
char *chain_key = NULL;
int res;
- res = hash_table_get_pair (jar->chains_by_domain, victim->domain,
+ res = hash_table_get_pair (jar->chains, victim->domain,
&chain_key, NULL);
assert (res != 0);
if (!victim->next)
{
/* VICTIM was the only cookie in the chain. Destroy the
chain and deallocate the chain key. */
- hash_table_remove (jar->chains_by_domain, victim->domain);
+ hash_table_remove (jar->chains, victim->domain);
xfree (chain_key);
}
else
- hash_table_put (jar->chains_by_domain, chain_key, victim->next);
+ hash_table_put (jar->chains, chain_key, victim->next);
}
delete_cookie (victim);
DEBUGP (("Discarded old cookie.\n"));
int passes, passcnt;
/* Bail out quickly if there are no cookies in the jar. */
- if (!hash_table_count (jar->chains_by_domain))
+ if (!hash_table_count (jar->chains))
return 0;
if (numeric_address_p (host))
srk.fer.hr's, then fer.hr's. */
while (1)
{
- struct cookie *chain = hash_table_get (jar->chains_by_domain, host);
+ struct cookie *chain = hash_table_get (jar->chains, host);
if (chain)
dest[dest_count++] = chain;
if (++passcnt >= passes)
fprintf (fp, "# Generated by Wget on %s.\n", datetime_str (NULL));
fputs ("# Edit at your own risk.\n\n", fp);
- hash_table_map (jar->chains_by_domain, save_cookies_mapper, fp);
+ hash_table_map (jar->chains, save_cookies_mapper, fp);
if (ferror (fp))
logprintf (LOG_NOTQUIET, _("Error writing to `%s': %s\n"),
struct cookie_jar *jar = (struct cookie_jar *)arg;
/* Remove the chain from the table and free the key. */
- hash_table_remove (jar->chains_by_domain, chain_key);
+ hash_table_remove (jar->chains, chain_key);
xfree (chain_key);
/* Then delete all the cookies in the chain. */
void
cookie_jar_delete (struct cookie_jar *jar)
{
- hash_table_map (jar->chains_by_domain, nuke_cookie_chain, jar);
- hash_table_destroy (jar->chains_by_domain);
+ hash_table_map (jar->chains, nuke_cookie_chain, jar);
+ hash_table_destroy (jar->chains);
xfree (jar);
}
\f