]> granicus.if.org Git - neomutt/commitdiff
encapsulate idna code
authorRichard Russon <rich@flatcap.org>
Fri, 22 Dec 2017 22:59:45 +0000 (22:59 +0000)
committerRichard Russon <rich@flatcap.org>
Thu, 28 Dec 2017 13:59:58 +0000 (13:59 +0000)
Move all the defines, etc, into mutt_idna.c

conn/socket.c
conn/ssl.c
mutt_idna.c
mutt_idna.h

index 112616f4138f9122bb46006a3c38a97f52a78ce7..a32d1510804cb6973cb20b1ee1048d2405d0ca5e 100644 (file)
@@ -505,7 +505,7 @@ int raw_socket_open(struct Connection *conn)
   snprintf(port, sizeof(port), "%d", conn->account.port);
 
 #ifdef HAVE_LIBIDN
-  if (idna_to_ascii_lz(conn->account.host, &host_idna, 1) != IDNA_SUCCESS)
+  if (mutt_idna_to_ascii_lz(conn->account.host, &host_idna, 1) != 0)
   {
     mutt_error(_("Bad IDN \"%s\"."), conn->account.host);
     return -1;
@@ -564,7 +564,7 @@ int raw_socket_open(struct Connection *conn)
   sin.sin_family = AF_INET;
 
 #ifdef HAVE_LIBIDN
-  if (idna_to_ascii_lz(conn->account.host, &host_idna, 1) != IDNA_SUCCESS)
+  if (mutt_idna_to_ascii_lz(conn->account.host, &host_idna, 1) != 0)
   {
     mutt_error(_("Bad IDN \"%s\"."), conn->account.host);
     return -1;
index 547e6bd04f5c87128ffca1241db50b887860ccef..8982283117b06045cd663e914b3ae5fe84fa9cdd 100644 (file)
@@ -829,7 +829,7 @@ static int check_host(X509 *x509cert, const char *hostname, char *err, size_t er
    * type DNS or the Common Name (CN). */
 
 #ifdef HAVE_LIBIDN
-  if (idna_to_ascii_lz(hostname, &hostname_ascii, 0) != IDNA_SUCCESS)
+  if (mutt_idna_to_ascii_lz(hostname, &hostname_ascii, 0) != 0)
   {
     hostname_ascii = mutt_str_strdup(hostname);
   }
index cf05b397883bbede28a469efe1785f458e27b18f..ac4719ca62de80434e38125cf345e16d02a5dce4 100644 (file)
 #include "globals.h"
 #include "mutt_charset.h"
 #include "options.h"
+#ifdef HAVE_IDNA_H
+#include <idna.h>
+#elif defined(HAVE_IDN_IDNA_H)
+#include <idn/idna.h>
+#endif
 
 #ifdef HAVE_LIBIDN
+/* Work around incompatibilities in the libidn API */
+#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 /* HAVE_LIBIDN */
+
+#ifdef HAVE_LIBIDN
+/**
+ * mutt_idna_to_ascii_lz - XXX
+ * @param input  XXX
+ * @param output XXX
+ * @param flags  XXX
+ * @retval 0 Success
+ * @retval >0 Failure, error code
+ */
+int mutt_idna_to_ascii_lz(const char *input, char **output, int flags)
+{
+  return idna_to_ascii_lz(input, output, flags);
+}
+
 static bool check_idn(char *domain)
 {
   if (!domain)
@@ -95,7 +129,7 @@ static void set_intl_mailbox(struct Address *a, char *intl_mailbox)
   a->is_intl = true;
 }
 
-static char *intl_to_local(char *orig_user, char *orig_domain, int flags)
+char *mutt_idna_intl_to_local(char *orig_user, char *orig_domain, int flags)
 {
   char *local_user = NULL, *local_domain = NULL, *mailbox = NULL;
   char *reversed_user = NULL, *reversed_domain = NULL;
@@ -196,7 +230,7 @@ cleanup:
   return mailbox;
 }
 
-static char *local_to_intl(char *user, char *domain)
+char *mutt_idna_local_to_intl(char *user, char *domain)
 {
   char *intl_user = NULL, *intl_domain = NULL;
   char *mailbox = NULL;
@@ -251,7 +285,7 @@ int mutt_addrlist_to_intl(struct Address *a, char **err)
     if (mbox_to_udomain(a->mailbox, &user, &domain) == -1)
       continue;
 
-    intl_mailbox = local_to_intl(user, domain);
+    intl_mailbox = mutt_idna_local_to_intl(user, domain);
     if (!intl_mailbox)
     {
       rc = -1;
@@ -279,7 +313,7 @@ int mutt_addrlist_to_local(struct Address *a)
     if (mbox_to_udomain(a->mailbox, &user, &domain) == -1)
       continue;
 
-    local_mailbox = intl_to_local(user, domain, 0);
+    local_mailbox = mutt_idna_intl_to_local(user, domain, 0);
     if (local_mailbox)
       set_local_mailbox(a, local_mailbox);
   }
@@ -304,7 +338,7 @@ const char *mutt_addr_for_display(struct Address *a)
   if (mbox_to_udomain(a->mailbox, &user, &domain) == -1)
     return a->mailbox;
 
-  local_mailbox = intl_to_local(user, domain, MI_MAY_BE_IRREVERSIBLE);
+  local_mailbox = mutt_idna_intl_to_local(user, domain, MI_MAY_BE_IRREVERSIBLE);
   if (!local_mailbox)
     return a->mailbox;
 
index 258801e938415c34cc624b730a890ee9545937bd..26c89d90c935a2b4f4673fbb5317e833bd0c33e0 100644 (file)
 #ifndef _MUTT_IDNA_H
 #define _MUTT_IDNA_H
 
-#ifdef HAVE_IDNA_H
-#include <idna.h>
-#elif defined(HAVE_IDN_IDNA_H)
-#include <idn/idna.h>
-#endif
-
 struct Envelope;
 struct Address;
 
 #define MI_MAY_BE_IRREVERSIBLE (1 << 0)
 
-/* 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 /* HAVE_LIBIDN */
+int mutt_idna_to_ascii_lz(const char *input, char **output, int flags);
+
+char *mutt_idna_intl_to_local(char *orig_user, char *orig_domain, int flags);
+char *mutt_idna_local_to_intl(char *user, char *domain);
 
 int mutt_addrlist_to_intl(struct Address *a, char **err);
 int mutt_addrlist_to_local(struct Address *a);