mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
Introduce virXMLValidatorInit
Split out all the code initializing the validator to a separate function.
This commit is contained in:
parent
8657c7a12f
commit
87ae612de9
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user