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:
parent
dd60ba082b
commit
95631700f7
@ -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>
|
2001-11-25 Hrvoje Niksic <hniksic@arsdigita.com>
|
||||||
|
|
||||||
* progress.c (dot_create): Align the "[ skipping ... ]" string
|
* progress.c (dot_create): Align the "[ skipping ... ]" string
|
||||||
|
@ -65,21 +65,9 @@ uerr_t
|
|||||||
make_connection (int *sock, char *hostname, unsigned short port)
|
make_connection (int *sock, char *hostname, unsigned short port)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sock_name;
|
struct sockaddr_in sock_name;
|
||||||
/* struct hostent *hptr; */
|
|
||||||
|
|
||||||
/* Get internet address of the host. We can do it either by calling
|
if (!lookup_host (hostname, (unsigned char *)&sock_name.sin_addr))
|
||||||
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))
|
|
||||||
return HOSTERR;
|
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 */
|
/* Set port and protocol */
|
||||||
sock_name.sin_family = AF_INET;
|
sock_name.sin_family = AF_INET;
|
||||||
|
127
src/host.c
127
src/host.c
@ -64,17 +64,10 @@ extern int errno;
|
|||||||
/* #### We should map to *lists* of IP addresses. */
|
/* #### We should map to *lists* of IP addresses. */
|
||||||
|
|
||||||
struct hash_table *host_name_address_map;
|
struct hash_table *host_name_address_map;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
/* The following two tables are obsolete, since we no longer do host
|
/* This function is no longer used. */
|
||||||
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;
|
|
||||||
|
|
||||||
/* The same as gethostbyname, but supports internet addresses of the
|
/* The same as gethostbyname, but supports internet addresses of the
|
||||||
form `N.N.N.N'. On some systems gethostbyname() knows how to do
|
form `N.N.N.N'. On some systems gethostbyname() knows how to do
|
||||||
@ -92,38 +85,20 @@ ngethostbyname (const char *name)
|
|||||||
hp = gethostbyname (name);
|
hp = gethostbyname (name);
|
||||||
return hp;
|
return hp;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Add host name HOST with the address ADDR_TEXT to the cache.
|
/* 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. */
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
add_host_to_cache (const char *host, const char *addr_text)
|
add_host_to_cache (const char *host, const char *addr_text)
|
||||||
{
|
{
|
||||||
char *canonical_name = hash_table_get (host_address_name_map, addr_text);
|
DEBUGP (("Caching %s => %s\n", host, addr_text));
|
||||||
if (canonical_name)
|
|
||||||
{
|
if (!host_name_address_map)
|
||||||
DEBUGP (("Mapping %s to %s in host_slave_master_map.\n",
|
host_name_address_map = make_nocase_string_hash_table (0);
|
||||||
host, canonical_name));
|
|
||||||
/* We've already dealt with that host under another name. */
|
hash_table_put (host_name_address_map,
|
||||||
hash_table_put (host_slave_master_map,
|
xstrdup_lower (host), xstrdup (addr_text));
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Store the address of HOSTNAME, internet-style (four octets in
|
/* 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. */
|
Return 1 on successful finding of the hostname, 0 otherwise. */
|
||||||
int
|
int
|
||||||
store_hostaddress (unsigned char *where, const char *hostname)
|
lookup_host (const char *hostname, unsigned char *store_ip)
|
||||||
{
|
{
|
||||||
unsigned long addr;
|
unsigned long addr;
|
||||||
char *addr_text;
|
char *addr_text = NULL;
|
||||||
char *canonical_name;
|
|
||||||
struct hostent *hptr;
|
struct hostent *hptr;
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
char *inet_s;
|
char *inet_s;
|
||||||
|
|
||||||
/* If the address is of the form d.d.d.d, there will be no trouble
|
/* If the address is of the form d.d.d.d, no further lookup is
|
||||||
with it. */
|
needed. */
|
||||||
addr = (unsigned long)inet_addr (hostname);
|
addr = (unsigned long)inet_addr (hostname);
|
||||||
/* If we have the numeric address, just store it. */
|
|
||||||
if ((int)addr != -1)
|
if ((int)addr != -1)
|
||||||
{
|
{
|
||||||
/* ADDR is defined to be in network byte order, meaning the code
|
/* ADDR is defined to be in network byte order, which is what
|
||||||
works on little and big endian 32-bit architectures without
|
this returns, so we can just copy it to STORE_IP. However,
|
||||||
change. On big endian 64-bit architectures we need to be
|
on big endian 64-bit architectures the value will be stored
|
||||||
careful to copy the correct four bytes. */
|
in the *last*, not first four bytes. OFFSET makes sure that
|
||||||
|
we copy the correct four bytes. */
|
||||||
int offset;
|
int offset;
|
||||||
have_addr:
|
have_addr:
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
@ -159,13 +133,15 @@ store_hostaddress (unsigned char *where, const char *hostname)
|
|||||||
#else
|
#else
|
||||||
offset = 0;
|
offset = 0;
|
||||||
#endif
|
#endif
|
||||||
memcpy (where, (char *)&addr + offset, 4);
|
memcpy (store_ip, (char *)&addr + offset, 4);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* By now we know that the address is not of the form d.d.d.d. Try
|
/* By now we know that the host name we got is not of the form
|
||||||
to find it in our cache of host addresses. */
|
d.d.d.d. Try to find it in our cache of host names. */
|
||||||
addr_text = hash_table_get (host_name_address_map, hostname);
|
if (host_name_address_map)
|
||||||
|
addr_text = hash_table_get (host_name_address_map, hostname);
|
||||||
|
|
||||||
if (addr_text)
|
if (addr_text)
|
||||||
{
|
{
|
||||||
DEBUGP (("Found %s in host_name_address_map: %s\n",
|
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;
|
goto have_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Maybe this host is known to us under another name. If so, we'll
|
/* Look up the host using gethostbyname(). Note that we use
|
||||||
find it in host_slave_master_map, and use the master name to find
|
gethostbyname() rather than ngethostbyname(), because we already
|
||||||
its address in host_name_address_map. */
|
know that the address is not numerical. */
|
||||||
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. */
|
|
||||||
hptr = gethostbyname (hostname);
|
hptr = gethostbyname (hostname);
|
||||||
if (!hptr)
|
if (!hptr)
|
||||||
return 0;
|
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
|
/* Store the IP address to the desired location. */
|
||||||
gethostbyname(), we can store this valuable information to the
|
assert (hptr->h_length == 4);
|
||||||
cache. First, we have to look for it by address to know if it's
|
memcpy (store_ip, hptr->h_addr_list[0], hptr->h_length);
|
||||||
already in the cache by another name. */
|
|
||||||
|
/* 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
|
/* Originally, we copied to in.s_addr, but it appears to be missing
|
||||||
on some systems. */
|
on some systems. */
|
||||||
memcpy (&in, *hptr->h_addr_list, sizeof (in));
|
memcpy (&in, *hptr->h_addr_list, sizeof (in));
|
||||||
inet_s = inet_ntoa (in);
|
inet_s = inet_ntoa (in);
|
||||||
add_host_to_cache (hostname, inet_s);
|
add_host_to_cache (hostname, inet_s);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,20 +234,6 @@ herrmsg (int error)
|
|||||||
void
|
void
|
||||||
host_cleanup (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);
|
free_keys_and_values (host_name_address_map);
|
||||||
hash_table_destroy (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);
|
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,12 @@ struct url;
|
|||||||
|
|
||||||
/* Function declarations */
|
/* Function declarations */
|
||||||
|
|
||||||
struct hostent *ngethostbyname PARAMS ((const char *));
|
int lookup_host PARAMS ((const char *, unsigned char *));
|
||||||
int store_hostaddress PARAMS ((unsigned char *, const char *));
|
char *herrmsg PARAMS ((int));
|
||||||
|
|
||||||
void host_cleanup PARAMS ((void));
|
|
||||||
|
|
||||||
int accept_domain PARAMS ((struct url *));
|
int accept_domain PARAMS ((struct url *));
|
||||||
int sufmatch PARAMS ((const char **, const char *));
|
int sufmatch PARAMS ((const char **, const char *));
|
||||||
|
|
||||||
char *herrmsg PARAMS ((int));
|
void host_cleanup PARAMS ((void));
|
||||||
|
|
||||||
#endif /* HOST_H */
|
#endif /* HOST_H */
|
||||||
|
14
src/http.c
14
src/http.c
@ -276,7 +276,7 @@ http_process_connection (const char *hdr, void *arg)
|
|||||||
/* Whether a persistent connection is active. */
|
/* Whether a persistent connection is active. */
|
||||||
static int pc_active_p;
|
static int pc_active_p;
|
||||||
/* Host and port of currently active persistent connection. */
|
/* 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;
|
static unsigned short pc_last_port;
|
||||||
|
|
||||||
/* File descriptor of the currently active persistent connection. */
|
/* 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
|
/* This lookup_host cannot fail, because it has the results in the
|
||||||
in the cache. */
|
cache. */
|
||||||
success = store_hostaddress (pc_last_host, host);
|
success = lookup_host (host, pc_last_host_ip);
|
||||||
assert (success);
|
assert (success);
|
||||||
pc_last_port = port;
|
pc_last_port = port;
|
||||||
pc_last_fd = fd;
|
pc_last_fd = fd;
|
||||||
@ -371,7 +371,7 @@ persistent_available_p (const char *host, unsigned short port
|
|||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
unsigned char this_host[4];
|
unsigned char this_host_ip[4];
|
||||||
/* First, check whether a persistent connection is active at all. */
|
/* First, check whether a persistent connection is active at all. */
|
||||||
if (!pc_active_p)
|
if (!pc_active_p)
|
||||||
return 0;
|
return 0;
|
||||||
@ -388,9 +388,9 @@ persistent_available_p (const char *host, unsigned short port
|
|||||||
if (ssl != pc_active_ssl)
|
if (ssl != pc_active_ssl)
|
||||||
return 0;
|
return 0;
|
||||||
#endif /* HAVE_SSL */
|
#endif /* HAVE_SSL */
|
||||||
if (!store_hostaddress (this_host, host))
|
if (!lookup_host (host, this_host_ip))
|
||||||
return 0;
|
return 0;
|
||||||
if (memcmp (pc_last_host, this_host, 4))
|
if (memcmp (pc_last_host_ip, this_host_ip, 4))
|
||||||
return 0;
|
return 0;
|
||||||
/* Third: check whether the connection is still open. This is
|
/* Third: check whether the connection is still open. This is
|
||||||
important because most server implement a liberal (short) timeout
|
important because most server implement a liberal (short) timeout
|
||||||
|
@ -525,7 +525,7 @@ cmd_address (const char *com, const char *val, void *closure)
|
|||||||
|
|
||||||
memset (&sin, '\0', sizeof (sin));
|
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"),
|
fprintf (stderr, _("%s: %s: Cannot convert `%s' to an IP address.\n"),
|
||||||
exec_name, com, val);
|
exec_name, com, val);
|
||||||
|
13
src/main.c
13
src/main.c
@ -104,18 +104,6 @@ i18n_initialize (void)
|
|||||||
textdomain ("wget");
|
textdomain ("wget");
|
||||||
#endif /* HAVE_NLS */
|
#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. */
|
/* Print the usage message. */
|
||||||
static void
|
static void
|
||||||
@ -335,7 +323,6 @@ main (int argc, char *const *argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
i18n_initialize ();
|
i18n_initialize ();
|
||||||
private_initialize ();
|
|
||||||
|
|
||||||
append_to_log = 0;
|
append_to_log = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user