started with libidn2 integration

This commit is contained in:
Tim Rühsen 2014-06-27 17:13:30 +02:00
parent fc8f72098b
commit 74f715bd9c
4 changed files with 63 additions and 32 deletions

View File

@ -1,7 +1,7 @@
AC_INIT([libpsl], [0.4.0], [tim.ruehsen@gmx.de], [libpsl], [http://github.com/rockdaboot/libpsl]) AC_INIT([libpsl], [0.4.0], [tim.ruehsen@gmx.de], [libpsl], [http://github.com/rockdaboot/libpsl])
AC_PREREQ([2.59]) AC_PREREQ([2.59])
AM_INIT_AUTOMAKE([1.10 -Wall no-define]) AM_INIT_AUTOMAKE([1.10 -Wall no-define foreign])
# Generate two configuration headers; one for building the library itself with # Generate two configuration headers; one for building the library itself with
# an autogenerated template, and a second one that will be installed alongside # an autogenerated template, and a second one that will be installed alongside
@ -93,25 +93,50 @@ AC_ARG_WITH(libicu,
# Check for enable/disable builtin PSL data # Check for enable/disable builtin PSL data
AC_ARG_ENABLE(builtin, AC_ARG_ENABLE(builtin,
AS_HELP_STRING([--disable-builtin], [do not compile PSL data into library]),
[ [
enable_builtin=no --enable-builtin[=IDNA library]
Specify the IDNA library used for built-in data generation:
libicu [[default]]: IDNA2008 UTS#46 library
libidn2: IDNA2008 library also needs libunistring
--disable-builtin Do not generate built-in data
], [ ], [
enable_builtin=yes if test "$enableval" = "libicu" -o "$enableval" = "yes"; then
if test "$HAVE_LIBICU" != "yes"; then
AC_MSG_ERROR(You requested libicu but it is not installed.)
fi
enable_builtin=libicu
AC_DEFINE([BUILTIN_GENERATOR_LIBICU], [1], [generate PSL data using libicu])
elif test "$enableval" = "libidn2"; then
if test "$HAVE_LIBIDN2" != "yes"; then
AC_MSG_ERROR(You requested libidn2 but it is not installed.)
fi
enable_builtin=libidn2
AC_DEFINE([BUILTIN_GENERATOR_LIBIDN2], [1], [generate PSL data using libidn2])
elif test "$enableval" = "no"; then
enable_builtin=no
else
AC_MSG_ERROR(Unknown value $enableval)
fi
], [
# this is the default if neither --enable-builtin nor --disable-built were specified
enable_builtin=libicu
if test "$HAVE_LIBIDN2" != "yes"; then
AC_MSG_ERROR(You requested libidn2 but it is not installed.)
fi
AC_DEFINE([BUILTIN_GENERATOR_LIBICU], [1], [generate PSL data using libicu])
AC_DEFINE([WITH_BUILTIN], [1], [compile PSL data into library]) AC_DEFINE([WITH_BUILTIN], [1], [compile PSL data into library])
AS_IF([test $HAVE_LIBICU != yes],
[
# Check for idn2 fallback to generate punycode
AC_CHECK_PROG(HAVE_IDN2, idn2, yes, AC_MSG_ERROR(Cannot find required tool 'idn2' as fallback.))
]) ])
])
AM_CONDITIONAL([WITH_BUILTIN], [test $enable_builtin = yes]) AM_CONDITIONAL([BUILTIN_GENERATOR_LIBICU], test "x$enable_builtin" = "xlibicu")
AM_CONDITIONAL([BUILTIN_GENERATOR_LIBIDN2], test "x$enable_builtin" = "xlibidn2")
AM_CONDITIONAL([WITH_BUILTIN], test $enable_builtin = yes)
# Check for valgrind # Check for valgrind
ac_enable_valgrind=no ac_enable_valgrind=no
AC_ARG_ENABLE(valgrind-tests, AC_ARG_ENABLE(valgrind-tests,
AS_HELP_STRING([--enable-valgrind-tests], [enable using Valgrind for tests]), AS_HELP_STRING([--enable-valgrind-tests], [enable using Valgrind for tests]),
[ac_enable_valgrind=$enableval], [ac_enable_valgrind=no]) [ac_enable_valgrind=$enableval],
[ac_enable_valgrind=no])
if test "${ac_enable_valgrind}" = "yes" ; then if test "${ac_enable_valgrind}" = "yes" ; then
AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no) AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no)

View File

@ -13,8 +13,15 @@ libpsl_la_LDFLAGS = -version-info $(LIBPSL_SO_VERSION)
noinst_PROGRAMS = psl2c noinst_PROGRAMS = psl2c
psl2c_SOURCES = psl2c.c psl2c_SOURCES = psl2c.c
psl2c_CPPFLAGS = -I$(top_srcdir)/include -D _GNU_SOURCE $(LIBICU_CFLAGS) psl2c_CPPFLAGS = -I$(top_srcdir)/include -D _GNU_SOURCE
psl2c_LDADD = $(LIBICU_LIBS) if BUILTIN_GENERATOR_LIBICU
psl2c_CPPFLAGS += $(LIBICU_CFLAGS)
psl2c_LDADD = $(LIBICU_LIBS)
endif
if BUILTIN_GENERATOR_LIBIDN2
psl2c_CPPFLAGS += $(LIBIDN2_CFLAGS)
psl2c_LDADD = $(LIBIDN2_LIBS)
endif
# Build rule for suffix.c # Build rule for suffix.c
# PSL_FILE can be set by ./configure --with-psl-file=[PATH] # PSL_FILE can be set by ./configure --with-psl-file=[PATH]

View File

@ -39,7 +39,7 @@
#include <ctype.h> #include <ctype.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifdef WITH_BUILTIN #if defined(BUILTIN_GENERATOR_LIBICU) || defined(BUILTIN_GENERATOR_LIBIDN2)
#include <libpsl.h> #include <libpsl.h>
@ -52,7 +52,7 @@ static void _print_psl_entries(FILE *fpout, const _psl_vector_t *v, const char *
{ {
int it; int it;
#ifdef WITH_LIBICU #ifdef BUILTIN_GENERATOR_LIBICU
do { do {
UVersionInfo version_info; UVersionInfo version_info;
char version[U_MAX_VERSION_STRING_LENGTH]; char version[U_MAX_VERSION_STRING_LENGTH];
@ -61,9 +61,11 @@ static void _print_psl_entries(FILE *fpout, const _psl_vector_t *v, const char *
u_versionToString(version_info, version); u_versionToString(version_info, version);
fprintf(fpout, "/* automatically generated by psl2c (punycode generated with libicu/%s) */\n", version); fprintf(fpout, "/* automatically generated by psl2c (punycode generated with libicu/%s) */\n", version);
} while (0); } while (0);
#elif BUILTIN_GENERATOR_LIBIDN2
fprintf(fpout, "/* automatically generated by psl2c (punycode generated with libidn2/%s) */\n", idn2_check_version(NULL));
#else #else
fprintf(fpout, "/* automatically generated by psl2c (without punycode support) */\n"); fprintf(fpout, "/* automatically generated by psl2c (without punycode support) */\n");
#endif /* WITH_LIBICU */ #endif
fprintf(fpout, "static _psl_entry_t %s[] = {\n", varname); fprintf(fpout, "static _psl_entry_t %s[] = {\n", varname);
@ -77,7 +79,7 @@ static void _print_psl_entries(FILE *fpout, const _psl_vector_t *v, const char *
fprintf(fpout, "};\n"); fprintf(fpout, "};\n");
} }
#ifndef WITH_LIBICU #if !defined(WITH_LIBICU) && !defined(WITH_IDN2)
static int _str_needs_encoding(const char *s) static int _str_needs_encoding(const char *s)
{ {
while (*s > 0) s++; while (*s > 0) s++;
@ -117,14 +119,14 @@ static void _add_punycode_if_needed(_psl_vector_t *v)
_vector_sort(v); _vector_sort(v);
} }
#endif /* ! WITH_LIBICU */ #endif /* !defined(WITH_LIBICU) && !defined(WITH_IDN2) */
#endif /* WITH_BUILTIN */ #endif /* defined(BUILTIN_GENERATOR_LIBICU) || defined(BUILTIN_GENERATOR_LIBIDN2) */
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
FILE *fpout; FILE *fpout;
#ifdef WITH_BUILTIN #if defined(BUILTIN_GENERATOR_LIBICU) || defined(BUILTIN_GENERATOR_LIBIDN2)
psl_ctx_t *psl; psl_ctx_t *psl;
#endif #endif
int ret = 0; int ret = 0;
@ -136,7 +138,7 @@ int main(int argc, const char **argv)
return 1; return 1;
} }
#ifdef WITH_BUILTIN #if defined(BUILTIN_GENERATOR_LIBICU) || defined(BUILTIN_GENERATOR_LIBIDN2)
if (!(psl = psl_load_file(argv[1]))) if (!(psl = psl_load_file(argv[1])))
return 2; return 2;
@ -146,9 +148,8 @@ int main(int argc, const char **argv)
size_t cmdsize = 16 + strlen(argv[1]); size_t cmdsize = 16 + strlen(argv[1]);
char *cmd = alloca(cmdsize), checksum[64] = ""; char *cmd = alloca(cmdsize), checksum[64] = "";
#ifndef WITH_LIBICU #if !defined(WITH_LIBICU) && !defined(WITH_IDN2)
/* If libicu is not configured, we still need to have punycode in our built-in data. */ /* library is compiled without ability to generate punycode, so let's generate punycode at least for the builtin data */
/* Else the test suite fails. */
_add_punycode_if_needed(psl->suffixes); _add_punycode_if_needed(psl->suffixes);
_add_punycode_if_needed(psl->suffix_exceptions); _add_punycode_if_needed(psl->suffix_exceptions);
#endif #endif
@ -193,7 +194,6 @@ int main(int argc, const char **argv)
fprintf(stderr, "Failed to write open '%s'\n", argv[2]); fprintf(stderr, "Failed to write open '%s'\n", argv[2]);
ret = 3; ret = 3;
} }
#endif /* WITH_BUILTIN */ #endif /* WITH_BUILTIN */
return ret; return ret;

View File

@ -2,18 +2,17 @@ DEFS = @DEFS@ -DDATADIR=\"$(top_srcdir)/data\" -DSRCDIR=\"$(srcdir)\" -DPSL_FILE
AM_CPPFLAGS = -I$(top_srcdir)/include AM_CPPFLAGS = -I$(top_srcdir)/include
LDADD = ../src/libpsl.la LDADD = ../src/libpsl.la
if WITH_BUILTIN
PSL_TESTS = test-is-public test-is-public-builtin test-is-public-all test-registrable-domain \
test-is-cookie-domain-acceptable
else
# ./configure'd with '--disable-builtin' # ./configure'd with '--disable-builtin'
# Do not call test-is-public-builtin here: it does not make sense. # Do not call test-is-public-builtin here: it does not make sense.
# Do not call test-registrable-domain here: it would fail due to missing punycode entries in PSL file. # Do not call test-registrable-domain here: it would fail due to missing punycode entries in PSL file.
PSL_TESTS = test-is-public test-is-public-all test-is-cookie-domain-acceptable PSL_TESTS = test-is-public test-is-public-all test-is-cookie-domain-acceptable
if BUILTIN_GENERATOR_LIBICU
PSL_TESTS += test-is-public-builtin test-registrable-domain
endif
if BUILTIN_GENERATOR_LIBIDN2
PSL_TESTS += test-is-public-builtin test-registrable-domain
endif endif
check_PROGRAMS = $(PSL_TESTS) check_PROGRAMS = $(PSL_TESTS)