#endif
#define UNBOUNDED (1 << 30)
-#define TODO \
+#define TODO \
xmlGenericError(xmlGenericErrorContext, \
"Unimplemented block at %s:%d\n", \
__FILE__, __LINE__);
xmlSAXHandlerPtr sax;
xmlParserCtxtPtr parserCtxt;
void *user_data; /* TODO: What is this for? */
+ char *filename;
int err;
int nberrors;
int hasKeyrefs;
int createIDCNodeTables;
int psviExposeIDCNodeTables;
+
+ /* Locator for error reporting in streaming mode */
+ xmlSchemaValidityLocatorFunc locFunc;
+ void *locCtxt;
};
/**
};
/************************************************************************
- * *
- * Some predeclarations *
- * *
+ * *
+ * Some predeclarations *
+ * *
************************************************************************/
static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt,
/************************************************************************
* *
- * Helper functions *
+ * Helper functions *
* *
************************************************************************/
/************************************************************************
* *
- * Error functions *
+ * Error functions *
* *
************************************************************************/
/************************************************************************
* *
- * Allround error functions *
+ * Allround error functions *
* *
************************************************************************/
(vctxt->parserCtxt->input != NULL))
file = vctxt->parserCtxt->input->filename;
}
+ if (vctxt->locFunc != NULL) {
+ if ((file == NULL) || (line == 0)) {
+ unsigned long l;
+ const char *f;
+ vctxt->locFunc(vctxt->locCtxt, &f, &l);
+ if (file == NULL)
+ file = f;
+ if (line == 0)
+ line = (int) l;
+ }
+ }
+ if ((file == NULL) && (vctxt->filename != NULL))
+ file = vctxt->filename;
+
__xmlRaiseError(schannel, channel, data, ctxt,
node, XML_FROM_SCHEMASV,
error, errorLevel, file, line,
}
/************************************************************************
- * *
- * Streamable error functions *
- * *
+ * *
+ * Streamable error functions *
+ * *
************************************************************************/
/************************************************************************
- * *
- * Validation helper functions *
- * *
+ * *
+ * Validation helper functions *
+ * *
************************************************************************/
/************************************************************************
- * *
- * Allocation functions *
- * *
+ * *
+ * Allocation functions *
+ * *
************************************************************************/
/**
}
/************************************************************************
- * *
- * Debug functions *
- * *
+ * *
+ * Debug functions *
+ * *
************************************************************************/
#ifdef LIBXML_OUTPUT_ENABLED
/************************************************************************
* *
- * Utilities *
+ * Utilities *
* *
************************************************************************/
}
/************************************************************************
- * *
- * Parsing functions *
- * *
+ * *
+ * Parsing functions *
+ * *
************************************************************************/
#define WXS_FIND_GLOBAL_ITEM(slot) \
}
/************************************************************************
- * *
- * Parsing functions *
- * *
+ * *
+ * Parsing functions *
+ * *
************************************************************************/
#define IS_BLANK_NODE(n) \
}
/************************************************************************
- * *
+ * *
* Utilities for parsing *
- * *
+ * *
************************************************************************/
/**
xmlFree((xmlChar *) value);
value = strip;
}
- res = xmlAddID(NULL, attr->doc, value, attr);
+ res = xmlAddID(NULL, attr->doc, value, attr);
if (res == NULL) {
ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
xmlSchemaPSimpleTypeErr(ctxt,
}
/************************************************************************
- * *
+ * *
* Shema extraction from an Infoset *
- * *
+ * *
************************************************************************/
static xmlSchemaTypePtr xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr
ctxt, xmlSchemaPtr schema,
*/
attr = xmlSchemaGetPropNode(node, "xpath");
if (attr == NULL) {
- xmlSchemaPMissingAttrErr(ctxt,
+ xmlSchemaPMissingAttrErr(ctxt,
XML_SCHEMAP_S4S_ATTR_MISSING,
NULL, node,
"name", NULL);
}
/************************************************************************
- * *
- * Validating using Schemas *
- * *
+ * *
+ * Validating using Schemas *
+ * *
************************************************************************/
/************************************************************************
- * *
- * Reading/Writing Schemas *
- * *
+ * *
+ * Reading/Writing Schemas *
+ * *
************************************************************************/
#if 0 /* Will be enabled if it is clear what options are needed. */
if (tmp2 != 1) ret = 0;
sub = sub->next;
}
+
+ /*
+ * epsilon needed to block previous trans from
+ * being allowed to enter back from another
+ * construct
+ */
+ pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
+ pctxt->state, NULL);
+
if (particle->minOccurs == 0) {
xmlAutomataNewEpsilon(pctxt->am, oldstate,
pctxt->state);
ref->name, ref->targetNamespace);
if (ause->attrDecl == NULL) {
xmlSchemaPResCompAttrErr(ctxt,
- XML_SCHEMAP_SRC_RESOLVE,
+ XML_SCHEMAP_SRC_RESOLVE,
WXS_BASIC_CAST ause, ause->node,
"ref", ref->name, ref->targetNamespace,
XML_SCHEMA_TYPE_ATTRIBUTE, NULL);
}
/************************************************************************
- * *
- * Simple type validation *
- * *
+ * *
+ * Simple type validation *
+ * *
************************************************************************/
/************************************************************************
- * *
- * DOM Validation code *
- * *
+ * *
+ * DOM Validation code *
+ * *
************************************************************************/
/**
}
/************************************************************************
- * *
+ * *
* Validation of identity-constraints (IDC) *
- * *
+ * *
************************************************************************/
/**
}
/************************************************************************
- * *
- * XML Reader validation code *
- * *
+ * *
+ * XML Reader validation code *
+ * *
************************************************************************/
static xmlSchemaAttrInfoPtr
return (vctxt->err);
}
if (actualType == NULL) {
- VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
- "The type definition is absent");
- return (XML_SCHEMAV_CVC_TYPE_1);
+ VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
+ "The type definition is absent");
+ return (XML_SCHEMAV_CVC_TYPE_1);
}
if (vctxt->nbAttrInfos != 0) {
int ret;
* No actual type definition.
*/
if (actualType == NULL) {
- VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
- "The type definition is absent");
- return (XML_SCHEMAV_CVC_TYPE_1);
+ VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
+ "The type definition is absent");
+ return (XML_SCHEMAV_CVC_TYPE_1);
}
/*
* Remember the actual type definition.
"AUTOMATON create on '%s'\n", inode->localName);
#endif
}
+
+ /*
+ * Do not check further content if the node has been nilled
+ */
+ if (INODE_NILLED(inode)) {
+ ret = 0;
+#ifdef DEBUG_AUTOMATA
+ xmlGenericError(xmlGenericErrorContext,
+ "AUTOMATON succeeded on nilled '%s'\n",
+ inode->localName);
+#endif
+ goto skip_nilled;
+ }
+
/*
* Get hold of the still expected content, since a further
* call to xmlRegExecPushString() will loose this information.
}
}
+
+skip_nilled:
+
if (inode->typeDef->contentType == XML_SCHEMA_CONTENT_ELEMENTS)
goto end_elem;
if (vctxt->inode->typeDef == NULL) {
vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE;
ret = XML_SCHEMAV_CVC_TYPE_1;
- VERROR(ret, NULL,
- "The type definition is absent");
+ VERROR(ret, NULL,
+ "The type definition is absent");
goto exit;
}
if (vctxt->inode->typeDef->flags & XML_SCHEMAS_TYPE_ABSTRACT) {
vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE;
ret = XML_SCHEMAV_CVC_TYPE_2;
- VERROR(ret, NULL,
- "The type definition is abstract");
+ VERROR(ret, NULL,
+ "The type definition is abstract");
goto exit;
}
/*
#endif
/************************************************************************
- * *
- * SAX validation handlers *
- * *
+ * *
+ * SAX validation handlers *
+ * *
************************************************************************/
/*
}
/************************************************************************
- * *
- * Validation interfaces *
- * *
+ * *
+ * Validation interfaces *
+ * *
************************************************************************/
/**
}
/**
+ * xmlSchemaValidateSetFilename:
+ * @vctxt: the schema validation context
+ * @filename: the file name
+ *
+ * Workaround to provide file error reporting information when this is
+ * not provided by current APIs
+ */
+void
+xmlSchemaValidateSetFilename(xmlSchemaValidCtxtPtr vctxt, const char *filename) {
+ if (vctxt == NULL)
+ return;
+ if (vctxt->filename != NULL)
+ xmlFree(vctxt->filename);
+ if (filename != NULL)
+ vctxt->filename = (char *) xmlStrdup((const xmlChar *) filename);
+ else
+ vctxt->filename = NULL;
+}
+
+/**
* xmlSchemaClearValidCtxt:
- * @ctxt: the schema validation context
+ * @vctxt: the schema validation context
*
* Free the resources associated to the schema validation context;
* leaves some fields alive intended for reuse of the context.
* where the user provides the dict?
*/
vctxt->dict = xmlDictCreate();
+
+ if (vctxt->filename != NULL) {
+ xmlFree(vctxt->filename);
+ vctxt->filename = NULL;
+ }
}
/**
xmlSchemaItemListFree(ctxt->nodeQNames);
if (ctxt->dict != NULL)
xmlDictFree(ctxt->dict);
+ if (ctxt->filename != NULL)
+ xmlFree(ctxt->filename);
xmlFree(ctxt);
}
const xmlChar *nsName;
/* DOC VAL TODO: Move this to the start function. */
- valRoot = xmlDocGetRootElement(vctxt->doc);
+ if (vctxt->validationRoot != NULL)
+ valRoot = vctxt->validationRoot;
+ else
+ valRoot = xmlDocGetRootElement(vctxt->doc);
if (valRoot == NULL) {
/* VAL TODO: Error code? */
VERROR(1, NULL, "The document has no document element");
/************************************************************************
- * *
- * Function and data for SAX streaming API *
- * *
+ * *
+ * Function and data for SAX streaming API *
+ * *
************************************************************************/
typedef struct _xmlSchemaSplitSAXData xmlSchemaSplitSAXData;
typedef xmlSchemaSplitSAXData *xmlSchemaSplitSAXDataPtr;
}
/**
+ * xmlSchemaValidateSetLocator:
+ * @vctxt: a schema validation context
+ * @f: the locator function pointer
+ * @ctxt: the locator context
+ *
+ * Allows to set a locator function to the validation context,
+ * which will be used to provide file and line information since
+ * those are not provided as part of the SAX validation flow
+ * Setting @f to NULL disable the locator.
+ */
+
+void
+xmlSchemaValidateSetLocator(xmlSchemaValidCtxtPtr vctxt,
+ xmlSchemaValidityLocatorFunc f,
+ void *ctxt)
+{
+ if (vctxt == NULL) return;
+ vctxt->locFunc = f;
+ vctxt->locCtxt = ctxt;
+}
+
+/**
+ * xmlSchemaValidateStreamLocator:
+ * @ctx: the xmlTextReaderPtr used
+ * @file: returned file information
+ * @line: returned line information
+ *
+ * Internal locator function for the readers
+ *
+ * Returns 0 in case the Schema validation could be (des)activated and
+ * -1 in case of error.
+ */
+static int
+xmlSchemaValidateStreamLocator(void *ctx, const char **file,
+ unsigned long *line) {
+ xmlParserCtxtPtr ctxt;
+
+ if ((ctx == NULL) || ((file == NULL) && (line == NULL)))
+ return(-1);
+
+ if (file != NULL)
+ *file = NULL;
+ if (line != NULL)
+ *line = 0;
+
+ ctxt = (xmlParserCtxtPtr) ctx;
+ if (ctxt->input != NULL) {
+ if (file != NULL)
+ *file = ctxt->input->filename;
+ if (line != NULL)
+ *line = ctxt->input->line;
+ return(0);
+ }
+ return(-1);
+}
+
+/**
* xmlSchemaValidateStream:
* @ctxt: a schema validation context
* @input: the input to use for reading the data
xmlCtxtUseOptions(pctxt, options);
#endif
pctxt->linenumbers = 1;
+ xmlSchemaValidateSetLocator(ctxt, xmlSchemaValidateStreamLocator, pctxt);
inputStream = xmlNewIOInputStream(pctxt, input, enc);;
if (inputStream == NULL) {