[PATCHv2 3/5] Introduce virXMLValidatorInit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Split out all the code initializing the validator
to a separate function.
---
 src/libvirt_private.syms |  1 +
 src/util/virxml.c        | 33 ++++++++++++++++++++++++---------
 src/util/virxml.h        |  3 +++
 3 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 53a7a97..e631c14 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2566,6 +2566,7 @@ virXMLPropString;
 virXMLSaveFile;
 virXMLValidateAgainstSchema;
 virXMLValidatorFree;
+virXMLValidatorInit;
 virXPathBoolean;
 virXPathInt;
 virXPathLong;
diff --git a/src/util/virxml.c b/src/util/virxml.c
index 49aed7d..19163db 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -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,
diff --git a/src/util/virxml.h b/src/util/virxml.h
index 607f063..6d4c991 100644
--- a/src/util/virxml.h
+++ b/src/util/virxml.h
@@ -187,6 +187,9 @@ typedef struct _virXMLValidator {
     char *schemafile;
 } virXMLValidator, *virXMLValidatorPtr;
 
+virXMLValidatorPtr
+virXMLValidatorInit(const char *schemafile);
+
 int
 virXMLValidateAgainstSchema(const char *schemafile,
                             xmlDocPtr xml);
-- 
2.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]