]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
IDN adjustments and host cleanups by Gisle
authorDaniel Stenberg <daniel@haxx.se>
Mon, 26 Apr 2004 14:03:25 +0000 (14:03 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 26 Apr 2004 14:03:25 +0000 (14:03 +0000)
lib/hostip6.c
lib/hostthre.c
lib/http.c
lib/url.c
lib/urldata.h

index 61b140b14e12bfa4773a92ce0a04c44ccae750a8..8ddcd84b1a83ab0068f45e08b0562ad787b7c10d 100644 (file)
@@ -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);
index 48f4786f97a0019d429712fb1e048a24dbbf947d..6a35244eed68593cf0fc66883bdfd3804e6e8dab 100644 (file)
@@ -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. */
index 1e95e1083058b3b5b1c474f9dba69eb8319b4291..4cc813e9892ef67a412b4ffe0b6185885ad6f4a1 100644 (file)
@@ -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;
index 7bdea96efc5b3b18a08190fdbc5349d0149f7a8f..6657b183245cdf6ba47813be7f2094a4d99e0f45 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
 #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
index 445788f8f987137bbc470d48e85327e58c0f4634..1912bcf0fae41d1a7fdf575e529a518d315e7967 100644 (file)
@@ -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