mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
util: new function virXMLNodeSanitizeNamespaces()
This is a generic version of virDomainDefMetadataSanitize() - the same functionality is now needed for network metadata.
This commit is contained in:
parent
328fccf135
commit
b874f26b8b
@ -3645,59 +3645,6 @@ virDomainDefRejectDuplicatePanics(virDomainDefPtr def)
|
|||||||
return 0;
|
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
|
static int
|
||||||
virDomainDefPostParseMemory(virDomainDefPtr def,
|
virDomainDefPostParseMemory(virDomainDefPtr def,
|
||||||
@ -4496,7 +4443,7 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* clean up possibly duplicated metadata entries */
|
/* clean up possibly duplicated metadata entries */
|
||||||
virDomainDefMetadataSanitize(def);
|
virXMLNodeSanitizeNamespaces(def->metadata);
|
||||||
|
|
||||||
virDomainDefPostParseGraphics(def);
|
virDomainDefPostParseGraphics(def);
|
||||||
|
|
||||||
|
@ -2602,6 +2602,7 @@ virUUIDParse;
|
|||||||
# util/virxml.h
|
# util/virxml.h
|
||||||
virXMLChildElementCount;
|
virXMLChildElementCount;
|
||||||
virXMLExtractNamespaceXML;
|
virXMLExtractNamespaceXML;
|
||||||
|
virXMLNodeSanitizeNamespaces;
|
||||||
virXMLNodeToString;
|
virXMLNodeToString;
|
||||||
virXMLParseHelper;
|
virXMLParseHelper;
|
||||||
virXMLPickShellSafeComment;
|
virXMLPickShellSafeComment;
|
||||||
|
@ -1083,6 +1083,58 @@ virXMLInjectNamespace(xmlNodePtr node,
|
|||||||
return 0;
|
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,
|
static void catchRNGError(void *ctx,
|
||||||
const char *msg,
|
const char *msg,
|
||||||
...)
|
...)
|
||||||
|
@ -179,6 +179,8 @@ int virXMLInjectNamespace(xmlNodePtr node,
|
|||||||
const char *uri,
|
const char *uri,
|
||||||
const char *key);
|
const char *key);
|
||||||
|
|
||||||
|
void virXMLNodeSanitizeNamespaces(xmlNodePtr node);
|
||||||
|
|
||||||
struct _virXMLValidator {
|
struct _virXMLValidator {
|
||||||
xmlRelaxNGParserCtxtPtr rngParser;
|
xmlRelaxNGParserCtxtPtr rngParser;
|
||||||
xmlRelaxNGPtr rng;
|
xmlRelaxNGPtr rng;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user