From 49d30890fb4b67aee70ac8bd536bb3730c9d88d1 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sat, 15 Jan 2005 12:56:23 +0000 Subject: Applied another patch from Joel Reed, fixed a segfault and changed the * tests/plugins/plugin.* tests/Makefile.am libxslt/extensions.c libxslt/Makefile.am configure.in: Applied another patch from Joel Reed, fixed a segfault and changed the configure code a bit to work in my debug environment. Daniel --- ChangeLog | 7 ++++ configure.in | 8 +++-- libxslt/Makefile.am | 16 +++++++++ libxslt/extensions.c | 89 +++++++++++++++++++++++++++++++++++------------ libxslt/xsltwin32config.h | 2 +- tests/Makefile.am | 13 +++++++ tests/plugins/plugin.out | 3 ++ tests/plugins/plugin.xml | 1 + tests/plugins/plugin.xsl | 12 +++++++ 9 files changed, 125 insertions(+), 26 deletions(-) create mode 100644 tests/plugins/plugin.out create mode 100644 tests/plugins/plugin.xml create mode 100644 tests/plugins/plugin.xsl diff --git a/ChangeLog b/ChangeLog index e40a500e..7ddae87c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Jan 15 13:54:28 CET 2005 Daniel Veillard + + * tests/plugins/plugin.* tests/Makefile.am libxslt/extensions.c + libxslt/Makefile.am configure.in: Applied another patch from + Joel Reed, fixed a segfault and changed the configure code + a bit to work in my debug environment. + Tue Jan 11 10:50:33 HKT 2005 William Brack * configure.in: added python2.4 to the list of accepted diff --git a/configure.in b/configure.in index a2183e30..33e36e2a 100644 --- a/configure.in +++ b/configure.in @@ -22,6 +22,7 @@ LIBXSLT_VERSION=$LIBXSLT_MAJOR_VERSION.$LIBXSLT_MINOR_VERSION.$LIBXSLT_MICRO_VER LIBXSLT_VERSION_INFO=`expr $LIBXSLT_MAJOR_VERSION + $LIBXSLT_MINOR_VERSION`:$LIBXSLT_MICRO_VERSION:$LIBXSLT_MINOR_VERSION LIBXSLT_VERSION_NUMBER=`expr $LIBXSLT_MAJOR_VERSION \* 10000 + $LIBXSLT_MINOR_VERSION \* 100 + $LIBXSLT_MICRO_VERSION` +LIBXSLT_MAJOR_MINOR_VERSION=$LIBXSLT_MAJOR_VERSION.$LIBXSLT_MINOR_VERSION if test -f CVS/Entries; then extra=`grep ChangeLog CVS/Entries | grep -v LIBXSLT | sed -e s\%/ChangeLog/1\.%% -e s\%/.*$%%` @@ -39,6 +40,7 @@ AC_SUBST(LIBXSLT_VERSION) AC_SUBST(LIBXSLT_VERSION_INFO) AC_SUBST(LIBXSLT_VERSION_NUMBER) AC_SUBST(LIBXSLT_VERSION_EXTRA) +AC_SUBST(LIBXSLT_MAJOR_MINOR_VERSION) dnl dnl libexslt is an extension library @@ -283,6 +285,7 @@ if [[ "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/XSLT" ]] || \ if test "$LOGNAME" = "veillard" then LIBXML_SRC="/u/veillard/XML" + EXTRA_LIBS="$EXTRA_LIBS -ldl" fi else STATIC_BINARIES= @@ -456,13 +459,14 @@ else fi AC_SUBST(WITH_MODULES) +AM_CONDITIONAL(WITH_MODULES, test "$WITH_MODULES" == "1") dnl dnl setup default module path dnl module_prefix=$prefix test "x$module_prefix" = xNONE && module_prefix=$ac_default_prefix -LIBXSLT_DEFAULT_PLUGINS_PATH="\"$module_prefix/lib/libxslt/$LIBXSLT_MAJOR_VERSION.$LIBXSLT_MINOR_VERSION/\"" +LIBXSLT_DEFAULT_PLUGINS_PATH="\"$module_prefix/lib/libxslt/$LIBXSLT_MAJOR_VERSION.$LIBXSLT_MINOR_VERSION\"" AC_SUBST(LIBXSLT_DEFAULT_PLUGINS_PATH) dnl @@ -518,7 +522,7 @@ AC_SUBST(EXSLT_LIBDIR) AC_SUBST(EXSLT_INCLUDEDIR) AC_SUBST(EXSLT_LIBS) -EXTRA_LIBS="$LIBXML_LIBS $M_LIBS" +EXTRA_LIBS="$EXTRA_LIBS $LIBXML_LIBS $M_LIBS" AC_SUBST(EXTRA_LIBS) AC_SUBST(M_LIBS) diff --git a/libxslt/Makefile.am b/libxslt/Makefile.am index c0dc1a3b..b42a22f5 100644 --- a/libxslt/Makefile.am +++ b/libxslt/Makefile.am @@ -57,5 +57,21 @@ man_MANS = libxslt.3 EXTRA_DIST = $(man_MANS) trio.h triodef.h + +# somewhat unconventional pkglibdir, but noinst_LTLIBRARIES +# never build DSOs (afaik). NOTE: must be defined outside the AM_CONDITIONAL +pkglibdir=$(shell pwd)/../tests/plugins + +if WITH_MODULES +pkglib_LTLIBRARIES = xmlsoft_org_xslt_testplugin.la + +xmlsoft_org_xslt_testplugin_la_CFLAGS = -DMODULE_COMPILE $(LIBXML_CFLAGS) $(LIBXSLT_CFLAGS) +xmlsoft_org_xslt_testplugin_la_SOURCES = testplugin.c +xmlsoft_org_xslt_testplugin_la_LDFLAGS = -module -avoid-version $(LIBXML_LIBS) $(LIBXSLT_LIBS) + +check-local: install-pkglibLTLIBRARIES + +endif + xsltproc: all @(cd ../xsltproc ; $(MAKE)) diff --git a/libxslt/extensions.c b/libxslt/extensions.c index e703c79b..f1e0cc47 100644 --- a/libxslt/extensions.c +++ b/libxslt/extensions.c @@ -298,8 +298,17 @@ typedef void (*exsltRegisterFunction) (void); * xsltExtModuleRegisterDynamic: * @URI: the function or element namespace URI * - * Looks up an extension module to dynamically load - * based on the namespace URI + * Dynamically loads an extension plugin when available. + * + * The plugin name is derived from the URI by removing the + * initial protocol designation, e.g. "http://", then converting + * the characters ".", "-", "/", and "\" into "_", the removing + * any trailing "/", then concatenating LIBXML_MODULE_EXTENSION. + * + * Plugins are loaded from the directory specified by the + * environment variable LIBXSLT_PLUGINS_PATH, or if NULL, + * by LIBXSLT_DEFAULT_PLUGINS_PATH() which is determined at + * compile time. * * Returns 0 if successful, -1 in case of error. */ @@ -310,10 +319,12 @@ xsltExtModuleRegisterDynamic(const xmlChar * URI) xmlModulePtr m; exsltRegisterFunction regfunc; + xmlChar *ext_name; xmlChar module_filename[PATH_MAX]; - const xmlChar *extNameBegin = NULL; - const xmlChar *extDirectory = NULL; - int i, rc, seen_before; + const xmlChar *ext_directory = NULL; + const xmlChar *protocol = NULL; + xmlChar *i, *regfunc_name; + int rc, seen_before; /* check for bad inputs */ if (URI == NULL) @@ -331,43 +342,75 @@ xsltExtModuleRegisterDynamic(const xmlChar * URI) return (-1); } - for (i = xmlStrlen(URI); i != 0 && extNameBegin == NULL; --i) { - if (URI[i - 1] == '/') - extNameBegin = URI + i; + /* transform extension namespace into a module name */ + protocol = xmlStrstr(URI, "://"); + if (protocol == NULL) { + ext_name = xmlStrdup(URI); + } else { + ext_name = xmlStrdup(protocol + 3); } - - if (extNameBegin == NULL || *extNameBegin == '\0') + if (ext_name == NULL) { return (-1); + } + + i = ext_name; + while ('\0' != *i) { + if (('/' == *i) || ('\\' == *i) || ('.' == *i) || ('-' == *i)) + *i = '_'; + i++; + } + + if (*(i - 1) == '_') + *i = '\0'; /* determine module directory */ - extDirectory = getenv(BAD_CAST "LIBXSLT_PLUGINS_PATH"); - if (NULL == extDirectory) - extDirectory = LIBXSLT_DEFAULT_PLUGINS_PATH(); - if (NULL == extDirectory) + ext_directory = getenv(BAD_CAST "LIBXSLT_PLUGINS_PATH"); + if (NULL == ext_directory) + ext_directory = LIBXSLT_DEFAULT_PLUGINS_PATH(); + if (NULL == ext_directory) return (-1); /* build the module filename, and confirm the module exists */ - xmlStrPrintf(module_filename, sizeof(module_filename), "%s%s%s", - extDirectory, extNameBegin, LIBXML_MODULE_EXTENSION); - if (1 != xmlCheckFilename(module_filename)) + xmlStrPrintf(module_filename, sizeof(module_filename), "%s/%s%s", + ext_directory, ext_name, LIBXML_MODULE_EXTENSION); + if (1 != xmlCheckFilename(module_filename)) { + xmlFree(ext_name); return (-1); + } + /* attempt to open the module */ m = xmlModuleOpen(module_filename, 0); - if (NULL == m) + if (NULL == m) { + xmlFree(ext_name); return (-1); + } - rc = xmlModuleSymbol(m, "exsltRegisterModule", (void **) ®func); + /* construct initialization func name */ + regfunc_name = xmlStrdup(ext_name); + regfunc_name = xmlStrcat(regfunc_name, "_init"); + + rc = xmlModuleSymbol(m, regfunc_name, (void **) ®func); if (0 == rc) { + /* call the module's init function */ (*regfunc) (); - } - /* register this module in our hash */ - xmlHashAddEntry(xsltModuleHash, URI, (void *) m); + /* register this module in our hash */ + xmlHashAddEntry(xsltModuleHash, URI, (void *) m); + } else { + /* if regfunc not found unload the module immediately */ + xmlModuleClose(m); + } + xmlFree(ext_name); + xmlFree(regfunc_name); return (NULL == regfunc) ? -1 : 0; } #else -#define xsltExtModuleRegisterDynamic(b) -1 +static int +xsltExtModuleRegisterDynamic(const xmlChar * ATTRIBUTE_UNUSED URI) +{ + return -1; +} #endif /************************************************************************ diff --git a/libxslt/xsltwin32config.h b/libxslt/xsltwin32config.h index 136dd560..417f6ec2 100644 --- a/libxslt/xsltwin32config.h +++ b/libxslt/xsltwin32config.h @@ -44,7 +44,7 @@ extern "C" { * * extra version information, used to show a CVS compilation */ -#define LIBXML_VERSION_EXTRA "-CVS978" +#define LIBXML_VERSION_EXTRA "-CVS980" /** * WITH_XSLT_DEBUG: diff --git a/tests/Makefile.am b/tests/Makefile.am index 8fd4e8b5..32e22e3c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -12,6 +12,7 @@ all: # and (if errors are expected) in *.err test tests: @(cur=`pwd` ; for dir in $(SUBDIRS) ; do cd $$dir ; $(MAKE) CHECKER='$(CHECKER)' tests ; cd $$cur ; done) + $(MAKE) plugin_tests valgrind: @echo '## Running the regression tests under Valgrind' @@ -23,3 +24,15 @@ full: tests docbook_tests docbook_tests: @(cd docbook ; $(MAKE) full) +if WITH_MODULES + +plugin_tests: + @echo Running the plugin tests... + @(cd plugins && LIBXSLT_PLUGINS_PATH=. $(top_builddir)/../xsltproc/xsltproc plugin.xsl plugin.xml) + +else + +plugin_tests: + @echo Skipping the plugin tests. + +endif diff --git a/tests/plugins/plugin.out b/tests/plugins/plugin.out new file mode 100644 index 00000000..c5235455 --- /dev/null +++ b/tests/plugins/plugin.out @@ -0,0 +1,3 @@ + + +SUCCESS diff --git a/tests/plugins/plugin.xml b/tests/plugins/plugin.xml new file mode 100644 index 00000000..69d62f2c --- /dev/null +++ b/tests/plugins/plugin.xml @@ -0,0 +1 @@ + diff --git a/tests/plugins/plugin.xsl b/tests/plugins/plugin.xsl new file mode 100644 index 00000000..0203d230 --- /dev/null +++ b/tests/plugins/plugin.xsl @@ -0,0 +1,12 @@ + + + + + + + + -- cgit v1.2.3