Split out the code for XML validation into a new function. --- src/libvirt_private.syms | 1 + src/util/virxml.c | 27 +++++++++++++++++++++------ src/util/virxml.h | 4 ++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index e631c14..4d56d1f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2567,6 +2567,7 @@ virXMLSaveFile; virXMLValidateAgainstSchema; virXMLValidatorFree; virXMLValidatorInit; +virXMLValidatorValidate; virXPathBoolean; virXPathInt; virXPathLong; diff --git a/src/util/virxml.c b/src/util/virxml.c index 19163db..aa97940 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1156,15 +1156,11 @@ virXMLValidatorInit(const char *schemafile) int -virXMLValidateAgainstSchema(const char *schemafile, - xmlDocPtr doc) +virXMLValidatorValidate(virXMLValidatorPtr validator, + 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, _("Unable to validate doc against %s\n%s"), @@ -1174,7 +1170,26 @@ virXMLValidateAgainstSchema(const char *schemafile, } ret = 0; + cleanup: + virBufferFreeAndReset(&validator->buf); + return ret; +} + + +int +virXMLValidateAgainstSchema(const char *schemafile, + xmlDocPtr doc) +{ + virXMLValidatorPtr validator = NULL; + int ret = -1; + if (!(validator = virXMLValidatorInit(schemafile))) + return -1; + + if (virXMLValidatorValidate(validator, doc) < 0) + goto cleanup; + + ret = 0; cleanup: virXMLValidatorFree(validator); return ret; diff --git a/src/util/virxml.h b/src/util/virxml.h index 6d4c991..20bad54 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -191,6 +191,10 @@ virXMLValidatorPtr virXMLValidatorInit(const char *schemafile); int +virXMLValidatorValidate(virXMLValidatorPtr validator, + xmlDocPtr doc); + +int virXMLValidateAgainstSchema(const char *schemafile, xmlDocPtr xml); void -- 2.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list