aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/hostip6.c2
-rw-r--r--lib/hostthre.c17
-rw-r--r--lib/http.c9
-rw-r--r--lib/url.c46
-rw-r--r--lib/urldata.h4
5 files changed, 42 insertions, 36 deletions
diff --git a/lib/hostip6.c b/lib/hostip6.c
index 61b140b14..8ddcd84b1 100644
--- a/lib/hostip6.c
+++ b/lib/hostip6.c
@@ -204,7 +204,7 @@ bool Curl_ipvalid(struct SessionHandle *data)
if(data->set.ip_version == CURL_IPRESOLVE_V6) {
/* see if we have an IPv6 stack */
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 */
return FALSE;
sclose(s);
diff --git a/lib/hostthre.c b/lib/hostthre.c
index 48f4786f9..6a35244ee 100644
--- a/lib/hostthre.c
+++ b/lib/hostthre.c
@@ -83,9 +83,7 @@
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
-#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
-#include "inet_ntoa_r.h"
-#endif
+#include "inet_ntop.h"
/* The last #include file should be: */
#ifdef CURLDEBUG
@@ -137,17 +135,14 @@ static void trace_it (const char *fmt, ...)
#endif
#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)
{
TRACE(("dump_addrinfo:\n"));
for ( ; ai; ai = ai->ai_next) {
char buf [INET6_ADDRSTRLEN];
+
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)))
trace_it("%s\n", buf);
else
@@ -283,6 +278,10 @@ static bool init_resolve_thread (struct connectdata *conn,
Curl_safefree(conn->async.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) {
free(td);
SetLastError(ENOMEM);
@@ -499,7 +498,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
/* see if we have an IPv6 stack */
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
* 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. */
diff --git a/lib/http.c b/lib/http.c
index 1e95e1083..4cc813e98 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -92,6 +92,7 @@
#include "http_negotiate.h"
#include "url.h"
#include "share.h"
+#include "hostip.h"
#include "http.h"
#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 */
if(!data->state.this_is_a_follow ||
!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) {
/* 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 */
result = Curl_ConnectHTTPProxyTunnel(conn, FIRSTSOCKET,
- conn->hostname, conn->remote_port);
+ TRUE_HOSTNAME(conn), conn->remote_port);
if(CURLE_OK != result)
return result;
}
@@ -1131,7 +1132,7 @@ CURLcode Curl_http_connect(struct connectdata *conn)
/* Free to avoid leaking memory on multiple requests*/
free(data->state.auth_host);
- data->state.auth_host = strdup(conn->hostname);
+ data->state.auth_host = strdup(TRUE_HOSTNAME(conn));
}
return CURLE_OK;
@@ -1218,7 +1219,7 @@ CURLcode Curl_http(struct connectdata *conn)
struct HTTP *http;
struct Cookie *co=NULL; /* no cookies from start */
char *ppath = conn->path;
- char *host = conn->hostname;
+ char *host = TRUE_HOSTNAME(conn);
const char *te = ""; /* tranfer-encoding */
char *ptr;
char *request;
diff --git a/lib/url.c b/lib/url.c
index 7bdea96ef..6657b1832 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -124,8 +124,6 @@
#include "inet_ntop.h"
#include <ca-bundle.h>
-#include <curl/types.h>
-
#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
#include "inet_ntoa_r.h"
#endif
@@ -152,8 +150,7 @@ static unsigned int ConnectionStore(struct SessionHandle *data,
static bool safe_strequal(char* str1, char* str2);
#ifdef USE_LIBIDN
-static bool is_ASCII_name (const char *hostname);
-static bool is_ACE_name (const char *hostname);
+static bool is_ASCII_name(const char *hostname);
#endif
#ifndef USE_ARES
@@ -1373,6 +1370,9 @@ CURLcode Curl_disconnect(struct connectdata *conn)
Curl_safefree(conn->newurl);
Curl_safefree(conn->pathbuffer); /* the URL path buffer */
Curl_safefree(conn->namebuffer); /* the URL host name buffer */
+#ifdef USE_LIBIDN
+ Curl_safefree(conn->ace_hostname);
+#endif
Curl_SSL_Close(conn);
/* close possibly still open sockets */
@@ -1473,7 +1473,7 @@ ConnectionExists(struct SessionHandle *data,
continue;
if(strequal(needle->protostr, check->protostr) &&
- strequal(needle->hostname, check->hostname) &&
+ strequal(TRUE_HOSTNAME(needle), TRUE_HOSTNAME(check)) &&
(needle->remote_port == check->remote_port) ) {
if(needle->protocol & PROT_SSL) {
/* This is SSL, verify that we're using the same
@@ -1763,7 +1763,7 @@ static int handleSock5Proxy(const char *proxy_name,
#ifndef ENABLE_IPV6
struct Curl_dns_entry *dns;
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)
return 1;
@@ -2917,6 +2917,10 @@ static CURLcode CreateConnection(struct SessionHandle *data,
free(conn->namebuffer); /* free the newly allocated name buffer */
conn->namebuffer = old_conn->namebuffer; /* use the old one */
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 */
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 */
/* 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)
*async = TRUE;
@@ -3154,13 +3158,12 @@ static CURLcode SetupConnection(struct connectdata *conn,
const char *host = conn->hostname;
char *ace_hostname;
- if (!is_ASCII_name(host) && !is_ACE_name(host)) {
- int rc = idna_to_ascii_lz (host, &ace_hostname, 0);
-
- if (rc == IDNA_SUCCESS)
- conn->ace_hostname = ace_hostname;
- else
- infof(data, "Failed to convert %s to ACE; IDNA error %d\n", host, rc);
+ if (!is_ASCII_name(host)) {
+ int rc = idna_to_ascii_lz (host, &ace_hostname, 0);
+ if (rc == IDNA_SUCCESS)
+ conn->ace_hostname = ace_hostname;
+ else
+ infof(data, "Failed to convert %s to ACE; IDNA error %d\n", host, rc);
}
}
#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
static bool is_ASCII_name (const char *hostname)
{
- (void) hostname;
- return (TRUE);
-}
+ const unsigned char *ch = (const unsigned char*)hostname;
-static bool is_ACE_name (const char *hostname)
-{
- (void) hostname;
- return (FALSE);
+ while (*ch) {
+ if (*ch++ > 0x80)
+ return FALSE;
+ }
+ return TRUE;
}
#endif
diff --git a/lib/urldata.h b/lib/urldata.h
index 445788f8f..1912bcf0f 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -433,6 +433,10 @@ struct connectdata {
somewhere within the namebuffer[] area */
#ifdef USE_LIBIDN
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
char *pathbuffer;/* allocated buffer to store the URL's path part in */
char *path; /* path to use, points to somewhere within the pathbuffer