* main.c (print_help): Document `--no-http-keep-alive'.
* utils.c (numdigit): Handle negative numbers *correctly*.
* hash.c (make_nocase_string_hash_table): Use term "nocase" rather
than the confusing "unsigned".
* utils.c (string_set_contains): Renamed from string_set_exists.
* hash.c (hash_table_contains): Renamed from hash_table_exists.
* cookies.c: Move case-insensitive hash tables to hash.c.
Published in <sxsheyq9vvl.fsf@florida.arsdigita.de>.
+2001-05-12 Hrvoje Niksic <hniksic@arsdigita.com>
+
+ * main.c (print_help): Document `--no-http-keep-alive'.
+
+ * utils.c (numdigit): Handle negative numbers *correctly*.
+
+ * hash.c (make_nocase_string_hash_table): Use term "nocase" rather
+ than the confusing "unsigned".
+
+ * utils.c (string_set_contains): Renamed from string_set_exists.
+
+ * hash.c (hash_table_contains): Renamed from hash_table_exists.
+
+ * cookies.c: Move case-insensitive hash tables to hash.c.
+
2001-05-09 Hrvoje Niksic <hniksic@arsdigita.com>
* http.c (gethttp): Before concluding that the file is already
xfree (cookie);
}
\f
-/* Functions for cookie-specific hash tables. These are regular hash
- tables, but with case-insensitive test and hash functions. */
-
-/* Like string_hash, but produces the same results regardless of the
- case. */
-
-static unsigned long
-unsigned_string_hash (const void *key)
-{
- const char *p = key;
- unsigned int h = TOLOWER (*p);
-
- if (h)
- for (p += 1; *p != '\0'; p++)
- h = (h << 5) - h + TOLOWER (*p);
-
- return h;
-}
-
-/* Front-end to strcasecmp. */
-
-static int
-unsigned_string_cmp (const void *s1, const void *s2)
-{
- return !strcasecmp ((const char *)s1, (const char *)s2);
-}
-
-/* Like make_string_hash_table, but uses unsigned_string_hash and
- unsigned_string_cmp. */
+/* Functions for storing cookies.
-static struct hash_table *
-make_unsigned_string_hash_table (int initial_size)
-{
- return hash_table_new (initial_size,
- unsigned_string_hash, unsigned_string_cmp);
-}
+ All cookies can be referenced through cookies_hash_table. 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. */
-/* Write "HOST:PORT" to RESULT. RESULT should be a pointer, and the
- memory for the contents is allocated on the stack. Useful for
+/* Write "HOST:PORT" to a stack-allocated area and make RESULT point
+ to that area. RESULT should be a character pointer. Useful for
creating HOST:PORT strings, which are the keys in the hash
table. */
SET_HOSTPORT (domain, port, key);
return hash_table_get (cookies_hash_table, key);
}
-\f
-/* Functions for storing cookies.
-
- All cookies can be referenced through cookies_hash_table. 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 the cookie whose domain, path, and attribute name
correspond to COOKIE. If found, PREVPTR will point to the location
if (!cookies_hash_table)
/* If the hash table is not initialized, do so now, because we'll
need to store things. */
- cookies_hash_table = make_unsigned_string_hash_table (0);
+ cookies_hash_table = make_nocase_string_hash_table (0);
/* Initialize hash table key. */
SET_HOSTPORT (cookie->domain, cookie->port, hostport);
The basics are all covered. hash_table_new creates a hash table,
and hash_table_destroy deletes it. hash_table_put establishes a
mapping between a key and a value. hash_table_get retrieves the
- value that corresponds to a key. hash_table_exists queries whether
- a key is stored in a table at all. hash_table_remove removes a
- mapping that corresponds to a key. hash_table_map allows you to
- map through all the entries in a hash table. hash_table_clear
- clears all the entries from the hash table.
+ value that corresponds to a key. hash_table_contains queries
+ whether a key is stored in a table at all. hash_table_remove
+ removes a mapping that corresponds to a key. hash_table_map allows
+ you to map through all the entries in a hash table.
+ hash_table_clear clears all the entries from the hash table.
The number of mappings in a table is not limited, except by the
amount of memory. As you add new elements to a table, it regrows
/* Get the value that corresponds to the key KEY in the hash table HT.
If no value is found, return NULL. Note that NULL is a legal value
for value; if you are storing NULLs in your hash table, you can use
- hash_table_exists to be sure that a (possibly NULL) value exists in
- the table. Or, you can use hash_table_get_pair instead of this
+ hash_table_contains to be sure that a (possibly NULL) value exists
+ in the table. Or, you can use hash_table_get_pair instead of this
function. */
void *
return 0;
}
-/* Return 1 if KEY exists in HT, 0 otherwise. */
+/* Return 1 if HT contains KEY, 0 otherwise. */
int
-hash_table_exists (struct hash_table *ht, const void *key)
+hash_table_contains (struct hash_table *ht, const void *key)
{
return find_mapping (ht, key) != NULL;
}
return ht->count;
}
\f
-/* Support for hash tables whose keys are strings. */
+/* Functions from this point onward are meant for convenience and
+ don't strictly belong to this file. However, this is as good a
+ place for them as any. */
+
+/* ========
+ Support for hash tables whose keys are strings.
+ ======== */
/* 31 bit hash function. Taken from Gnome's glib, modified to use
standard C types.
return h;
}
+/* Frontend for strcmp usable for hash tables. */
+
+int
+string_cmp (const void *s1, const void *s2)
+{
+ return !strcmp ((const char *)s1, (const char *)s2);
+}
+
+/* Return a hash table of initial size INITIAL_SIZE suitable to use
+ strings as keys. */
+
+struct hash_table *
+make_string_hash_table (int initial_size)
+{
+ return hash_table_new (initial_size, string_hash, string_cmp);
+}
+
+/* ========
+ Support for hash tables whose keys are strings, but which are
+ compared case-insensitively.
+ ======== */
+
+/* Like string_hash, but produce the same hash regardless of the case. */
+
+static unsigned long
+string_hash_nocase (const void *key)
+{
+ const char *p = key;
+ unsigned int h = TOLOWER (*p);
+
+ if (h)
+ for (p += 1; *p != '\0'; p++)
+ h = (h << 5) - h + TOLOWER (*p);
+
+ return h;
+}
+
+/* Like string_cmp, but doing case-insensitive compareison. */
+
+static int
+string_cmp_nocase (const void *s1, const void *s2)
+{
+ return !strcasecmp ((const char *)s1, (const char *)s2);
+}
+
+/* Like make_string_hash_table, but uses string_hash_nocase and
+ string_cmp_nocase. */
+
+struct hash_table *
+make_nocase_string_hash_table (int initial_size)
+{
+ return hash_table_new (initial_size, string_hash_nocase, string_cmp_nocase);
+}
+
#if 0
/* If I ever need it: hashing of integers. */
return key;
}
#endif
-
-int
-string_cmp (const void *s1, const void *s2)
-{
- return !strcmp ((const char *)s1, (const char *)s2);
-}
-
-/* Return a hash table of initial size INITIAL_SIZE suitable to use
- strings as keys. */
-
-struct hash_table *
-make_string_hash_table (int initial_size)
-{
- return hash_table_new (initial_size, string_hash, string_cmp);
-}
-
\f
#ifdef STANDALONE
if (len <= 1)
continue;
line[--len] = '\0';
- if (!hash_table_exists (ht, line))
+ if (!hash_table_contains (ht, line))
hash_table_put (ht, strdup (line), "here I am!");
#if 1
if (len % 5 == 0)
void *hash_table_get PARAMS ((struct hash_table *, const void *));
int hash_table_get_pair PARAMS ((struct hash_table *, const void *,
void *, void *));
-int hash_table_exists PARAMS ((struct hash_table *, const void *));
+int hash_table_contains PARAMS ((struct hash_table *, const void *));
void hash_table_put PARAMS ((struct hash_table *, const void *, void *));
int hash_table_remove PARAMS ((struct hash_table *, const void *));
unsigned long string_hash PARAMS ((const void *));
int string_cmp PARAMS ((const void *, const void *));
struct hash_table *make_string_hash_table PARAMS ((int));
+struct hash_table *make_nocase_string_hash_table PARAMS ((int));
char *master_name;
DEBUGP (("Checking for %s in host_name_address_map.\n", host));
- if (hash_table_exists (host_name_address_map, host))
+ if (hash_table_contains (host_name_address_map, host))
{
DEBUGP (("Found; %s was already used, by that name.\n", host));
return xstrdup_lower (host);
--referer=URL include `Referer: URL\' header in HTTP request.\n\
-s, --save-headers save the HTTP headers to file.\n\
-U, --user-agent=AGENT identify as AGENT instead of Wget/VERSION.\n\
+ --no-http-keep-alive disable HTTP keep-alive (persistent connections).\n\
--cookies=off don't use cookies.\n\
--load-cookies=FILE load cookies from FILE before session.\n\
--save-cookies=FILE save cookies to FILE after session.\n\
/* inl is set if the URL we are working on (constr) is stored in
undesirable_urls. Using it is crucial to avoid unnecessary
repeated continuous hits to the hash table. */
- inl = string_set_exists (undesirable_urls, constr);
+ inl = string_set_contains (undesirable_urls, constr);
/* If it is FTP, and FTP is not followed, chuck it out. */
if (!inl)
/* The new location is OK. Let's check for redirection cycle by
peeking through the history of redirections. */
- if (string_set_exists (redirections, newloc_struct->url))
+ if (string_set_contains (redirections, newloc_struct->url))
{
logprintf (LOG_NOTQUIET, _("%s: Redirection cycle detected.\n"),
mynewloc);
/* First check whether the set element already exists. If it does,
do nothing so that we don't have to free() the old element and
then strdup() a new one. */
- if (hash_table_exists (ht, s))
+ if (hash_table_contains (ht, s))
return;
/* We use "1" as value. It provides us a useful and clear arbitrary
hash_table_put (ht, xstrdup (s), "1");
}
-/* Synonym for hash_table_exists... */
+/* Synonym for hash_table_contains... */
int
-string_set_exists (struct hash_table *ht, const char *s)
+string_set_contains (struct hash_table *ht, const char *s)
{
- return hash_table_exists (ht, s);
+ return hash_table_contains (ht, s);
}
static int
bytes are sufficient. Using more might be a good idea.
This function does not go through the hoops that long_to_string
- goes to because it doesn't need to be fast. (It's called perhaps
+ goes to because it doesn't aspire to be fast. (It's called perhaps
once in a Wget run.) */
static void
{
int res = 1;
if (a < 0)
- a = -a;
+ {
+ a = -a;
+ ++res;
+ }
while ((a /= 10) != 0)
++res;
return res;
#define DIGITS_9(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_8 ((figure) / 10)
#define DIGITS_10(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_9 ((figure) / 10)
-/* DIGITS_<11-20> are only used on 64-bit machines. */
+/* DIGITS_<11-20> are only used on machines with 64-bit longs. */
#define DIGITS_11(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_10 ((figure) / 10)
#define DIGITS_12(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_11 ((figure) / 10)
slow compared to this function.
BUFFER should accept as many bytes as you expect the number to take
- up. On 64-bit machines, the maximum needed size is 24 bytes. That
- includes all the digits, as well as the `-' sign for negative
- numbers and the trailing \0. */
+ up. On machines with 64-bit longs the maximum needed size is 24
+ bytes. That includes the worst-case digits, the optional `-' sign,
+ and the trailing \0. */
void
long_to_string (char *buffer, long number)
};
/* Allocate a timer. It is not legal to do anything with a freshly
- allocated timer, except call wtimer_reset(). */
+ allocated timer, except call wtimer_reset() or wtimer_delete(). */
struct wget_timer *
wtimer_allocate (void)
void slist_free PARAMS ((slist *));
void string_set_add PARAMS ((struct hash_table *, const char *));
-int string_set_exists PARAMS ((struct hash_table *, const char *));
+int string_set_contains PARAMS ((struct hash_table *, const char *));
void string_set_free PARAMS ((struct hash_table *));
void free_keys_and_values PARAMS ((struct hash_table *));