[PATCH] conf: Remove <metadata> elements with no namespace

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

 



Our docs state that subelements of <metadata> shall have a namespace
and the medatata APIs expect that too. To avoid inaccessible
<metadata> sub-elements, just remove those that don't conform to the
documentation.

Apart from adding the new condition this patch renames the function and
refactors the code flow to allow the changes.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1245525
---
 src/conf/domain_conf.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 29e55f2..65e0d8e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3688,27 +3688,40 @@ virDomainDefRejectDuplicateControllers(virDomainDefPtr def)


 /**
- * virDomainDefRemoveDuplicateMetadata:
- * @def: Remove duplicate metadata for this def
+ * 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.
+ * The first metadata entry of every duplicate namespace is kept. Additionally
+ * elements with no namespace are deleted.
  */
 static void
-virDomainDefRemoveDuplicateMetadata(virDomainDefPtr def)
+virDomainDefMetadataSanitize(virDomainDefPtr def)
 {
     xmlNodePtr child;
     xmlNodePtr next;
+    xmlNodePtr dupl;

     if (!def || !def->metadata)
         return;

-    for (child = def->metadata->children; child; child = child->next) {
+    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) {
-            xmlNodePtr dupl = NULL;
+            dupl = NULL;

             if (child->ns && next->ns &&
                 STREQ_NULLABLE((const char *) child->ns->href,
@@ -3722,6 +3735,8 @@ virDomainDefRemoveDuplicateMetadata(virDomainDefPtr def)
                 xmlFreeNode(dupl);
             }
         }
+
+        child = child->next;
     }
 }

@@ -3956,7 +3971,7 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
     }

     /* clean up possibly duplicated metadata entries */
-    virDomainDefRemoveDuplicateMetadata(def);
+    virDomainDefMetadataSanitize(def);

     return 0;
 }
-- 
2.4.5

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