/**
- * 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,
xmlFreeNode(dupl);
}
}
+
+ child = child->next;
}
}
}
/* clean up possibly duplicated metadata entries */
- virDomainDefRemoveDuplicateMetadata(def);
+ virDomainDefMetadataSanitize(def);
return 0;
}
</devices>
<!-- intentional mis-indentation -->
<metadata>
+ <herp2erp xmlns:foobar="http://foo.bar3/"/>
+ <herp2erp xmlns:foobar="http://foo.bar3/"/>
+ <herp2erp xmlns:foobar="http://foo.bar3/"/>
<app1:foo xmlns:app1="http://foo.org/">fooish</app1:foo>
<app3:foo xmlns:app3="http://foo.org/">fooish</app3:foo>
<app1:foo xmlns:app1="http://foo.org/">fooish</app1:foo>