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

[svn] Remove host canonicalization code.

Published in <sxsg072ai5v.fsf@florida.arsdigita.de>.
This commit is contained in:
hniksic 2001-11-25 09:13:20 -08:00
parent dd60ba082b
commit 95631700f7
7 changed files with 68 additions and 128 deletions

View File

@ -1,3 +1,21 @@
2001-11-25 Hrvoje Niksic <hniksic@arsdigita.com>
* main.c (private_initialize): Removed.
(main): Don't call private_initialize.
* http.c: Call lookup_host.
* host.c (host_init): Removed.
(add_host_to_cache): Initialize host_name_address_map here, on
demand.
(ngethostbyname): Commented out.
* connect.c (make_connection): Remove dead code; use lookup_host.
* host.c (store_hostaddress): Renamed to lookup_host and reversed
the args.
Removed host_address_name_map and host_slave_master_map.
2001-11-25 Hrvoje Niksic <hniksic@arsdigita.com>
* progress.c (dot_create): Align the "[ skipping ... ]" string

View File

@ -65,21 +65,9 @@ uerr_t
make_connection (int *sock, char *hostname, unsigned short port)
{
struct sockaddr_in sock_name;
/* struct hostent *hptr; */
/* Get internet address of the host. We can do it either by calling
ngethostbyname, or by calling store_hostaddress, from host.c.
storehostaddress is better since it caches calls to
gethostbyname. */
#if 1
if (!store_hostaddress ((unsigned char *)&sock_name.sin_addr, hostname))
if (!lookup_host (hostname, (unsigned char *)&sock_name.sin_addr))
return HOSTERR;
#else /* never */
if (!(hptr = ngethostbyname (hostname)))
return HOSTERR;
/* Copy the address of the host to socket description. */
memcpy (&sock_name.sin_addr, hptr->h_addr, hptr->h_length);
#endif /* never */
/* Set port and protocol */
sock_name.sin_family = AF_INET;

View File

@ -64,17 +64,10 @@ extern int errno;
/* #### We should map to *lists* of IP addresses. */
struct hash_table *host_name_address_map;
#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);
assert (hptr->h_length == 4);
/* 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. */
/* 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. */
/* 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);
}

View File

@ -24,14 +24,12 @@ struct url;
/* Function declarations */
struct hostent *ngethostbyname PARAMS ((const char *));
int store_hostaddress PARAMS ((unsigned char *, const char *));
void host_cleanup PARAMS ((void));
int lookup_host PARAMS ((const char *, unsigned char *));
char *herrmsg PARAMS ((int));
int accept_domain PARAMS ((struct url *));
int sufmatch PARAMS ((const char **, const char *));
char *herrmsg PARAMS ((int));
void host_cleanup PARAMS ((void));
#endif /* HOST_H */

View File

@ -276,7 +276,7 @@ http_process_connection (const char *hdr, void *arg)
/* Whether a persistent connection is active. */
static int pc_active_p;
/* Host and port of currently active persistent connection. */
static unsigned char pc_last_host[4];
static unsigned char pc_last_host_ip[4];
static unsigned short pc_last_port;
/* File descriptor of the currently active persistent connection. */
@ -347,9 +347,9 @@ register_persistent (const char *host, unsigned short port, int fd
}
}
/* This store_hostaddress may not fail, because it has the results
in the cache. */
success = store_hostaddress (pc_last_host, host);
/* This lookup_host cannot fail, because it has the results in the
cache. */
success = lookup_host (host, pc_last_host_ip);
assert (success);
pc_last_port = port;
pc_last_fd = fd;
@ -371,7 +371,7 @@ persistent_available_p (const char *host, unsigned short port
#endif
)
{
unsigned char this_host[4];
unsigned char this_host_ip[4];
/* First, check whether a persistent connection is active at all. */
if (!pc_active_p)
return 0;
@ -388,9 +388,9 @@ persistent_available_p (const char *host, unsigned short port
if (ssl != pc_active_ssl)
return 0;
#endif /* HAVE_SSL */
if (!store_hostaddress (this_host, host))
if (!lookup_host (host, this_host_ip))
return 0;
if (memcmp (pc_last_host, this_host, 4))
if (memcmp (pc_last_host_ip, this_host_ip, 4))
return 0;
/* Third: check whether the connection is still open. This is
important because most server implement a liberal (short) timeout

View File

@ -525,7 +525,7 @@ cmd_address (const char *com, const char *val, void *closure)
memset (&sin, '\0', sizeof (sin));
if (!store_hostaddress ((unsigned char *)&sin.sin_addr, val))
if (!lookup_host (val, (unsigned char *)&sin.sin_addr))
{
fprintf (stderr, _("%s: %s: Cannot convert `%s' to an IP address.\n"),
exec_name, com, val);

View File

@ -104,18 +104,6 @@ i18n_initialize (void)
textdomain ("wget");
#endif /* HAVE_NLS */
}
/* It's kosher to declare these here because their interface _has_ to
be void foo(void). */
void host_init PARAMS ((void));
/* This just calls the various initialization functions from the
modules that need one-time initialization. */
static void
private_initialize (void)
{
host_init ();
}
/* Print the usage message. */
static void
@ -335,7 +323,6 @@ main (int argc, char *const *argv)
};
i18n_initialize ();
private_initialize ();
append_to_log = 0;