From: Thomas Roessler Date: Mon, 3 Mar 2003 14:13:40 +0000 (+0000) Subject: IDNA support for the socket back-end. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3cc67405b5bbf84cfe29c84e537add5c3a09e079;p=neomutt IDNA support for the socket back-end. --- diff --git a/mutt_socket.c b/mutt_socket.c index e89a9f5cc..5c5524c96 100644 --- a/mutt_socket.c +++ b/mutt_socket.c @@ -26,6 +26,10 @@ # include "mutt_ssl.h" #endif +#ifdef HAVE_LIBIDN +#include +#endif + #include #include #include @@ -385,6 +389,8 @@ int raw_socket_open (CONNECTION* conn) int rc; int fd; + char *host_idna = NULL; + #ifdef HAVE_GETADDRINFO /* --- IPv4/6 --- */ @@ -406,9 +412,25 @@ int raw_socket_open (CONNECTION* conn) snprintf (port, sizeof (port), "%d", conn->account.port); +# ifdef HAVE_LIBIDN + if (idna_to_ascii_from_locale (conn->account.host, &host_idna, 0, 1) != IDNA_SUCCESS) + { + mutt_error (_("Bad IDN \"%s\"."), conn->account.host); + return -1; + } +# else + host_idna = conn->account.host; +# endif + mutt_message (_("Looking up %s..."), conn->account.host); - rc = getaddrinfo (conn->account.host, port, &hints, &res); + + rc = getaddrinfo (host_idna, port, &hints, &res); + +# ifdef HAVE_LIBIDN + FREE (&host_idna); +# endif + if (rc) { mutt_error (_("Could not find the host \"%s\""), conn->account.host); @@ -447,14 +469,27 @@ int raw_socket_open (CONNECTION* conn) sin.sin_port = htons (conn->account.port); sin.sin_family = AF_INET; +# ifdef HAVE_LIBIDN + if (idna_to_ascii_from_locale (conn->account.host, &host_idna, 0, 1) != IDNA_SUCCESS) + { + mutt_error (_("Bad IDN \"%s\"."), conn->account.host); + return -1; + } +# else + host_idna = conn->account.host; +# endif + mutt_message (_("Looking up %s..."), conn->account.host); - if ((he = gethostbyname (conn->account.host)) == NULL) + if ((he = gethostbyname (host_idna)) == NULL) { + FREE (&host_idna); mutt_error (_("Could not find the host \"%s\""), conn->account.host); return -1; } + + FREE (&host_idna); mutt_message (_("Connecting to %s..."), conn->account.host);