conf: replace validation with variables passed to virXMLParse()

virXMLParse() now allows validating xml against schema directly,
eliminating the need to do it individually in each function.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Kristina Hanicova 2021-08-11 14:36:48 +02:00 committed by Ján Tomko
parent 6106327b23
commit 68d386913f
3 changed files with 6 additions and 36 deletions

View File

@ -281,7 +281,8 @@ virDomainBackupDefParseString(const char *xmlStr,
g_autoptr(xmlDoc) xml = NULL;
int keepBlanksDefault = xmlKeepBlanksDefault(0);
if ((xml = virXMLParse(NULL, xmlStr, _("(domain_backup)"), NULL, false))) {
if ((xml = virXMLParse(NULL, xmlStr, _("(domain_backup)"), "domainbackup.rng",
!(flags & VIR_DOMAIN_BACKUP_PARSE_INTERNAL)))) {
xmlKeepBlanksDefault(keepBlanksDefault);
ret = virDomainBackupDefParseNode(xml, xmlDocGetRootElement(xml),
xmlopt, flags);
@ -299,23 +300,12 @@ virDomainBackupDefParseNode(xmlDocPtr xml,
unsigned int flags)
{
g_autoptr(xmlXPathContext) ctxt = NULL;
g_autofree char *schema = NULL;
if (!virXMLNodeNameEqual(root, "domainbackup")) {
virReportError(VIR_ERR_XML_ERROR, "%s", _("domainbackup"));
return NULL;
}
if (!(flags & VIR_DOMAIN_BACKUP_PARSE_INTERNAL)) {
if (!(schema = virFileFindResource("domainbackup.rng",
abs_top_srcdir "/docs/schemas",
PKGDATADIR "/schemas")))
return NULL;
if (virXMLValidateAgainstSchema(schema, xml) < 0)
return NULL;
}
if (!(ctxt = virXMLXPathContextNew(xml)))
return NULL;

View File

@ -193,22 +193,12 @@ virDomainCheckpointDefParseNode(xmlDocPtr xml,
unsigned int flags)
{
g_autoptr(xmlXPathContext) ctxt = NULL;
g_autofree char *schema = NULL;
if (!virXMLNodeNameEqual(root, "domaincheckpoint")) {
virReportError(VIR_ERR_XML_ERROR, "%s", _("domaincheckpoint"));
return NULL;
}
/* This is a new enough API to make schema validation unconditional */
schema = virFileFindResource("domaincheckpoint.rng",
abs_top_srcdir "/docs/schemas",
PKGDATADIR "/schemas");
if (!schema)
return NULL;
if (virXMLValidateAgainstSchema(schema, xml) < 0)
return NULL;
if (!(ctxt = virXMLXPathContextNew(xml)))
return NULL;
@ -226,7 +216,8 @@ virDomainCheckpointDefParseString(const char *xmlStr,
xmlDocPtr xml;
int keepBlanksDefault = xmlKeepBlanksDefault(0);
if ((xml = virXMLParse(NULL, xmlStr, _("(domain_checkpoint)"), NULL, false))) {
if ((xml = virXMLParse(NULL, xmlStr, _("(domain_checkpoint)"),
"domaincheckpoint.rng", true))) {
xmlKeepBlanksDefault(keepBlanksDefault);
ret = virDomainCheckpointDefParseNode(xml, xmlDocGetRootElement(xml),
xmlopt, parseOpaque, flags);

View File

@ -432,18 +432,6 @@ virDomainSnapshotDefParseNode(xmlDocPtr xml,
return NULL;
}
if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE) {
g_autofree char *schema = NULL;
schema = virFileFindResource("domainsnapshot.rng",
abs_top_srcdir "/docs/schemas",
PKGDATADIR "/schemas");
if (!schema)
return NULL;
if (virXMLValidateAgainstSchema(schema, xml) < 0)
return NULL;
}
if (!(ctxt = virXMLXPathContextNew(xml)))
return NULL;
@ -462,7 +450,8 @@ virDomainSnapshotDefParseString(const char *xmlStr,
xmlDocPtr xml;
int keepBlanksDefault = xmlKeepBlanksDefault(0);
if ((xml = virXMLParse(NULL, xmlStr, _("(domain_snapshot)"), NULL, false))) {
if ((xml = virXMLParse(NULL, xmlStr, _("(domain_snapshot)"), "domainsnapshot.rng",
flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE))) {
xmlKeepBlanksDefault(keepBlanksDefault);
ret = virDomainSnapshotDefParseNode(xml, xmlDocGetRootElement(xml),
xmlopt, parseOpaque,