libidn + libidn2 support, as proposed by WJ Liu / multiSnow in a github gist.
authorNils Gillmann <ng0@n0.is>
Sun, 21 Oct 2018 17:48:50 +0000 (17:48 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 25 Oct 2018 10:01:28 +0000 (12:01 +0200)
Signed-off-by: Nils Gillmann <ng0@n0.is>
README
configure.ac
src/util/Makefile.am
src/util/dnsparser.c

diff --git a/README b/README
index 0498e3def4c3c0fac5a4a1f4addb7f261a62130c..3a28702793b1d5add07a1a2771ee7da04c2dfc96 100644 (file)
--- a/README
+++ b/README
@@ -36,7 +36,10 @@ These are the direct dependencies for running GNUnet:
 - libcurl            >= 7.35.0      (alternative to libgnurl)
 - libunistring       >= 0.9.2
 - gnutls             >= 3.2.12      (highly recommended a gnutls linked against libunbound)
-- libidn             >= 1.0
+- libidn:
+  - libidn2 (prefered)
+  or
+  - libidn             >= 1.0
 - libextractor       >= 0.6.1       (highly recommended)
 - openssl            >= 1.0         (binary, used to generate X.509 certificate)
 - libltdl            >= 2.2         (part of GNU libtool)
index e9e540419aa71206974bd93c041356512498698b..e36d0b2d3cbbf3e28e0e64cecea77f3440cd4584 100644 (file)
@@ -827,28 +827,131 @@ fi
 # restore LIBS
 LIBS=$SAVE_LIBS
 
+# libidn and libidn2. The ideal goal is this:
+# check for libidn2, if it doesn't exist check for libidn
+# if both exist, prefer libidn2
+# if none exist, fail and message that libidn or libidn2
+# is required with a preference for libidn2.
+# TODO: What we have right here can probably be improved.
+my_with_libidn=1
+AC_ARG_WITH(libidn,
+            AS_HELP_STRING([--with-libidn=pathname],
+                           [Support IDN (needs libidn)]),
+            [],
+            [withval="yes"])
+if test x_$withval = x_yes; then
+   for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do
+       if test -f "$dir/include/idna.h"; then
+          CFLAGS="$CFLAGS -I$dir/include"
+          LDFLAGS="$LDFLAGS -L$dir/lib"
+          AC_MSG_NOTICE([Found libidn in $dir])
+          break
+       fi
+       if test -f "$dir/include/idn/idna.h"; then
+          CFLAGS="$CFLAGS -I$dir/include/idn"
+          LDFLAGS="$LDFLAGS -L$dir/lib"
+          AC_MSG_NOTICE([Found libidn in $dir])
+          break
+       fi
+   done
+   if test -f "/usr/include/idn/idna.h"; then
+          CFLAGS="$CFLAGS -I/usr/include/idn"
+          #LDFLAGS="$LDFLAGS -L/usr/lib"
+          AC_MSG_NOTICE([Found libidn in /usr])
+   fi
+else
+        if test x_$withval != x_no; then
+           CFLAGS="$CFLAGS -I$withval/include"
+           LDFLAGS="$LDFLAGS -L$withval/lib"
+        else
+           my_with_libidn=0
+        fi
+fi
 
-# libidn
-AC_MSG_CHECKING([if Libidn can be used])
-AC_ARG_WITH(libidn, AC_HELP_STRING([--with-libidn=[DIR]],
-                                    [Support IDN (needs GNU Libidn)]),
-libidn=$withval, libidn=yes)
-if test "$libidn" != "no"; then
-  if test "$libidn" != "yes"; then
-     LDFLAGS="${LDFLAGS} -L$libidn/lib"
-     CPPFLAGS="${CPPFLAGS} -I$libidn/include"
-  fi
+my_with_libidn2=1
+AC_ARG_WITH(libidn2,
+            AS_HELP_STRING([--with-libidn2=pathname],
+                           [Support IDN (needs libidn2)]),
+            [],
+            [withval="yes"])
+if test x_$withval = x_yes; then
+   for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do
+       if test -f "$dir/include/idn2.h"; then
+          CFLAGS="$CFLAGS -I$dir/include"
+          LDFLAGS="$LDFLAGS -L$dir/lib"
+          AC_MSG_NOTICE([Found libidn2 in $dir])
+          break
+       fi
+       if test -f "$dir/include/idn2/idn2.h"; then
+          CFLAGS="$CFLAGS -I$dir/include/idn2"
+          LDFLAGS="$LDFLAGS -L$dir/lib"
+          AC_MSG_NOTICE([Found libidn2 in $dir])
+          break
+       fi
+   done
+   if test -f "/usr/include/idn2/idn2.h"; then
+      CFLAGS="$CFLAGS -I/usr/include/idn2"
+      #LDFLAGS="$LDFLAGS -L/usr/lib"
+      AC_MSG_NOTICE([Found libidn2 in /usr])
+   fi
+else
+        if test x_$withval != x_no; then
+           CFLAGS="$CFLAGS -I$withval/include"
+           LDFLAGS="$LDFLAGS -L$withval/lib"
+        else
+                my_with_libidn2=0
+        fi
 fi
-libidn=no
-AC_CHECK_HEADER(idna.h,
-  AC_CHECK_LIB(idn, stringprep_check_version,
-    [libidn=yes LIBS="${LIBS} -lidn"], []), [])
-if test "$libidn" != "yes"; then
-  AC_MSG_FAILURE([GNUnet requires libidn.
-libidn-1.13 should be sufficient, newer versions work too.])
+
+AC_MSG_CHECKING([if libidn can be used])
+# Check for LIBIDNs
+there_can_only_be_one=1
+
+working_libidn2=0
+if test $my_with_libidn2 = 1
+then
+        AC_MSG_NOTICE([Checking for libidn2])
+        AC_CHECK_LIB([idn2],
+                     [idn2_to_unicode_8z8z],
+                     [working_libidn2=1
+                     LIBS="-lidn2 $LIBS"
+                     AC_DEFINE_UNQUOTED([HAVE_LIBIDN2],
+                                        [1],
+                                        [Define to 1 if you have 'libidn2' (-lidn).])],
+                     [MISSING_DEPS="${MISSING_DEPS}${MISSING_SEP}libidn2"
+                     MISSING_SEP=", "])
+fi
+if test $working_libidn2 = 0
+then
+        if test $my_with_libidn = 1
+        then
+                AC_MSG_NOTICE([Checking for libidn])
+                AC_CHECK_LIB([idn],
+                             [idna_to_ascii_8z],
+                             [LIBS="-lidn $LIBS"
+                             AC_DEFINE_UNQUOTED([HAVE_LIBIDN],
+                                                [1],
+                                                [Define to 1 if you have 'libidn' (-lidn).])],
+                             [there_can_only_be_one=0])
+        else
+                if test $my_with_libidn2 = 1
+                then
+                        there_can_only_be_one=0
+                        AC_MSG_FAILURE([* There can only be one libidn.
+                                        * Provide either libidn >= 1.13
+                                        * or
+                                        * libidn2 to the configure
+                                        * script via
+                                        * --with-libidn2
+                                        * --with-libidn])
+                fi
+        fi
 fi
-AC_MSG_RESULT($libidn)
 
+if test $there_can_only_be_one = 0
+then
+    AC_MSG_FAILURE([Missing dependencies: $MISSING_DEPS])
+fi
 
 # test for zlib
 SAVE_LDFLAGS=$LDFLAGS
index b0f45b1dae891684832d9bcc9f6e3f39712880d3..165d41d0180ae61dbb281ad9129a5361fb28323b 100644 (file)
@@ -122,12 +122,22 @@ libgnunetutil_la_SOURCES = \
   tun.c \
   speedup.c speedup.h
 
+if HAVE_LIBIDN
+  LIBIDN= -lidn
+else
+  LIBIDN=
+
+if HAVE_LIBIDN2
+  LIBIDN2= -lidn2
+else
+  LIBIDN2=
+
 libgnunetutil_la_LIBADD = \
   $(GCLIBADD) $(WINLIB) \
   $(LIBGCRYPT_LIBS) \
   $(LTLIBICONV) \
   $(LTLIBINTL) \
-  -lltdl -lidn $(Z_LIBS) -lunistring $(XLIB) $(PTHREAD)
+  -lltdl $(LIBIDN) $(LIBIDN2) $(Z_LIBS) -lunistring $(XLIB) $(PTHREAD)
 
 libgnunetutil_la_LDFLAGS = \
   $(GN_LIB_LDFLAGS) \
index 24f1b18cf47a0a1a29f51e2b55e6cb25bdc2d4d2..79d723f120915e2e44412db180a1427556a4f7f8 100644 (file)
  */
 
 /**
- * @file dns/dnsparser.c
+ * @file util/dnsparser.c
  * @brief helper library to parse DNS packets.
  * @author Philipp Toelke
  * @author Christian Grothoff
  */
 #include "platform.h"
+#if defined(HAVE_LIBIDN2)
+#include <idn2.h>
+#elif defined(HAVE_LIBIDN)
 #include <idna.h>
+#endif
 #if WINDOWS
 #include <idn-free.h>
 #endif