提交 87ae612d 编写于 作者: J Ján Tomko

Introduce virXMLValidatorInit

Split out all the code initializing the validator
to a separate function.
上级 8657c7a1
......@@ -2566,6 +2566,7 @@ virXMLPropString;
virXMLSaveFile;
virXMLValidateAgainstSchema;
virXMLValidatorFree;
virXMLValidatorInit;
virXPathBoolean;
virXPathInt;
virXPathLong;
......
......@@ -1104,25 +1104,23 @@ static void ignoreRNGError(void *ctx ATTRIBUTE_UNUSED,
{}
int
virXMLValidateAgainstSchema(const char *schemafile,
xmlDocPtr doc)
virXMLValidatorPtr
virXMLValidatorInit(const char *schemafile)
{
virXMLValidatorPtr validator = NULL;
int ret = -1;
if (VIR_ALLOC(validator) < 0)
return -1;
return NULL;
if (VIR_STRDUP(validator->schemafile, schemafile) < 0)
goto cleanup;
goto error;
if (!(validator->rngParser =
xmlRelaxNGNewParserCtxt(validator->schemafile))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to create RNG parser for %s"),
validator->schemafile);
goto cleanup;
goto error;
}
xmlRelaxNGSetParserErrors(validator->rngParser,
......@@ -1135,20 +1133,37 @@ virXMLValidateAgainstSchema(const char *schemafile,
_("Unable to parse RNG %s: %s"),
validator->schemafile,
virBufferCurrentContent(&validator->buf));
goto cleanup;
goto error;
}
if (!(validator->rngValid = xmlRelaxNGNewValidCtxt(validator->rng))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to create RNG validation context %s"),
validator->schemafile);
goto cleanup;
goto error;
}
xmlRelaxNGSetValidErrors(validator->rngValid,
catchRNGError,
ignoreRNGError,
&validator->buf);
return validator;
error:
virXMLValidatorFree(validator);
return NULL;
}
int
virXMLValidateAgainstSchema(const char *schemafile,
xmlDocPtr doc)
{
virXMLValidatorPtr validator = NULL;
int ret = -1;
if (!(validator = virXMLValidatorInit(schemafile)))
return -1;
if (xmlRelaxNGValidateDoc(validator->rngValid, doc) != 0) {
virReportError(VIR_ERR_XML_INVALID_SCHEMA,
......
......@@ -189,6 +189,9 @@ struct _virXMLValidator {
typedef struct _virXMLValidator virXMLValidator;
typedef virXMLValidator *virXMLValidatorPtr;
virXMLValidatorPtr
virXMLValidatorInit(const char *schemafile);
int
virXMLValidateAgainstSchema(const char *schemafile,
xmlDocPtr xml);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册