[PATCH 07/10] snapshot_conf: Allow parsing an XML node

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

 



Similar to how other objects arrange their parse APIs. This will be
used by the test driver.
---
 src/conf/snapshot_conf.c | 85 ++++++++++++++++++++++++++++++++++--------------
 src/conf/snapshot_conf.h |  6 ++++
 2 files changed, 67 insertions(+), 24 deletions(-)

diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 2a52418..45d6af4 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -166,15 +166,13 @@ cleanup:
  * If flags does not include VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE, then
  * caps and expectedVirtTypes are ignored.
  */
-virDomainSnapshotDefPtr
-virDomainSnapshotDefParseString(const char *xmlStr,
-                                virCapsPtr caps,
-                                virDomainXMLOptionPtr xmlopt,
-                                unsigned int expectedVirtTypes,
-                                unsigned int flags)
+static virDomainSnapshotDefPtr
+virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
+                          virCapsPtr caps,
+                          virDomainXMLOptionPtr xmlopt,
+                          unsigned int expectedVirtTypes,
+                          unsigned int flags)
 {
-    xmlXPathContextPtr ctxt = NULL;
-    xmlDocPtr xml = NULL;
     virDomainSnapshotDefPtr def = NULL;
     virDomainSnapshotDefPtr ret = NULL;
     xmlNodePtr *nodes = NULL;
@@ -184,26 +182,13 @@ virDomainSnapshotDefParseString(const char *xmlStr,
     struct timeval tv;
     int active;
     char *tmp;
-    int keepBlanksDefault = xmlKeepBlanksDefault(0);
     char *memorySnapshot = NULL;
     char *memoryFile = NULL;
     bool offline = !!(flags & VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE);
 
-    xml = virXMLParseCtxt(NULL, xmlStr, _("(domain_snapshot)"), &ctxt);
-    if (!xml) {
-        xmlKeepBlanksDefault(keepBlanksDefault);
-        return NULL;
-    }
-    xmlKeepBlanksDefault(keepBlanksDefault);
-
     if (VIR_ALLOC(def) < 0)
         goto cleanup;
 
-    if (!xmlStrEqual(ctxt->node->name, BAD_CAST "domainsnapshot")) {
-        virReportError(VIR_ERR_XML_ERROR, "%s", _("domainsnapshot"));
-        goto cleanup;
-    }
-
     gettimeofday(&tv, NULL);
 
     def->name = virXPathString("string(./name)", ctxt);
@@ -261,7 +246,8 @@ virDomainSnapshotDefParseString(const char *xmlStr,
                                _("missing domain in snapshot"));
                 goto cleanup;
             }
-            def->dom = virDomainDefParseNode(xml, domainNode, caps, xmlopt,
+            def->dom = virDomainDefParseNode(ctxt->node->doc, domainNode,
+                                             caps, xmlopt,
                                              expectedVirtTypes,
                                              (VIR_DOMAIN_XML_INACTIVE |
                                               VIR_DOMAIN_XML_SECURE));
@@ -348,10 +334,61 @@ cleanup:
     VIR_FREE(nodes);
     VIR_FREE(memorySnapshot);
     VIR_FREE(memoryFile);
-    xmlXPathFreeContext(ctxt);
     if (ret == NULL)
         virDomainSnapshotDefFree(def);
-    xmlFreeDoc(xml);
+
+    return ret;
+}
+
+virDomainSnapshotDefPtr
+virDomainSnapshotDefParseNode(xmlDocPtr xml,
+                              xmlNodePtr root,
+                              virCapsPtr caps,
+                              virDomainXMLOptionPtr xmlopt,
+                              unsigned int expectedVirtTypes,
+                              unsigned int flags)
+{
+    xmlXPathContextPtr ctxt = NULL;
+    virDomainSnapshotDefPtr def = NULL;
+
+    if (!xmlStrEqual(root->name, BAD_CAST "domainsnapshot")) {
+        virReportError(VIR_ERR_XML_ERROR, "%s", _("domainsnapshot"));
+        goto cleanup;
+    }
+
+    ctxt = xmlXPathNewContext(xml);
+    if (ctxt == NULL) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    ctxt->node = root;
+    def = virDomainSnapshotDefParse(ctxt, caps, xmlopt,
+                                    expectedVirtTypes, flags);
+cleanup:
+    xmlXPathFreeContext(ctxt);
+    return def;
+}
+
+virDomainSnapshotDefPtr
+virDomainSnapshotDefParseString(const char *xmlStr,
+                                virCapsPtr caps,
+                                virDomainXMLOptionPtr xmlopt,
+                                unsigned int expectedVirtTypes,
+                                unsigned int flags)
+{
+    virDomainSnapshotDefPtr ret = NULL;
+    xmlDocPtr xml;
+    int keepBlanksDefault = xmlKeepBlanksDefault(0);
+
+    if ((xml = virXMLParse(NULL, xmlStr, _("(domain_snapshot)")))) {
+        xmlKeepBlanksDefault(keepBlanksDefault);
+        ret = virDomainSnapshotDefParseNode(xml, xmlDocGetRootElement(xml),
+                                            caps, xmlopt,
+                                            expectedVirtTypes, flags);
+        xmlFreeDoc(xml);
+    }
+    xmlKeepBlanksDefault(keepBlanksDefault);
 
     return ret;
 }
diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h
index 6d625a7..0b8d18a 100644
--- a/src/conf/snapshot_conf.h
+++ b/src/conf/snapshot_conf.h
@@ -104,6 +104,12 @@ virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
                                                         virDomainXMLOptionPtr xmlopt,
                                                         unsigned int expectedVirtTypes,
                                                         unsigned int flags);
+virDomainSnapshotDefPtr virDomainSnapshotDefParseNode(xmlDocPtr xml,
+                                                      xmlNodePtr root,
+                                                      virCapsPtr caps,
+                                                      virDomainXMLOptionPtr xmlopt,
+                                                      unsigned int expectedVirtTypes,
+                                                      unsigned int flags);
 void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def);
 char *virDomainSnapshotDefFormat(const char *domain_uuid,
                                  virDomainSnapshotDefPtr def,
-- 
1.8.3.1

--
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]