mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
conf: Remove <metadata> elements with no namespace
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
This commit is contained in:
parent
bb5fc5c778
commit
51a4178f24
@ -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;
|
||||
}
|
||||
|
@ -24,6 +24,9 @@
|
||||
</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>
|
||||
|
Loading…
Reference in New Issue
Block a user