aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--HTMLparser.c3
-rw-r--r--valid.c128
-rw-r--r--xmlregexp.c1
4 files changed, 126 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 5fc261a6..6e36738a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* python/libxml_wrap.h: stupid bug found by mattam@netcourrier.com
diff --git a/HTMLparser.c b/HTMLparser.c
index 5f078d6a..7200a3b1 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -4881,7 +4881,8 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding)
}
memset(inputStream, 0, sizeof(htmlParserInput));
- inputStream->filename = xmlNormalizeWindowsPath(filename);
+ inputStream->filename = (char *)
+ xmlNormalizeWindowsPath((xmlChar *)filename);
inputStream->line = 1;
inputStream->col = 1;
inputStream->buf = buf;
diff --git a/valid.c b/valid.c
index adab5afc..03b97c4a 100644
--- a/valid.c
+++ b/valid.c
@@ -27,6 +27,10 @@
/* #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
*/
@@ -385,27 +389,49 @@ xmlValidBuildAContentModel(xmlElementContentPtr content,
break;
case XML_ELEMENT_CONTENT_ELEMENT: {
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) {
case XML_ELEMENT_CONTENT_ONCE:
ctxt->state = xmlAutomataNewTransition(ctxt->am,
- ctxt->state, NULL, content->name, NULL);
+ ctxt->state, NULL, fname, NULL);
break;
case XML_ELEMENT_CONTENT_OPT:
ctxt->state = xmlAutomataNewTransition(ctxt->am,
- ctxt->state, NULL, content->name, NULL);
+ ctxt->state, NULL, fname, NULL);
xmlAutomataNewEpsilon(ctxt->am, oldstate, ctxt->state);
break;
case XML_ELEMENT_CONTENT_PLUS:
ctxt->state = xmlAutomataNewTransition(ctxt->am,
- ctxt->state, NULL, content->name, NULL);
+ ctxt->state, NULL, fname, NULL);
xmlAutomataNewTransition(ctxt->am, ctxt->state,
- ctxt->state, content->name, NULL);
+ ctxt->state, fname, NULL);
break;
case XML_ELEMENT_CONTENT_MULT:
xmlAutomataNewTransition(ctxt->am, ctxt->state,
- ctxt->state, content->name, NULL);
+ ctxt->state, fname, NULL);
break;
}
+ if (QName != NULL)
+ xmlFree(QName);
break;
}
case XML_ELEMENT_CONTENT_SEQ: {
@@ -417,11 +443,12 @@ xmlValidBuildAContentModel(xmlElementContentPtr content,
*/
oldstate = ctxt->state;
ocur = content->ocur;
- while (content->type == XML_ELEMENT_CONTENT_SEQ) {
+ do {
xmlValidBuildAContentModel(content->c1, ctxt, name);
content = content->c2;
- }
- xmlValidBuildAContentModel(content->c2, ctxt, name);
+ } while ((content->type == XML_ELEMENT_CONTENT_SEQ) &&
+ (content->ocur == XML_ELEMENT_CONTENT_ONCE));
+ xmlValidBuildAContentModel(content, ctxt, name);
switch (ocur) {
case XML_ELEMENT_CONTENT_ONCE:
break;
@@ -450,14 +477,15 @@ xmlValidBuildAContentModel(xmlElementContentPtr content,
* iterate over the subtypes and remerge the end with an
* epsilon transition
*/
- while (content->type == XML_ELEMENT_CONTENT_OR) {
+ do {
ctxt->state = start;
xmlValidBuildAContentModel(content->c1, ctxt, name);
xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end);
content = content->c2;
- }
+ } while ((content->type == XML_ELEMENT_CONTENT_OR) &&
+ (content->ocur == XML_ELEMENT_CONTENT_ONCE));
ctxt->state = start;
- xmlValidBuildAContentModel(content->c1, ctxt, name);
+ xmlValidBuildAContentModel(content, ctxt, name);
xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end);
ctxt->state = end;
switch (ocur) {
@@ -4280,6 +4308,82 @@ xmlValidateElementContent(xmlValidCtxtPtr ctxt, xmlNodePtr child,
cont = elemDecl->content;
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
*/
@@ -4395,6 +4499,7 @@ xmlValidateElementContent(xmlValidCtxtPtr ctxt, xmlNodePtr child,
STATE = 0;
ret = xmlValidateElementType(ctxt);
}
+#endif /* LIBXML_REGEXP_ENABLED */
if ((warn) && ((ret != 1) && (ret != -3))) {
if ((ctxt != NULL) && (ctxt->warning != NULL)) {
char expr[5000];
@@ -4436,7 +4541,6 @@ xmlValidateElementContent(xmlValidCtxtPtr ctxt, xmlNodePtr child,
if (ret == -3)
ret = 1;
-
done:
/*
* Deallocate the copy if done, and free up the validation stack
diff --git a/xmlregexp.c b/xmlregexp.c
index d613d4ce..8ff73852 100644
--- a/xmlregexp.c
+++ b/xmlregexp.c
@@ -161,6 +161,7 @@ struct _xmlRegAtom {
int max;
void *valuep;
+ void *valuep2;
int neg;
int codepoint;
xmlRegStatePtr start;