]> xenbits.xensource.com Git - libvirt.git/commitdiff
Introduce virXMLValidatorInit
authorJán Tomko <jtomko@redhat.com>
Tue, 7 Jun 2016 16:56:23 +0000 (18:56 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 8 Jun 2016 07:58:54 +0000 (09:58 +0200)
Split out all the code initializing the validator
to a separate function.

src/libvirt_private.syms
src/util/virxml.c
src/util/virxml.h

index 53a7a9780da47759ff835dfda2e7338e48a0c996..e631c146716e98de729ed819daac0020c0f3d746 100644 (file)
@@ -2566,6 +2566,7 @@ virXMLPropString;
 virXMLSaveFile;
 virXMLValidateAgainstSchema;
 virXMLValidatorFree;
+virXMLValidatorInit;
 virXPathBoolean;
 virXPathInt;
 virXPathLong;
index 49aed7d7770f79860b3fc4b3e27ae9f444a93a29..19163dbb466d5d10d722c382065abe58974961f3 100644 (file)
@@ -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,
index 21ca578691c412d50d4d0fdb04eb5cc93804fe2e..f2df6168e6df28af706b31fbbea50649e7624df9 100644 (file)
@@ -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);