From 679fb29f52a98ebff8a0cb1f463bcd165fd1da87 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Wed, 12 Nov 2003 13:49:32 +0000 Subject: [PATCH] Fix IDN API incompatibility problems. --- configure.in | 7 ++++++- mutt_idna.c | 6 +++--- mutt_idna.h | 14 ++++++++++++++ mutt_socket.c | 8 +++----- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/configure.in b/configure.in index 6a4214a1c..892f2f608 100644 --- a/configure.in +++ b/configure.in @@ -685,7 +685,12 @@ AC_ARG_WITH(idn, [ --with-idn=[PFX] Use GNU libidn for domain names], ] ) -AC_CHECK_LIB(idn, idna_to_ascii_from_utf8) +if test "x$with_idn" != "xno"; then + AC_CHECK_LIB(idn, stringprep_check_version) + AC_CHECK_FUNCS(idna_to_unicode_utf8_from_utf8 idna_to_unicode_8z8z) + AC_CHECK_FUNCS(idna_to_ascii_from_utf8 idna_to_ascii_8z) + AC_CHECK_FUNCS(idna_to_ascii_lz idna_to_ascii_from_locale) +fi if test "$need_md5" = "yes" then diff --git a/mutt_idna.c b/mutt_idna.c index 6c0cc24c6..9a3fbb465 100644 --- a/mutt_idna.c +++ b/mutt_idna.c @@ -47,7 +47,7 @@ int mutt_idna_to_local (const char *in, char **out, int flags) goto notrans; /* Is this the right function? Interesting effects with some bad identifiers! */ - if (idna_to_unicode_utf8_from_utf8 (in, out, 1, 0) != IDNA_SUCCESS) + if (idna_to_unicode_8z8z (in, out, 1) != IDNA_SUCCESS) goto notrans; if (mutt_convert_string (out, "utf-8", Charset, M_ICONV_HOOK_TO) == -1) goto notrans; @@ -63,7 +63,7 @@ int mutt_idna_to_local (const char *in, char **out, int flags) char *tmp = safe_strdup (*out); if (mutt_convert_string (&tmp, Charset, "utf-8", M_ICONV_HOOK_FROM) == -1) irrev = 1; - if (!irrev && idna_to_ascii_from_utf8 (tmp, &t2, 1, 0) != IDNA_SUCCESS) + if (!irrev && idna_to_ascii_8z (tmp, &t2, 1) != IDNA_SUCCESS) irrev = 1; if (!irrev && ascii_strcasecmp (t2, in)) { @@ -101,7 +101,7 @@ int mutt_local_to_idna (const char *in, char **out) if (mutt_convert_string (&tmp, Charset, "utf-8", M_ICONV_HOOK_FROM) == -1) rv = -1; - if (!rv && idna_to_ascii_from_utf8 (tmp, out, 1, 0) != IDNA_SUCCESS) + if (!rv && idna_to_ascii_8z (tmp, out, 1) != IDNA_SUCCESS) rv = -2; FREE (&tmp); diff --git a/mutt_idna.h b/mutt_idna.h index 270c42097..0e2534a8f 100644 --- a/mutt_idna.h +++ b/mutt_idna.h @@ -40,4 +40,18 @@ int mutt_env_to_idna (ENVELOPE *, char **, char **); const char *mutt_addr_for_display (ADDRESS *a); +/* Work around incompatibilities in the libidn API */ + +#ifdef HAVE_LIBIDN +# if (!defined(HAVE_IDNA_TO_ASCII_8Z) && defined(HAVE_IDNA_TO_ASCII_FROM_UTF8)) +# define idna_to_ascii_8z(a,b,c) idna_to_ascii_from_utf8(a,b,(c)&1,((c)&2)?1:0) +# endif +# if (!defined(HAVE_IDNA_TO_ASCII_LZ) && defined(HAVE_IDNA_TO_ASCII_FROM_LOCALE)) +# define idna_to_ascii_lz(a,b,c) idna_to_ascii_from_locale(a,b,(c)&1,((c)&2)?1:0) +# endif +# if (!defined(HAVE_IDNA_TO_UNICODE_8Z8Z) && defined(HAVE_IDNA_TO_UNICODE_UTF8_FROM_UTF8)) +# define idna_to_unicode_8z8z(a,b,c) idna_to_unicode_utf8_from_utf8(a,b,(c)&1,((c)&2)?1:0) +# endif +#endif + #endif diff --git a/mutt_socket.c b/mutt_socket.c index b860192f1..50ee94d52 100644 --- a/mutt_socket.c +++ b/mutt_socket.c @@ -26,9 +26,7 @@ # include "mutt_ssl.h" #endif -#ifdef HAVE_LIBIDN -#include -#endif +#include "mutt_idna.h" #include #include @@ -413,7 +411,7 @@ 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, 1, 0) != IDNA_SUCCESS) + if (idna_to_ascii_lz (conn->account.host, &host_idna, 1) != IDNA_SUCCESS) { mutt_error (_("Bad IDN \"%s\"."), conn->account.host); return -1; @@ -470,7 +468,7 @@ int raw_socket_open (CONNECTION* conn) sin.sin_family = AF_INET; # ifdef HAVE_LIBIDN - if (idna_to_ascii_from_locale (conn->account.host, &host_idna, 1, 0) != IDNA_SUCCESS) + if (idna_to_ascii_lz (conn->account.host, &host_idna, 1) != IDNA_SUCCESS) { mutt_error (_("Bad IDN \"%s\"."), conn->account.host); return -1; -- 2.40.0