cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl with idn works

From: Gisle Vanem <gvanem_at_broadpark.no>
Date: Tue, 27 Apr 2004 16:59:00 +0200

"Daniel Stenberg" <daniel-curl_at_haxx.se> said:

> I tried resolving with IPv6, IPv4 and ares and they could all resolve and get
> the root pages from both www.tromsø.no and www.hörby.se when CHARSET was set
> to ISO8859-1.

Which was my reason for setting $CHARSET in idna_init().
IMHO it's better use the charset or code-page the OS it using
for character input. Windows users should not need to worry about
configuring idn/iconv. My patch only sets $CHARSET if not already set.

Here it is again:

--- CVS-latest/lib/easy.c Mon Apr 26 09:11:24 2004
+++ lib/easy.c Mon Apr 26 14:51:27 2004
@@ -66,7 +66,7 @@
 #include <sys/select.h>
 #endif

-#endif
+#endif /* WIN32 ... */

 #include "urldata.h"
 #include <curl/curl.h>
@@ -138,6 +138,28 @@
 static void win32_cleanup(void) { }
 #endif

+#ifdef USE_LIBIDN
+/*
+ * Initialise use of IDNA library.
+ * It falls back to ASCII if $CHARSET isn't defined. This doesn't work for
+ * idna_to_ascii_lz().
+ */
+static void idna_init (void)
+{
+#ifdef WIN32
+ char buf[60];
+ UINT cp = GetACP();
+
+ if (!getenv("CHARSET") && cp > 0) {
+ snprintf(buf, sizeof(buf), "CHARSET=cp%u", cp);
+ putenv(buf);
+ }
+#else
+ /* to do? */
+#endif
+}
+#endif /* USE_LIBIDN */
+
 /* true globals -- for curl_global_init() and curl_global_cleanup() */
 static unsigned int initialized = 0;
 static long init_flags = 0;
@@ -163,6 +185,10 @@
     return CURLE_FAILED_INIT;
 #endif

+#ifdef USE_LIBIDN
+ idna_init();
+#endif
+
   initialized = 1;
   init_flags = flags;

--------

putenv() has only effect for current process, so other programs
are unaffected. Tell me why this isn't a good idea.

--gv
Received on 2004-04-27