diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index 0f2fba115d..7dfc8ee635 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -277,9 +277,10 @@ virDomainBackupDefParseString(const char *xmlStr, virDomainBackupDef *ret = NULL; g_autoptr(xmlDoc) xml = NULL; int keepBlanksDefault = xmlKeepBlanksDefault(0); + bool validate = !(flags & VIR_DOMAIN_BACKUP_PARSE_INTERNAL); - if ((xml = virXMLParse(NULL, xmlStr, _("(domain_backup)"), "domainbackup.rng", - !(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); diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 338cf10d12..0d2d2050da 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -212,7 +212,7 @@ virDomainCheckpointDefParseString(const char *xmlStr, g_autoptr(xmlDoc) xml = NULL; int keepBlanksDefault = xmlKeepBlanksDefault(0); - if ((xml = virXMLParse(NULL, xmlStr, _("(domain_checkpoint)"), + if ((xml = virXMLParse(NULL, xmlStr, _("(domain_checkpoint)"), NULL, NULL, "domaincheckpoint.rng", true))) { xmlKeepBlanksDefault(keepBlanksDefault); ret = virDomainCheckpointDefParseNode(xml, xmlDocGetRootElement(xml), diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a609cc4f68..b3202c9f76 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19083,8 +19083,10 @@ virDomainDefParse(const char *xmlStr, virDomainDef *def = NULL; int keepBlanksDefault = xmlKeepBlanksDefault(0); xmlNodePtr root; - if (!(xml = virXMLParse(filename, xmlStr, _("(domain_definition)"), "domain.rng", - flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA))) + bool validate = flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; + + if (!(xml = virXMLParse(filename, xmlStr, _("(domain_definition)"), + NULL, NULL, "domain.rng", validate))) goto cleanup; root = xmlDocGetRootElement(xml); diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index dc61b378b9..a3f6b6bed6 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -700,9 +700,10 @@ virInterfaceDefParse(const char *xmlStr, unsigned int flags) { g_autoptr(xmlDoc) xml = NULL; + bool validate = flags & VIR_INTERFACE_DEFINE_VALIDATE; xml = virXMLParse(filename, xmlStr, _("(interface_definition)"), - "interface.rng", flags & VIR_INTERFACE_DEFINE_VALIDATE); + NULL, NULL, "interface.rng", validate); if (!xml) return NULL; diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index b8450b75a9..b1d77a80c3 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2036,7 +2036,7 @@ virNetworkDefParse(const char *xmlStr, int keepBlanksDefault = xmlKeepBlanksDefault(0); if ((xml = virXMLParse(filename, xmlStr, _("(network_definition)"), - "network.rng", validate))) + NULL, NULL, "network.rng", validate))) def = virNetworkDefParseNode(xml, xmlDocGetRootElement(xml), xmlopt); xmlKeepBlanksDefault(keepBlanksDefault); diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index d5bfc098b2..1db9a3240a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2508,7 +2508,8 @@ virNodeDeviceDefParse(const char *str, g_autoptr(xmlDoc) xml = NULL; g_autoptr(virNodeDeviceDef) def = NULL; - if (!(xml = virXMLParse(filename, str, _("(node_device_definition)"), NULL, false)) || + if (!(xml = virXMLParse(filename, str, _("(node_device_definition)"), + NULL, NULL, NULL, false)) || !(def = virNodeDeviceDefParseNode(xml, xmlDocGetRootElement(xml), create, virt_type))) return NULL; diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index b5fd266457..44ea056823 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -2713,9 +2713,10 @@ virNWFilterDefParse(const char *xmlStr, { virNWFilterDef *def = NULL; g_autoptr(xmlDoc) xml = NULL; + bool validate = flags & VIR_NWFILTER_DEFINE_VALIDATE; - if ((xml = virXMLParse(filename, xmlStr, _("(nwfilter_definition)"), "nwfilter.rng", - flags & VIR_NWFILTER_DEFINE_VALIDATE))) { + if ((xml = virXMLParse(filename, xmlStr, _("(nwfilter_definition)"), + NULL, NULL, "nwfilter.rng", validate))) { def = virNWFilterDefParseNode(xml, xmlDocGetRootElement(xml)); } diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index 011fdaa12b..02c2e38964 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -193,9 +193,10 @@ virSecretDefParse(const char *xmlStr, { g_autoptr(xmlDoc) xml = NULL; virSecretDef *ret = NULL; + bool validate = flags & VIR_SECRET_DEFINE_VALIDATE; - if ((xml = virXMLParse(filename, xmlStr, _("(definition_of_secret)"), "secret.rng", - flags & VIR_SECRET_DEFINE_VALIDATE))) { + if ((xml = virXMLParse(filename, xmlStr, _("(definition_of_secret)"), + NULL, NULL, "secret.rng", validate))) { ret = secretXMLParseNode(xml, xmlDocGetRootElement(xml)); } diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index ae635edd08..a5974053f4 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -421,9 +421,10 @@ virDomainSnapshotDefParseString(const char *xmlStr, virDomainSnapshotDef *ret = NULL; g_autoptr(xmlDoc) xml = NULL; int keepBlanksDefault = xmlKeepBlanksDefault(0); + bool validate = flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE; - if ((xml = virXMLParse(NULL, xmlStr, _("(domain_snapshot)"), "domainsnapshot.rng", - flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE))) { + if ((xml = virXMLParse(NULL, xmlStr, _("(domain_snapshot)"), + NULL, NULL, "domainsnapshot.rng", validate))) { xmlKeepBlanksDefault(keepBlanksDefault); ret = virDomainSnapshotDefParseNode(xml, xmlDocGetRootElement(xml), xmlopt, parseOpaque, diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 79f16aadf3..d7375a5160 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1001,9 +1001,10 @@ virStoragePoolDefParse(const char *xmlStr, { virStoragePoolDef *ret = NULL; g_autoptr(xmlDoc) xml = NULL; + bool validate = flags & VIR_STORAGE_POOL_DEFINE_VALIDATE; if ((xml = virXMLParse(filename, xmlStr, _("(storage_pool_definition)"), - "storagepool.rng", flags & VIR_STORAGE_POOL_DEFINE_VALIDATE))) { + NULL, NULL, "storagepool.rng", validate))) { ret = virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml)); } @@ -1470,7 +1471,8 @@ virStorageVolDefParse(virStoragePoolDef *pool, virStorageVolDef *ret = NULL; g_autoptr(xmlDoc) xml = NULL; - if ((xml = virXMLParse(filename, xmlStr, _("(storage_volume_definition)"), NULL, false))) { + if ((xml = virXMLParse(filename, xmlStr, _("(storage_volume_definition)"), + NULL, NULL, NULL, false))) { ret = virStorageVolDefParseNode(pool, xml, xmlDocGetRootElement(xml), flags); } diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index 39fa895fae..40cadc4ae8 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -279,10 +279,10 @@ virNetworkPortDefParse(const char *xmlStr, { virNetworkPortDef *def = NULL; g_autoptr(xmlDoc) xml = NULL; + bool validate = flags & VIR_NETWORK_PORT_CREATE_VALIDATE; if ((xml = virXMLParse(filename, xmlStr, _("(networkport_definition)"), - "networkport.rng", - flags & VIR_NETWORK_PORT_CREATE_VALIDATE))) { + NULL, NULL, "networkport.rng", validate))) { def = virNetworkPortDefParseNode(xml, xmlDocGetRootElement(xml)); } diff --git a/src/conf/virnwfilterbindingdef.c b/src/conf/virnwfilterbindingdef.c index cc50ba944a..e58bab3f08 100644 --- a/src/conf/virnwfilterbindingdef.c +++ b/src/conf/virnwfilterbindingdef.c @@ -182,10 +182,10 @@ virNWFilterBindingDefParse(const char *xmlStr, { virNWFilterBindingDef *def = NULL; g_autoptr(xmlDoc) xml = NULL; + bool validate = flags & VIR_NWFILTER_BINDING_CREATE_VALIDATE; if ((xml = virXMLParse(filename, xmlStr, _("(nwfilterbinding_definition)"), - "nwfilterbinding.rng", - flags & VIR_NWFILTER_BINDING_CREATE_VALIDATE))) { + NULL, NULL, "nwfilterbinding.rng", validate))) { def = virNWFilterBindingDefParseNode(xml, xmlDocGetRootElement(xml)); } diff --git a/src/conf/virnwfilterbindingobj.c b/src/conf/virnwfilterbindingobj.c index 47455c7e35..cc6009d1f2 100644 --- a/src/conf/virnwfilterbindingobj.c +++ b/src/conf/virnwfilterbindingobj.c @@ -257,7 +257,8 @@ virNWFilterBindingObjParse(const char *xmlStr, virNWFilterBindingObj *obj = NULL; g_autoptr(xmlDoc) xml = NULL; - if ((xml = virXMLParse(filename, xmlStr, _("(nwfilterbinding_status)"), NULL, false))) { + if ((xml = virXMLParse(filename, xmlStr, _("(nwfilterbinding_status)"), + NULL, NULL, NULL, false))) { obj = virNWFilterBindingObjParseNode(xml, xmlDocGetRootElement(xml)); } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 686ff051a8..1c10124564 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -851,7 +851,7 @@ testParseXMLDocFromFile(xmlNodePtr node, const char *file, const char *type) if ((relFile = virXMLPropString(node, "file"))) { absFile = testBuildFilename(file, relFile); - if (!(doc = virXMLParse(absFile, NULL, type, NULL, false))) + if (!(doc = virXMLParse(absFile, NULL, type, NULL, NULL, NULL, false))) return NULL; ret = xmlCopyNode(xmlDocGetRootElement(doc), 1); diff --git a/src/util/virxml.h b/src/util/virxml.h index 65db46ca98..0a5759fd45 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -204,13 +204,17 @@ virXMLPickShellSafeComment(const char *str1, * @filename: file to parse, or NULL for string parsing * @xmlStr: if @filename is NULL, a string to parse * @url: if @filename is NULL, an optional filename to attribute the parse to + * @rootelement: if non-NULL, validate that the root element name equals to this parameter + * @ctxt: if non-NULL, filled with a new XPath context including populating the root node + * @schemafile: name of the appropriate schema file for the parsed XML for validation (may be NULL) + * @validate: if true and @schemafile is non-NULL, validate the XML against @schemafile * * Parse xml from either a file or a string. * * Return the parsed document object, or NULL on failure. */ -#define virXMLParse(filename, xmlStr, url, schemafile, validate) \ - virXMLParseHelper(VIR_FROM_THIS, filename, xmlStr, url, NULL, NULL, schemafile, validate) +#define virXMLParse(filename, xmlStr, url, rootelement, ctxt, schemafile, validate) \ + virXMLParseHelper(VIR_FROM_THIS, filename, xmlStr, url, rootelement, ctxt, schemafile, validate) /** * virXMLParseString: diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index 90afac179e..6dce9cdf0f 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -584,7 +584,7 @@ virVBoxSnapshotConfLoadVboxFile(const char *filePath, machineDescription = g_new0(virVBoxSnapshotConfMachine, 1); - xml = virXMLParse(filePath, NULL, NULL, NULL, false); + xml = virXMLParse(filePath, NULL, NULL, NULL, NULL, NULL, false); if (xml == NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Unable to parse the xml")); @@ -1214,7 +1214,7 @@ virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(const char *filePath, _("filePath is null")); goto cleanup; } - xml = virXMLParse(filePath, NULL, NULL, NULL, false); + xml = virXMLParse(filePath, NULL, NULL, NULL, NULL, NULL, false); if (xml == NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Unable to parse the xml")); @@ -1271,7 +1271,7 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(const char *filePath, _("filePath is null")); goto cleanup; } - xml = virXMLParse(filePath, NULL, NULL, NULL, false); + xml = virXMLParse(filePath, NULL, NULL, NULL, NULL, NULL, false); if (xml == NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Unable to parse the xml")); diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index ecf610d7db..8fb7a9948d 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -4581,7 +4581,8 @@ prlsdkParseSnapshotTree(const char *treexml) if (*treexml == '\0') return snapshots; - if (!(xml = virXMLParse(NULL, treexml, _("(snapshot_tree)"), NULL, false))) + if (!(xml = virXMLParse(NULL, treexml, _("(snapshot_tree)"), + NULL, NULL, NULL, false))) goto cleanup; root = xmlDocGetRootElement(xml); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b96ec69fa7..825273c8c6 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -672,7 +672,8 @@ testCompareXMLToArgv(const void *data) if (testCheckExclusiveFlags(info->flags) < 0) goto cleanup; - if (!(xml = virXMLParse(info->infile, NULL, "(domain_definition)", NULL, false))) + if (!(xml = virXMLParse(info->infile, NULL, "(domain_definition)", + NULL, NULL, NULL, false))) goto cleanup; root = xmlDocGetRootElement(xml);