Various patches and bug fixes, and XInclude progresses:

- nanohttp.[ch]: applied Wayne Davison patches to access
  the WWW-Authorization header.
- parser.c: Closed Bug#30847: Problems when switching encoding
  in short files by applying Simon Berg's patch.
- valid.c: fixed a validation problem
- hash.c parser.h parserInternals.h testHTML.c testSAX.c tree.h
  xmlerror.h xmlmemory.h xmlversion.h.in: applied a DLL patch from
  Wayne Davison
- xpointer.[ch]: added first version of xmlXPtrBuildNodeList()
  need to be extended to non full nodes selections.
- xinclude.c: starts to work decently
Daniel
This commit is contained in:
Daniel Veillard 2000-11-07 14:21:01 +00:00
parent 9e8bfae59a
commit c2def84b48
23 changed files with 247 additions and 54 deletions

View File

@ -1,3 +1,17 @@
Tue Nov 7 15:11:34 CET 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* nanohttp.[ch]: applied Wayne Davison patches to access
the WWW-Authorization header.
* parser.c: Closed Bug#30847: Problems when switching encoding
in short files by applying Simon Berg's patch.
* valid.c: fixed a validation problem
* hash.c parser.h parserInternals.h testHTML.c testSAX.c tree.h
xmlerror.h xmlmemory.h xmlversion.h.in: applied a DLL patch from
Wayne Davison
* xpointer.[ch]: added first version of xmlXPtrBuildNodeList()
need to be extended to non full nodes selections.
* xinclude.c: starts to work decently
Mon Nov 6 17:22:46 CET 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* tree.[ch] xinclude.[ch] xmllint.c configure.in valid.c

6
hash.c
View File

@ -17,6 +17,12 @@
* Author: bjorn.reese@systematic.dk
*/
#ifdef WIN32
#include "win32config.h"
#else
#include "config.h"
#endif
#include <string.h>
#include <libxml/hash.h>
#include <libxml/xmlmemory.h>

View File

@ -29,6 +29,7 @@ void * xmlNanoHTTPMethod (const char *URL,
void * xmlNanoHTTPOpen (const char *URL,
char **contentType);
int xmlNanoHTTPReturnCode (void *ctx);
const char * xmlNanoHTTPAuthHeader(void *ctx);
int xmlNanoHTTPRead (void *ctx,
void *dest,
int len);

View File

@ -294,19 +294,19 @@ typedef xmlParserInputPtr (*xmlExternalEntityLoader)(const char *URL,
* Global variables: just the default SAX interface tables and XML
* version infos.
*/
extern const char *xmlParserVersion;
LIBXML_DLL_IMPORT extern const char *xmlParserVersion;
extern xmlSAXLocator xmlDefaultSAXLocator;
extern xmlSAXHandler xmlDefaultSAXHandler;
extern xmlSAXHandler htmlDefaultSAXHandler;
extern xmlSAXHandler sgmlDefaultSAXHandler;
LIBXML_DLL_IMPORT extern xmlSAXLocator xmlDefaultSAXLocator;
LIBXML_DLL_IMPORT extern xmlSAXHandler xmlDefaultSAXHandler;
LIBXML_DLL_IMPORT extern xmlSAXHandler htmlDefaultSAXHandler;
LIBXML_DLL_IMPORT extern xmlSAXHandler sgmlDefaultSAXHandler;
/**
* entity substitution default behaviour.
*/
extern int xmlSubstituteEntitiesDefaultValue;
extern int xmlGetWarningsDefaultValue;
LIBXML_DLL_IMPORT extern int xmlSubstituteEntitiesDefaultValue;
LIBXML_DLL_IMPORT extern int xmlGetWarningsDefaultValue;
/**

View File

@ -101,13 +101,13 @@ extern "C" {
* Global vaiables affecting the default parser behaviour.
*/
extern int xmlParserDebugEntities;
extern int xmlGetWarningsDefaultValue;
extern int xmlParserDebugEntities;
extern int xmlSubstituteEntitiesDefaultValue;
extern int xmlDoValidityCheckingDefaultValue;
extern int xmlPedanticParserDefaultValue;
extern int xmlKeepBlanksDefaultValue;
LIBXML_DLL_IMPORT extern int xmlParserDebugEntities;
LIBXML_DLL_IMPORT extern int xmlGetWarningsDefaultValue;
LIBXML_DLL_IMPORT extern int xmlParserDebugEntities;
LIBXML_DLL_IMPORT extern int xmlSubstituteEntitiesDefaultValue;
LIBXML_DLL_IMPORT extern int xmlDoValidityCheckingDefaultValue;
LIBXML_DLL_IMPORT extern int xmlPedanticParserDefaultValue;
LIBXML_DLL_IMPORT extern int xmlKeepBlanksDefaultValue;
/*
* Function to finish teh work of the macros where needed

View File

@ -374,11 +374,11 @@ struct _xmlDoc {
/*
* Variables.
*/
extern xmlNsPtr baseDTD;
extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
extern xmlBufferAllocationScheme xmlBufferAllocScheme; /* alloc scheme to use */
extern int xmlSaveNoEmptyTags; /* save empty tags as <empty></empty> */
LIBXML_DLL_IMPORT extern xmlNsPtr baseDTD;
LIBXML_DLL_IMPORT extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
LIBXML_DLL_IMPORT extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
LIBXML_DLL_IMPORT extern xmlBufferAllocationScheme xmlBufferAllocScheme; /* alloc scheme to use */
LIBXML_DLL_IMPORT extern int xmlSaveNoEmptyTags; /* save empty tags as <empty></empty> */
/*
* Handling Buffers.
@ -533,6 +533,10 @@ void xmlTextConcat (xmlNodePtr node,
int len);
void xmlFreeNodeList (xmlNodePtr cur);
void xmlFreeNode (xmlNodePtr cur);
void xmlSetTreeDoc (xmlNodePtr tree,
xmlDocPtr doc);
void xmlSetListDoc (xmlNodePtr list,
xmlDocPtr doc);
/*
* Namespaces

View File

@ -146,8 +146,8 @@ typedef void (*xmlGenericErrorFunc) (void *ctx, const char *msg, ...);
* when when there is an error and no parsing or validity context available
*/
extern xmlGenericErrorFunc xmlGenericError;
extern void *xmlGenericErrorContext;
LIBXML_DLL_IMPORT extern xmlGenericErrorFunc xmlGenericError;
LIBXML_DLL_IMPORT extern void *xmlGenericErrorContext;
/*
* Use the following function to reset the two previous global variables.

View File

@ -111,6 +111,14 @@ extern void xmlCheckVersion(int version);
#define DEBUG_MEMORY_LOCATION
#endif
#ifndef LIBXML_DLL_IMPORT
#if defined(WIN32) && !defined(STATIC)
#define LIBXML_DLL_IMPORT __declspec(dllimport)
#else
#define LIBXML_DLL_IMPORT
#endif
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -48,6 +48,7 @@ xmlXPathObjectPtr xmlXPtrEval (const xmlChar *str,
xmlXPathContextPtr ctx);
void xmlXPtrRangeToFunction (xmlXPathParserContextPtr ctxt,
int nargs);
xmlNodePtr xmlXPtrBuildNodeList (xmlXPathObjectPtr obj);
#ifdef __cplusplus
}

View File

@ -106,6 +106,7 @@ typedef struct xmlNanoHTTPCtxt {
int returnValue; /* the protocol return value */
char *contentType; /* the MIME type for the input */
char *location; /* the new URL in case of redirect */
char *authHeader; /* contents of {WWW,Proxy}-Authenticate header */
} xmlNanoHTTPCtxt, *xmlNanoHTTPCtxtPtr;
static int initialized = 0;
@ -390,6 +391,7 @@ xmlNanoHTTPFreeCtxt(xmlNanoHTTPCtxtPtr ctxt) {
if (ctxt->in != NULL) xmlFree(ctxt->in);
if (ctxt->contentType != NULL) xmlFree(ctxt->contentType);
if (ctxt->location != NULL) xmlFree(ctxt->location);
if (ctxt->authHeader != NULL) xmlFree(ctxt->authHeader);
ctxt->state = XML_NANO_HTTP_NONE;
if (ctxt->fd >= 0) closesocket(ctxt->fd);
ctxt->fd = -1;
@ -607,6 +609,18 @@ xmlNanoHTTPScanAnswer(xmlNanoHTTPCtxtPtr ctxt, const char *line) {
if (ctxt->location != NULL)
xmlFree(ctxt->location);
ctxt->location = xmlMemStrdup(cur);
} else if (!xmlStrncasecmp(BAD_CAST line, BAD_CAST"WWW-Authenticate:", 17)) {
cur += 17;
while ((*cur == ' ') || (*cur == '\t')) cur++;
if (ctxt->authHeader != NULL)
xmlFree(ctxt->authHeader);
ctxt->authHeader = xmlMemStrdup(cur);
} else if (!xmlStrncasecmp(BAD_CAST line, BAD_CAST"Proxy-Authenticate:", 19)) {
cur += 19;
while ((*cur == ' ') || (*cur == '\t')) cur++;
if (ctxt->authHeader != NULL)
xmlFree(ctxt->authHeader);
ctxt->authHeader = xmlMemStrdup(cur);
}
}
@ -1105,6 +1119,22 @@ xmlNanoHTTPReturnCode(void *ctx) {
return(ctxt->returnValue);
}
/**
* xmlNanoHTTPAuthHeader:
* @ctx: the HTTP context
*
* Returns the stashed value of the WWW-Authenticate or Proxy-Authenticate
* header.
*/
const char *
xmlNanoHTTPAuthHeader(void *ctx) {
xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
if (ctxt == NULL) return(NULL);
return(ctxt->authHeader);
}
#ifdef STANDALONE
int main(int argc, char **argv) {
char *contentType = NULL;

View File

@ -29,6 +29,7 @@ void * xmlNanoHTTPMethod (const char *URL,
void * xmlNanoHTTPOpen (const char *URL,
char **contentType);
int xmlNanoHTTPReturnCode (void *ctx);
const char * xmlNanoHTTPAuthHeader(void *ctx);
int xmlNanoHTTPRead (void *ctx,
void *dest,
int len);

View File

@ -8171,6 +8171,15 @@ xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size,
if ((terminate) || (ctxt->input->buf->buffer->use > 80))
xmlParseTryOrFinish(ctxt, terminate);
} else if (ctxt->instate != XML_PARSER_EOF)
if ((ctxt->input != NULL) && ctxt->input->buf != NULL) {
xmlParserInputBufferPtr in = ctxt->input->buf;
int nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw);
if (nbchars < 0) {
xmlGenericError(xmlGenericErrorContext,
"xmlParseChunk: encoder error\n");
return(XML_ERR_INVALID_ENCODING);
}
}
xmlParseTryOrFinish(ctxt, terminate);
if (terminate) {
/*

View File

@ -294,19 +294,19 @@ typedef xmlParserInputPtr (*xmlExternalEntityLoader)(const char *URL,
* Global variables: just the default SAX interface tables and XML
* version infos.
*/
extern const char *xmlParserVersion;
LIBXML_DLL_IMPORT extern const char *xmlParserVersion;
extern xmlSAXLocator xmlDefaultSAXLocator;
extern xmlSAXHandler xmlDefaultSAXHandler;
extern xmlSAXHandler htmlDefaultSAXHandler;
extern xmlSAXHandler sgmlDefaultSAXHandler;
LIBXML_DLL_IMPORT extern xmlSAXLocator xmlDefaultSAXLocator;
LIBXML_DLL_IMPORT extern xmlSAXHandler xmlDefaultSAXHandler;
LIBXML_DLL_IMPORT extern xmlSAXHandler htmlDefaultSAXHandler;
LIBXML_DLL_IMPORT extern xmlSAXHandler sgmlDefaultSAXHandler;
/**
* entity substitution default behaviour.
*/
extern int xmlSubstituteEntitiesDefaultValue;
extern int xmlGetWarningsDefaultValue;
LIBXML_DLL_IMPORT extern int xmlSubstituteEntitiesDefaultValue;
LIBXML_DLL_IMPORT extern int xmlGetWarningsDefaultValue;
/**

View File

@ -101,13 +101,13 @@ extern "C" {
* Global vaiables affecting the default parser behaviour.
*/
extern int xmlParserDebugEntities;
extern int xmlGetWarningsDefaultValue;
extern int xmlParserDebugEntities;
extern int xmlSubstituteEntitiesDefaultValue;
extern int xmlDoValidityCheckingDefaultValue;
extern int xmlPedanticParserDefaultValue;
extern int xmlKeepBlanksDefaultValue;
LIBXML_DLL_IMPORT extern int xmlParserDebugEntities;
LIBXML_DLL_IMPORT extern int xmlGetWarningsDefaultValue;
LIBXML_DLL_IMPORT extern int xmlParserDebugEntities;
LIBXML_DLL_IMPORT extern int xmlSubstituteEntitiesDefaultValue;
LIBXML_DLL_IMPORT extern int xmlDoValidityCheckingDefaultValue;
LIBXML_DLL_IMPORT extern int xmlPedanticParserDefaultValue;
LIBXML_DLL_IMPORT extern int xmlKeepBlanksDefaultValue;
/*
* Function to finish teh work of the macros where needed

View File

@ -8,6 +8,7 @@
#ifdef WIN32
#include "win32config.h"
#undef LIBXML_DLL_IMPORT
#else
#include "config.h"
#endif

View File

@ -8,6 +8,7 @@
#ifdef WIN32
#include "win32config.h"
#undef LIBXML_DLL_IMPORT
#else
#include "config.h"
#endif

14
tree.h
View File

@ -374,11 +374,11 @@ struct _xmlDoc {
/*
* Variables.
*/
extern xmlNsPtr baseDTD;
extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
extern xmlBufferAllocationScheme xmlBufferAllocScheme; /* alloc scheme to use */
extern int xmlSaveNoEmptyTags; /* save empty tags as <empty></empty> */
LIBXML_DLL_IMPORT extern xmlNsPtr baseDTD;
LIBXML_DLL_IMPORT extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
LIBXML_DLL_IMPORT extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
LIBXML_DLL_IMPORT extern xmlBufferAllocationScheme xmlBufferAllocScheme; /* alloc scheme to use */
LIBXML_DLL_IMPORT extern int xmlSaveNoEmptyTags; /* save empty tags as <empty></empty> */
/*
* Handling Buffers.
@ -533,6 +533,10 @@ void xmlTextConcat (xmlNodePtr node,
int len);
void xmlFreeNodeList (xmlNodePtr cur);
void xmlFreeNode (xmlNodePtr cur);
void xmlSetTreeDoc (xmlNodePtr tree,
xmlDocPtr doc);
void xmlSetListDoc (xmlNodePtr list,
xmlDocPtr doc);
/*
* Namespaces

View File

@ -3503,10 +3503,12 @@ child_ok:
VERROR(ctxt->userData,
"Element %s doesn't carry attribute %s\n",
elem->name, attr->name);
ret = 0;
} else {
VERROR(ctxt->userData,
"Element %s doesn't carry attribute %s:%s\n",
elem->name, attr->prefix,attr->name);
ret = 0;
}
} else if (qualified == 0) {
VWARNING(ctxt->userData,

View File

@ -256,12 +256,31 @@ xmlXIncludeNewContext(xmlDocPtr doc) {
*/
void
xmlXIncludeFreeContext(xmlXIncludeCtxtPtr ctxt) {
int i;
if (ctxt == NULL)
return;
for (i = 0;i < ctxt->docNr;i++) {
xmlFreeDoc(ctxt->docTab[i]);
if (ctxt->urlTab[i] != NULL)
xmlFree(ctxt->urlTab[i]);
}
for (i = 0;i < ctxt->txtNr;i++) {
if (ctxt->txturlTab[i] != NULL)
xmlFree(ctxt->txturlTab[i]);
}
if (ctxt->incTab != NULL)
xmlFree(ctxt->incTab);
if (ctxt->repTab != NULL)
xmlFree(ctxt->repTab);
if (ctxt->urlTab != NULL)
xmlFree(ctxt->urlTab);
if (ctxt->docTab != NULL)
xmlFree(ctxt->docTab);
if (ctxt->txtTab != NULL)
xmlFree(ctxt->txtTab);
if (ctxt->txturlTab != NULL)
xmlFree(ctxt->txturlTab);
memset(ctxt, 0xeb, sizeof(xmlXIncludeCtxt));
xmlFree(ctxt);
}
@ -285,6 +304,7 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
xmlDocPtr doc;
xmlURIPtr uri;
xmlChar *URL;
xmlChar *fragment = NULL;
int i;
/*
* Check the URL and remove any fragment identifier
@ -296,14 +316,16 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
return;
}
if (uri->fragment != NULL) {
xmlFree(uri->fragment);
uri->fragment = NULL; /* TODO: kkep it for later processing */
fragment = (xmlChar *) uri->fragment;
uri->fragment = NULL;
}
URL = xmlSaveUri(uri);
xmlFreeURI(uri);
if (URL == NULL) {
xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value URI %s\n", url);
if (fragment != NULL)
xmlFree(fragment);
return;
}
@ -311,9 +333,9 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
* Handling of references to the local document are done
* directly through ctxt->doc.
*/
if (URL[0] == 0) {
xmlFree(URL);
return;
if ((URL[0] == 0) || (URL[0] == '#')) {
doc = NULL;
goto loaded;
}
/*
@ -333,15 +355,56 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
xmlGenericError(xmlGenericErrorContext,
"XInclude: could not load %s\n", URL);
xmlFree(URL);
if (fragment != NULL)
xmlFree(fragment);
return;
}
xmlXIncludeAddDoc(ctxt, doc, URL);
loaded:
/*
* Add the top children list as the replacement copy.
*/
ctxt->repTab[nr] = xmlCopyNodeList(doc->children);
if (fragment == NULL) {
/*
* Add the top children list as the replacement copy.
* ISSUE: seems we should scrap DTD info from the copied list.
*/
if (doc == NULL)
ctxt->repTab[nr] = xmlCopyNodeList(ctxt->doc->children);
else
ctxt->repTab[nr] = xmlCopyNodeList(doc->children);
} else {
/*
* Computes the XPointer expression and make a copy used
* as the replacement copy.
*/
xmlXPathObjectPtr xptr;
xmlXPathContextPtr xptrctxt;
if (doc == NULL) {
xptrctxt = xmlXPtrNewContext(ctxt->doc, ctxt->incTab[nr], NULL);
} else {
xptrctxt = xmlXPtrNewContext(doc, NULL, NULL);
}
if (xptrctxt == NULL) {
xmlGenericError(xmlGenericErrorContext,
"XInclude: could create XPointer context\n");
xmlFree(URL);
xmlFree(fragment);
return;
}
xptr = xmlXPtrEval(fragment, xptrctxt);
if (xptr == NULL) {
xmlGenericError(xmlGenericErrorContext,
"XInclude: XPointer evaluation failed: #%s\n",
fragment);
xmlFree(URL);
xmlFree(fragment);
return;
}
ctxt->repTab[nr] = xmlXPtrBuildNodeList(xptr);
xmlXPathFreeObject(xptr);
xmlXPathFreeContext(xptrctxt);
xmlFree(fragment);
}
xmlFree(URL);
}
@ -370,9 +433,10 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
return;
}
if (uri->fragment != NULL) {
xmlFreeURI(uri);
xmlGenericError(xmlGenericErrorContext,
"XInclude: fragment identifier forbidden for text\n");
"XInclude: fragment identifier forbidden for text: %s\n",
uri->fragment);
xmlFreeURI(uri);
return;
}
URL = xmlSaveUri(uri);

View File

@ -146,8 +146,8 @@ typedef void (*xmlGenericErrorFunc) (void *ctx, const char *msg, ...);
* when when there is an error and no parsing or validity context available
*/
extern xmlGenericErrorFunc xmlGenericError;
extern void *xmlGenericErrorContext;
LIBXML_DLL_IMPORT extern xmlGenericErrorFunc xmlGenericError;
LIBXML_DLL_IMPORT extern void *xmlGenericErrorContext;
/*
* Use the following function to reset the two previous global variables.

View File

@ -111,6 +111,14 @@ extern void xmlCheckVersion(int version);
#define DEBUG_MEMORY_LOCATION
#endif
#ifndef LIBXML_DLL_IMPORT
#if defined(WIN32) && !defined(STATIC)
#define LIBXML_DLL_IMPORT __declspec(dllimport)
#else
#define LIBXML_DLL_IMPORT
#endif
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -21,7 +21,6 @@
* TODO: Access into entities references are not supported now ...
* need a start to be able to pop out of entities refs since
* parent is the endity declaration, not the ref.
* TODO: some functions are still missing !
*/
#include <stdio.h>
@ -1302,6 +1301,45 @@ xmlXPtrEval(const xmlChar *str, xmlXPathContextPtr ctx) {
return(res);
}
/**
* xmlXPtrBuildNodeList:
* @obj: the XPointer result from the evaluation.
*
* Build a node list copy of the XPointer result.
*
* Returns an xmlNodePtr list or NULL.
* the caller has to free the node list.
*/
xmlNodePtr
xmlXPtrBuildNodeList(xmlXPathObjectPtr obj) {
xmlNodePtr list = NULL, last = NULL;
int i;
if (obj == NULL)
return(NULL);
switch (obj->type) {
case XPATH_NODESET: {
xmlNodeSetPtr set = obj->nodesetval;
if (set == NULL)
return(NULL);
for (i = 0;i < set->nodeNr;i++) {
if (last == NULL)
list = last = xmlCopyNode(set->nodeTab[i], 1);
else {
xmlAddNextSibling(last, xmlCopyNode(set->nodeTab[i], 1));
if (last->next != NULL)
last = last->next;
}
}
break;
}
case XPATH_LOCATIONSET:
break;
default:
break;
}
return(list);
}
/************************************************************************
* *

View File

@ -48,6 +48,7 @@ xmlXPathObjectPtr xmlXPtrEval (const xmlChar *str,
xmlXPathContextPtr ctx);
void xmlXPtrRangeToFunction (xmlXPathParserContextPtr ctxt,
int nargs);
xmlNodePtr xmlXPtrBuildNodeList (xmlXPathObjectPtr obj);
#ifdef __cplusplus
}