From 68d386913f9d9b2d00fe2f8e22e1857b2469bb14 Mon Sep 17 00:00:00 2001 From: Kristina Hanicova Date: Wed, 11 Aug 2021 14:36:48 +0200 Subject: [PATCH] conf: replace validation with variables passed to virXMLParse() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit virXMLParse() now allows validating xml against schema directly, eliminating the need to do it individually in each function. Signed-off-by: Kristina Hanicova Reviewed-by: Ján Tomko Signed-off-by: Ján Tomko --- src/conf/backup_conf.c | 14 ++------------ src/conf/checkpoint_conf.c | 13 ++----------- src/conf/snapshot_conf.c | 15 ++------------- 3 files changed, 6 insertions(+), 36 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index 9307357d84..694553a544 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -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; diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index dd0e6035fa..d2041dd0ac 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -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); diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 3282627044..6d3c59f98e 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -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,