From 5b39b63698885fecf982bfd575196ccd1aafa62a Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 24 May 2019 10:04:29 +0200 Subject: [PATCH] Added --with-libxml2 to configure --- CHANGELOG.md | 8 ++++---- apps/backend/backend_main.c | 4 ++-- apps/cli/cli_main.c | 8 ++++---- configure | 31 ++++++++++++++----------------- configure.ac | 14 ++++++++------ include/clixon_config.h.in | 3 --- test/test_cli.sh | 4 +++- util/clixon_util_regexp.c | 2 +- 8 files changed, 36 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26eec9d4..4ba02309 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -141,14 +141,14 @@ ### Minor changes -* Regexp improvements - * Added libxml2 XSD regexp mode as alternative to posix translation +* Regexp improvements: Added libxml2 XSD regexp mode as alternative to posix translation + * Configure with: `./configure --with-libxml2` + * Set `CLICON_YANG_REGEXP` to libxml2 (default is posix) * Better compliance with XSD regexps (when transforming to Posix regexps) * Added `\p{L}` and `\p{N}` * Added escaping of `$` - * Added `CLICON_YANG_REGEXP`option with possible values libxml2 and posix * Added clixon_util_regexp utility function - * Added regexp test [test/test_pattern.sh] + * Added regexp test [test/test_pattern.sh] for both posix and libxml2 * Yang state get improvements * Integrated state and config into same tree on retrieval, not separate trees * Added cli functions `cli_show_config_state()` and `cli_show_auto_state()` for showing combined config and state info. diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index e77773fc..85ef14c3 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -497,9 +497,9 @@ main(int argc, if (help) usage(h, argv[0]); -#ifndef HAVE_LIBXML_XMLREGEXP_H +#ifndef HAVE_LIBXML2 if (strcmp(clicon_yang_regexp(h), "libxml2")==0){ - clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXM_XMLREGEXP_H not set (Either change CLICON_YANG_REGEXP to posix, or configure with libxml2?))"); + clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))"); goto done; } #endif diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c index 7401f74a..36b0d255 100644 --- a/apps/cli/cli_main.c +++ b/apps/cli/cli_main.c @@ -447,11 +447,11 @@ main(int argc, char **argv) usage(h, argv[0]); if (strcmp(clicon_yang_regexp(h), "libxml2")==0){ -#ifdef HAVE_LIBXML_XMLREGEXP_H - /* Enable XSD libxml2 */ - cligen_regex_set(cli_cligen(h), 1); +#ifdef HAVE_LIBXML2 + /* Enable XSD libxml2 regex engine */ + cligen_regex_xsd_set(cli_cligen(h), 1); #else - clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML_XMLREGEXP_H not set (Either change CLICON_YANG_REGEXP to posix, or configure with libxml2))"); + clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))"); goto done; #endif } diff --git a/configure b/configure index bd23e4cb..9b7dd0c1 100755 --- a/configure +++ b/configure @@ -717,6 +717,7 @@ enable_publish with_restconf with_wwwuser with_configfile +with_libxml2 ' ac_precious_vars='build_alias host_alias @@ -1365,6 +1366,7 @@ Optional Packages: --without-restconf disable support for restconf --with-wwwuser= Set www user different from www-data --with-configfile=FILE set default path to config file + --with-libxml2 use gnome/libxml2 regex engine Some influential environment variables: CC C compiler command @@ -4417,8 +4419,18 @@ _ACEOF fi -# This is for libxml2 code which we can use for XSD regexp -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for xmlRegexpCompile in -lxml2" >&5 +# This is for libxml2 XSD regex engine +# Note this only enables the compiling of the code. In order to actually +# use it you need to set Clixon config option CLICON_YANG_REGEXP to libxml2 + +# Check whether --with-libxml2 was given. +if test "${with_libxml2+set}" = set; then : + withval=$with_libxml2; +fi + +if test "${with_libxml2}"; then + # Find libxml2 lib + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for xmlRegexpCompile in -lxml2" >&5 $as_echo_n "checking for xmlRegexpCompile in -lxml2... " >&6; } if ${ac_cv_lib_xml2_xmlRegexpCompile+:} false; then : $as_echo_n "(cached) " >&6 @@ -4463,23 +4475,8 @@ _ACEOF fi - -# Libxml2 may hide its include files under /usr/include/libxml2/libxml -# You may need to prepend CFLAGS="-I/usr/include/libxml2 to configure -for ac_header in libxml/xmlregexp.h -do : - ac_fn_c_check_header_compile "$LINENO" "libxml/xmlregexp.h" "ac_cv_header_libxml_xmlregexp_h" "#include \"libxml/xmlversion.h\" -" -if test "x$ac_cv_header_libxml_xmlregexp_h" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBXML_XMLREGEXP_H 1 -_ACEOF - fi -done - - # for ac_func in inet_aton sigaction sigvec strlcpy strsep strndup alphasort versionsort do : diff --git a/configure.ac b/configure.ac index bd811155..3c9f8cc9 100644 --- a/configure.ac +++ b/configure.ac @@ -220,12 +220,14 @@ AC_CHECK_LIB(socket, socket) AC_CHECK_LIB(nsl, xdr_char) AC_CHECK_LIB(dl, dlopen) -# This is for libxml2 code which we can use for XSD regexp -AC_CHECK_LIB(xml2, xmlRegexpCompile) - -# Libxml2 may hide its include files under /usr/include/libxml2/libxml -# You may need to prepend CFLAGS="-I/usr/include/libxml2 to configure -AC_CHECK_HEADERS([libxml/xmlregexp.h], [], [], [#include "libxml/xmlversion.h"]) +# This is for libxml2 XSD regex engine +# Note this only enables the compiling of the code. In order to actually +# use it you need to set Clixon config option CLICON_YANG_REGEXP to libxml2 +AC_ARG_WITH(libxml2, [ --with-libxml2 use gnome/libxml2 regex engine ] ) +if test "${with_libxml2}"; then + # Find libxml2 lib + AC_CHECK_LIB(xml2, xmlRegexpCompile) +fi # AC_CHECK_FUNCS(inet_aton sigaction sigvec strlcpy strsep strndup alphasort versionsort) diff --git a/include/clixon_config.h.in b/include/clixon_config.h.in index 66ef2062..7bd27d76 100644 --- a/include/clixon_config.h.in +++ b/include/clixon_config.h.in @@ -60,9 +60,6 @@ /* Define to 1 if you have the `xml2' library (-lxml2). */ #undef HAVE_LIBXML2 -/* Define to 1 if you have the header file. */ -#undef HAVE_LIBXML_XMLREGEXP_H - /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_IF_VLAN_H diff --git a/test/test_cli.sh b/test/test_cli.sh index 90ddb28e..66f98394 100755 --- a/test/test_cli.sh +++ b/test/test_cli.sh @@ -76,9 +76,11 @@ expectfn "$clixon_cli -1 -f $cfg set interfaces interface fddi&< type ianaift:et new "cli failed validate" expectfn "$clixon_cli -1 -f $cfg -l o validate" 255 "Validate failed. Edit and try again or discard changes: application missing-element Mandatory variable type" -new "cli configure more" +new "cli configure ip addr" expectfn "$clixon_cli -1 -f $cfg set interfaces interface eth/0/0 ipv4 address 1.2.3.4 prefix-length 24" 0 "^$" +new "cli configure ip descr" expectfn "$clixon_cli -1 -f $cfg set interfaces interface eth/0/0 description mydesc" 0 "^$" +new "cli configure ip type" expectfn "$clixon_cli -1 -f $cfg set interfaces interface eth/0/0 type ex:eth" 0 "^$" new "cli show xpath description" diff --git a/util/clixon_util_regexp.c b/util/clixon_util_regexp.c index 7cebe239..1687a32d 100644 --- a/util/clixon_util_regexp.c +++ b/util/clixon_util_regexp.c @@ -99,7 +99,7 @@ regex_posix(char *regexp, int retval = -1; char *posix = NULL; char pattern[1024]; - int status; + int status = 0; regex_t re; char errbuf[1024]; int len0;