mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-28 00:21:53 +03:00
small cleanup switched DTD validation to use only regexp when configured
* HTMLparser.c: small cleanup * valid.c xmlregexp.c: switched DTD validation to use only regexp when configured with them. A bit of debugging around the determinism checks is still needed Daniel
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
Tue Sep 17 23:48:07 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* HTMLparser.c: small cleanup
|
||||||
|
* valid.c xmlregexp.c: switched DTD validation to use only regexp
|
||||||
|
when configured with them. A bit of debugging around the determinism
|
||||||
|
checks is still needed
|
||||||
|
|
||||||
Tue Sep 17 21:22:25 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
Tue Sep 17 21:22:25 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* python/libxml_wrap.h: stupid bug found by mattam@netcourrier.com
|
* python/libxml_wrap.h: stupid bug found by mattam@netcourrier.com
|
||||||
|
@ -4881,7 +4881,8 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding)
|
|||||||
}
|
}
|
||||||
memset(inputStream, 0, sizeof(htmlParserInput));
|
memset(inputStream, 0, sizeof(htmlParserInput));
|
||||||
|
|
||||||
inputStream->filename = xmlNormalizeWindowsPath(filename);
|
inputStream->filename = (char *)
|
||||||
|
xmlNormalizeWindowsPath((xmlChar *)filename);
|
||||||
inputStream->line = 1;
|
inputStream->line = 1;
|
||||||
inputStream->col = 1;
|
inputStream->col = 1;
|
||||||
inputStream->buf = buf;
|
inputStream->buf = buf;
|
||||||
|
128
valid.c
128
valid.c
@ -27,6 +27,10 @@
|
|||||||
|
|
||||||
/* #define DEBUG_VALID_ALGO */
|
/* #define DEBUG_VALID_ALGO */
|
||||||
|
|
||||||
|
#define TODO \
|
||||||
|
xmlGenericError(xmlGenericErrorContext, \
|
||||||
|
"Unimplemented block at %s:%d\n", \
|
||||||
|
__FILE__, __LINE__);
|
||||||
/*
|
/*
|
||||||
* Generic function for accessing stacks in the Validity Context
|
* Generic function for accessing stacks in the Validity Context
|
||||||
*/
|
*/
|
||||||
@ -385,27 +389,49 @@ xmlValidBuildAContentModel(xmlElementContentPtr content,
|
|||||||
break;
|
break;
|
||||||
case XML_ELEMENT_CONTENT_ELEMENT: {
|
case XML_ELEMENT_CONTENT_ELEMENT: {
|
||||||
xmlAutomataStatePtr oldstate = ctxt->state;
|
xmlAutomataStatePtr oldstate = ctxt->state;
|
||||||
|
xmlChar *QName = NULL;
|
||||||
|
const xmlChar *fname = content->name;
|
||||||
|
|
||||||
|
if (content->prefix != NULL) {
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = xmlStrlen(content->name) +
|
||||||
|
xmlStrlen(content->prefix) + 2;
|
||||||
|
QName = xmlMalloc(len);
|
||||||
|
if (QName == NULL) {
|
||||||
|
VERROR(ctxt->userData,
|
||||||
|
"ContentModel %s : alloc failed\n", name);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
snprintf((char *) QName, len, "%s:%s",
|
||||||
|
(char *)content->prefix,
|
||||||
|
(char *)content->name);
|
||||||
|
fname = QName;
|
||||||
|
}
|
||||||
|
|
||||||
switch (content->ocur) {
|
switch (content->ocur) {
|
||||||
case XML_ELEMENT_CONTENT_ONCE:
|
case XML_ELEMENT_CONTENT_ONCE:
|
||||||
ctxt->state = xmlAutomataNewTransition(ctxt->am,
|
ctxt->state = xmlAutomataNewTransition(ctxt->am,
|
||||||
ctxt->state, NULL, content->name, NULL);
|
ctxt->state, NULL, fname, NULL);
|
||||||
break;
|
break;
|
||||||
case XML_ELEMENT_CONTENT_OPT:
|
case XML_ELEMENT_CONTENT_OPT:
|
||||||
ctxt->state = xmlAutomataNewTransition(ctxt->am,
|
ctxt->state = xmlAutomataNewTransition(ctxt->am,
|
||||||
ctxt->state, NULL, content->name, NULL);
|
ctxt->state, NULL, fname, NULL);
|
||||||
xmlAutomataNewEpsilon(ctxt->am, oldstate, ctxt->state);
|
xmlAutomataNewEpsilon(ctxt->am, oldstate, ctxt->state);
|
||||||
break;
|
break;
|
||||||
case XML_ELEMENT_CONTENT_PLUS:
|
case XML_ELEMENT_CONTENT_PLUS:
|
||||||
ctxt->state = xmlAutomataNewTransition(ctxt->am,
|
ctxt->state = xmlAutomataNewTransition(ctxt->am,
|
||||||
ctxt->state, NULL, content->name, NULL);
|
ctxt->state, NULL, fname, NULL);
|
||||||
xmlAutomataNewTransition(ctxt->am, ctxt->state,
|
xmlAutomataNewTransition(ctxt->am, ctxt->state,
|
||||||
ctxt->state, content->name, NULL);
|
ctxt->state, fname, NULL);
|
||||||
break;
|
break;
|
||||||
case XML_ELEMENT_CONTENT_MULT:
|
case XML_ELEMENT_CONTENT_MULT:
|
||||||
xmlAutomataNewTransition(ctxt->am, ctxt->state,
|
xmlAutomataNewTransition(ctxt->am, ctxt->state,
|
||||||
ctxt->state, content->name, NULL);
|
ctxt->state, fname, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (QName != NULL)
|
||||||
|
xmlFree(QName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case XML_ELEMENT_CONTENT_SEQ: {
|
case XML_ELEMENT_CONTENT_SEQ: {
|
||||||
@ -417,11 +443,12 @@ xmlValidBuildAContentModel(xmlElementContentPtr content,
|
|||||||
*/
|
*/
|
||||||
oldstate = ctxt->state;
|
oldstate = ctxt->state;
|
||||||
ocur = content->ocur;
|
ocur = content->ocur;
|
||||||
while (content->type == XML_ELEMENT_CONTENT_SEQ) {
|
do {
|
||||||
xmlValidBuildAContentModel(content->c1, ctxt, name);
|
xmlValidBuildAContentModel(content->c1, ctxt, name);
|
||||||
content = content->c2;
|
content = content->c2;
|
||||||
}
|
} while ((content->type == XML_ELEMENT_CONTENT_SEQ) &&
|
||||||
xmlValidBuildAContentModel(content->c2, ctxt, name);
|
(content->ocur == XML_ELEMENT_CONTENT_ONCE));
|
||||||
|
xmlValidBuildAContentModel(content, ctxt, name);
|
||||||
switch (ocur) {
|
switch (ocur) {
|
||||||
case XML_ELEMENT_CONTENT_ONCE:
|
case XML_ELEMENT_CONTENT_ONCE:
|
||||||
break;
|
break;
|
||||||
@ -450,14 +477,15 @@ xmlValidBuildAContentModel(xmlElementContentPtr content,
|
|||||||
* iterate over the subtypes and remerge the end with an
|
* iterate over the subtypes and remerge the end with an
|
||||||
* epsilon transition
|
* epsilon transition
|
||||||
*/
|
*/
|
||||||
while (content->type == XML_ELEMENT_CONTENT_OR) {
|
do {
|
||||||
ctxt->state = start;
|
ctxt->state = start;
|
||||||
xmlValidBuildAContentModel(content->c1, ctxt, name);
|
xmlValidBuildAContentModel(content->c1, ctxt, name);
|
||||||
xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end);
|
xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end);
|
||||||
content = content->c2;
|
content = content->c2;
|
||||||
}
|
} while ((content->type == XML_ELEMENT_CONTENT_OR) &&
|
||||||
|
(content->ocur == XML_ELEMENT_CONTENT_ONCE));
|
||||||
ctxt->state = start;
|
ctxt->state = start;
|
||||||
xmlValidBuildAContentModel(content->c1, ctxt, name);
|
xmlValidBuildAContentModel(content, ctxt, name);
|
||||||
xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end);
|
xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end);
|
||||||
ctxt->state = end;
|
ctxt->state = end;
|
||||||
switch (ocur) {
|
switch (ocur) {
|
||||||
@ -4280,6 +4308,82 @@ xmlValidateElementContent(xmlValidCtxtPtr ctxt, xmlNodePtr child,
|
|||||||
cont = elemDecl->content;
|
cont = elemDecl->content;
|
||||||
name = elemDecl->name;
|
name = elemDecl->name;
|
||||||
|
|
||||||
|
#ifdef LIBXML_REGEXP_ENABLED
|
||||||
|
/* Build the regexp associated to the content model */
|
||||||
|
if (elemDecl->contModel == NULL)
|
||||||
|
ret = xmlValidBuildContentModel(ctxt, elemDecl);
|
||||||
|
if (elemDecl->contModel == NULL) {
|
||||||
|
ret = -1;
|
||||||
|
} else {
|
||||||
|
xmlRegExecCtxtPtr exec;
|
||||||
|
|
||||||
|
exec = xmlRegNewExecCtxt(elemDecl->contModel, NULL, NULL);
|
||||||
|
if (exec != NULL) {
|
||||||
|
cur = child;
|
||||||
|
while (cur != NULL) {
|
||||||
|
switch (cur->type) {
|
||||||
|
case XML_ENTITY_REF_NODE:
|
||||||
|
/*
|
||||||
|
* Push the current node to be able to roll back
|
||||||
|
* and process within the entity
|
||||||
|
*/
|
||||||
|
if ((cur->children != NULL) &&
|
||||||
|
(cur->children->children != NULL)) {
|
||||||
|
nodeVPush(ctxt, cur);
|
||||||
|
cur = cur->children->children;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case XML_TEXT_NODE:
|
||||||
|
if (xmlIsBlankNode(cur))
|
||||||
|
break;
|
||||||
|
ret = 0;
|
||||||
|
goto fail;
|
||||||
|
case XML_CDATA_SECTION_NODE:
|
||||||
|
TODO
|
||||||
|
ret = 0;
|
||||||
|
goto fail;
|
||||||
|
case XML_ELEMENT_NODE:
|
||||||
|
if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) {
|
||||||
|
xmlChar *QName;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = xmlStrlen(cur->name) +
|
||||||
|
xmlStrlen(cur->ns->prefix) + 2;
|
||||||
|
QName = xmlMalloc(len);
|
||||||
|
if (QName == NULL) {
|
||||||
|
ret = -1;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
snprintf((char *) QName, len, "%s:%s",
|
||||||
|
(char *)cur->ns->prefix,
|
||||||
|
(char *)cur->name);
|
||||||
|
ret = xmlRegExecPushString(exec, QName, NULL);
|
||||||
|
xmlFree(QName);
|
||||||
|
} else {
|
||||||
|
ret = xmlRegExecPushString(exec, cur->name, NULL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Switch to next element
|
||||||
|
*/
|
||||||
|
cur = cur->next;
|
||||||
|
while (cur == NULL) {
|
||||||
|
cur = nodeVPop(ctxt);
|
||||||
|
if (cur == NULL)
|
||||||
|
break;
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret = xmlRegExecPushString(exec, NULL, NULL);
|
||||||
|
fail:
|
||||||
|
xmlRegFreeExecCtxt(exec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else /* LIBXML_REGEXP_ENABLED */
|
||||||
/*
|
/*
|
||||||
* Allocate the stack
|
* Allocate the stack
|
||||||
*/
|
*/
|
||||||
@ -4395,6 +4499,7 @@ xmlValidateElementContent(xmlValidCtxtPtr ctxt, xmlNodePtr child,
|
|||||||
STATE = 0;
|
STATE = 0;
|
||||||
ret = xmlValidateElementType(ctxt);
|
ret = xmlValidateElementType(ctxt);
|
||||||
}
|
}
|
||||||
|
#endif /* LIBXML_REGEXP_ENABLED */
|
||||||
if ((warn) && ((ret != 1) && (ret != -3))) {
|
if ((warn) && ((ret != 1) && (ret != -3))) {
|
||||||
if ((ctxt != NULL) && (ctxt->warning != NULL)) {
|
if ((ctxt != NULL) && (ctxt->warning != NULL)) {
|
||||||
char expr[5000];
|
char expr[5000];
|
||||||
@ -4436,7 +4541,6 @@ xmlValidateElementContent(xmlValidCtxtPtr ctxt, xmlNodePtr child,
|
|||||||
if (ret == -3)
|
if (ret == -3)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
|
|
||||||
done:
|
done:
|
||||||
/*
|
/*
|
||||||
* Deallocate the copy if done, and free up the validation stack
|
* Deallocate the copy if done, and free up the validation stack
|
||||||
|
@ -161,6 +161,7 @@ struct _xmlRegAtom {
|
|||||||
int max;
|
int max;
|
||||||
|
|
||||||
void *valuep;
|
void *valuep;
|
||||||
|
void *valuep2;
|
||||||
int neg;
|
int neg;
|
||||||
int codepoint;
|
int codepoint;
|
||||||
xmlRegStatePtr start;
|
xmlRegStatePtr start;
|
||||||
|
Reference in New Issue
Block a user