]> sjero.net Git - wget/blobdiff - src/host.c
[svn] Remove host canonicalization code.
[wget] / src / host.c
index 4fb1197b40eeafc9c62f7a90a13d2a9bf364a333..2c0ef425f10d64d01e0189ed737242437c37fd48 100644 (file)
@@ -64,17 +64,10 @@ extern int errno;
 /* #### We should map to *lists* of IP addresses. */
 
 struct hash_table *host_name_address_map;
+\f
+#if 0
 
-/* The following two tables are obsolete, since we no longer do host
-   canonicalization.  */
-
-/* Mapping between all known addresses (n.n.n.n) to their hosts.  This
-   is the inverse of host_name_address_map.  These two tables share
-   the strdup'ed strings. */
-struct hash_table *host_address_name_map;
-
-/* Mapping between auxilliary (slave) and master host names. */
-struct hash_table *host_slave_master_map;
+/* This function is no longer used. */
 
 /* The same as gethostbyname, but supports internet addresses of the
    form `N.N.N.N'.  On some systems gethostbyname() knows how to do
@@ -92,38 +85,20 @@ ngethostbyname (const char *name)
     hp = gethostbyname (name);
   return hp;
 }
+#endif
 
-/* Add host name HOST with the address ADDR_TEXT to the cache.
-   Normally this means that the (HOST, ADDR_TEXT) pair will be to
-   host_name_address_map and to host_address_name_map.  (It is the
-   caller's responsibility to make sure that HOST is not already in
-   host_name_address_map.)
-
-   If the ADDR_TEXT has already been seen and belongs to another host,
-   HOST will be added to host_slave_master_map instead.  */
+/* Add host name HOST with the address ADDR_TEXT to the cache.  */
 
 static void
 add_host_to_cache (const char *host, const char *addr_text)
 {
-  char *canonical_name = hash_table_get (host_address_name_map, addr_text);
-  if (canonical_name)
-    {
-      DEBUGP (("Mapping %s to %s in host_slave_master_map.\n",
-              host, canonical_name));
-      /* We've already dealt with that host under another name. */
-      hash_table_put (host_slave_master_map,
-                     xstrdup_lower (host),
-                     xstrdup_lower (canonical_name));
-    }
-  else
-    {
-      /* This is really the first time we're dealing with that host.  */
-      char *h_copy = xstrdup_lower (host);
-      char *a_copy = xstrdup (addr_text);
-      DEBUGP (("Caching %s <-> %s\n", h_copy, a_copy));
-      hash_table_put (host_name_address_map, h_copy, a_copy);
-      hash_table_put (host_address_name_map, a_copy, h_copy);
-    }
+  DEBUGP (("Caching %s => %s\n", host, addr_text));
+
+  if (!host_name_address_map)
+    host_name_address_map = make_nocase_string_hash_table (0);
+
+  hash_table_put (host_name_address_map,
+                 xstrdup_lower (host), xstrdup (addr_text));
 }
 
 /* Store the address of HOSTNAME, internet-style (four octets in
@@ -133,25 +108,24 @@ add_host_to_cache (const char *host, const char *addr_text)
 
    Return 1 on successful finding of the hostname, 0 otherwise.  */
 int
-store_hostaddress (unsigned char *where, const char *hostname)
+lookup_host (const char *hostname, unsigned char *store_ip)
 {
   unsigned long addr;
-  char *addr_text;
-  char *canonical_name;
+  char *addr_text = NULL;
   struct hostent *hptr;
   struct in_addr in;
   char *inet_s;
 
-  /* If the address is of the form d.d.d.d, there will be no trouble
-     with it.  */
+  /* If the address is of the form d.d.d.d, no further lookup is
+     needed.  */
   addr = (unsigned long)inet_addr (hostname);
-  /* If we have the numeric address, just store it.  */
   if ((int)addr != -1)
     {
-      /* ADDR is defined to be in network byte order, meaning the code
-         works on little and big endian 32-bit architectures without
-         change.  On big endian 64-bit architectures we need to be
-         careful to copy the correct four bytes.  */
+      /* ADDR is defined to be in network byte order, which is what
+        this returns, so we can just copy it to STORE_IP.  However,
+        on big endian 64-bit architectures the value will be stored
+        in the *last*, not first four bytes.  OFFSET makes sure that
+        we copy the correct four bytes.  */
       int offset;
     have_addr:
 #ifdef WORDS_BIGENDIAN
@@ -159,13 +133,15 @@ store_hostaddress (unsigned char *where, const char *hostname)
 #else
       offset = 0;
 #endif
-      memcpy (where, (char *)&addr + offset, 4);
+      memcpy (store_ip, (char *)&addr + offset, 4);
       return 1;
     }
 
-  /* By now we know that the address is not of the form d.d.d.d.  Try
-     to find it in our cache of host addresses.  */
-  addr_text = hash_table_get (host_name_address_map, hostname);
+  /* By now we know that the host name we got is not of the form
+     d.d.d.d.  Try to find it in our cache of host names.  */
+  if (host_name_address_map)
+    addr_text = hash_table_get (host_name_address_map, hostname);
+
   if (addr_text)
     {
       DEBUGP (("Found %s in host_name_address_map: %s\n",
@@ -174,39 +150,26 @@ store_hostaddress (unsigned char *where, const char *hostname)
       goto have_addr;
     }
 
-  /* Maybe this host is known to us under another name.  If so, we'll
-     find it in host_slave_master_map, and use the master name to find
-     its address in host_name_address_map. */
-  canonical_name = hash_table_get (host_slave_master_map, hostname);
-  if (canonical_name)
-    {
-      addr_text = hash_table_get (host_name_address_map, canonical_name);
-      assert (addr_text != NULL);
-      DEBUGP (("Found %s as slave of %s -> %s\n",
-              hostname, canonical_name, addr_text));
-      addr = (unsigned long)inet_addr (addr_text);
-      goto have_addr;
-    }
-
-  /* Since all else has failed, let's try gethostbyname().  Note that
-     we use gethostbyname() rather than ngethostbyname(), because we
-     already know that the address is not numerical.  */
+  /* Look up the host using gethostbyname().  Note that we use
+     gethostbyname() rather than ngethostbyname(), because we already
+     know that the address is not numerical.  */
   hptr = gethostbyname (hostname);
   if (!hptr)
     return 0;
-  /* Copy the address of the host to socket description.  */
-  memcpy (where, hptr->h_addr_list[0], hptr->h_length);
+
+  /* Store the IP address to the desired location. */
   assert (hptr->h_length == 4);
+  memcpy (store_ip, hptr->h_addr_list[0], hptr->h_length);
+
+  /* Now that we've successfully looked up the host, store this
+     information in the cache.  */
 
-  /* Now that we've gone through the truoble of calling
-     gethostbyname(), we can store this valuable information to the
-     cache.  First, we have to look for it by address to know if it's
-     already in the cache by another name.  */
   /* Originally, we copied to in.s_addr, but it appears to be missing
      on some systems.  */
   memcpy (&in, *hptr->h_addr_list, sizeof (in));
   inet_s = inet_ntoa (in);
   add_host_to_cache (hostname, inet_s);
+
   return 1;
 }
 
@@ -271,20 +234,6 @@ herrmsg (int error)
 void
 host_cleanup (void)
 {
-  /* host_name_address_map and host_address_name_map share the
-     strings.  Because of that, calling free_keys_and_values once
-     suffices for both.  */
   free_keys_and_values (host_name_address_map);
   hash_table_destroy (host_name_address_map);
-  hash_table_destroy (host_address_name_map);
-  free_keys_and_values (host_slave_master_map);
-  hash_table_destroy (host_slave_master_map);
-}
-
-void
-host_init (void)
-{
-  host_name_address_map = make_string_hash_table (0);
-  host_address_name_map = make_string_hash_table (0);
-  host_slave_master_map = make_string_hash_table (0);
 }