Commit a0571d38 authored by Michał Kępień's avatar Michał Kępień

Rework libidn2 detection

Clean up the parts of configure.in responsible for handling libidn2
detection and adjust other pieces of the build system to match these
cleanups:

  - use pkg-config when --with-libidn2 is used without an explicit path,

  - look for idn2_to_ascii_lz() rather than idn2_to_ascii_8z() as the
    former is used in BIND while the latter is not,

  - do not look for idn2_to_unicode_8zlz() as it is present in all
    libidn2 versions which have idn2_to_ascii_lz(),

  - check whether the <idn2.h> header is usable,

  - set LDFLAGS in the Makefile for dig so that, if specified, the
    requested libidn2 path is used when linking with libidn2,

  - override CPPFLAGS when looking for libidn2 components so that the
    configure script does not produce warnings when libidn2 is not
    installed system-wide,

  - merge the AS_CASE() call into the AS_IF() call below it to simplify
    code,

  - indicate the default value of --with-libidn2 in "./configure --help"
    output,

  - use $with_libidn2 rather than $use_libidn2 to better match the name
    of the configure script argument,

  - stop differentiating between IDN "in" and "out" support, i.e. make
    dig either support libidn2 or not; remove WITH_* Autoconf macros and
    use a new one, HAVE_LIBIDN2, to determine whether libidn2 support
    should be enabled.
parent f02e3c4b
......@@ -64,6 +64,8 @@ MANOBJS = ${MANPAGES} ${HTMLPAGES}
@BIND9_MAKE_RULES@
LDFLAGS = @LIBIDN2_LDFLAGS@
dig@EXEEXT@: dig.@O@ dighost.@O@ ${UOBJS} ${DEPLIBS}
export BASEOBJS="dig.@O@ dighost.@O@ ${UOBJS}"; \
export LIBS0="${DNSLIBS} ${IRSLIBS}"; \
......
......@@ -1051,7 +1051,7 @@ plus_option(char *option, isc_boolean_t is_batchfile,
switch (cmd[3]) {
case 'i':
FULLCHECK("idnin");
#ifndef WITH_IDN_SUPPORT
#ifndef HAVE_LIBIDN2
fprintf(stderr, ";; IDN input support"
" not enabled\n");
#else
......@@ -1060,7 +1060,7 @@ plus_option(char *option, isc_boolean_t is_batchfile,
break;
case 'o':
FULLCHECK("idnout");
#ifndef WITH_IDN_OUT_SUPPORT
#ifndef HAVE_LIBIDN2
fprintf(stderr, ";; IDN output support"
" not enabled\n");
#else
......
......@@ -30,12 +30,9 @@
#include <locale.h>
#endif
#ifdef WITH_IDN_SUPPORT
#ifdef WITH_LIBIDN2
#ifdef HAVE_LIBIDN2
#include <idn2.h>
#endif
#endif /* WITH_IDN_SUPPORT */
#endif /* HAVE_LIBIDN2 */
#include <dns/byaddr.h>
#include <dns/fixedname.h>
......@@ -135,14 +132,11 @@ int lookup_counter = 0;
static char servercookie[256];
#ifdef WITH_IDN_SUPPORT
#ifdef HAVE_LIBIDN2
static void idn_initialize(void);
static isc_result_t idn_locale_to_ace(const char *from,
char *to,
size_t tolen);
#endif /* WITH_IDN_SUPPORT */
#ifdef WITH_IDN_OUT_SUPPORT
static isc_result_t idn_ace_to_locale(const char *from,
char *to,
size_t tolen);
......@@ -150,8 +144,7 @@ static isc_result_t output_filter(isc_buffer_t *buffer,
unsigned int used_org,
isc_boolean_t absolute);
#define MAXDLEN 256
#endif /* WITH_IDN_OUT_SUPPORT */
#endif /* HAVE_LIBIDN2 */
isc_socket_t *keep = NULL;
isc_sockaddr_t keepaddr;
......@@ -638,16 +631,13 @@ make_empty_lookup(void) {
looknew->ttlunits = ISC_FALSE;
looknew->ttlunits = ISC_FALSE;
looknew->qr = ISC_FALSE;
#ifdef WITH_IDN_SUPPORT
#ifdef HAVE_LIBIDN2
looknew->idnin = ISC_TRUE;
#else
looknew->idnin = ISC_FALSE;
#endif
#ifdef WITH_IDN_OUT_SUPPORT
looknew->idnout = ISC_TRUE;
#else
looknew->idnin = ISC_FALSE;
looknew->idnout = ISC_FALSE;
#endif
#endif /* HAVE_LIBIDN2 */
looknew->udpsize = 0;
looknew->edns = -1;
looknew->recurse = ISC_TRUE;
......@@ -1301,15 +1291,13 @@ setup_system(isc_boolean_t ipv4only, isc_boolean_t ipv6only) {
(void)setlocale(LC_ALL, "");
#endif
#ifdef WITH_IDN_SUPPORT
#ifdef HAVE_LIBIDN2
idn_initialize();
#endif
#ifdef WITH_IDN_OUT_SUPPORT
/* Set domain name -> text post-conversion filter. */
result = dns_name_settotextfilter(output_filter);
check_result(result, "dns_name_settotextfilter");
#endif
#endif /* HAVE_LIBIDN2 */
if (keyfile[0] != 0)
setup_file_key();
......@@ -2033,15 +2021,13 @@ setup_lookup(dig_lookup_t *lookup) {
char cookiebuf[256];
char *origin = NULL;
char *textname = NULL;
#ifdef WITH_IDN_SUPPORT
#ifdef HAVE_LIBIDN2
char idn_origin[MXNAME], idn_textname[MXNAME];
#endif
#ifdef WITH_IDN_OUT_SUPPORT
result = dns_name_settotextfilter(lookup->idnout ?
output_filter : NULL);
check_result(result, "dns_name_settotextfilter");
#endif
#endif /* HAVE_LIBIDN2 */
REQUIRE(lookup != NULL);
INSIST(!free_now);
......@@ -2076,14 +2062,14 @@ setup_lookup(dig_lookup_t *lookup) {
* TLD.
*/
textname = lookup->textname;
#ifdef WITH_IDN_SUPPORT
#ifdef HAVE_LIBIDN2
if (lookup->idnin) {
result = idn_locale_to_ace(textname, idn_textname, sizeof(idn_textname));
check_result(result, "convert textname to IDN encoding");
debug("idn_textname: %s", idn_textname);
textname = idn_textname;
}
#endif
#endif /* HAVE_LIBIDN2 */
/*
* If the name has too many dots, force the origin to be NULL
......@@ -2112,14 +2098,14 @@ setup_lookup(dig_lookup_t *lookup) {
dns_name_init(lookup->oname, NULL);
/* XXX Helper funct to conv char* to name? */
origin = lookup->origin->origin;
#ifdef WITH_IDN_SUPPORT
#ifdef HAVE_LIBIDN2
if (lookup->idnin) {
result = idn_locale_to_ace(origin, idn_origin, sizeof(idn_origin));
check_result(result, "convert origin to IDN encoding");
debug("trying idn origin %s", idn_origin);
origin = idn_origin;
}
#endif
#endif /* HAVE_LIBIDN2 */
len = (unsigned int) strlen(origin);
isc_buffer_init(&b, origin, len);
isc_buffer_add(&b, len);
......@@ -4144,9 +4130,9 @@ cancel_all(void) {
*/
void
destroy_libs(void) {
#ifdef WITH_IDN_SUPPORT
#ifdef HAVE_LIBIDN2
isc_result_t result;
#endif
#endif /* HAVE_LIBIDN2 */
if (keep != NULL)
isc_socket_detach(&keep);
......@@ -4178,10 +4164,10 @@ destroy_libs(void) {
clear_searchlist();
#ifdef WITH_IDN_SUPPORT
#ifdef HAVE_LIBIDN2
result = dns_name_settotextfilter(NULL);
check_result(result, "dns_name_settotextfilter");
#endif
#endif /* HAVE_LIBIDN2 */
dns_name_destroy();
if (commctx != NULL) {
......@@ -4221,7 +4207,7 @@ destroy_libs(void) {
isc_mem_destroy(&mctx);
}
#ifdef WITH_IDN_OUT_SUPPORT
#ifdef HAVE_LIBIDN2
static isc_result_t
output_filter(isc_buffer_t *buffer, unsigned int used_org,
isc_boolean_t absolute)
......@@ -4274,10 +4260,7 @@ output_filter(isc_buffer_t *buffer, unsigned int used_org,
return (ISC_R_SUCCESS);
}
#endif
#ifdef WITH_IDN_SUPPORT
#ifdef WITH_LIBIDN2
static void
idn_initialize(void) {
}
......@@ -4325,7 +4308,6 @@ idn_locale_to_ace(const char *from, char *to, size_t tolen) {
return ISC_R_FAILURE;
}
#ifdef WITH_IDN_OUT_SUPPORT
static isc_result_t
idn_ace_to_locale(const char *from, char *to, size_t tolen) {
int res;
......@@ -4350,6 +4332,4 @@ idn_ace_to_locale(const char *from, char *to, size_t tolen) {
fatal("'%s' is not a legal IDN name (%s), use +noidnout", from, idn2_strerror(res));
return ISC_R_FAILURE;
}
#endif /* WITH_IDN_OUT_SUPPORT */
#endif /* WITH_LIBIDN2 */
#endif /* WITH_IDN_SUPPORT */
#endif /* HAVE_LIBIDN2 */
......@@ -153,7 +153,7 @@ main(int argc, char **argv) {
}
if (strcmp(argv[1], "--with-idn") == 0) {
#ifdef WITH_LIBIDN2
#ifdef HAVE_LIBIDN2
return (0);
#else
return (1);
......
......@@ -293,6 +293,9 @@ int sigwait(const unsigned int *set, int *sig);
/* Define to 1 if you have the <gssapi_krb5.h> header file. */
#undef HAVE_GSSAPI_KRB5_H
/* Define to 1 if you have the <idn2.h> header file. */
#undef HAVE_IDN2_H
/* Define to 1 if you have the if_nametoindex function. */
#undef HAVE_IF_NAMETOINDEX
......@@ -323,6 +326,9 @@ int sigwait(const unsigned int *set, int *sig);
/* Define to 1 if you have the `c_r' library (-lc_r). */
#undef HAVE_LIBC_R
/* Define if libidn2 was found */
#undef HAVE_LIBIDN2
/* Define to 1 if you have the `nsl' library (-lnsl). */
#undef HAVE_LIBNSL
......@@ -620,15 +626,6 @@ int sigwait(const unsigned int *set, int *sig);
/* Define to enable very verbose query trace logging. */
#undef WANT_QUERYTRACE
/* define if IDN output support is to be included. */
#undef WITH_IDN_OUT_SUPPORT
/* define if IDN input support is to be included. */
#undef WITH_IDN_SUPPORT
/* define if libidn2 support is to be included. */
#undef WITH_LIBIDN2
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
......
This diff is collapsed.
......@@ -4521,38 +4521,35 @@ NOM_PATH_FILE(XSLT_DBLATEX_FASTBOOK, xsl/latex_book_fast.xsl, $dblatex_xsl_trees
LIBIDN2_CFLAGS=
LIBIDN2_LDFLAGS=
LIBIDN2_LIBS=
AC_ARG_WITH(libidn2,
AS_HELP_STRING([--with-libidn2[=PATH]], [enable IDN support using GNU libidn2 [yes|no|path]]),
use_libidn2="$withval", use_libidn2="no")
AS_CASE([$use_libidn2],
[no],[:],
[yes],[:],
[*],[
LIBIDN2_CFLAGS="-I$use_libidn2/include"
LIBIDN2_LDFLAGS="-L$use_libidn2/lib"
])
AS_IF([test "$use_libidn2" != "no"],
[save_CFLAGS="$CFLAGS"
save_LIBS="$LIBS"
save_LDFLAGS="$LDFLAGS"
CFLAGS="$LIBIDN2_CFLAGS $CFLAGS"
LDFLAGS="$LIBIDN2_LDFLAGS $LDFLAGS"
AC_SEARCH_LIBS([idn2_to_ascii_8z], [idn2],
[AC_DEFINE(WITH_IDN_SUPPORT, 1, [define if IDN input support is to be included.])
AC_DEFINE(WITH_LIBIDN2, 1, [define if libidn2 support is to be included.])
LIBIDN2_LIBS="$LIBIDN2_LDFLAGS -lidn2"],
[AC_MSG_ERROR([libidn2 requested, but not found])])
AC_TRY_LINK([#include <idn2.h>],
[idn2_to_unicode_8zlz(".", NULL, IDN2_NONTRANSITIONAL|IDN2_NFC_INPUT);],
[AC_MSG_RESULT(yes)
AC_DEFINE(WITH_IDN_OUT_SUPPORT, 1, [define if IDN output support is to be included.])],
[AC_MSG_RESULT([no])])
CFLAGS="$save_CFLAGS"
LIBS="$save_LIBS"
LDFLAGS="$save_LDFLAGS"
])
AC_ARG_WITH([libidn2],
[AS_HELP_STRING([--with-libidn2[=PATH]], [enable IDN support using GNU libidn2 [yes|no(default)|path]])],
[with_libidn2="$withval"], [with_libidn2="no"])
AS_CASE([$with_libidn2],
[yes], [PKG_CHECK_MODULES([LIBIDN2], [libidn2],
[AC_DEFINE([HAVE_LIBIDN2], [1], [Define if libidn2 was found])])],
[no], [],
[*], [save_CFLAGS="$CFLAGS"
save_CPPFLAGS="$CPPFLAGS"
save_LDFLAGS="$LDFLAGS"
save_LIBS="$LIBS"
LIBIDN2_CFLAGS="-I$with_libidn2/include"
LIBIDN2_LDFLAGS="-L$with_libidn2/lib"
CFLAGS="$LIBIDN2_CFLAGS $CFLAGS"
CPPFLAGS="$LIBIDN2_CFLAGS $CPPFLAGS"
LDFLAGS="$LIBIDN2_LDFLAGS $LDFLAGS"
AC_CHECK_HEADERS([idn2.h],
[],
[AC_MSG_ERROR([idn2.h not found])])
AC_SEARCH_LIBS([idn2_to_ascii_lz], [idn2],
[LIBIDN2_LIBS="$ac_cv_search_idn2_to_ascii_lz"
AC_DEFINE([HAVE_LIBIDN2], [1], [Define if libidn2 was found])],
[AC_MSG_ERROR([libidn2 requested, but not found])])
CFLAGS="$save_CFLAGS"
CPPFLAGS="$save_CPPFLAGS"
LDFLAGS="$save_LDFLAGS"
LIBS="$save_LIBS"])
AC_SUBST([LIBIDN2_CFLAGS])
AC_SUBST([LIBIDN2_LDFLAGS])
AC_SUBST([LIBIDN2_LIBS])
#
......@@ -5313,7 +5310,7 @@ report() {
test "X$JSONSTATS" = "X" || echo " JSON statistics (--with-libjson)"
test "X$ZLIB" = "X" || echo " HTTP zlib compression (--with-zlib)"
test "X$NZD_TOOLS" = "X" || echo " LMDB database to store configuration for 'addzone' zones (--with-lmdb)"
test "no" = "$use_libidn2" || echo " IDN support (--with-libidn2)"
test "no" = "$with_libidn2" || echo " IDN support (--with-libidn2)"
fi
if test "no" != "$use_pkcs11"; then
......@@ -5410,7 +5407,7 @@ report() {
test "X$JSONSTATS" = "X" && echo " JSON statistics (--with-libjson)"
test "X$ZLIB" = "X" && echo " HTTP zlib compression (--with-zlib)"
test "X$NZD_TOOLS" = "X" && echo " LMDB database to store configuration for 'addzone' zones (--with-lmdb)"
test "no" = "$use_libidn2" && echo " IDN support (--with-libidn2)"
test "no" = "$with_libidn2" && echo " IDN support (--with-libidn2)"
echo "-------------------------------------------------------------------------------"
echo "Configured paths:"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment