mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 19:02:25 +00:00
util: xml: Expose all arguments of virXMLParseHelper in virXMLParse macro
The generic helper also has helper code to validate the root element and create an XPath context. Many places in the code duplicate code for doing these operations. Extend the helper to provide all arguments and fix all callers. In many cases this patch refactors the passing of the 'validate' field into a separate variable to avoid quirky looking arguments. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
0327bbb767
commit
0c5378bc07
@ -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);
|
||||
|
@ -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),
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
|
@ -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"));
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user