1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

Jumbo patch, resync of W3C/Gnome CVS trees:

- uri.c tree.c SAX.c parser.c entities.c debugXML.c: finished
  the cleanup of the computation of URI references when seeking
  external entities. The URI reference string and the resulting
  URI are both stored now.
- parser.c HTMLparser.c valid.c nanoftp.c nanohttp.c xpath.c:
  large s(n)printf checks and cleanup from Denis Barbier
  <barbier@imacs.polytechnique.fr>
- xmlversion.h.in tree.h: couple of SGML declarations for a
  possible docbook module.
- result/VC/ : a couple of test output changed due to the change
  of the entities URI
Daniel
This commit is contained in:
Daniel Veillard
2000-09-10 16:14:55 +00:00
parent b513f5a00d
commit 39c7d71a3b
29 changed files with 605 additions and 246 deletions

View File

@ -1,3 +1,17 @@
Sun Sep 10 17:53:48 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* uri.c tree.c SAX.c parser.c entities.c debugXML.c: finished
the cleanup of the computation of URI references when seeking
external entities. The URI reference string and the resulting
URI are both stored now.
* parser.c HTMLparser.c valid.c nanoftp.c nanohttp.c xpath.c:
large s(n)printf checks and cleanup from Denis Barbier
<barbier@imacs.polytechnique.fr>
* xmlversion.h.in tree.h: couple of SGML declarations for a
possible docbook module.
* result/VC/ : a couple of test output changed due to the change
of the entities URI
Sun Sep 10 15:59:58 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org> Sun Sep 10 15:59:58 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* parser.h: added a _private field for linking user's data * parser.h: added a _private field for linking user's data

View File

@ -630,7 +630,7 @@ htmlTagLookup(const xmlChar *tag) {
int int
htmlCheckAutoClose(const xmlChar *newtag, const xmlChar *oldtag) { htmlCheckAutoClose(const xmlChar *newtag, const xmlChar *oldtag) {
int i, index; int i, index;
char **close; char **close = NULL;
if (htmlStartCloseIndexinitialized == 0) htmlInitAutoClose(); if (htmlStartCloseIndexinitialized == 0) htmlInitAutoClose();
@ -3535,6 +3535,10 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt)
xmlMalloc(5 * sizeof(htmlParserInputPtr)); xmlMalloc(5 * sizeof(htmlParserInputPtr));
if (ctxt->inputTab == NULL) { if (ctxt->inputTab == NULL) {
fprintf(stderr, "htmlInitParserCtxt: out of memory\n"); fprintf(stderr, "htmlInitParserCtxt: out of memory\n");
ctxt->inputNr = 0;
ctxt->inputMax = 0;
ctxt->input = NULL;
return;
} }
ctxt->inputNr = 0; ctxt->inputNr = 0;
ctxt->inputMax = 5; ctxt->inputMax = 5;
@ -3546,12 +3550,35 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt)
/* Allocate the Node stack */ /* Allocate the Node stack */
ctxt->nodeTab = (htmlNodePtr *) xmlMalloc(10 * sizeof(htmlNodePtr)); ctxt->nodeTab = (htmlNodePtr *) xmlMalloc(10 * sizeof(htmlNodePtr));
if (ctxt->nodeTab == NULL) {
fprintf(stderr, "htmlInitParserCtxt: out of memory\n");
ctxt->nodeNr = 0;
ctxt->nodeMax = 0;
ctxt->node = NULL;
ctxt->inputNr = 0;
ctxt->inputMax = 0;
ctxt->input = NULL;
return;
}
ctxt->nodeNr = 0; ctxt->nodeNr = 0;
ctxt->nodeMax = 10; ctxt->nodeMax = 10;
ctxt->node = NULL; ctxt->node = NULL;
/* Allocate the Name stack */ /* Allocate the Name stack */
ctxt->nameTab = (xmlChar **) xmlMalloc(10 * sizeof(xmlChar *)); ctxt->nameTab = (xmlChar **) xmlMalloc(10 * sizeof(xmlChar *));
if (ctxt->nameTab == NULL) {
fprintf(stderr, "htmlInitParserCtxt: out of memory\n");
ctxt->nameNr = 0;
ctxt->nameMax = 10;
ctxt->name = NULL;
ctxt->nodeNr = 0;
ctxt->nodeMax = 0;
ctxt->node = NULL;
ctxt->inputNr = 0;
ctxt->inputMax = 0;
ctxt->input = NULL;
return;
}
ctxt->nameNr = 0; ctxt->nameNr = 0;
ctxt->nameMax = 10; ctxt->nameMax = 10;
ctxt->name = NULL; ctxt->name = NULL;

View File

@ -181,12 +181,13 @@ htmlSetMetaEncoding(htmlDocPtr doc, const xmlChar *encoding) {
return(-1); return(-1);
if (encoding != NULL) { if (encoding != NULL) {
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(newcontent, sizeof(newcontent), "text/html; charset=%s",
encoding);
#else
sprintf(newcontent, "text/html; charset=%s", encoding); sprintf(newcontent, "text/html; charset=%s", encoding);
#else /* HAVE_SNPRINTF */ #endif
snprintf(newcontent, 99, "text/html; charset=%s", encoding); newcontent[sizeof(newcontent) - 1] = 0;
#endif /* HAVE_SNPRINTF */
newcontent[99] = 0;
} }
cur = doc->children; cur = doc->children;

111
SAX.c
View File

@ -311,13 +311,26 @@ xmlParserInputPtr
resolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId) resolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
{ {
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr ret;
char *URI;
const char *base = NULL;
if (ctxt->input != NULL)
base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
URI = xmlBuildURI(systemId, base);
#ifdef DEBUG_SAX #ifdef DEBUG_SAX
fprintf(stderr, "SAX.resolveEntity(%s, %s)\n", publicId, systemId); fprintf(stderr, "SAX.resolveEntity(%s, %s)\n", publicId, systemId);
#endif #endif
return(xmlLoadExternalEntity((const char *) systemId, ret = xmlLoadExternalEntity((const char *) URI,
(const char *) publicId, ctxt)); (const char *) publicId, ctxt);
if (URI != NULL)
xmlFree(URI);
return(ret);
} }
/** /**
@ -409,6 +422,18 @@ entityDecl(void *ctx, const xmlChar *name, int type,
(ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt, ctxt->sax->warning(ctxt,
"Entity(%s) already defined in the internal subset\n", name); "Entity(%s) already defined in the internal subset\n", name);
if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
char *URI;
const char *base = NULL;
if (ctxt->input != NULL)
base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
URI = xmlBuildURI(systemId, base);
ent->URI = URI;
}
} else if (ctxt->inSubset == 2) { } else if (ctxt->inSubset == 2) {
ent = xmlAddDtdEntity(ctxt->myDoc, name, type, publicId, ent = xmlAddDtdEntity(ctxt->myDoc, name, type, publicId,
systemId, content); systemId, content);
@ -416,6 +441,18 @@ entityDecl(void *ctx, const xmlChar *name, int type,
(ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt, ctxt->sax->warning(ctxt,
"Entity(%s) already defined in the external subset\n", name); "Entity(%s) already defined in the external subset\n", name);
if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
char *URI;
const char *base = NULL;
if (ctxt->input != NULL)
base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
URI = xmlBuildURI(systemId, base);
ent->URI = URI;
}
} else { } else {
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt, ctxt->sax->error(ctxt,
@ -1603,3 +1640,73 @@ htmlDefaultSAXHandlerInit(void)
htmlDefaultSAXHandler.error = xmlParserError; htmlDefaultSAXHandler.error = xmlParserError;
htmlDefaultSAXHandler.fatalError = xmlParserError; htmlDefaultSAXHandler.fatalError = xmlParserError;
} }
/*
* Default handler for HTML, builds the DOM tree
*/
xmlSAXHandler sgmlDefaultSAXHandler = {
internalSubset,
NULL,
NULL,
NULL,
NULL,
getEntity,
NULL,
NULL,
NULL,
NULL,
NULL,
setDocumentLocator,
startDocument,
endDocument,
startElement,
endElement,
NULL,
characters,
ignorableWhitespace,
NULL,
comment,
xmlParserWarning,
xmlParserError,
xmlParserError,
getParameterEntity,
NULL,
NULL,
};
/**
* sgmlDefaultSAXHandlerInit:
*
* Initialize the default SAX handler
*/
void
sgmlDefaultSAXHandlerInit(void)
{
sgmlDefaultSAXHandler.internalSubset = internalSubset;
sgmlDefaultSAXHandler.externalSubset = NULL;
sgmlDefaultSAXHandler.isStandalone = NULL;
sgmlDefaultSAXHandler.hasInternalSubset = NULL;
sgmlDefaultSAXHandler.hasExternalSubset = NULL;
sgmlDefaultSAXHandler.resolveEntity = NULL;
sgmlDefaultSAXHandler.getEntity = getEntity;
sgmlDefaultSAXHandler.getParameterEntity = NULL;
sgmlDefaultSAXHandler.entityDecl = NULL;
sgmlDefaultSAXHandler.attributeDecl = NULL;
sgmlDefaultSAXHandler.elementDecl = NULL;
sgmlDefaultSAXHandler.notationDecl = NULL;
sgmlDefaultSAXHandler.unparsedEntityDecl = NULL;
sgmlDefaultSAXHandler.setDocumentLocator = setDocumentLocator;
sgmlDefaultSAXHandler.startDocument = startDocument;
sgmlDefaultSAXHandler.endDocument = endDocument;
sgmlDefaultSAXHandler.startElement = startElement;
sgmlDefaultSAXHandler.endElement = endElement;
sgmlDefaultSAXHandler.reference = NULL;
sgmlDefaultSAXHandler.characters = characters;
sgmlDefaultSAXHandler.cdataBlock = NULL;
sgmlDefaultSAXHandler.ignorableWhitespace = ignorableWhitespace;
sgmlDefaultSAXHandler.processingInstruction = NULL;
sgmlDefaultSAXHandler.comment = comment;
sgmlDefaultSAXHandler.warning = xmlParserWarning;
sgmlDefaultSAXHandler.error = xmlParserError;
sgmlDefaultSAXHandler.fatalError = xmlParserError;
}

1
SAX.h
View File

@ -109,6 +109,7 @@ void cdataBlock (void *ctx,
void xmlDefaultSAXHandlerInit (void); void xmlDefaultSAXHandlerInit (void);
void htmlDefaultSAXHandlerInit (void); void htmlDefaultSAXHandlerInit (void);
void sgmlDefaultSAXHandlerInit (void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -249,11 +249,11 @@ void xmlDebugDumpElemDecl(FILE *output, xmlElementPtr elem, int depth) {
break; break;
} }
if (elem->content != NULL) { if (elem->content != NULL) {
char buf[1001]; char buf[5001];
buf[0] = 0; buf[0] = 0;
xmlSprintfElementContent(buf, elem->content, 1); xmlSprintfElementContent(buf, elem->content, 1);
buf[1000] = 0; buf[5000] = 0;
fprintf(output, "%s", buf); fprintf(output, "%s", buf);
} }
printf("\n"); printf("\n");
@ -325,15 +325,19 @@ void xmlDebugDumpEntityDecl(FILE *output, xmlEntityPtr ent, int depth) {
} }
if (ent->ExternalID) { if (ent->ExternalID) {
fprintf(output, shift); fprintf(output, shift);
fprintf(output, "ExternalID=%s\n", ent->ExternalID); fprintf(output, " ExternalID=%s\n", ent->ExternalID);
} }
if (ent->SystemID) { if (ent->SystemID) {
fprintf(output, shift); fprintf(output, shift);
fprintf(output, "SystemID=%s\n", ent->SystemID); fprintf(output, " SystemID=%s\n", ent->SystemID);
}
if (ent->URI != NULL) {
fprintf(output, shift);
fprintf(output, " URI=%s\n", ent->URI);
} }
if (ent->content) { if (ent->content) {
fprintf(output, shift); fprintf(output, shift);
fprintf(output, "content="); fprintf(output, " content=");
xmlDebugDumpString(output, ent->content); xmlDebugDumpString(output, ent->content);
fprintf(output, "\n"); fprintf(output, "\n");
} }
@ -434,6 +438,10 @@ void xmlDebugDumpEntity(FILE *output, xmlEntityPtr ent, int depth) {
fprintf(output, shift); fprintf(output, shift);
fprintf(output, "SystemID=%s\n", ent->SystemID); fprintf(output, "SystemID=%s\n", ent->SystemID);
} }
if (ent->URI) {
fprintf(output, shift);
fprintf(output, "URI=%s\n", ent->URI);
}
if (ent->content) { if (ent->content) {
fprintf(output, shift); fprintf(output, shift);
fprintf(output, "content="); fprintf(output, "content=");
@ -618,7 +626,7 @@ void xmlDebugDumpOneNode(FILE *output, xmlNodePtr node, int depth) {
void xmlDebugDumpNode(FILE *output, xmlNodePtr node, int depth) { void xmlDebugDumpNode(FILE *output, xmlNodePtr node, int depth) {
xmlDebugDumpOneNode(output, node, depth); xmlDebugDumpOneNode(output, node, depth);
if (node->children != NULL) if ((node->children != NULL) && (node->type != XML_ENTITY_REF_NODE))
xmlDebugDumpNodeList(output, node->children, depth + 1); xmlDebugDumpNodeList(output, node->children, depth + 1);
} }
@ -695,6 +703,11 @@ void xmlDebugDumpDocumentHead(FILE *output, xmlDocPtr doc) {
xmlDebugDumpString(output, doc->encoding); xmlDebugDumpString(output, doc->encoding);
fprintf(output, "\n"); fprintf(output, "\n");
} }
if (doc->URL != NULL) {
fprintf(output, "URL=");
xmlDebugDumpString(output, doc->URL);
fprintf(output, "\n");
}
if (doc->standalone) if (doc->standalone)
fprintf(output, "standalone=true\n"); fprintf(output, "standalone=true\n");
if (doc->oldNs != NULL) if (doc->oldNs != NULL)
@ -714,6 +727,47 @@ void xmlDebugDumpDocument(FILE *output, xmlDocPtr doc) {
xmlDebugDumpNodeList(output, doc->children, 1); xmlDebugDumpNodeList(output, doc->children, 1);
} }
void xmlDebugDumpDTD(FILE *output, xmlDtdPtr dtd) {
if (dtd == NULL)
return;
if (dtd->type != XML_DTD_NODE) {
fprintf(output, "PBM: not a DTD\n");
return;
}
if (dtd->name != NULL)
fprintf(output, "DTD(%s)", dtd->name);
else
fprintf(output, "DTD");
if (dtd->ExternalID != NULL)
fprintf(output, ", PUBLIC %s", dtd->ExternalID);
if (dtd->SystemID != NULL)
fprintf(output, ", SYSTEM %s", dtd->SystemID);
fprintf(output, "\n");
/*
* Do a bit of checking
*/
if ((dtd->parent != NULL) && (dtd->doc != dtd->parent->doc))
fprintf(output, "PBM: Dtd doc differs from parent's one\n");
if (dtd->prev == NULL) {
if ((dtd->parent != NULL) && (dtd->parent->children != (xmlNodePtr)dtd))
fprintf(output, "PBM: Dtd has no prev and not first of list\n");
} else {
if (dtd->prev->next != (xmlNodePtr) dtd)
fprintf(output, "PBM: Dtd prev->next : back link wrong\n");
}
if (dtd->next == NULL) {
if ((dtd->parent != NULL) && (dtd->parent->last != (xmlNodePtr) dtd))
fprintf(output, "PBM: Dtd has no next and not last of list\n");
} else {
if (dtd->next->prev != (xmlNodePtr) dtd)
fprintf(output, "PBM: Dtd next->prev : forward link wrong\n");
}
if (dtd->children == NULL)
fprintf(output, " DTD is empty\n");
else
xmlDebugDumpNodeList(output, dtd->children, 1);
}
void xmlDebugDumpEntities(FILE *output, xmlDocPtr doc) { void xmlDebugDumpEntities(FILE *output, xmlDocPtr doc) {
int i; int i;
xmlEntityPtr cur; xmlEntityPtr cur;
@ -1456,9 +1510,29 @@ xmlShellPwd(xmlShellCtxtPtr ctxt, char *buffer, xmlNodePtr node,
next = cur->parent; next = cur->parent;
} }
if (occur == 0) if (occur == 0)
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "%c%s%s", sep, name, buffer);
#else
sprintf(buf, "%c%s%s", sep, name, buffer); sprintf(buf, "%c%s%s", sep, name, buffer);
#endif
else else
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "%c%s[%d]%s",
sep, name, occur, buffer);
#else
sprintf(buf, "%c%s[%d]%s", sep, name, occur, buffer); sprintf(buf, "%c%s[%d]%s", sep, name, occur, buffer);
#endif
buf[sizeof(buf) - 1] = 0;
/*
* This test prevents buffer overflow, because this routine
* is only called by xmlShell, in which the second argument is
* 500 chars long.
* It is a dirty hack before a cleaner solution is found.
* Documentation should mention that the second argument must
* be at least 500 chars long, and could be stripped if too long.
*/
if (strlen(buffer) + strlen(buf) > 499)
break;
strcpy(buffer, buf); strcpy(buffer, buf);
cur = next; cur = next;
} while (cur != NULL); } while (cur != NULL);
@ -1516,9 +1590,14 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
if (ctxt->node == (xmlNodePtr) ctxt->doc) if (ctxt->node == (xmlNodePtr) ctxt->doc)
sprintf(prompt, "%s > ", "/"); sprintf(prompt, "%s > ", "/");
else if (ctxt->node->name) else if (ctxt->node->name)
sprintf(prompt, "%s > ", ctxt->node->name); #ifdef HAVE_SNPRINTF
snprintf(prompt, sizeof(prompt), "%s > ", ctxt->node->name);
#else
sprintf(buf, "%s > ", ctxt->node->name);
#endif
else else
sprintf(prompt, "? > "); sprintf(prompt, "? > ");
prompt[sizeof(prompt) - 1] = 0;
cmdline = ctxt->input(prompt); cmdline = ctxt->input(prompt);
if (cmdline == NULL) break; if (cmdline == NULL) break;

View File

@ -42,6 +42,8 @@ void xmlDebugDumpDocumentHead(FILE *output,
xmlDocPtr doc); xmlDocPtr doc);
void xmlDebugDumpDocument (FILE *output, void xmlDebugDumpDocument (FILE *output,
xmlDocPtr doc); xmlDocPtr doc);
void xmlDebugDumpDTD (FILE *output,
xmlDtdPtr doc);
void xmlDebugDumpEntities (FILE *output, void xmlDebugDumpEntities (FILE *output,
xmlDocPtr doc); xmlDocPtr doc);
void xmlLsOneNode (FILE *output, void xmlLsOneNode (FILE *output,

View File

@ -76,6 +76,8 @@ void xmlFreeEntity(xmlEntityPtr entity) {
xmlFree((char *) entity->ExternalID); xmlFree((char *) entity->ExternalID);
if (entity->SystemID != NULL) if (entity->SystemID != NULL)
xmlFree((char *) entity->SystemID); xmlFree((char *) entity->SystemID);
if (entity->URI != NULL)
xmlFree((char *) entity->URI);
if (entity->content != NULL) if (entity->content != NULL)
xmlFree((char *) entity->content); xmlFree((char *) entity->content);
if (entity->orig != NULL) if (entity->orig != NULL)
@ -198,6 +200,8 @@ xmlAddEntity(xmlEntitiesTablePtr table, const xmlChar *name, int type,
ret->length = 0; ret->length = 0;
ret->content = NULL; ret->content = NULL;
} }
ret->URI = NULL; /* to be computed by the layer knowing
the defining entity */
ret->orig = NULL; ret->orig = NULL;
table->nb_entities++; table->nb_entities++;
@ -590,8 +594,6 @@ xmlGetParameterEntity(xmlDocPtr doc, const xmlChar *name) {
xmlEntitiesTablePtr table; xmlEntitiesTablePtr table;
xmlEntityPtr ret; xmlEntityPtr ret;
if (doc == NULL)
return(NULL);
if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) { if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) {
table = (xmlEntitiesTablePtr) doc->intSubset->entities; table = (xmlEntitiesTablePtr) doc->intSubset->entities;
ret = xmlGetEntityFromTable(table, name, 1); ret = xmlGetEntityFromTable(table, name, 1);
@ -619,8 +621,6 @@ xmlEntityPtr
xmlGetDtdEntity(xmlDocPtr doc, const xmlChar *name) { xmlGetDtdEntity(xmlDocPtr doc, const xmlChar *name) {
xmlEntitiesTablePtr table; xmlEntitiesTablePtr table;
if (doc == NULL)
return(NULL);
if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) { if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) {
table = (xmlEntitiesTablePtr) doc->extSubset->entities; table = (xmlEntitiesTablePtr) doc->extSubset->entities;
return(xmlGetEntityFromTable(table, name, 0)); return(xmlGetEntityFromTable(table, name, 0));
@ -783,11 +783,13 @@ xmlEncodeEntities(xmlDocPtr doc, const xmlChar *input) {
#ifndef USE_UTF_8 #ifndef USE_UTF_8
} else if ((sizeof(xmlChar) == 1) && (*cur >= 0x80)) { } else if ((sizeof(xmlChar) == 1) && (*cur >= 0x80)) {
char buf[10], *ptr; char buf[10], *ptr;
#ifdef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(buf, 9, "&#%d;", *cur); snprintf(buf, sizeof(buf), "&#%d;", *cur);
#else #else
sprintf(buf, "&#%d;", *cur); sprintf(buf, "&#%d;", *cur);
#endif #endif
buf[sizeof(buf) - 1] = 0;
ptr = buf; ptr = buf;
while (*ptr != 0) *out++ = *ptr++; while (*ptr != 0) *out++ = *ptr++;
#endif #endif
@ -795,10 +797,11 @@ xmlEncodeEntities(xmlDocPtr doc, const xmlChar *input) {
char buf[10], *ptr; char buf[10], *ptr;
#ifdef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(buf, 9, "&#%d;", *cur); snprintf(buf, sizeof(buf), "&#%d;", *cur);
#else #else
sprintf(buf, "&#%d;", *cur); sprintf(buf, "&#%d;", *cur);
#endif #endif
buf[sizeof(buf) - 1] = 0;
ptr = buf; ptr = buf;
while (*ptr != 0) *out++ = *ptr++; while (*ptr != 0) *out++ = *ptr++;
} }
@ -918,7 +921,13 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
} else if (*cur >= 0x80) { } else if (*cur >= 0x80) {
if ((doc->encoding != NULL) || (html)) { if ((doc->encoding != NULL) || (html)) {
/* /*
* TODO !!! * Bj<EFBFBD>rn Reese <br@sseusa.com> provided the patch
xmlChar xc;
xc = (*cur & 0x3F) << 6;
if (cur[1] != 0) {
xc += *(++cur) & 0x3F;
*out++ = xc;
} else
*/ */
*out++ = *cur; *out++ = *cur;
} else { } else {
@ -933,10 +942,11 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
"xmlEncodeEntitiesReentrant : input not UTF-8\n"); "xmlEncodeEntitiesReentrant : input not UTF-8\n");
doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
#ifdef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(buf, 9, "&#%d;", *cur); snprintf(buf, sizeof(buf), "&#%d;", *cur);
#else #else
sprintf(buf, "&#%d;", *cur); sprintf(buf, "&#%d;", *cur);
#endif #endif
buf[sizeof(buf) - 1] = 0;
ptr = buf; ptr = buf;
while (*ptr != 0) *out++ = *ptr++; while (*ptr != 0) *out++ = *ptr++;
continue; continue;
@ -967,11 +977,11 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
"xmlEncodeEntitiesReentrant : char out of range\n"); "xmlEncodeEntitiesReentrant : char out of range\n");
doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
#ifdef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(buf, 9, "&#%d;", *cur); snprintf(buf, sizeof(buf), "&#%d;", *cur);
#else #else
sprintf(buf, "&#%d;", *cur); sprintf(buf, "&#%d;", *cur);
#endif #endif
buf[9] = 0; buf[sizeof(buf) - 1] = 0;
ptr = buf; ptr = buf;
while (*ptr != 0) *out++ = *ptr++; while (*ptr != 0) *out++ = *ptr++;
cur++; cur++;
@ -981,11 +991,11 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
* We could do multiple things here. Just save as a char ref * We could do multiple things here. Just save as a char ref
*/ */
#ifdef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(buf, 9, "&#x%X;", val); snprintf(buf, sizeof(buf), "&#x%X;", val);
#else #else
sprintf(buf, "&#x%X;", val); sprintf(buf, "&#x%X;", val);
#endif #endif
buf[9] = 0; buf[sizeof(buf) - 1] = 0;
ptr = buf; ptr = buf;
while (*ptr != 0) *out++ = *ptr++; while (*ptr != 0) *out++ = *ptr++;
cur += l; cur += l;
@ -995,11 +1005,11 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
char buf[10], *ptr; char buf[10], *ptr;
#ifdef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(buf, 9, "&#%d;", *cur); snprintf(buf, sizeof(buf), "&#%d;", *cur);
#else #else
sprintf(buf, "&#%d;", *cur); sprintf(buf, "&#%d;", *cur);
#endif #endif
buf[9] = 0; buf[sizeof(buf) - 1] = 0;
ptr = buf; ptr = buf;
while (*ptr != 0) *out++ = *ptr++; while (*ptr != 0) *out++ = *ptr++;
} }

View File

@ -55,6 +55,7 @@ struct _xmlEntity {
const xmlChar *SystemID; /* URI for a SYSTEM or PUBLIC Entity */ const xmlChar *SystemID; /* URI for a SYSTEM or PUBLIC Entity */
struct _xmlEntity *nexte; /* next entity in the hash table */ struct _xmlEntity *nexte; /* next entity in the hash table */
const xmlChar *URI; /* the full URI as computed */
#ifdef WITH_EXTRA_ENT_DETECT #ifdef WITH_EXTRA_ENT_DETECT
/* Referenced entities name stack */ /* Referenced entities name stack */

33
error.c
View File

@ -87,29 +87,33 @@ void
xmlParserError(void *ctx, const char *msg, ...) xmlParserError(void *ctx, const char *msg, ...)
{ {
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr input; xmlParserInputPtr input = NULL;
xmlParserInputPtr cur = NULL; xmlParserInputPtr cur = NULL;
va_list args; va_list args;
if (ctxt != NULL) {
input = ctxt->input; input = ctxt->input;
if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { if ((input != NULL) && (input->filename == NULL) &&
(ctxt->inputNr > 1)) {
cur = input; cur = input;
input = ctxt->inputTab[ctxt->inputNr - 2]; input = ctxt->inputTab[ctxt->inputNr - 2];
} }
xmlParserPrintFileInfo(input); xmlParserPrintFileInfo(input);
}
fprintf(stderr, "error: "); fprintf(stderr, "error: ");
va_start(args, msg); va_start(args, msg);
vfprintf(stderr, msg, args); vfprintf(stderr, msg, args);
va_end(args); va_end(args);
if (ctxt != NULL) {
xmlParserPrintFileContext(input); xmlParserPrintFileContext(input);
if (cur != NULL) { if (cur != NULL) {
xmlParserPrintFileInfo(cur); xmlParserPrintFileInfo(cur);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
xmlParserPrintFileContext(cur); xmlParserPrintFileContext(cur);
} }
}
} }
/** /**
@ -125,30 +129,33 @@ void
xmlParserWarning(void *ctx, const char *msg, ...) xmlParserWarning(void *ctx, const char *msg, ...)
{ {
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr input; xmlParserInputPtr input = NULL;
xmlParserInputPtr cur = NULL; xmlParserInputPtr cur = NULL;
va_list args; va_list args;
if (ctxt != NULL) {
input = ctxt->input; input = ctxt->input;
if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { if ((input != NULL) && (input->filename == NULL) &&
(ctxt->inputNr > 1)) {
cur = input; cur = input;
input = ctxt->inputTab[ctxt->inputNr - 2]; input = ctxt->inputTab[ctxt->inputNr - 2];
} }
xmlParserPrintFileInfo(input); xmlParserPrintFileInfo(input);
}
fprintf(stderr, "warning: "); fprintf(stderr, "warning: ");
va_start(args, msg); va_start(args, msg);
vfprintf(stderr, msg, args); vfprintf(stderr, msg, args);
va_end(args); va_end(args);
if (ctxt != NULL) {
xmlParserPrintFileContext(input); xmlParserPrintFileContext(input);
if (cur != NULL) { if (cur != NULL) {
xmlParserPrintFileInfo(cur); xmlParserPrintFileInfo(cur);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
xmlParserPrintFileContext(cur); xmlParserPrintFileContext(cur);
} }
}
} }
/** /**
@ -164,21 +171,25 @@ void
xmlParserValidityError(void *ctx, const char *msg, ...) xmlParserValidityError(void *ctx, const char *msg, ...)
{ {
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr input; xmlParserInputPtr input = NULL;
va_list args; va_list args;
if (ctxt != NULL) {
input = ctxt->input; input = ctxt->input;
if ((input->filename == NULL) && (ctxt->inputNr > 1)) if ((input->filename == NULL) && (ctxt->inputNr > 1))
input = ctxt->inputTab[ctxt->inputNr - 2]; input = ctxt->inputTab[ctxt->inputNr - 2];
xmlParserPrintFileInfo(input); xmlParserPrintFileInfo(input);
}
fprintf(stderr, "validity error: "); fprintf(stderr, "validity error: ");
va_start(args, msg); va_start(args, msg);
vfprintf(stderr, msg, args); vfprintf(stderr, msg, args);
va_end(args); va_end(args);
if (ctxt != NULL) {
xmlParserPrintFileContext(input); xmlParserPrintFileContext(input);
}
} }
/** /**
@ -194,20 +205,24 @@ void
xmlParserValidityWarning(void *ctx, const char *msg, ...) xmlParserValidityWarning(void *ctx, const char *msg, ...)
{ {
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr input; xmlParserInputPtr input = NULL;
va_list args; va_list args;
if (ctxt != NULL) {
input = ctxt->input; input = ctxt->input;
if ((input->filename == NULL) && (ctxt->inputNr > 1)) if ((input->filename == NULL) && (ctxt->inputNr > 1))
input = ctxt->inputTab[ctxt->inputNr - 2]; input = ctxt->inputTab[ctxt->inputNr - 2];
xmlParserPrintFileInfo(input); xmlParserPrintFileInfo(input);
}
fprintf(stderr, "validity warning: "); fprintf(stderr, "validity warning: ");
va_start(args, msg); va_start(args, msg);
vfprintf(stderr, msg, args); vfprintf(stderr, msg, args);
va_end(args); va_end(args);
if (ctxt != NULL) {
xmlParserPrintFileContext(input); xmlParserPrintFileContext(input);
}
} }

View File

@ -109,6 +109,7 @@ void cdataBlock (void *ctx,
void xmlDefaultSAXHandlerInit (void); void xmlDefaultSAXHandlerInit (void);
void htmlDefaultSAXHandlerInit (void); void htmlDefaultSAXHandlerInit (void);
void sgmlDefaultSAXHandlerInit (void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -42,6 +42,8 @@ void xmlDebugDumpDocumentHead(FILE *output,
xmlDocPtr doc); xmlDocPtr doc);
void xmlDebugDumpDocument (FILE *output, void xmlDebugDumpDocument (FILE *output,
xmlDocPtr doc); xmlDocPtr doc);
void xmlDebugDumpDTD (FILE *output,
xmlDtdPtr doc);
void xmlDebugDumpEntities (FILE *output, void xmlDebugDumpEntities (FILE *output,
xmlDocPtr doc); xmlDocPtr doc);
void xmlLsOneNode (FILE *output, void xmlLsOneNode (FILE *output,

View File

@ -55,6 +55,7 @@ struct _xmlEntity {
const xmlChar *SystemID; /* URI for a SYSTEM or PUBLIC Entity */ const xmlChar *SystemID; /* URI for a SYSTEM or PUBLIC Entity */
struct _xmlEntity *nexte; /* next entity in the hash table */ struct _xmlEntity *nexte; /* next entity in the hash table */
const xmlChar *URI; /* the full URI as computed */
#ifdef WITH_EXTRA_ENT_DETECT #ifdef WITH_EXTRA_ENT_DETECT
/* Referenced entities name stack */ /* Referenced entities name stack */

View File

@ -41,7 +41,12 @@ typedef enum {
XML_DTD_NODE= 14, XML_DTD_NODE= 14,
XML_ELEMENT_DECL= 15, XML_ELEMENT_DECL= 15,
XML_ATTRIBUTE_DECL= 16, XML_ATTRIBUTE_DECL= 16,
#ifdef LIBXML_SGML_ENABLED
XML_ENTITY_DECL= 17,
XML_SGML_DOCUMENT_NODE= 18
#else
XML_ENTITY_DECL= 17 XML_ENTITY_DECL= 17
#endif
} xmlElementType; } xmlElementType;
/* /*

View File

@ -37,7 +37,7 @@ struct _xmlParserInputBuffer {
xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */ xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */
xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 or ISOLatin */ xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 */
xmlBufferPtr raw; /* if encoder != NULL buffer for raw input */ xmlBufferPtr raw; /* if encoder != NULL buffer for raw input */
}; };

View File

@ -49,6 +49,15 @@ extern void xmlCheckVersion(int version);
#define LIBXML_HTML_DISABLED #define LIBXML_HTML_DISABLED
#endif #endif
/*
* Whether the Docbook support is configured in
#if @WITH_SGML@
#define LIBXML_SGML_ENABLED
#else
#define LIBXML_SGML_DISABLED
#endif
*/
/* /*
* Whether XPath is configured in * Whether XPath is configured in
*/ */

216
nanoftp.c
View File

@ -731,17 +731,15 @@ xmlNanoFTPSendUser(void *ctx) {
int res; int res;
if (ctxt->user == NULL) if (ctxt->user == NULL)
#ifndef HAVE_SNPRINTF sprintf(buf, "USER anonymous\r\n");
len = sprintf(buf, "USER anonymous\r\n");
#else /* HAVE_SNPRINTF */
len = snprintf(buf, sizeof(buf), "USER anonymous\r\n");
#endif /* HAVE_SNPRINTF */
else else
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "USER %s\r\n", ctxt->user); snprintf(buf, sizeof(buf), "USER %s\r\n", ctxt->user);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "USER %s\r\n", ctxt->user); sprintf(buf, "USER %s\r\n", ctxt->user);
#endif /* HAVE_SNPRINTF */ #endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -762,17 +760,19 @@ xmlNanoFTPSendPasswd(void *ctx) {
int res; int res;
if (ctxt->passwd == NULL) if (ctxt->passwd == NULL)
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "PASS libxml@%s\r\n", hostname); snprintf(buf, sizeof(buf), "PASS libxml@%s\r\n", hostname);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "PASS libxml@%s\r\n", hostname); sprintf(buf, "PASS libxml@%s\r\n", hostname);
#endif /* HAVE_SNPRINTF */ #endif
else else
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "PASS %s\r\n", ctxt->passwd); snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd); sprintf(buf, "PASS %s\r\n", ctxt->passwd);
#endif /* HAVE_SNPRINTF */ #endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -798,11 +798,8 @@ xmlNanoFTPQuit(void *ctx) {
int len; int len;
int res; int res;
#ifndef HAVE_SNPRINTF sprintf(buf, "QUIT\r\n");
len = sprintf(buf, "QUIT\r\n"); len = strlen(buf);
#else /* HAVE_SNPRINTF */
len = snprintf(buf, sizeof(buf), "QUIT\r\n");
#endif /* HAVE_SNPRINTF */
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -922,11 +919,13 @@ xmlNanoFTPConnect(void *ctx) {
/* /*
* We need proxy auth * We need proxy auth
*/ */
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "USER %s\r\n", proxyUser); snprintf(buf, sizeof(buf), "USER %s\r\n", proxyUser);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "USER %s\r\n", proxyUser); sprintf(buf, "USER %s\r\n", proxyUser);
#endif /* HAVE_SNPRINTF */ #endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -943,19 +942,20 @@ xmlNanoFTPConnect(void *ctx) {
break; break;
case 3: case 3:
if (proxyPasswd != NULL) if (proxyPasswd != NULL)
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "PASS %s\r\n", proxyPasswd); snprintf(buf, sizeof(buf), "PASS %s\r\n", proxyPasswd);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "PASS %s\r\n", proxyPasswd); sprintf(buf, "PASS %s\r\n", proxyPasswd);
#endif /* HAVE_SNPRINTF */ #endif
else else
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "PASS libxml@%s\r\n", snprintf(buf, sizeof(buf), "PASS libxml@%s\r\n",
hostname); hostname);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "PASS libxml@%s\r\n", sprintf(buf, "PASS libxml@%s\r\n", hostname);
hostname); #endif
#endif /* HAVE_SNPRINTF */ buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -993,11 +993,13 @@ xmlNanoFTPConnect(void *ctx) {
/* we will try in seqence */ /* we will try in seqence */
case 1: case 1:
/* Using SITE command */ /* Using SITE command */
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "SITE %s\r\n", ctxt->hostname); snprintf(buf, sizeof(buf), "SITE %s\r\n", ctxt->hostname);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "SITE %s\r\n", ctxt->hostname); sprintf(buf, "SITE %s\r\n", ctxt->hostname);
#endif /* HAVE_SNPRINTF */ #endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -1021,19 +1023,22 @@ xmlNanoFTPConnect(void *ctx) {
case 2: case 2:
/* USER user@host command */ /* USER user@host command */
if (ctxt->user == NULL) if (ctxt->user == NULL)
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "USER anonymous@%s\r\n", snprintf(buf, sizeof(buf), "USER anonymous@%s\r\n",
#else /* HAVE_SNPRINTF */
len = snprintf(buf, sizeof(buf), "USER anonymous@%s\r\n",
#endif /* HAVE_SNPRINTF */
ctxt->hostname); ctxt->hostname);
#else
sprintf(buf, "USER anonymous@%s\r\n", ctxt->hostname);
#endif
else else
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "USER %s@%s\r\n", snprintf(buf, sizeof(buf), "USER %s@%s\r\n",
#else /* HAVE_SNPRINTF */
len = snprintf(buf, sizeof(buf), "USER %s@%s\r\n",
#endif /* HAVE_SNPRINTF */
ctxt->user, ctxt->hostname); ctxt->user, ctxt->hostname);
#else
sprintf(buf, "USER %s@%s\r\n",
ctxt->user, ctxt->hostname);
#endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -1050,17 +1055,19 @@ xmlNanoFTPConnect(void *ctx) {
return(0); return(0);
} }
if (ctxt->passwd == NULL) if (ctxt->passwd == NULL)
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "PASS libxml@%s\r\n", hostname); snprintf(buf, sizeof(buf), "PASS libxml@%s\r\n", hostname);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "PASS libxml@%s\r\n", hostname); sprintf(buf, "PASS libxml@%s\r\n", hostname);
#endif /* HAVE_SNPRINTF */ #endif
else else
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "PASS %s\r\n", ctxt->passwd); snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd); sprintf(buf, "PASS %s\r\n", ctxt->passwd);
#endif /* HAVE_SNPRINTF */ #endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -1195,11 +1202,13 @@ xmlNanoFTPCwd(void *ctx, char *directory) {
* 250 * 250
* 500, 501, 502, 421, 530, 550 * 500, 501, 502, 421, 530, 550
*/ */
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "CWD %s\r\n", directory); snprintf(buf, sizeof(buf), "CWD %s\r\n", directory);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "CWD %s\r\n", directory); sprintf(buf, "CWD %s\r\n", directory);
#endif /* HAVE_SNPRINTF */ #endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -1246,11 +1255,8 @@ xmlNanoFTPGetConnection(void *ctx) {
dataAddr.sin_family = AF_INET; dataAddr.sin_family = AF_INET;
if (ctxt->passive) { if (ctxt->passive) {
#ifndef HAVE_SNPRINTF sprintf(buf, "PASV\r\n");
len = sprintf(buf, "PASV\r\n"); len = strlen(buf);
#else /* HAVE_SNPRINTF */
len = snprintf(buf, sizeof(buf), "PASV\r\n");
#endif /* HAVE_SNPRINTF */
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -1308,16 +1314,17 @@ xmlNanoFTPGetConnection(void *ctx) {
} }
adp = (unsigned char *) &dataAddr.sin_addr; adp = (unsigned char *) &dataAddr.sin_addr;
portp = (unsigned char *) &dataAddr.sin_port; portp = (unsigned char *) &dataAddr.sin_port;
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "PORT %d,%d,%d,%d,%d,%d\r\n", snprintf(buf, sizeof(buf), "PORT %d,%d,%d,%d,%d,%d\r\n",
adp[0] & 0xff, adp[1] & 0xff, adp[2] & 0xff, adp[3] & 0xff, adp[0] & 0xff, adp[1] & 0xff, adp[2] & 0xff, adp[3] & 0xff,
portp[0] & 0xff, portp[1] & 0xff); portp[0] & 0xff, portp[1] & 0xff);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "PORT %d,%d,%d,%d,%d,%d\r\n", sprintf(buf, "PORT %d,%d,%d,%d,%d,%d\r\n",
adp[0] & 0xff, adp[1] & 0xff, adp[2] & 0xff, adp[3] & 0xff, adp[0] & 0xff, adp[1] & 0xff, adp[2] & 0xff, adp[3] & 0xff,
portp[0] & 0xff, portp[1] & 0xff); portp[0] & 0xff, portp[1] & 0xff);
#endif /* HAVE_SNPRINTF */ #endif
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -1538,11 +1545,7 @@ xmlNanoFTPList(void *ctx, ftpListCallback callback, void *userData,
ctxt->dataFd = xmlNanoFTPGetConnection(ctxt); ctxt->dataFd = xmlNanoFTPGetConnection(ctxt);
if (ctxt->dataFd == -1) if (ctxt->dataFd == -1)
return(-1); return(-1);
#ifndef HAVE_SNPRINTF sprintf(buf, "LIST -L\r\n");
len = sprintf(buf, "LIST -L\r\n");
#else /* HAVE_SNPRINTF */
len = snprintf(buf, sizeof(buf), "LIST -L\r\n");
#endif /* HAVE_SNPRINTF */
} else { } else {
if (filename[0] != '/') { if (filename[0] != '/') {
if (xmlNanoFTPCwd(ctxt, ctxt->path) < 1) if (xmlNanoFTPCwd(ctxt, ctxt->path) < 1)
@ -1551,12 +1554,14 @@ xmlNanoFTPList(void *ctx, ftpListCallback callback, void *userData,
ctxt->dataFd = xmlNanoFTPGetConnection(ctxt); ctxt->dataFd = xmlNanoFTPGetConnection(ctxt);
if (ctxt->dataFd == -1) if (ctxt->dataFd == -1)
return(-1); return(-1);
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "LIST -L %s\r\n", filename); snprintf(buf, sizeof(buf), "LIST -L %s\r\n", filename);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "LIST -L %s\r\n", filename); sprintf(buf, "LIST -L %s\r\n", filename);
#endif /* HAVE_SNPRINTF */ #endif
} }
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -1649,11 +1654,8 @@ xmlNanoFTPGetSocket(void *ctx, const char *filename) {
if (ctxt->dataFd == -1) if (ctxt->dataFd == -1)
return(-1); return(-1);
#ifndef HAVE_SNPRINTF sprintf(buf, "TYPE I\r\n");
len = sprintf(buf, "TYPE I\r\n"); len = strlen(buf);
#else /* HAVE_SNPRINTF */
len = snprintf(buf, sizeof(buf), "TYPE I\r\n");
#endif /* HAVE_SNPRINTF */
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif
@ -1668,17 +1670,19 @@ xmlNanoFTPGetSocket(void *ctx, const char *filename) {
return(-res); return(-res);
} }
if (filename == NULL) if (filename == NULL)
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "RETR %s\r\n", ctxt->path); snprintf(buf, sizeof(buf), "RETR %s\r\n", ctxt->path);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "RETR %s\r\n", ctxt->path); sprintf(buf, "RETR %s\r\n", ctxt->path);
#endif /* HAVE_SNPRINTF */ #endif
else else
#ifndef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
len = sprintf(buf, "RETR %s\r\n", filename); snprintf(buf, sizeof(buf), "RETR %s\r\n", filename);
#else /* HAVE_SNPRINTF */ #else
len = snprintf(buf, sizeof(buf), "RETR %s\r\n", filename); sprintf(buf, "RETR %s\r\n", filename);
#endif /* HAVE_SNPRINTF */ #endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP #ifdef DEBUG_FTP
printf(buf); printf(buf);
#endif #endif

View File

@ -772,20 +772,21 @@ retry:
} }
ctxt->fd = ret; ctxt->fd = ret;
if (proxy) { if (proxy) {
#ifdef HAVE_SNPRINTF
if (ctxt->port != 80) if (ctxt->port != 80)
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), snprintf(buf, sizeof(buf),
"GET http://%s:%d%s HTTP/1.0\r\nHost: %s\r\n\r\n", "GET http://%s:%d%s HTTP/1.0\r\nHost: %s\r\n\r\n",
ctxt->hostname, ctxt->port, ctxt->path, ctxt->hostname); ctxt->hostname, ctxt->port, ctxt->path, ctxt->hostname);
else
snprintf(buf, sizeof(buf),"GET http://%s%s HTTP/1.0\r\nHost: %s\r\n\r\n",
ctxt->hostname, ctxt->path, ctxt->hostname);
#else #else
if (ctxt->port != 80)
sprintf(buf, sprintf(buf,
"GET http://%s:%d%s HTTP/1.0\r\nHost: %s\r\n\r\n", "GET http://%s:%d%s HTTP/1.0\r\nHost: %s\r\n\r\n",
ctxt->hostname, ctxt->port, ctxt->path, ctxt->hostname); ctxt->hostname, ctxt->port, ctxt->path, ctxt->hostname);
#endif
else else
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf),"GET http://%s%s HTTP/1.0\r\nHost: %s\r\n\r\n",
ctxt->hostname, ctxt->path, ctxt->hostname);
#else
sprintf(buf, "GET http://%s%s HTTP/1.0\r\nHost: %s\r\n\r\n", sprintf(buf, "GET http://%s%s HTTP/1.0\r\nHost: %s\r\n\r\n",
ctxt->hostname, ctxt->path, ctxt->hostname); ctxt->hostname, ctxt->path, ctxt->hostname);
#endif #endif
@ -810,6 +811,7 @@ retry:
ctxt->path, ctxt->hostname); ctxt->path, ctxt->hostname);
#endif #endif
} }
buf[sizeof(buf) - 1] = 0;
ctxt->outptr = ctxt->out = xmlMemStrdup(buf); ctxt->outptr = ctxt->out = xmlMemStrdup(buf);
ctxt->state = XML_NANO_HTTP_WRITE; ctxt->state = XML_NANO_HTTP_WRITE;
xmlNanoHTTPSend(ctxt); xmlNanoHTTPSend(ctxt);
@ -1073,6 +1075,7 @@ retry:
} }
} }
} }
buf[sizeof(buf) - 1] = 0;
#ifdef DEBUG_HTTP #ifdef DEBUG_HTTP
printf("-> %s", buf); printf("-> %s", buf);
#endif #endif

129
parser.c
View File

@ -16,8 +16,10 @@
#ifdef WIN32 #ifdef WIN32
#include "win32config.h" #include "win32config.h"
#define XML_DIR_SEP '\\'
#else #else
#include "config.h" #include "config.h"
#define XML_DIR_SEP '/'
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -307,6 +309,11 @@ xmlSetFeature(xmlParserCtxtPtr ctxt, const char *name, void *value) {
/* Allocate the Node stack */ /* Allocate the Node stack */
ctxt->vctxt.nodeTab = (xmlNodePtr *) ctxt->vctxt.nodeTab = (xmlNodePtr *)
xmlMalloc(4 * sizeof(xmlNodePtr)); xmlMalloc(4 * sizeof(xmlNodePtr));
if (ctxt->vctxt.nodeTab == NULL) {
ctxt->vctxt.nodeMax = 0;
ctxt->validate = 0;
return(-1);
}
ctxt->vctxt.nodeNr = 0; ctxt->vctxt.nodeNr = 0;
ctxt->vctxt.nodeMax = 4; ctxt->vctxt.nodeMax = 4;
ctxt->vctxt.node = NULL; ctxt->vctxt.node = NULL;
@ -1861,7 +1868,7 @@ xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) {
break; break;
case XML_EXTERNAL_GENERAL_PARSED_ENTITY: case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
case XML_EXTERNAL_PARAMETER_ENTITY: case XML_EXTERNAL_PARAMETER_ENTITY:
return(xmlLoadExternalEntity((char *) entity->SystemID, return(xmlLoadExternalEntity((char *) entity->URI,
(char *) entity->ExternalID, ctxt)); (char *) entity->ExternalID, ctxt));
case XML_INTERNAL_GENERAL_ENTITY: case XML_INTERNAL_GENERAL_ENTITY:
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
@ -1887,7 +1894,7 @@ xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) {
if (input == NULL) { if (input == NULL) {
return(NULL); return(NULL);
} }
input->filename = (char *) entity->SystemID; input->filename = (char *) entity->URI;
input->base = entity->content; input->base = entity->content;
input->cur = entity->content; input->cur = entity->content;
input->length = entity->length; input->length = entity->length;
@ -1939,49 +1946,26 @@ xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) {
xmlParserInputBufferPtr buf; xmlParserInputBufferPtr buf;
xmlParserInputPtr inputStream; xmlParserInputPtr inputStream;
char *directory = NULL; char *directory = NULL;
xmlChar *URI = NULL;
if (xmlParserDebugEntities) if (xmlParserDebugEntities)
fprintf(stderr, "new input from file: %s\n", filename); fprintf(stderr, "new input from file: %s\n", filename);
if (ctxt == NULL) return(NULL); if (ctxt == NULL) return(NULL);
buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE);
if (buf == NULL) {
char name[XML_PARSER_BIG_BUFFER_SIZE];
if ((ctxt->input != NULL) && (ctxt->input->directory != NULL)) {
#ifdef WIN32
sprintf(name, "%s\\%s", ctxt->input->directory, filename);
#else
sprintf(name, "%s/%s", ctxt->input->directory, filename);
#endif
buf = xmlParserInputBufferCreateFilename(name,
XML_CHAR_ENCODING_NONE);
if (buf != NULL)
directory = xmlParserGetDirectory(name);
}
if ((buf == NULL) && (ctxt->directory != NULL)) {
#ifdef WIN32
sprintf(name, "%s\\%s", ctxt->directory, filename);
#else
sprintf(name, "%s/%s", ctxt->directory, filename);
#endif
buf = xmlParserInputBufferCreateFilename(name,
XML_CHAR_ENCODING_NONE);
if (buf != NULL)
directory = xmlParserGetDirectory(name);
}
if (buf == NULL) if (buf == NULL)
return(NULL); return(NULL);
}
if (directory == NULL) URI = xmlStrdup((xmlChar *) filename);
directory = xmlParserGetDirectory(filename); directory = xmlParserGetDirectory(URI);
inputStream = xmlNewInputStream(ctxt); inputStream = xmlNewInputStream(ctxt);
if (inputStream == NULL) { if (inputStream == NULL) {
if (directory != NULL) xmlFree((char *) directory); if (directory != NULL) xmlFree((char *) directory);
if (URI != NULL) xmlFree((char *) URI);
return(NULL); return(NULL);
} }
inputStream->filename = xmlMemStrdup(filename); inputStream->filename = URI;
inputStream->directory = directory; inputStream->directory = directory;
inputStream->buf = buf; inputStream->buf = buf;
@ -2020,6 +2004,13 @@ xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
/* Allocate the Input stack */ /* Allocate the Input stack */
ctxt->inputTab = (xmlParserInputPtr *) xmlMalloc(5 * sizeof(xmlParserInputPtr)); ctxt->inputTab = (xmlParserInputPtr *) xmlMalloc(5 * sizeof(xmlParserInputPtr));
if (ctxt->inputTab == NULL) {
fprintf(stderr, "xmlInitParserCtxt: out of memory\n");
ctxt->inputNr = 0;
ctxt->inputMax = 0;
ctxt->input = NULL;
return;
}
ctxt->inputNr = 0; ctxt->inputNr = 0;
ctxt->inputMax = 5; ctxt->inputMax = 5;
ctxt->input = NULL; ctxt->input = NULL;
@ -2037,18 +2028,57 @@ xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
/* Allocate the Node stack */ /* Allocate the Node stack */
ctxt->nodeTab = (xmlNodePtr *) xmlMalloc(10 * sizeof(xmlNodePtr)); ctxt->nodeTab = (xmlNodePtr *) xmlMalloc(10 * sizeof(xmlNodePtr));
if (ctxt->nodeTab == NULL) {
fprintf(stderr, "xmlInitParserCtxt: out of memory\n");
ctxt->nodeNr = 0;
ctxt->nodeMax = 0;
ctxt->node = NULL;
ctxt->inputNr = 0;
ctxt->inputMax = 0;
ctxt->input = NULL;
return;
}
ctxt->nodeNr = 0; ctxt->nodeNr = 0;
ctxt->nodeMax = 10; ctxt->nodeMax = 10;
ctxt->node = NULL; ctxt->node = NULL;
/* Allocate the Name stack */ /* Allocate the Name stack */
ctxt->nameTab = (xmlChar **) xmlMalloc(10 * sizeof(xmlChar *)); ctxt->nameTab = (xmlChar **) xmlMalloc(10 * sizeof(xmlChar *));
if (ctxt->nameTab == NULL) {
fprintf(stderr, "xmlInitParserCtxt: out of memory\n");
ctxt->nodeNr = 0;
ctxt->nodeMax = 0;
ctxt->node = NULL;
ctxt->inputNr = 0;
ctxt->inputMax = 0;
ctxt->input = NULL;
ctxt->nameNr = 0;
ctxt->nameMax = 0;
ctxt->name = NULL;
return;
}
ctxt->nameNr = 0; ctxt->nameNr = 0;
ctxt->nameMax = 10; ctxt->nameMax = 10;
ctxt->name = NULL; ctxt->name = NULL;
/* Allocate the space stack */ /* Allocate the space stack */
ctxt->spaceTab = (int *) xmlMalloc(10 * sizeof(int)); ctxt->spaceTab = (int *) xmlMalloc(10 * sizeof(int));
if (ctxt->spaceTab == NULL) {
fprintf(stderr, "xmlInitParserCtxt: out of memory\n");
ctxt->nodeNr = 0;
ctxt->nodeMax = 0;
ctxt->node = NULL;
ctxt->inputNr = 0;
ctxt->inputMax = 0;
ctxt->input = NULL;
ctxt->nameNr = 0;
ctxt->nameMax = 0;
ctxt->name = NULL;
ctxt->spaceNr = 0;
ctxt->spaceMax = 0;
ctxt->space = NULL;
return;
}
ctxt->spaceNr = 1; ctxt->spaceNr = 1;
ctxt->spaceMax = 10; ctxt->spaceMax = 10;
ctxt->spaceTab[0] = -1; ctxt->spaceTab[0] = -1;
@ -2076,9 +2106,17 @@ xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
ctxt->vctxt.warning = xmlParserValidityWarning; ctxt->vctxt.warning = xmlParserValidityWarning;
/* Allocate the Node stack */ /* Allocate the Node stack */
ctxt->vctxt.nodeTab = (xmlNodePtr *) xmlMalloc(4 * sizeof(xmlNodePtr)); ctxt->vctxt.nodeTab = (xmlNodePtr *) xmlMalloc(4 * sizeof(xmlNodePtr));
if (ctxt->vctxt.nodeTab == NULL) {
fprintf(stderr, "xmlInitParserCtxt: out of memory\n");
ctxt->vctxt.nodeMax = 0;
ctxt->validate = 0;
ctxt->vctxt.error = NULL;
ctxt->vctxt.warning = NULL;
} else {
ctxt->vctxt.nodeNr = 0; ctxt->vctxt.nodeNr = 0;
ctxt->vctxt.nodeMax = 4; ctxt->vctxt.nodeMax = 4;
ctxt->vctxt.node = NULL; ctxt->vctxt.node = NULL;
}
} else { } else {
ctxt->vctxt.error = NULL; ctxt->vctxt.error = NULL;
ctxt->vctxt.warning = NULL; ctxt->vctxt.warning = NULL;
@ -5861,7 +5899,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
* handle the various case of definitions... * handle the various case of definitions...
*/ */
if (isParameter) { if (isParameter) {
if ((RAW == '"') || (RAW == '\'')) if ((RAW == '"') || (RAW == '\'')) {
value = xmlParseEntityValue(ctxt, &orig); value = xmlParseEntityValue(ctxt, &orig);
if (value) { if (value) {
if ((ctxt->sax != NULL) && if ((ctxt->sax != NULL) &&
@ -5870,7 +5908,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
XML_INTERNAL_PARAMETER_ENTITY, XML_INTERNAL_PARAMETER_ENTITY,
NULL, NULL, value); NULL, NULL, value);
} }
else { } else {
URI = xmlParseExternalID(ctxt, &literal, 1); URI = xmlParseExternalID(ctxt, &literal, 1);
if ((URI == NULL) && (literal == NULL)) { if ((URI == NULL) && (literal == NULL)) {
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
@ -7648,7 +7686,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
ctxt->depth++; ctxt->depth++;
ret = xmlParseExternalEntity(ctxt->myDoc, ret = xmlParseExternalEntity(ctxt->myDoc,
ctxt->sax, NULL, ctxt->depth, ctxt->sax, NULL, ctxt->depth,
ent->SystemID, ent->ExternalID, &list); ent->URI, ent->ExternalID, &list);
ctxt->depth--; ctxt->depth--;
} else { } else {
ret = -1; ret = -1;
@ -11004,6 +11042,7 @@ xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
* @cur: a pointer to an array of xmlChar * @cur: a pointer to an array of xmlChar
* *
* Creates a parser context for an XML in-memory document. * Creates a parser context for an XML in-memory document.
* TODO: buggy need to be converted to new I/O functions ....
* *
* Returns the new parser context or NULL * Returns the new parser context or NULL
*/ */
@ -11298,7 +11337,7 @@ xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const xmlChar *URL,
return(-1); return(-1);
ctxt = xmlCreateEntityParserCtxt(URL, ID, ctx->myDoc->URL); ctxt = xmlCreateEntityParserCtxt(URL, ID, NULL);
if (ctxt == NULL) return(-1); if (ctxt == NULL) return(-1);
ctxt->userData = ctxt; ctxt->userData = ctxt;
oldsax = ctxt->sax; oldsax = ctxt->sax;
@ -11354,9 +11393,16 @@ xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const xmlChar *URL,
ctxt->vctxt.warning = ctx->vctxt.warning; ctxt->vctxt.warning = ctx->vctxt.warning;
/* Allocate the Node stack */ /* Allocate the Node stack */
ctxt->vctxt.nodeTab = (xmlNodePtr *) xmlMalloc(4 * sizeof(xmlNodePtr)); ctxt->vctxt.nodeTab = (xmlNodePtr *) xmlMalloc(4 * sizeof(xmlNodePtr));
if (ctxt->vctxt.nodeTab == NULL) {
fprintf(stderr, "xmlParseCtxtExternalEntity: out of memory\n");
ctxt->validate = 0;
ctxt->vctxt.error = NULL;
ctxt->vctxt.warning = NULL;
} else {
ctxt->vctxt.nodeNr = 0; ctxt->vctxt.nodeNr = 0;
ctxt->vctxt.nodeMax = 4; ctxt->vctxt.nodeMax = 4;
ctxt->vctxt.node = NULL; ctxt->vctxt.node = NULL;
}
} else { } else {
ctxt->vctxt.error = NULL; ctxt->vctxt.error = NULL;
ctxt->vctxt.warning = NULL; ctxt->vctxt.warning = NULL;
@ -11462,7 +11508,7 @@ xmlParseExternalEntity(xmlDocPtr doc, xmlSAXHandlerPtr sax, void *user_data,
return(-1); return(-1);
ctxt = xmlCreateEntityParserCtxt(URL, ID, doc->URL); ctxt = xmlCreateEntityParserCtxt(URL, ID, NULL);
if (ctxt == NULL) return(-1); if (ctxt == NULL) return(-1);
ctxt->userData = ctxt; ctxt->userData = ctxt;
if (sax != NULL) { if (sax != NULL) {
@ -11829,10 +11875,15 @@ xmlCreateFileParserCtxt(const char *filename)
char *directory = NULL; char *directory = NULL;
buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE);
if (buf == NULL) return(NULL); if (buf == NULL) {
return(NULL);
}
ctxt = xmlNewParserCtxt(); ctxt = xmlNewParserCtxt();
if (ctxt == NULL) { if (ctxt == NULL) {
if (xmlDefaultSAXHandler.error != NULL) {
xmlDefaultSAXHandler.error(NULL, "out of memory\n");
}
return(NULL); return(NULL);
} }
@ -11879,7 +11930,9 @@ xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename,
char *directory = NULL; char *directory = NULL;
ctxt = xmlCreateFileParserCtxt(filename); ctxt = xmlCreateFileParserCtxt(filename);
if (ctxt == NULL) return(NULL); if (ctxt == NULL) {
return(NULL);
}
if (sax != NULL) { if (sax != NULL) {
if (ctxt->sax != NULL) if (ctxt->sax != NULL)
xmlFree(ctxt->sax); xmlFree(ctxt->sax);

View File

@ -1,3 +1,3 @@
dtds/doc.dtd:2: validity error: Element doc has ID attributes defined in the internal and external subset : val ./test/VC/dtds/doc.dtd:2: validity error: Element doc has ID attributes defined in the internal and external subset : val
<!ATTLIST doc val ID #IMPLIED> <!ATTLIST doc val ID #IMPLIED>
^ ^

View File

@ -1,3 +1,3 @@
dtds/a.dtd:1: validity error: Redefinition of element a ./test/VC/dtds/a.dtd:1: validity error: Redefinition of element a
<!ELEMENT a (#PCDATA | b | c)*> <!ELEMENT a (#PCDATA | b | c)*>
^ ^

9
tree.c
View File

@ -2634,12 +2634,12 @@ xmlNodeSetLang(xmlNodePtr cur, const xmlChar *lang) {
case XML_ELEMENT_DECL: case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL: case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL: case XML_ENTITY_DECL:
return;
case XML_ELEMENT_NODE:
case XML_ATTRIBUTE_NODE:
case XML_PI_NODE: case XML_PI_NODE:
case XML_ENTITY_REF_NODE: case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE: case XML_ENTITY_NODE:
return;
case XML_ELEMENT_NODE:
case XML_ATTRIBUTE_NODE:
break; break;
} }
xmlSetProp(cur, BAD_CAST "xml:lang", lang); xmlSetProp(cur, BAD_CAST "xml:lang", lang);
@ -2757,6 +2757,9 @@ xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) {
if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) {
cur = doc->children; cur = doc->children;
while ((cur != NULL) && (cur->name != NULL)) { while ((cur != NULL) && (cur->name != NULL)) {
if (cur->type == XML_ENTITY_DECL) {
/* TODO: we are crossing entity boundaries */
}
if (cur->type != XML_ELEMENT_NODE) { if (cur->type != XML_ELEMENT_NODE) {
cur = cur->next; cur = cur->next;
continue; continue;

5
tree.h
View File

@ -41,7 +41,12 @@ typedef enum {
XML_DTD_NODE= 14, XML_DTD_NODE= 14,
XML_ELEMENT_DECL= 15, XML_ELEMENT_DECL= 15,
XML_ATTRIBUTE_DECL= 16, XML_ATTRIBUTE_DECL= 16,
#ifdef LIBXML_SGML_ENABLED
XML_ENTITY_DECL= 17,
XML_SGML_DOCUMENT_NODE= 18
#else
XML_ENTITY_DECL= 17 XML_ENTITY_DECL= 17
#endif
} xmlElementType; } xmlElementType;
/* /*

6
uri.c
View File

@ -1637,8 +1637,8 @@ xmlBuildURI(const xmlChar *URI, const xmlChar *base) {
/* /*
* Ensure the path includes a '/' * Ensure the path includes a '/'
*/ */
if (res->path[0] != '/' && ref->path[0] != 0 && if ((out >0) && (res->path[out -1] != '/') &&
ref->path[index] != '/') { (ref->path[0] != 0) && (ref->path[index] != '/')) {
res->path[out++] = '/'; res->path[out++] = '/';
} }
while (ref->path[index] != 0) { while (ref->path[index] != 0) {
@ -1664,7 +1664,7 @@ step_7:
done: done:
if (ref != NULL) if (ref != NULL)
xmlFreeURI(ref); xmlFreeURI(ref);
if (base != NULL) if (bas != NULL)
xmlFreeURI(bas); xmlFreeURI(bas);
if (res != NULL) if (res != NULL)
xmlFreeURI(res); xmlFreeURI(res);

13
valid.c
View File

@ -2856,8 +2856,9 @@ xmlValidNormalizeAttributeValue(xmlDocPtr doc, xmlNodePtr elem,
snprintf((char *) qname, sizeof(qname), "%s:%s", snprintf((char *) qname, sizeof(qname), "%s:%s",
elem->ns->prefix, elem->name); elem->ns->prefix, elem->name);
#else #else
sprintf(qname, "%s:%s", elem->name, elem->ns->prefix); sprintf((char *) qname, "%s:%s", elem->ns->prefix, elem->name);
#endif #endif
qname[sizeof(qname) - 1] = 0;
attrDecl = xmlGetDtdAttrDesc(doc->intSubset, qname, name); attrDecl = xmlGetDtdAttrDesc(doc->intSubset, qname, name);
if ((attrDecl == NULL) && (doc->extSubset != NULL)) if ((attrDecl == NULL) && (doc->extSubset != NULL))
attrDecl = xmlGetDtdAttrDesc(doc->extSubset, qname, name); attrDecl = xmlGetDtdAttrDesc(doc->extSubset, qname, name);
@ -3133,8 +3134,9 @@ xmlValidateOneAttribute(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
snprintf((char *) qname, sizeof(qname), "%s:%s", snprintf((char *) qname, sizeof(qname), "%s:%s",
elem->ns->prefix, elem->name); elem->ns->prefix, elem->name);
#else #else
sprintf(qname, "%s:%s", elem->name, elem->ns->prefix); sprintf((char *) qname, "%s:%s", elem->ns->prefix, elem->name);
#endif #endif
qname[sizeof(qname) - 1] = 0;
if (attr->ns != NULL) { if (attr->ns != NULL) {
attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, qname, attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, qname,
attr->name, attr->ns->prefix); attr->name, attr->ns->prefix);
@ -3699,8 +3701,10 @@ xmlValidateOneElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
snprintf((char *) qname, sizeof(qname), "%s:%s", snprintf((char *) qname, sizeof(qname), "%s:%s",
child->ns->prefix, child->name); child->ns->prefix, child->name);
#else #else
sprintf(qname, "%s:%s", child->name, child->ns->prefix); sprintf((char *) qname, "%s:%s",
child->ns->prefix, child->name);
#endif #endif
qname[sizeof(qname) - 1] = 0;
cont = elemDecl->content; cont = elemDecl->content;
while (cont != NULL) { while (cont != NULL) {
if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) {
@ -3876,8 +3880,9 @@ xmlValidateRoot(xmlValidCtxtPtr ctxt, xmlDocPtr doc) {
snprintf((char *) qname, sizeof(qname), "%s:%s", snprintf((char *) qname, sizeof(qname), "%s:%s",
root->ns->prefix, root->name); root->ns->prefix, root->name);
#else #else
sprintf(qname, "%s:%s", root->name, root->ns->prefix); sprintf((char *) qname, "%s:%s", root->ns->prefix, root->name);
#endif #endif
qname[sizeof(qname) - 1] = 0;
if (!xmlStrcmp(doc->intSubset->name, qname)) if (!xmlStrcmp(doc->intSubset->name, qname))
goto name_ok; goto name_ok;
} }

View File

@ -873,9 +873,6 @@ xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {
} }
} }
if (context == NULL) { if (context == NULL) {
#ifdef DEBUG_INPUT
fprintf(stderr, "No input filter matching \"%s\"\n", URI);
#endif
return(NULL); return(NULL);
} }
@ -947,9 +944,6 @@ xmlOutputBufferCreateFilename(const char *URI,
} }
} }
if (context == NULL) { if (context == NULL) {
#ifdef DEBUG_INPUT
fprintf(stderr, "No output filter matching \"%s\"\n", URI);
#endif
return(NULL); return(NULL);
} }
@ -1533,6 +1527,7 @@ xmlParserInputPtr
xmlDefaultExternalEntityLoader(const char *URL, const char *ID, xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
xmlParserCtxtPtr ctxt) { xmlParserCtxtPtr ctxt) {
xmlParserInputPtr ret = NULL; xmlParserInputPtr ret = NULL;
#ifdef DEBUG_EXTERNAL_ENTITIES #ifdef DEBUG_EXTERNAL_ENTITIES
fprintf(stderr, "xmlDefaultExternalEntityLoader(%s, xxx)\n", URL); fprintf(stderr, "xmlDefaultExternalEntityLoader(%s, xxx)\n", URL);
#endif #endif

View File

@ -37,7 +37,7 @@ struct _xmlParserInputBuffer {
xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */ xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */
xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 or ISOLatin */ xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 */
xmlBufferPtr raw; /* if encoder != NULL buffer for raw input */ xmlBufferPtr raw; /* if encoder != NULL buffer for raw input */
}; };

View File

@ -49,6 +49,15 @@ extern void xmlCheckVersion(int version);
#define LIBXML_HTML_DISABLED #define LIBXML_HTML_DISABLED
#endif #endif
/*
* Whether the Docbook support is configured in
#if @WITH_SGML@
#define LIBXML_SGML_ENABLED
#else
#define LIBXML_SGML_DISABLED
#endif
*/
/* /*
* Whether XPath is configured in * Whether XPath is configured in
*/ */

View File

@ -2417,9 +2417,16 @@ xmlXPathNameFunction(xmlXPathParserContextPtr ctxt, int nargs) {
else { else {
char name[2000]; char name[2000];
#ifdef HAVE_SNPRINTF
snprintf(name, sizeof(name), "%s:%s",
(char *) cur->nodesetval->nodeTab[i]->ns->prefix,
(char *) cur->nodesetval->nodeTab[i]->name);
#else
sprintf(name, "%s:%s", sprintf(name, "%s:%s",
(char *) cur->nodesetval->nodeTab[i]->ns->prefix, (char *) cur->nodesetval->nodeTab[i]->ns->prefix,
(char *) cur->nodesetval->nodeTab[i]->name); (char *) cur->nodesetval->nodeTab[i]->name);
#endif
name[sizeof(name) - 1] = 0;
valuePush(ctxt, xmlXPathNewCString(name)); valuePush(ctxt, xmlXPathNewCString(name));
} }
} }