conf: backup: Remove virDomainBackupDefParseNode

Rename virDomainBackupDefParse to virDomainBackupDefParseXML and use
it in place of virDomainBackupDefParseNode. This is possible as
virXMLParse can be used to replace XPath context allocation and root
node checking.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-09-22 18:02:50 +02:00
parent a84a2d8e1c
commit 573f764ee4
4 changed files with 22 additions and 40 deletions

View File

@ -190,10 +190,10 @@ virDomainBackupDefParsePrivate(virDomainBackupDef *def,
}
static virDomainBackupDef *
virDomainBackupDefParse(xmlXPathContextPtr ctxt,
virDomainXMLOption *xmlopt,
unsigned int flags)
virDomainBackupDef *
virDomainBackupDefParseXML(xmlXPathContextPtr ctxt,
virDomainXMLOption *xmlopt,
unsigned int flags)
{
g_autoptr(virDomainBackupDef) def = NULL;
g_autofree xmlNodePtr *nodes = NULL;
@ -274,41 +274,20 @@ virDomainBackupDefParseString(const char *xmlStr,
virDomainXMLOption *xmlopt,
unsigned int flags)
{
virDomainBackupDef *ret = NULL;
g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
int keepBlanksDefault = xmlKeepBlanksDefault(0);
bool validate = !(flags & VIR_DOMAIN_BACKUP_PARSE_INTERNAL);
if ((xml = virXMLParse(NULL, xmlStr, _("(domain_backup)"),
NULL, NULL, "domainbackup.rng", validate))) {
xmlKeepBlanksDefault(keepBlanksDefault);
ret = virDomainBackupDefParseNode(xml, xmlDocGetRootElement(xml),
xmlopt, flags);
}
xml = virXMLParse(NULL, xmlStr, _("(domain_backup)"),
"domainbackup", &ctxt, "domainbackup.rng", validate);
xmlKeepBlanksDefault(keepBlanksDefault);
return ret;
}
virDomainBackupDef *
virDomainBackupDefParseNode(xmlDocPtr xml,
xmlNodePtr root,
virDomainXMLOption *xmlopt,
unsigned int flags)
{
g_autoptr(xmlXPathContext) ctxt = NULL;
if (!virXMLNodeNameEqual(root, "domainbackup")) {
virReportError(VIR_ERR_XML_ERROR, "%s", _("domainbackup"));
return NULL;
}
if (!(ctxt = virXMLXPathContextNew(xml)))
if (!xml)
return NULL;
ctxt->node = root;
return virDomainBackupDefParse(ctxt, xmlopt, flags);
return virDomainBackupDefParseXML(ctxt, xmlopt, flags);
}

View File

@ -105,16 +105,16 @@ typedef enum {
VIR_DOMAIN_BACKUP_PARSE_INTERNAL = 1 << 0,
} virDomainBackupParseFlags;
virDomainBackupDef *
virDomainBackupDefParseXML(xmlXPathContextPtr ctxt,
virDomainXMLOption *xmlopt,
unsigned int flags);
virDomainBackupDef *
virDomainBackupDefParseString(const char *xmlStr,
virDomainXMLOption *xmlopt,
unsigned int flags);
virDomainBackupDef *
virDomainBackupDefParseNode(xmlDocPtr xml,
xmlNodePtr root,
virDomainXMLOption *xmlopt,
unsigned int flags);
void
virDomainBackupDefFree(virDomainBackupDef *def);

View File

@ -46,8 +46,8 @@ virAccessPermStorageVolTypeToString;
virDomainBackupAlignDisks;
virDomainBackupDefFormat;
virDomainBackupDefFree;
virDomainBackupDefParseNode;
virDomainBackupDefParseString;
virDomainBackupDefParseXML;
# conf/capabilities.h

View File

@ -2860,6 +2860,7 @@ static int
qemuDomainObjPrivateXMLParseBackups(qemuDomainObjPrivate *priv,
xmlXPathContextPtr ctxt)
{
VIR_XPATH_NODE_AUTORESTORE(ctxt)
g_autofree xmlNodePtr *nodes = NULL;
ssize_t nnodes = 0;
@ -2875,9 +2876,11 @@ qemuDomainObjPrivateXMLParseBackups(qemuDomainObjPrivate *priv,
if (nnodes == 0)
return 0;
if (!(priv->backup = virDomainBackupDefParseNode(ctxt->doc, nodes[0],
priv->driver->xmlopt,
VIR_DOMAIN_BACKUP_PARSE_INTERNAL)))
ctxt->node = nodes[0];
if (!(priv->backup = virDomainBackupDefParseXML(ctxt,
priv->driver->xmlopt,
VIR_DOMAIN_BACKUP_PARSE_INTERNAL)))
return -1;
return 0;