From 88ae8b8b0c6d479fa68eca366b31d07c6cf11ecd Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 5 Jul 2019 22:02:03 -0500 Subject: [PATCH] snapshot: Add internal option to validate XML against schema Similar to VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; the next patch will put it to use with a counterpart public API flag. No need to change qemudomainsnapshotxml2xmltest to use the flag, since the testsuite already has a separate virschematest that does the same. Signed-off-by: Eric Blake Acked-by: Peter Krempa --- src/conf/snapshot_conf.c | 13 +++++++++++++ src/conf/snapshot_conf.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index c7f29360e7..ea04413aec 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -25,6 +25,7 @@ #include #include +#include "configmake.h" #include "internal.h" #include "virbitmap.h" #include "virbuffer.h" @@ -409,6 +410,18 @@ virDomainSnapshotDefParseNode(xmlDocPtr xml, goto cleanup; } + if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE) { + VIR_AUTOFREE(char *) schema = NULL; + + schema = virFileFindResource("domainsnapshot.rng", + abs_top_srcdir "/docs/schemas", + PKGDATADIR "/schemas"); + if (!schema) + goto cleanup; + if (virXMLValidateAgainstSchema(schema, xml) < 0) + goto cleanup; + } + ctxt = xmlXPathNewContext(xml); if (ctxt == NULL) { virReportOOMError(); diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index 08b2a3b955..a0c87e7ade 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -92,6 +92,7 @@ typedef enum { VIR_DOMAIN_SNAPSHOT_PARSE_DISKS = 1 << 1, VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL = 1 << 2, VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE = 1 << 3, + VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE = 1 << 4, } virDomainSnapshotParseFlags; typedef enum { -- GitLab