1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

IDN adjustments and host cleanups by Gisle

This commit is contained in:
Daniel Stenberg 2004-04-26 14:03:25 +00:00
parent 712c67b4ae
commit f5042cce34
5 changed files with 42 additions and 36 deletions

View File

@ -204,7 +204,7 @@ bool Curl_ipvalid(struct SessionHandle *data)
if(data->set.ip_version == CURL_IPRESOLVE_V6) { if(data->set.ip_version == CURL_IPRESOLVE_V6) {
/* see if we have an IPv6 stack */ /* see if we have an IPv6 stack */
curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0); curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0);
if (s < 0) if (s != CURL_SOCKET_BAD)
/* an ipv6 address was requested and we can't get/use one */ /* an ipv6 address was requested and we can't get/use one */
return FALSE; return FALSE;
sclose(s); sclose(s);

View File

@ -83,9 +83,7 @@
#define _MPRINTF_REPLACE /* use our functions only */ #define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h> #include <curl/mprintf.h>
#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL) #include "inet_ntop.h"
#include "inet_ntoa_r.h"
#endif
/* The last #include file should be: */ /* The last #include file should be: */
#ifdef CURLDEBUG #ifdef CURLDEBUG
@ -137,17 +135,14 @@ static void trace_it (const char *fmt, ...)
#endif #endif
#ifdef DEBUG_THREADING_GETADDRINFO #ifdef DEBUG_THREADING_GETADDRINFO
/* inet_ntop.c */
extern const char *Curl_inet_ntop (int af, const void *addr, char *buf, size_t size);
static void dump_addrinfo (struct connectdata *conn, const struct addrinfo *ai) static void dump_addrinfo (struct connectdata *conn, const struct addrinfo *ai)
{ {
TRACE(("dump_addrinfo:\n")); TRACE(("dump_addrinfo:\n"));
for ( ; ai; ai = ai->ai_next) { for ( ; ai; ai = ai->ai_next) {
char buf [INET6_ADDRSTRLEN]; char buf [INET6_ADDRSTRLEN];
trace_it(" fam %2d, CNAME %s, ", trace_it(" fam %2d, CNAME %s, ",
af, ai->ai_canonname ? ai->ai_canonname : "<none>"); ai->ai_family, ai->ai_canonname ? ai->ai_canonname : "<none>");
if (Curl_printable_address(ai->ai_family, ai->ai_addr, buf, sizeof(buf))) if (Curl_printable_address(ai->ai_family, ai->ai_addr, buf, sizeof(buf)))
trace_it("%s\n", buf); trace_it("%s\n", buf);
else else
@ -283,6 +278,10 @@ static bool init_resolve_thread (struct connectdata *conn,
Curl_safefree(conn->async.hostname); Curl_safefree(conn->async.hostname);
conn->async.hostname = strdup(hostname); conn->async.hostname = strdup(hostname);
#ifdef USE_LIBIDN
if (conn->ace_hostname)
TRACE(("ACE name '%s'\n", conn->ace_hostname));
#endif
if (!conn->async.hostname) { if (!conn->async.hostname) {
free(td); free(td);
SetLastError(ENOMEM); SetLastError(ENOMEM);
@ -499,7 +498,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
/* see if we have an IPv6 stack */ /* see if we have an IPv6 stack */
s = socket(PF_INET6, SOCK_DGRAM, 0); s = socket(PF_INET6, SOCK_DGRAM, 0);
if (s < 0) { if (s != CURL_SOCKET_BAD) {
/* Some non-IPv6 stacks have been found to make very slow name resolves /* Some non-IPv6 stacks have been found to make very slow name resolves
* when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if * when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if
* the stack seems to be a non-ipv6 one. */ * the stack seems to be a non-ipv6 one. */

View File

@ -92,6 +92,7 @@
#include "http_negotiate.h" #include "http_negotiate.h"
#include "url.h" #include "url.h"
#include "share.h" #include "share.h"
#include "hostip.h"
#include "http.h" #include "http.h"
#define _MPRINTF_REPLACE /* use our functions only */ #define _MPRINTF_REPLACE /* use our functions only */
@ -252,7 +253,7 @@ static CURLcode http_auth_headers(struct connectdata *conn,
host due to a location-follow, we do some weirdo checks here */ host due to a location-follow, we do some weirdo checks here */
if(!data->state.this_is_a_follow || if(!data->state.this_is_a_follow ||
!data->state.auth_host || !data->state.auth_host ||
curl_strequal(data->state.auth_host, conn->hostname) || curl_strequal(data->state.auth_host, TRUE_HOSTNAME(conn)) ||
data->set.http_disable_hostname_check_before_authentication) { data->set.http_disable_hostname_check_before_authentication) {
/* Send proxy authentication header if needed */ /* Send proxy authentication header if needed */
@ -1112,7 +1113,7 @@ CURLcode Curl_http_connect(struct connectdata *conn)
/* either HTTPS over proxy, OR explicitly asked for a tunnel */ /* either HTTPS over proxy, OR explicitly asked for a tunnel */
result = Curl_ConnectHTTPProxyTunnel(conn, FIRSTSOCKET, result = Curl_ConnectHTTPProxyTunnel(conn, FIRSTSOCKET,
conn->hostname, conn->remote_port); TRUE_HOSTNAME(conn), conn->remote_port);
if(CURLE_OK != result) if(CURLE_OK != result)
return result; return result;
} }
@ -1131,7 +1132,7 @@ CURLcode Curl_http_connect(struct connectdata *conn)
/* Free to avoid leaking memory on multiple requests*/ /* Free to avoid leaking memory on multiple requests*/
free(data->state.auth_host); free(data->state.auth_host);
data->state.auth_host = strdup(conn->hostname); data->state.auth_host = strdup(TRUE_HOSTNAME(conn));
} }
return CURLE_OK; return CURLE_OK;
@ -1218,7 +1219,7 @@ CURLcode Curl_http(struct connectdata *conn)
struct HTTP *http; struct HTTP *http;
struct Cookie *co=NULL; /* no cookies from start */ struct Cookie *co=NULL; /* no cookies from start */
char *ppath = conn->path; char *ppath = conn->path;
char *host = conn->hostname; char *host = TRUE_HOSTNAME(conn);
const char *te = ""; /* tranfer-encoding */ const char *te = ""; /* tranfer-encoding */
char *ptr; char *ptr;
char *request; char *request;

View File

@ -124,8 +124,6 @@
#include "inet_ntop.h" #include "inet_ntop.h"
#include <ca-bundle.h> #include <ca-bundle.h>
#include <curl/types.h>
#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL) #if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
#include "inet_ntoa_r.h" #include "inet_ntoa_r.h"
#endif #endif
@ -152,8 +150,7 @@ static unsigned int ConnectionStore(struct SessionHandle *data,
static bool safe_strequal(char* str1, char* str2); static bool safe_strequal(char* str1, char* str2);
#ifdef USE_LIBIDN #ifdef USE_LIBIDN
static bool is_ASCII_name (const char *hostname); static bool is_ASCII_name(const char *hostname);
static bool is_ACE_name (const char *hostname);
#endif #endif
#ifndef USE_ARES #ifndef USE_ARES
@ -1373,6 +1370,9 @@ CURLcode Curl_disconnect(struct connectdata *conn)
Curl_safefree(conn->newurl); Curl_safefree(conn->newurl);
Curl_safefree(conn->pathbuffer); /* the URL path buffer */ Curl_safefree(conn->pathbuffer); /* the URL path buffer */
Curl_safefree(conn->namebuffer); /* the URL host name buffer */ Curl_safefree(conn->namebuffer); /* the URL host name buffer */
#ifdef USE_LIBIDN
Curl_safefree(conn->ace_hostname);
#endif
Curl_SSL_Close(conn); Curl_SSL_Close(conn);
/* close possibly still open sockets */ /* close possibly still open sockets */
@ -1473,7 +1473,7 @@ ConnectionExists(struct SessionHandle *data,
continue; continue;
if(strequal(needle->protostr, check->protostr) && if(strequal(needle->protostr, check->protostr) &&
strequal(needle->hostname, check->hostname) && strequal(TRUE_HOSTNAME(needle), TRUE_HOSTNAME(check)) &&
(needle->remote_port == check->remote_port) ) { (needle->remote_port == check->remote_port) ) {
if(needle->protocol & PROT_SSL) { if(needle->protocol & PROT_SSL) {
/* This is SSL, verify that we're using the same /* This is SSL, verify that we're using the same
@ -1763,7 +1763,7 @@ static int handleSock5Proxy(const char *proxy_name,
#ifndef ENABLE_IPV6 #ifndef ENABLE_IPV6
struct Curl_dns_entry *dns; struct Curl_dns_entry *dns;
Curl_addrinfo *hp=NULL; Curl_addrinfo *hp=NULL;
int rc = Curl_resolv(conn, conn->hostname, conn->remote_port, &dns); int rc = Curl_resolv(conn, TRUE_HOSTNAME(conn), conn->remote_port, &dns);
if(rc == -1) if(rc == -1)
return 1; return 1;
@ -2917,6 +2917,10 @@ static CURLcode CreateConnection(struct SessionHandle *data,
free(conn->namebuffer); /* free the newly allocated name buffer */ free(conn->namebuffer); /* free the newly allocated name buffer */
conn->namebuffer = old_conn->namebuffer; /* use the old one */ conn->namebuffer = old_conn->namebuffer; /* use the old one */
conn->hostname = old_conn->hostname; conn->hostname = old_conn->hostname;
#ifdef USE_LIBIDN
Curl_safefree(conn->ace_hostname);
conn->ace_hostname = old_conn->ace_hostname;
#endif
free(conn->pathbuffer); /* free the newly allocated path pointer */ free(conn->pathbuffer); /* free the newly allocated path pointer */
conn->pathbuffer = old_conn->pathbuffer; /* use the old one */ conn->pathbuffer = old_conn->pathbuffer; /* use the old one */
@ -3057,7 +3061,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
conn->port = conn->remote_port; /* it is the same port */ conn->port = conn->remote_port; /* it is the same port */
/* Resolve target host right on */ /* Resolve target host right on */
rc = Curl_resolv(conn, conn->hostname, conn->port, &hostaddr); rc = Curl_resolv(conn, TRUE_HOSTNAME(conn), conn->port, &hostaddr);
if(rc == 1) if(rc == 1)
*async = TRUE; *async = TRUE;
@ -3154,13 +3158,12 @@ static CURLcode SetupConnection(struct connectdata *conn,
const char *host = conn->hostname; const char *host = conn->hostname;
char *ace_hostname; char *ace_hostname;
if (!is_ASCII_name(host) && !is_ACE_name(host)) { if (!is_ASCII_name(host)) {
int rc = idna_to_ascii_lz (host, &ace_hostname, 0); int rc = idna_to_ascii_lz (host, &ace_hostname, 0);
if (rc == IDNA_SUCCESS)
if (rc == IDNA_SUCCESS) conn->ace_hostname = ace_hostname;
conn->ace_hostname = ace_hostname; else
else infof(data, "Failed to convert %s to ACE; IDNA error %d\n", host, rc);
infof(data, "Failed to convert %s to ACE; IDNA error %d\n", host, rc);
} }
} }
#endif #endif
@ -3499,18 +3502,17 @@ void Curl_free_ssl_config(struct ssl_config_data* sslc)
} }
/* /*
* Helpers for IDNA convertions. To do. * Helpers for IDNA convertions.
*/ */
#ifdef USE_LIBIDN #ifdef USE_LIBIDN
static bool is_ASCII_name (const char *hostname) static bool is_ASCII_name (const char *hostname)
{ {
(void) hostname; const unsigned char *ch = (const unsigned char*)hostname;
return (TRUE);
}
static bool is_ACE_name (const char *hostname) while (*ch) {
{ if (*ch++ > 0x80)
(void) hostname; return FALSE;
return (FALSE); }
return TRUE;
} }
#endif #endif

View File

@ -433,6 +433,10 @@ struct connectdata {
somewhere within the namebuffer[] area */ somewhere within the namebuffer[] area */
#ifdef USE_LIBIDN #ifdef USE_LIBIDN
char *ace_hostname; /* hostname possibly converted to ACE form */ char *ace_hostname; /* hostname possibly converted to ACE form */
#define TRUE_HOSTNAME(conn) \
(conn->ace_hostname ? conn->ace_hostname : conn->hostname)
#else
#define TRUE_HOSTNAME(conn) conn->hostname
#endif #endif
char *pathbuffer;/* allocated buffer to store the URL's path part in */ char *pathbuffer;/* allocated buffer to store the URL's path part in */
char *path; /* path to use, points to somewhere within the pathbuffer char *path; /* path to use, points to somewhere within the pathbuffer