]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: new function virXMLNodeSanitizeNamespaces()
authorLaine Stump <laine@laine.org>
Fri, 24 Jun 2016 15:19:35 +0000 (11:19 -0400)
committerLaine Stump <laine@laine.org>
Fri, 1 Jul 2016 17:04:49 +0000 (13:04 -0400)
This is a generic version of virDomainDefMetadataSanitize() - the same
functionality is now needed for network metadata.

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

index b88afbc4e808b66e39b6f05d7e19f09dc88bb06d..2569c6780fcfde52f8a0003b71a96c6810f5f5d4 100644 (file)
@@ -3645,59 +3645,6 @@ virDomainDefRejectDuplicatePanics(virDomainDefPtr def)
     return 0;
 }
 
-/**
- * virDomainDefMetadataSanitize:
- * @def: Sanitize metadata for this def
- *
- * This function removes metadata elements in @def that share the namespace.
- * The first metadata entry of every duplicate namespace is kept. Additionally
- * elements with no namespace are deleted.
- */
-static void
-virDomainDefMetadataSanitize(virDomainDefPtr def)
-{
-    xmlNodePtr child;
-    xmlNodePtr next;
-    xmlNodePtr dupl;
-
-    if (!def || !def->metadata)
-        return;
-
-    child = def->metadata->children;
-    while (child) {
-        /* remove metadata entries that don't have any namespace at all */
-        if (!child->ns || !child->ns->href) {
-            dupl = child;
-            child = child->next;
-
-            xmlUnlinkNode(dupl);
-            xmlFreeNode(dupl);
-            continue;
-        }
-
-        /* check that every other child of @root doesn't share the namespace of
-         * the current one and delete them possibly */
-        next = child->next;
-        while (next) {
-            dupl = NULL;
-
-            if (child->ns && next->ns &&
-                STREQ_NULLABLE((const char *) child->ns->href,
-                               (const char *) next->ns->href))
-                dupl = next;
-
-            next = next->next;
-
-            if (dupl) {
-                xmlUnlinkNode(dupl);
-                xmlFreeNode(dupl);
-            }
-        }
-
-        child = child->next;
-    }
-}
-
 
 static int
 virDomainDefPostParseMemory(virDomainDefPtr def,
@@ -4496,7 +4443,7 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
     }
 
     /* clean up possibly duplicated metadata entries */
-    virDomainDefMetadataSanitize(def);
+    virXMLNodeSanitizeNamespaces(def->metadata);
 
     virDomainDefPostParseGraphics(def);
 
index de620a853a4eb77f35e825c207b303080773dda5..04fcb47445eec64508580e11449d5ae2da05cdd0 100644 (file)
@@ -2602,6 +2602,7 @@ virUUIDParse;
 # util/virxml.h
 virXMLChildElementCount;
 virXMLExtractNamespaceXML;
+virXMLNodeSanitizeNamespaces;
 virXMLNodeToString;
 virXMLParseHelper;
 virXMLPickShellSafeComment;
index aa97940ab7a83d7e62acf291a02e0de9deba5d32..03bd78437af181d8e3576f38d023e58cc22668cc 100644 (file)
@@ -1083,6 +1083,58 @@ virXMLInjectNamespace(xmlNodePtr node,
     return 0;
 }
 
+/**
+ * virXMLNodeSanitizeNamespaces()
+ * @node: Sanitize the namespaces for this node
+ *
+ * This function removes subnodes in node that share the namespace.
+ * The first instance of every duplicate namespace is kept.
+ * Additionally nodes with no namespace are deleted.
+ */
+void
+virXMLNodeSanitizeNamespaces(xmlNodePtr node)
+{
+    xmlNodePtr child;
+    xmlNodePtr next;
+    xmlNodePtr dupl;
+
+    if (!node)
+       return;
+
+    child = node->children;
+    while (child) {
+        /* remove subelements that don't have any namespace at all */
+        if (!child->ns || !child->ns->href) {
+            dupl = child;
+            child = child->next;
+
+            xmlUnlinkNode(dupl);
+            xmlFreeNode(dupl);
+            continue;
+        }
+
+        /* check that every other child of @root doesn't share the namespace of
+         * the current one and delete them possibly */
+        next = child->next;
+        while (next) {
+            dupl = NULL;
+
+            if (child->ns && next->ns &&
+                STREQ_NULLABLE((const char *) child->ns->href,
+                               (const char *) next->ns->href))
+                dupl = next;
+
+            next = next->next;
+            if (dupl) {
+                xmlUnlinkNode(dupl);
+                xmlFreeNode(dupl);
+            }
+        }
+        child = child->next;
+    }
+}
+
+
 static void catchRNGError(void *ctx,
                           const char *msg,
                           ...)
index 7a89518b9a7702e41184701db1d41f65d6af79e1..7a0a1dad7754e591d6ecb11eca1082978c5a5149 100644 (file)
@@ -179,6 +179,8 @@ int virXMLInjectNamespace(xmlNodePtr node,
                           const char *uri,
                           const char *key);
 
+void virXMLNodeSanitizeNamespaces(xmlNodePtr node);
+
 struct _virXMLValidator {
     xmlRelaxNGParserCtxtPtr rngParser;
     xmlRelaxNGPtr rng;