]> sjero.net Git - wget/commitdiff
[svn] Commit several minor changes:
authorhniksic <devnull@localhost>
Sat, 12 May 2001 20:06:41 +0000 (13:06 -0700)
committerhniksic <devnull@localhost>
Sat, 12 May 2001 20:06:41 +0000 (13:06 -0700)
* 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>.

src/ChangeLog
src/cookies.c
src/hash.c
src/hash.h
src/host.c
src/main.c
src/recur.c
src/retr.c
src/utils.c
src/utils.h

index 6666f589d65369eaa823cd794cc7a2a95e2601cd..b873a47c39f05e6bb5c476bc531d18ec559c4407 100644 (file)
@@ -1,3 +1,18 @@
+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
 2001-05-09  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * http.c (gethttp): Before concluding that the file is already
index ccf2ea7aac4d142e8aa7ec3d75934565a1b5f2cf..d2a906c22a8a17a42c8683413092863586ced125 100644 (file)
@@ -104,45 +104,15 @@ delete_cookie (struct cookie *cookie)
   xfree (cookie);
 }
 \f
   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.  */
 
   creating HOST:PORT strings, which are the keys in the hash
   table.  */
 
@@ -165,13 +135,6 @@ find_cookie_chain_exact (const char *domain, int port)
   SET_HOSTPORT (domain, port, key);
   return hash_table_get (cookies_hash_table, key);
 }
   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
 
 /* Find and return the cookie whose domain, path, and attribute name
    correspond to COOKIE.  If found, PREVPTR will point to the location
@@ -225,7 +188,7 @@ store_cookie (struct cookie *cookie)
   if (!cookies_hash_table)
     /* If the hash table is not initialized, do so now, because we'll
        need to store things.  */
   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);
 
   /* Initialize hash table key.  */
   SET_HOSTPORT (cookie->domain, cookie->port, hostport);
index 338cb7821fd9f4021d5a64757770b48a7b283571..4d6ceee6ad278e661cf08c9cee3dff01b31da0c6 100644 (file)
@@ -54,11 +54,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
    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
    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
 
    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
@@ -242,8 +242,8 @@ find_mapping (struct hash_table *ht, const void *key)
 /* 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
 /* 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 *
    function.  */
 
 void *
@@ -277,10 +277,10 @@ hash_table_get_pair (struct hash_table *ht, const void *lookup_key,
     return 0;
 }
 
     return 0;
 }
 
-/* Return 1 if KEY exists in HT, 0 otherwise. */
+/* Return 1 if HT contains KEY, 0 otherwise. */
 
 int
 
 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 find_mapping (ht, key) != NULL;
 }
@@ -450,7 +450,13 @@ hash_table_count (struct hash_table *ht)
   return ht->count;
 }
 \f
   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.
 
 /* 31 bit hash function.  Taken from Gnome's glib, modified to use
    standard C types.
@@ -471,6 +477,60 @@ string_hash (const void *key)
   return h;
 }
 
   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. */
 
 #if 0
 /* If I ever need it: hashing of integers. */
 
@@ -488,22 +548,6 @@ inthash (unsigned int key)
   return key;
 }
 #endif
   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
 
 \f
 #ifdef STANDALONE
 
@@ -537,7 +581,7 @@ main (void)
       if (len <= 1)
        continue;
       line[--len] = '\0';
       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)
        hash_table_put (ht, strdup (line), "here I am!");
 #if 1
       if (len % 5 == 0)
index f3a1b21bc10fd646c33e7d81b04acc6444e891a9..941d5bb3f627a4f67511142cd12b775a75d8e541 100644 (file)
@@ -40,7 +40,7 @@ void hash_table_destroy PARAMS ((struct hash_table *));
 void *hash_table_get PARAMS ((struct hash_table *, const void *));
 int hash_table_get_pair PARAMS ((struct hash_table *, const void *,
                                 void *, void *));
 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 *));
 
 void hash_table_put PARAMS ((struct hash_table *, const void *, void *));
 int hash_table_remove PARAMS ((struct hash_table *, const void *));
@@ -54,3 +54,4 @@ int hash_table_count PARAMS ((struct hash_table *));
 unsigned long string_hash PARAMS ((const void *));
 int string_cmp PARAMS ((const void *, const void *));
 struct hash_table *make_string_hash_table PARAMS ((int));
 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));
index eaf70762d0f190e9c6d57793711a156393a6eed3..9dc42e1043460b5a7f3046a516ab22d252a96f4c 100644 (file)
@@ -221,7 +221,7 @@ realhost (const char *host)
   char *master_name;
 
   DEBUGP (("Checking for %s in host_name_address_map.\n", host));
   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);
     {
       DEBUGP (("Found; %s was already used, by that name.\n", host));
       return xstrdup_lower (host);
index d1735246339a821eff580bb558bf2bdd28a27849..8189f644c2d8d8111e803061fdc7680eafca8671 100644 (file)
@@ -192,6 +192,7 @@ HTTP options:\n\
        --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\
        --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\
        --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\
index 23a5e3ab5a29f140f17b238aee68992012950629..c721eeb62585306d2b17ae25fc931813e4a5853d 100644 (file)
@@ -270,7 +270,7 @@ recursive_retrieve (const char *file, const char *this_url)
       /* 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 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)
 
       /* If it is FTP, and FTP is not followed, chuck it out.  */
       if (!inl)
index dd6380d3d4c399c94e07c0aff6a75fc8047e948f..9a4ff9573671d0ad727d7a78cf71bf704709aba2 100644 (file)
@@ -476,7 +476,7 @@ retrieve_url (const char *origurl, char **file, char **newloc,
 
       /* The new location is OK.  Let's check for redirection cycle by
          peeking through the history of redirections. */
 
       /* 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);
        {
          logprintf (LOG_NOTQUIET, _("%s: Redirection cycle detected.\n"),
                     mynewloc);
index 77ea43489df4574ef11bf59cf838adf4fed66f62..e5000aa39d92e3e799ea63a59532da507330b3ce 100644 (file)
@@ -1206,7 +1206,7 @@ string_set_add (struct hash_table *ht, const char *s)
   /* 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.  */
   /* 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
     return;
 
   /* We use "1" as value.  It provides us a useful and clear arbitrary
@@ -1216,12 +1216,12 @@ string_set_add (struct hash_table *ht, const char *s)
   hash_table_put (ht, xstrdup (s), "1");
 }
 
   hash_table_put (ht, xstrdup (s), "1");
 }
 
-/* Synonym for hash_table_exists... */
+/* Synonym for hash_table_contains... */
 
 int
 
 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
 }
 
 static int
@@ -1316,7 +1316,7 @@ legible (long l)
    bytes are sufficient.  Using more might be a good idea.
 
    This function does not go through the hoops that long_to_string
    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
    once in a Wget run.)  */
 
 static void
@@ -1359,7 +1359,10 @@ numdigit (long a)
 {
   int res = 1;
   if (a < 0)
 {
   int res = 1;
   if (a < 0)
-    a = -a;
+    {
+      a = -a;
+      ++res;
+    }
   while ((a /= 10) != 0)
     ++res;
   return res;
   while ((a /= 10) != 0)
     ++res;
   return res;
@@ -1379,7 +1382,7 @@ numdigit (long a)
 #define DIGITS_9(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_8 ((figure) / 10)
 #define DIGITS_10(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_9 ((figure) / 10)
 
 #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)
 
 #define DIGITS_11(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_10 ((figure) / 10)
 #define DIGITS_12(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_11 ((figure) / 10)
@@ -1400,9 +1403,9 @@ numdigit (long a)
    slow compared to this function.
 
    BUFFER should accept as many bytes as you expect the number to take
    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)
 
 void
 long_to_string (char *buffer, long number)
@@ -1516,7 +1519,7 @@ struct wget_timer {
 };
 
 /* Allocate a timer.  It is not legal to do anything with a freshly
 };
 
 /* 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)
 
 struct wget_timer *
 wtimer_allocate (void)
index edc779f75c14caf8fd1ced30228187094ed03a0c..c230bc002acf0666159894d7927146d95a52a05e 100644 (file)
@@ -81,7 +81,7 @@ int slist_contains PARAMS ((slist *, const char *));
 void slist_free PARAMS ((slist *));
 
 void string_set_add PARAMS ((struct hash_table *, const char *));
 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 *));
 
 void string_set_free PARAMS ((struct hash_table *));
 void free_keys_and_values PARAMS ((struct hash_table *));