aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--Makefile.am4
-rw-r--r--configure.in8
-rw-r--r--result/XInclude/fallback.xml5
-rw-r--r--test/XInclude/docs/fallback.xml6
-rw-r--r--xinclude.c88
6 files changed, 98 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index ea6126ee..fd8b9f8a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Wed Aug 14 16:05:37 CEST 2002 Daniel Veillard <daniel@veillard.com>
+
+ * xinclude.c: quick but apparently working implementation of
+ xi:fallback, should close bug #89684
+ * Makefile.am test/XInclude/docs/fallback.xml
+ result/XInclude/fallback.xml: added a basic test for fallback,
+ and run with --nowarning to avoid a spurious warning
+ * configure.in: applied patch from Frederic Crozat for python
+ bindings on AMD 64bits machines.
+
Wed Aug 14 10:47:46 CEST 2002 Daniel Veillard <daniel@veillard.com>
* parser.c: xmlSAXUserParseMemory() really ought to fail if
diff --git a/Makefile.am b/Makefile.am
index 0d3162f1..f9d94262 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -399,10 +399,10 @@ XIncludetests : xmllint$(EXEEXT)
if [ ! -d $$i ] ; then \
if [ ! -f $(srcdir)/result/XInclude/$$name ] ; then \
echo New test file $$name ; \
- $(CHECKER) $(top_builddir)/xmllint --xinclude $$i > $(srcdir)/result/XInclude/$$name ; \
+ $(CHECKER) $(top_builddir)/xmllint --nowarning --xinclude $$i > $(srcdir)/result/XInclude/$$name ; \
else \
echo Testing $$name ; \
- $(CHECKER) $(top_builddir)/xmllint --xinclude $$i > result.$$name ; \
+ $(CHECKER) $(top_builddir)/xmllint --nowarning --xinclude $$i > result.$$name ; \
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\
diff $(srcdir)/result/XInclude/$$name result.$$name ; \
rm result.$$name ; \
diff --git a/configure.in b/configure.in
index 28bcada9..54986028 100644
--- a/configure.in
+++ b/configure.in
@@ -230,16 +230,20 @@ if test "$with_python" != "no" ; then
if test -r $prefix/include/python$PYTHON_VERSION/Python.h
then
PYTHON_INCLUDES='$(prefix)/include/python$(PYTHON_VERSION)'
- PYTHON_SITE_PACKAGES='$(prefix)/lib/python$(PYTHON_VERSION)/site-packages'
+ PYTHON_SITE_PACKAGES='$(libdir)/python$(PYTHON_VERSION)/site-packages'
else
if test -r /usr/include/python$PYTHON_VERSION/Python.h
then
PYTHON_INCLUDES=/usr/include/python$PYTHON_VERSION
- PYTHON_SITE_PACKAGES='$(prefix)/lib/python$(PYTHON_VERSION)/site-packages'
+ PYTHON_SITE_PACKAGES='$(libdir)/python$(PYTHON_VERSION)/site-packages'
else
echo could not find python$PYTHON_VERSION/Python.h
fi
fi
+ if ! test -d "$PYTHON_SITE_PACKAGES"
+ then
+ PYTHON_SITE_PACKAGES=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib()"`
+ fi
fi
fi
fi
diff --git a/result/XInclude/fallback.xml b/result/XInclude/fallback.xml
new file mode 100644
index 00000000..d7eed528
--- /dev/null
+++ b/result/XInclude/fallback.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<x xmlns:xinclude="http://www.w3.org/2001/XInclude">
+ <!-- Simple test of a fallback on unavailble URI -->
+ <warning>Inclusion failed</warning>
+</x>
diff --git a/test/XInclude/docs/fallback.xml b/test/XInclude/docs/fallback.xml
new file mode 100644
index 00000000..e80222e4
--- /dev/null
+++ b/test/XInclude/docs/fallback.xml
@@ -0,0 +1,6 @@
+<x xmlns:xinclude="http://www.w3.org/2001/XInclude">
+ <!-- Simple test of a fallback on unavailble URI -->
+ <xinclude:include href="something.xml">
+ <xinclude:fallback><warning>Inclusion failed</warning></xinclude:fallback>
+ </xinclude:include>
+</x>
diff --git a/xinclude.c b/xinclude.c
index 1e96fe9f..63cb5e9b 100644
--- a/xinclude.c
+++ b/xinclude.c
@@ -710,8 +710,10 @@ xmlXIncludeCopyXPointer(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
* @nr: the xinclude node number
*
* Load the document, and store the result in the XInclude context
+ *
+ * Returns 0 in case of success, -1 in case of failure
*/
-static void
+static int
xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
xmlDocPtr doc;
xmlURIPtr uri;
@@ -725,7 +727,7 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
if (uri == NULL) {
xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value URI %s\n", url);
- return;
+ return(-1);
}
if (uri->fragment != NULL) {
fragment = (xmlChar *) uri->fragment;
@@ -738,7 +740,7 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
"XInclude: invalid value URI %s\n", url);
if (fragment != NULL)
xmlFree(fragment);
- return;
+ return(-1);
}
/*
@@ -764,12 +766,10 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
*/
doc = xmlParseFile((const char *)URL);
if (doc == NULL) {
- xmlGenericError(xmlGenericErrorContext,
- "XInclude: could not load %s\n", URL);
xmlFree(URL);
if (fragment != NULL)
xmlFree(fragment);
- return;
+ return(-1);
}
xmlXIncludeAddDoc(ctxt, doc, URL);
@@ -806,7 +806,7 @@ loaded:
"XInclude: could create XPointer context\n");
xmlFree(URL);
xmlFree(fragment);
- return;
+ return(-1);
}
xptr = xmlXPtrEval(fragment, xptrctxt);
if (xptr == NULL) {
@@ -816,7 +816,7 @@ loaded:
xmlXPathFreeContext(xptrctxt);
xmlFree(URL);
xmlFree(fragment);
- return;
+ return(-1);
}
switch (xptr->type) {
case XPATH_UNDEFINED:
@@ -832,7 +832,7 @@ loaded:
xmlXPathFreeContext(xptrctxt);
xmlFree(URL);
xmlFree(fragment);
- return;
+ return(-1);
case XPATH_NODESET:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
@@ -893,6 +893,7 @@ loaded:
xmlFree(fragment);
}
xmlFree(URL);
+ return(0);
}
/**
@@ -902,8 +903,10 @@ loaded:
* @nr: the xinclude node number
*
* Load the content, and store the result in the XInclude context
+ *
+ * Returns 0 in case of success, -1 in case of failure
*/
-static void
+static int
xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
xmlParserInputBufferPtr buf;
xmlNodePtr node;
@@ -917,21 +920,21 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
if (uri == NULL) {
xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value URI %s\n", url);
- return;
+ return(-1);
}
if (uri->fragment != NULL) {
xmlGenericError(xmlGenericErrorContext,
"XInclude: fragment identifier forbidden for text: %s\n",
uri->fragment);
xmlFreeURI(uri);
- return;
+ return(-1);
}
URL = xmlSaveUri(uri);
xmlFreeURI(uri);
if (URL == NULL) {
xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value URI %s\n", url);
- return;
+ return(-1);
}
/*
@@ -942,7 +945,7 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
xmlGenericError(xmlGenericErrorContext,
"XInclude: text serialization of document not available\n");
xmlFree(URL);
- return;
+ return(-1);
}
/*
@@ -960,10 +963,8 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
*/
buf = xmlParserInputBufferCreateFilename((const char *)URL, 0);
if (buf == NULL) {
- xmlGenericError(xmlGenericErrorContext,
- "XInclude: could not load %s\n", URL);
xmlFree(URL);
- return;
+ return(-1);
}
node = xmlNewText(NULL);
@@ -998,6 +999,27 @@ loaded:
*/
ctxt->repTab[nr] = node;
xmlFree(URL);
+ return(0);
+}
+
+/**
+ * xmlXIncludeLoadFallback:
+ * @ctxt: the XInclude context
+ * @fallback: the fallback node
+ * @nr: the xinclude node number
+ *
+ * Load the content of teh fallback node, and store the result
+ * in the XInclude context
+ *
+ * Returns 0 in case of success, -1 in case of failure
+ */
+static int
+xmlXIncludeLoadFallback(xmlXIncludeCtxtPtr ctxt, xmlNodePtr fallback, int nr) {
+ if ((fallback == NULL) || (ctxt == NULL))
+ return(-1);
+
+ ctxt->repTab[nr] = xmlCopyNode(fallback->children, 1);
+ return(0);
}
/************************************************************************
@@ -1039,6 +1061,7 @@ xmlXIncludeLoadNode(xmlXIncludeCtxtPtr ctxt, int nr) {
xmlChar *base;
xmlChar *URI;
int xml = 1; /* default Issue 64 */
+ int ret;
if (ctxt == NULL)
return(-1);
@@ -1126,10 +1149,37 @@ xmlXIncludeLoadNode(xmlXIncludeCtxtPtr ctxt, int nr) {
* Cleanup
*/
if (xml) {
- xmlXIncludeLoadDoc(ctxt, URI, nr);
+ ret = xmlXIncludeLoadDoc(ctxt, URI, nr);
/* xmlXIncludeGetFragment(ctxt, cur, URI); */
} else {
- xmlXIncludeLoadTxt(ctxt, URI, nr);
+ ret = xmlXIncludeLoadTxt(ctxt, URI, nr);
+ }
+ if (ret < 0) {
+ xmlNodePtr children;
+
+ /*
+ * Time to try a fallback if availble
+ */
+#ifdef DEBUG_XINCLUDE
+ xmlGenericError(xmlGenericErrorContext, "error looking for fallback\n");
+#endif
+ children = cur->children;
+ while (children != NULL) {
+ if ((children->type == XML_ELEMENT_NODE) &&
+ (children->ns != NULL) &&
+ (xmlStrEqual(children->name, XINCLUDE_FALLBACK)) &&
+ (xmlStrEqual(children->ns->href, XINCLUDE_NS))) {
+ ret = xmlXIncludeLoadFallback(ctxt, children, nr);
+ if (ret == 0)
+ break;
+ }
+ children = children->next;
+ }
+ }
+ if (ret < 0) {
+ xmlGenericError(xmlGenericErrorContext,
+ "XInclude: could not load %s, and no fallback was found\n",
+ URI);
}
/*