[PATCH 19/43] conf: secret: Refactor secretXMLParseNode

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

 



Rename it to virSecretParseXML and move the root node validation and
context fetching into the caller (by properly calling virXMLParse).

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/secret_conf.c | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index 02c2e38964..d41d8157cd 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -123,28 +123,15 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt,
     return 0;
 }

+
 static virSecretDef *
-secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
+virSecretParseXML(xmlXPathContext *ctxt)
 {
-    g_autoptr(xmlXPathContext) ctxt = NULL;
     g_autoptr(virSecretDef) def = NULL;
     g_autofree char *ephemeralstr = NULL;
     g_autofree char *privatestr = NULL;
     g_autofree char *uuidstr = NULL;

-    if (!virXMLNodeNameEqual(root, "secret")) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("unexpected root element <%s>, "
-                         "expecting <secret>"),
-                       root->name);
-        return NULL;
-    }
-
-    if (!(ctxt = virXMLXPathContextNew(xml)))
-        return NULL;
-
-    ctxt->node = root;
-
     def = g_new0(virSecretDef, 1);

     if ((ephemeralstr = virXPathString("string(./@ephemeral)", ctxt))) {
@@ -186,21 +173,21 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
     return g_steal_pointer(&def);
 }

+
 static virSecretDef *
 virSecretDefParse(const char *xmlStr,
                   const char *filename,
                   unsigned int flags)
 {
     g_autoptr(xmlDoc) xml = NULL;
-    virSecretDef *ret = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     bool validate = flags & VIR_SECRET_DEFINE_VALIDATE;

-    if ((xml = virXMLParse(filename, xmlStr, _("(definition_of_secret)"),
-                           NULL, NULL, "secret.rng", validate))) {
-        ret = secretXMLParseNode(xml, xmlDocGetRootElement(xml));
-    }
+    if (!(xml = virXMLParse(filename, xmlStr, _("(definition_of_secret)"),
+                            "secret", &ctxt, "secret.rng", validate)))
+        return NULL;

-    return ret;
+    return virSecretParseXML(ctxt);
 }

 virSecretDef *
-- 
2.37.3




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

  Powered by Linux