From nobody Sun Apr 28 15:42:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628685571; cv=none; d=zohomail.com; s=zohoarc; b=JZ8xWzGu2n/+pOmNRSb4HJ4B2RZS1YdSZukkH3RvSxmZvLwVg4E2jt8Uexe+epEOsT4Vz5OUuxhB0k2hePo03uVw3itijSX44DoB4B5S6RpdTTmvn7To58ko3bObaCxqmt5YUsRi6YrtSgkqnjJ0cD6IWfL7siGxH4j70xJAAVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628685571; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=odW0badMs6ocvGl0H74dlV3vuFKBfIZhCfwIX0vK03M=; b=WfkYz9+d6E0UVq9KNdQC3TxeoIx0efNv1rn81CkNuiGUR3OF8fA+e2Q64wls7ArQutab3P2U78Yougd+Mti9lC1JmF41OBpyaIfD1FoKgA5RR3fyg8mCLaeqylz374ejffJ1BoPi2yCfbXnLqO/ZAnKHKzz+GBcg0t4nC4wFeEI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1628685570602519.6092333713357; Wed, 11 Aug 2021 05:39:30 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-44-sIxqB3mvPCCm9heYewuBgg-1; Wed, 11 Aug 2021 08:39:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 24BC018C89DC; Wed, 11 Aug 2021 12:39:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 12B5D5D740; Wed, 11 Aug 2021 12:39:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9D26D4A700; Wed, 11 Aug 2021 12:39:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17BCbdJo020047 for ; Wed, 11 Aug 2021 08:37:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id ECE7881F76; Wed, 11 Aug 2021 12:37:39 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7402481F78 for ; Wed, 11 Aug 2021 12:37:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628685569; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=odW0badMs6ocvGl0H74dlV3vuFKBfIZhCfwIX0vK03M=; b=WEVTwf4pG4uFuQdqQphfqYEQ2kSR1JioFJwgWDX3v23E6YPAw2ep/27SPNdktszs67ljST uOjjVEUeZl66cXeIUresgeYcrHeokVzunNaqE1oZZ+Dv3Te04r+bBjl2Rn7Op3NNlekdh+ sZwqHAcEEtxDHWKoNouI5zWJMzknIzs= X-MC-Unique: sIxqB3mvPCCm9heYewuBgg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 1/5] src: add 'schema' and 'validate' variable to virXMLParseHelper() Date: Wed, 11 Aug 2021 14:36:44 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628685571511100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova --- src/conf/backup_conf.c | 2 +- src/conf/checkpoint_conf.c | 2 +- src/conf/domain_conf.c | 2 +- src/conf/interface_conf.c | 2 +- src/conf/network_conf.c | 2 +- src/conf/node_device_conf.c | 2 +- src/conf/nwfilter_conf.c | 2 +- src/conf/secret_conf.c | 2 +- src/conf/snapshot_conf.c | 2 +- src/conf/storage_conf.c | 4 ++-- src/conf/virnetworkportdef.c | 2 +- src/conf/virnwfilterbindingdef.c | 2 +- src/conf/virnwfilterbindingobj.c | 2 +- src/test/test_driver.c | 2 +- src/util/virxml.c | 6 +++++- src/util/virxml.h | 20 +++++++++++--------- src/vbox/vbox_snapshot_conf.c | 6 +++--- src/vz/vz_sdk.c | 2 +- tests/qemuxml2argvtest.c | 2 +- 19 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index ac92bd4f26..9307357d84 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -281,7 +281,7 @@ virDomainBackupDefParseString(const char *xmlStr, g_autoptr(xmlDoc) xml =3D NULL; int keepBlanksDefault =3D xmlKeepBlanksDefault(0); =20 - if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_backup)")))) { + if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_backup)"), NULL, fal= se))) { xmlKeepBlanksDefault(keepBlanksDefault); ret =3D virDomainBackupDefParseNode(xml, xmlDocGetRootElement(xml), xmlopt, flags); diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 7b26da416b..dd0e6035fa 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -226,7 +226,7 @@ virDomainCheckpointDefParseString(const char *xmlStr, xmlDocPtr xml; int keepBlanksDefault =3D xmlKeepBlanksDefault(0); =20 - if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_checkpoint)")))) { + if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_checkpoint)"), NULL,= false))) { xmlKeepBlanksDefault(keepBlanksDefault); ret =3D virDomainCheckpointDefParseNode(xml, xmlDocGetRootElement(= xml), xmlopt, parseOpaque, flags); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 15452ef6fc..b996a0cc3c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20400,7 +20400,7 @@ virDomainDefParse(const char *xmlStr, virDomainDef *def =3D NULL; int keepBlanksDefault =3D xmlKeepBlanksDefault(0); xmlNodePtr root; - if (!(xml =3D virXMLParse(filename, xmlStr, _("(domain_definition)")))) + if (!(xml =3D virXMLParse(filename, xmlStr, _("(domain_definition)"), = NULL, false))) goto cleanup; =20 root =3D xmlDocGetRootElement(xml); diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index d84ec66def..c4b763d0de 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -824,7 +824,7 @@ virInterfaceDefParse(const char *xmlStr, xmlDocPtr xml; virInterfaceDef *def =3D NULL; =20 - if ((xml =3D virXMLParse(filename, xmlStr, _("(interface_definition)")= ))) { + if ((xml =3D virXMLParse(filename, xmlStr, _("(interface_definition)")= , NULL, false))) { def =3D virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml)); xmlFreeDoc(xml); } diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index e34ac52a68..fbd939a1f1 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2091,7 +2091,7 @@ virNetworkDefParse(const char *xmlStr, virNetworkDef *def =3D NULL; int keepBlanksDefault =3D xmlKeepBlanksDefault(0); =20 - if ((xml =3D virXMLParse(filename, xmlStr, _("(network_definition)")))) + if ((xml =3D virXMLParse(filename, xmlStr, _("(network_definition)"), = NULL, false))) def =3D virNetworkDefParseNode(xml, xmlDocGetRootElement(xml), xml= opt); =20 xmlKeepBlanksDefault(keepBlanksDefault); diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index d6093f4aa9..bda1a11b37 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2177,7 +2177,7 @@ virNodeDeviceDefParse(const char *str, xmlDocPtr xml; g_autoptr(virNodeDeviceDef) def =3D NULL; =20 - if ((xml =3D virXMLParse(filename, str, _("(node_device_definition)"))= )) { + if ((xml =3D virXMLParse(filename, str, _("(node_device_definition)"),= NULL, false))) { def =3D virNodeDeviceDefParseNode(xml, xmlDocGetRootElement(xml), create, virt_type); xmlFreeDoc(xml); diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index fc81fd97ea..b7adae7161 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -2744,7 +2744,7 @@ virNWFilterDefParse(const char *xmlStr, virNWFilterDef *def =3D NULL; xmlDocPtr xml; =20 - if ((xml =3D virXMLParse(filename, xmlStr, _("(nwfilter_definition)"))= )) { + if ((xml =3D virXMLParse(filename, xmlStr, _("(nwfilter_definition)"),= NULL, false))) { def =3D virNWFilterDefParseNode(xml, xmlDocGetRootElement(xml)); xmlFreeDoc(xml); } diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index 7bfdc58b83..5968b4365c 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -196,7 +196,7 @@ virSecretDefParse(const char *xmlStr, xmlDocPtr xml; virSecretDef *ret =3D NULL; =20 - if ((xml =3D virXMLParse(filename, xmlStr, _("(definition_of_secret)")= ))) { + if ((xml =3D virXMLParse(filename, xmlStr, _("(definition_of_secret)")= , NULL, false))) { ret =3D secretXMLParseNode(xml, xmlDocGetRootElement(xml)); xmlFreeDoc(xml); } diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 0592640dd9..3282627044 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -462,7 +462,7 @@ virDomainSnapshotDefParseString(const char *xmlStr, xmlDocPtr xml; int keepBlanksDefault =3D xmlKeepBlanksDefault(0); =20 - if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_snapshot)")))) { + if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_snapshot)"), NULL, f= alse))) { xmlKeepBlanksDefault(keepBlanksDefault); ret =3D virDomainSnapshotDefParseNode(xml, xmlDocGetRootElement(xm= l), xmlopt, parseOpaque, diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index ad2eb66417..e72e8d0ade 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1009,7 +1009,7 @@ virStoragePoolDefParse(const char *xmlStr, virStoragePoolDef *ret =3D NULL; xmlDocPtr xml; =20 - if ((xml =3D virXMLParse(filename, xmlStr, _("(storage_pool_definition= )")))) { + if ((xml =3D virXMLParse(filename, xmlStr, _("(storage_pool_definition= )"), NULL, false))) { ret =3D virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml)); xmlFreeDoc(xml); } @@ -1478,7 +1478,7 @@ virStorageVolDefParse(virStoragePoolDef *pool, virStorageVolDef *ret =3D NULL; xmlDocPtr xml; =20 - if ((xml =3D virXMLParse(filename, xmlStr, _("(storage_volume_definiti= on)")))) { + if ((xml =3D virXMLParse(filename, xmlStr, _("(storage_volume_definiti= on)"), NULL, false))) { ret =3D virStorageVolDefParseNode(pool, xml, xmlDocGetRootElement(= xml), flags); xmlFreeDoc(xml); } diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index adda66590a..9c2a6298d2 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -297,7 +297,7 @@ virNetworkPortDefParse(const char *xmlStr, virNetworkPortDef *def =3D NULL; xmlDocPtr xml; =20 - if ((xml =3D virXMLParse(filename, xmlStr, _("(networkport_definition)= ")))) { + if ((xml =3D virXMLParse(filename, xmlStr, _("(networkport_definition)= "), NULL, false))) { def =3D virNetworkPortDefParseNode(xml, xmlDocGetRootElement(xml)); xmlFreeDoc(xml); } diff --git a/src/conf/virnwfilterbindingdef.c b/src/conf/virnwfilterbinding= def.c index 22ecf7b828..4079fcdba4 100644 --- a/src/conf/virnwfilterbindingdef.c +++ b/src/conf/virnwfilterbindingdef.c @@ -188,7 +188,7 @@ virNWFilterBindingDefParse(const char *xmlStr, virNWFilterBindingDef *def =3D NULL; xmlDocPtr xml; =20 - if ((xml =3D virXMLParse(filename, xmlStr, _("(nwfilterbinding_definit= ion)")))) { + if ((xml =3D virXMLParse(filename, xmlStr, _("(nwfilterbinding_definit= ion)"), NULL, false))) { def =3D virNWFilterBindingDefParseNode(xml, xmlDocGetRootElement(x= ml)); xmlFreeDoc(xml); } diff --git a/src/conf/virnwfilterbindingobj.c b/src/conf/virnwfilterbinding= obj.c index d48c95af88..11426e0a4d 100644 --- a/src/conf/virnwfilterbindingobj.c +++ b/src/conf/virnwfilterbindingobj.c @@ -265,7 +265,7 @@ virNWFilterBindingObjParse(const char *xmlStr, virNWFilterBindingObj *obj =3D NULL; xmlDocPtr xml; =20 - if ((xml =3D virXMLParse(filename, xmlStr, _("(nwfilterbinding_status)= ")))) { + if ((xml =3D virXMLParse(filename, xmlStr, _("(nwfilterbinding_status)= "), NULL, false))) { obj =3D virNWFilterBindingObjParseNode(xml, xmlDocGetRootElement(x= ml)); xmlFreeDoc(xml); } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 7c3bb70be3..00cc13511a 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -832,7 +832,7 @@ testParseXMLDocFromFile(xmlNodePtr node, const char *fi= le, const char *type) if ((relFile =3D virXMLPropString(node, "file"))) { absFile =3D testBuildFilename(file, relFile); =20 - if (!(doc =3D virXMLParse(absFile, NULL, type))) + if (!(doc =3D virXMLParse(absFile, NULL, type, NULL, false))) goto error; =20 ret =3D xmlCopyNode(xmlDocGetRootElement(doc), 1); diff --git a/src/util/virxml.c b/src/util/virxml.c index 4360b15486..0220c5906f 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1096,6 +1096,8 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSE= D, ...) * @url: URL of XML document for string parser * @rootelement: Optional name of the expected root element * @ctxt: optional pointer to populate with new context pointer + * @schemafile: unused + * @validate: unused * * Parse XML document provided either as a file or a string. The function * guarantees that the XML document contains a root element. @@ -1111,7 +1113,9 @@ virXMLParseHelper(int domcode, const char *xmlStr, const char *url, const char *rootelement, - xmlXPathContextPtr *ctxt) + xmlXPathContextPtr *ctxt, + const char *schemafile G_GNUC_UNUSED, + bool validate G_GNUC_UNUSED) { struct virParserData private; g_autoptr(xmlParserCtxt) pctxt =3D NULL; diff --git a/src/util/virxml.h b/src/util/virxml.h index 0bb0d1c118..e9359b1ef1 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -170,7 +170,9 @@ virXMLParseHelper(int domcode, const char *xmlStr, const char *url, const char *rootelement, - xmlXPathContextPtr *ctxt); + xmlXPathContextPtr *ctxt, + const char *schemafile, + bool validate); =20 const char * virXMLPickShellSafeComment(const char *str1, @@ -185,8 +187,8 @@ virXMLPickShellSafeComment(const char *str1, * * Return the parsed document object, or NULL on failure. */ -#define virXMLParse(filename, xmlStr, url) \ - virXMLParseHelper(VIR_FROM_THIS, filename, xmlStr, url, NULL, NULL) +#define virXMLParse(filename, xmlStr, url, schemafile, validate) \ + virXMLParseHelper(VIR_FROM_THIS, filename, xmlStr, url, NULL, NULL, sc= hemafile, validate) =20 /** * virXMLParseString: @@ -198,7 +200,7 @@ virXMLPickShellSafeComment(const char *str1, * Return the parsed document object, or NULL on failure. */ #define virXMLParseString(xmlStr, url) \ - virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, NULL, NULL) + virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, NULL, NULL, NULL, = false) =20 /** * virXMLParseFile: @@ -209,7 +211,7 @@ virXMLPickShellSafeComment(const char *str1, * Return the parsed document object, or NULL on failure. */ #define virXMLParseFile(filename) \ - virXMLParseHelper(VIR_FROM_THIS, filename, NULL, NULL, NULL, NULL) + virXMLParseHelper(VIR_FROM_THIS, filename, NULL, NULL, NULL, NULL, NUL= L, false) =20 /** * virXMLParseCtxt: @@ -224,7 +226,7 @@ virXMLPickShellSafeComment(const char *str1, * Return the parsed document object, or NULL on failure. */ #define virXMLParseCtxt(filename, xmlStr, url, pctxt) \ - virXMLParseHelper(VIR_FROM_THIS, filename, xmlStr, url, NULL, pctxt) + virXMLParseHelper(VIR_FROM_THIS, filename, xmlStr, url, NULL, pctxt, N= ULL, false) =20 /** * virXMLParseStringCtxt: @@ -238,11 +240,11 @@ virXMLPickShellSafeComment(const char *str1, * Return the parsed document object, or NULL on failure. */ #define virXMLParseStringCtxt(xmlStr, url, pctxt) \ - virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, NULL, pctxt) + virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, NULL, pctxt, NULL,= false) =20 /* virXMLParseStringCtxtRoot is same as above, except it also validates ro= ot node name */ #define virXMLParseStringCtxtRoot(xmlStr, url, rootnode, pctxt) \ - virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, rootnode, pctxt) + virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, rootnode, pctxt, N= ULL, false) =20 /** * virXMLParseFileCtxt: @@ -255,7 +257,7 @@ virXMLPickShellSafeComment(const char *str1, * Return the parsed document object, or NULL on failure. */ #define virXMLParseFileCtxt(filename, pctxt) \ - virXMLParseHelper(VIR_FROM_THIS, filename, NULL, NULL, NULL, pctxt) + virXMLParseHelper(VIR_FROM_THIS, filename, NULL, NULL, NULL, pctxt, NU= LL, false) =20 int virXMLSaveFile(const char *path, diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index f7423f60fc..7fb97d49d9 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -593,7 +593,7 @@ virVBoxSnapshotConfLoadVboxFile(const char *filePath, =20 machineDescription =3D g_new0(virVBoxSnapshotConfMachine, 1); =20 - xml =3D virXMLParse(filePath, NULL, NULL); + xml =3D virXMLParse(filePath, NULL, NULL, NULL, false); if (xml =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Unable to parse the xml")); @@ -1230,7 +1230,7 @@ virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(cons= t char *filePath, _("filePath is null")); goto cleanup; } - xml =3D virXMLParse(filePath, NULL, NULL); + xml =3D virXMLParse(filePath, NULL, NULL, NULL, false); if (xml =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Unable to parse the xml")); @@ -1292,7 +1292,7 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(cons= t char *filePath, _("filePath is null")); goto cleanup; } - xml =3D virXMLParse(filePath, NULL, NULL); + xml =3D virXMLParse(filePath, NULL, NULL, NULL, false); if (xml =3D=3D 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 26a3acb386..6d3a873158 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -4595,7 +4595,7 @@ prlsdkParseSnapshotTree(const char *treexml) if (*treexml =3D=3D '\0') return snapshots; =20 - if (!(xml =3D virXMLParse(NULL, treexml, _("(snapshot_tree)")))) + if (!(xml =3D virXMLParse(NULL, treexml, _("(snapshot_tree)"), NULL, f= alse))) goto cleanup; =20 root =3D xmlDocGetRootElement(xml); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b552f5deed..2754a8a780 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -678,7 +678,7 @@ testCompareXMLToArgv(const void *data) if (testCheckExclusiveFlags(info->flags) < 0) goto cleanup; =20 - if (!(xml =3D virXMLParse(info->infile, NULL, "(domain_definition)"))) + if (!(xml =3D virXMLParse(info->infile, NULL, "(domain_definition)", N= ULL, false))) goto cleanup; =20 root =3D xmlDocGetRootElement(xml); --=20 2.31.1 From nobody Sun Apr 28 15:42:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628685712; cv=none; d=zohomail.com; s=zohoarc; b=bcVHSAcXJi/mbT49lgRMWfaamE5WGgjC3hAPYhNIMkm7IfcxJhItULgZ7jLvge3p4D69GD5Nx/kZTrDSVAPAqlPhSqVUdIiv0zUEx01CsGpTAV34RFyZRDRwQz2uub0a4/sOSosE1HrY1dUiCKDzbb3eQgwzydGVxTpXGa41HMU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628685712; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jsUDFFIy5Ng+6D5oZS/e+76qBvA/OPvZTE2hv3CX8VA=; b=PPFZQr8syUHGHcs0NCurGc9N/V5ot0mh9nYhEktJF/UsR5g8Ay7BaDxHK8EM9aGWI3EsRaN0IJVkUiEXlWj5rrQZbLxX4sWmBGvMPXZNK+PgvkdFNW58S2+ZhmDsA6eAJ13hqkwubCKNDIrmEnBM4ES5/JWNDzelN1QuuirLIQk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1628685712246657.1495392414018; Wed, 11 Aug 2021 05:41:52 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-492-Ii56hSu_O0i0WDvwFFUfHA-1; Wed, 11 Aug 2021 08:41:45 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6588FC7401; Wed, 11 Aug 2021 12:41:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FC5610013C1; Wed, 11 Aug 2021 12:41:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0C5684A706; Wed, 11 Aug 2021 12:41:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17BCbiNY020070 for ; Wed, 11 Aug 2021 08:37:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id A10FE81F78; Wed, 11 Aug 2021 12:37:44 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AA5181F76 for ; Wed, 11 Aug 2021 12:37:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628685711; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=jsUDFFIy5Ng+6D5oZS/e+76qBvA/OPvZTE2hv3CX8VA=; b=aV3Nh5hk2MEorT2D4T8MZ6EHWoEgMkIIUFxVgSXtPWwGipELH0+4U4rSfahgrE7gzBUHAE XC9pxL05dXnZVcFAV8q9Aq5QlC+vuiXMYgM8yv6n/RWjPxs3pw001IVXjJ+EyKUXoB7+1d Kx8YO6bWdQXuhB5hpKSjRwLX2cQLOXs= X-MC-Unique: Ii56hSu_O0i0WDvwFFUfHA-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 2/5] util: add xml validation against schema in virXMLParseHelper() Date: Wed, 11 Aug 2021 14:36:45 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628685713724100001 Content-Type: text/plain; charset="utf-8" We need this in order to validate XML against schema at one place, rather than have the same code for validation in different functions. I will add '--validate' option to more virsh commands soon and this makes it easier as virXMLParse() is called in every one I plan to change. Signed-off-by: Kristina Hanicova --- src/util/virxml.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 0220c5906f..b896a80460 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -33,6 +33,7 @@ #include "virfile.h" #include "virstring.h" #include "virutil.h" +#include "configmake.h" =20 #define VIR_FROM_THIS VIR_FROM_XML =20 @@ -1096,8 +1097,8 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSE= D, ...) * @url: URL of XML document for string parser * @rootelement: Optional name of the expected root element * @ctxt: optional pointer to populate with new context pointer - * @schemafile: unused - * @validate: unused + * @schemafile: optional name of the file the parsed XML will be validated= against + * @validate: if true, the XML will be validated against schema in @schema= file * * Parse XML document provided either as a file or a string. The function * guarantees that the XML document contains a root element. @@ -1114,8 +1115,8 @@ virXMLParseHelper(int domcode, const char *url, const char *rootelement, xmlXPathContextPtr *ctxt, - const char *schemafile G_GNUC_UNUSED, - bool validate G_GNUC_UNUSED) + const char *schemafile, + bool validate) { struct virParserData private; g_autoptr(xmlParserCtxt) pctxt =3D NULL; @@ -1181,6 +1182,15 @@ virXMLParseHelper(int domcode, (*ctxt)->node =3D rootnode; } =20 + if (validate && schemafile !=3D NULL) { + g_autofree char *schema =3D virFileFindResource(schemafile, + abs_top_srcdir "/doc= s/schemas", + PKGDATADIR "/schemas= "); + if (!schema || + (virXMLValidateAgainstSchema(schema, xml) < 0)) + return NULL; + } + return g_steal_pointer(&xml); } =20 --=20 2.31.1 From nobody Sun Apr 28 15:42:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628685756; cv=none; d=zohomail.com; s=zohoarc; b=LYVXB10mSd/oX1bQ7vhnXNyT3GOsi43dw2Avgrzi33RXVotO3V90UH9AbsKwVKs4RRi2kLVk69WqCYMgrkP6cGcjUfUF58brc7oDMGVw8lTdj3WIBQlvhaG62hU75T4zIR7QTNGubrA+J0JleoaSLxfZvhJ6WqZGfPem/DCqGWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628685756; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I/oKVLMst+LOVPb5kbvmJuqtcTIK2pI9gdPQXZRGDDo=; b=njST/X3fHC4sZTqtklvGPt4ySwXabX1uSWEWxhB3dYqOwrGKRkhHdWgkrLf4U9upUsJeK/7xHlhwilWfJvDg4HlKZQTd8FLN+LsfrmR2CLz0P07Hh4y/XkJBYK7Nfr6phtxoBkLOUk5XZVqQVj04EjYEr9gF/YUiE4/Lexx6H+o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1628685756503267.31008792617126; Wed, 11 Aug 2021 05:42:36 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-517-i2u0EmnzOA2CueMDLHaPjw-1; Wed, 11 Aug 2021 08:42:34 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0004F8799F5; Wed, 11 Aug 2021 12:42:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D432C60BF1; Wed, 11 Aug 2021 12:42:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A40204A700; Wed, 11 Aug 2021 12:42:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17BCbjO1020076 for ; Wed, 11 Aug 2021 08:37:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 73E6581F7B; Wed, 11 Aug 2021 12:37:45 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id F096A81F76 for ; Wed, 11 Aug 2021 12:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628685755; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=I/oKVLMst+LOVPb5kbvmJuqtcTIK2pI9gdPQXZRGDDo=; b=RXreXaS0TetLjYGpXS12MuINaPiGFRvIC3PueKVXmJ+nzZuUGoP/tlHM9Y1nk7sEG0Qeq5 XJGmeIc94RUUW77ac6lNbHTIdkK0sTrqKTw5IeypkZrrhv42Tawq98GBpq2LzWrS71b2Ym lOQckt5qezLXw+iPFcRLqP2p8/8sOoo= X-MC-Unique: i2u0EmnzOA2CueMDLHaPjw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 3/5] domain_conf: replace validation with variables passed to virXMLParse() Date: Wed, 11 Aug 2021 14:36:46 +0200 Message-Id: <2530a3fdfcc69c408f1292acdfa4fe2fc459c91c.1628684959.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628685756745100001 Content-Type: text/plain; charset="utf-8" virXMLParse() now allows to validate xml against schema directly, eliminating the need to do it individually. Signed-off-by: Kristina Hanicova --- src/conf/domain_conf.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b996a0cc3c..492d5524ec 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19515,7 +19515,7 @@ virDomainDefControllersParse(virDomainDef *def, } =20 static virDomainDef * -virDomainDefParseXML(xmlDocPtr xml, +virDomainDefParseXML(xmlDocPtr xml G_GNUC_UNUSED, xmlXPathContextPtr ctxt, virDomainXMLOption *xmlopt, unsigned int flags) @@ -19529,18 +19529,6 @@ virDomainDefParseXML(xmlDocPtr xml, g_autofree xmlNodePtr *nodes =3D NULL; g_autofree char *tmp =3D NULL; =20 - if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { - g_autofree char *schema =3D NULL; - - schema =3D virFileFindResource("domain.rng", - abs_top_srcdir "/docs/schemas", - PKGDATADIR "/schemas"); - if (!schema) - return NULL; - if (virXMLValidateAgainstSchema(schema, xml) < 0) - return NULL; - } - if (!(def =3D virDomainDefNew())) return NULL; =20 @@ -20400,7 +20388,8 @@ virDomainDefParse(const char *xmlStr, virDomainDef *def =3D NULL; int keepBlanksDefault =3D xmlKeepBlanksDefault(0); xmlNodePtr root; - if (!(xml =3D virXMLParse(filename, xmlStr, _("(domain_definition)"), = NULL, false))) + if (!(xml =3D virXMLParse(filename, xmlStr, _("(domain_definition)"), = "domain.rng", + flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA))) goto cleanup; =20 root =3D xmlDocGetRootElement(xml); --=20 2.31.1 From nobody Sun Apr 28 15:42:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628685594; cv=none; d=zohomail.com; s=zohoarc; b=OQj7P12GPQxOmoveAXJrEMragZYCldPfzaR1/UKDoQLm62Ppv2h5De09PsfO8YLZMve3+lX2nZXxWQoIAUY0PmQXPAB6hYsjeeJPL9GmRXm63tlLXcv5txko89vIRpvt/Ta+aRGKNQyDkZXh626bCuhJyTbjtJVH6OLNhkEHLxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628685594; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TWjxmw8pmVSHHDj7Ha2KRS35nEMQicbcneivvKNwyvY=; b=PoumZa7leOvt2s6YqQdVnAzyT0OpyWFoAViH3w7o/uqnLKwW1rBikAYiKOB7M5WMR+1Faplpe5UvyLOmYFtbm8Q6JF7bJMTjnaoOdIj+8U4/dCOZkQjYqCShPpYhZe/3ZT7DlxNJMC/sKDUwMKPZz5QAdYUBpwxHOjRF5QOt8aM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1628685594468440.7288798805714; Wed, 11 Aug 2021 05:39:54 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-559-xQlagOvfP5aJMGu1bLXoiQ-1; Wed, 11 Aug 2021 08:39:52 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 782CBC7404; Wed, 11 Aug 2021 12:39:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1698060C9D; Wed, 11 Aug 2021 12:39:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A46324A704; Wed, 11 Aug 2021 12:39:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17BCbkEV020083 for ; Wed, 11 Aug 2021 08:37:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 448F581F7B; Wed, 11 Aug 2021 12:37:46 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id C210381F76 for ; Wed, 11 Aug 2021 12:37:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628685593; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=TWjxmw8pmVSHHDj7Ha2KRS35nEMQicbcneivvKNwyvY=; b=MRT4uNGOX8ISj+t8yYreYEEI+Jpjp9PB2tS3DJ1ZC7JQuEBR+zpUhJokqkqQrxQpGW5Yrx pR3b10pDnMEGFgn3rhvNAYWqhK9efafFyH1r4SH38+Wgf789BnpiGR2MAGepNE5alP8a3I a0FQWEO1gZwMWARzTK8dCLLwh4nFEes= X-MC-Unique: xQlagOvfP5aJMGu1bLXoiQ-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 4/5] domain_conf: Remove redundant variable Date: Wed, 11 Aug 2021 14:36:47 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628685595642100001 Content-Type: text/plain; charset="utf-8" xmlDocPtr is no longer needed, because validation against schema was moved to another function. Signed-off-by: Kristina Hanicova --- src/conf/domain_conf.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 492d5524ec..16cbb7d0c3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19515,8 +19515,7 @@ virDomainDefControllersParse(virDomainDef *def, } =20 static virDomainDef * -virDomainDefParseXML(xmlDocPtr xml G_GNUC_UNUSED, - xmlXPathContextPtr ctxt, +virDomainDefParseXML(xmlXPathContextPtr ctxt, virDomainXMLOption *xmlopt, unsigned int flags) { @@ -20281,8 +20280,7 @@ virDomainDefParseXML(xmlDocPtr xml G_GNUC_UNUSED, =20 =20 static virDomainObj * -virDomainObjParseXML(xmlDocPtr xml, - xmlXPathContextPtr ctxt, +virDomainObjParseXML(xmlXPathContextPtr ctxt, virDomainXMLOption *xmlopt, unsigned int flags) { @@ -20310,7 +20308,7 @@ virDomainObjParseXML(xmlDocPtr xml, =20 oldnode =3D ctxt->node; ctxt->node =3D config; - obj->def =3D virDomainDefParseXML(xml, ctxt, xmlopt, flags); + obj->def =3D virDomainDefParseXML(ctxt, xmlopt, flags); ctxt->node =3D oldnode; if (!obj->def) return NULL; @@ -20443,7 +20441,7 @@ virDomainDefParseNode(xmlDocPtr xml, =20 ctxt->node =3D root; =20 - if (!(def =3D virDomainDefParseXML(xml, ctxt, xmlopt, flags))) + if (!(def =3D virDomainDefParseXML(ctxt, xmlopt, flags))) return NULL; =20 /* callback to fill driver specific domain aspects */ @@ -20478,7 +20476,7 @@ virDomainObjParseNode(xmlDocPtr xml, return NULL; =20 ctxt->node =3D root; - return virDomainObjParseXML(xml, ctxt, xmlopt, flags); + return virDomainObjParseXML(ctxt, xmlopt, flags); } =20 =20 --=20 2.31.1 From nobody Sun Apr 28 15:42:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628685598; cv=none; d=zohomail.com; s=zohoarc; b=KYkMZdTcRacRb84UwW5RYeI1BM1mzPQlFANrGNQ+R9v9W64C+bVXJExNpBAG3iIYuRw9/jzd0UwlFuz6aA559FH4GTVjTYwOiRu6mM+gTcJPLOG1HM5MFNwjHaYJU8mQdvpWHbiTCgusTPpoHPjZdIyqqh8Ype28HcVqw5UONl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628685598; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TvN4oL5mSPVqhGOki7v/FaozEUoB4KGMVJmwSGc97m4=; b=er1NIeZdFJa/LwE2dxXuUzyjNhdjibxgTwv+tIWmhKyS6Y7S6vMUhK/bMb6TILLRgucOwznueOVStCNh/sf7+ipcU5CTaYnMzteWszhI9GA4rEnUyB2wDx/eQE3pEC00pzbhRsOSmp/u7PUbbFCfSrSDo1758JNOMXHfKuqit1g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1628685598449816.6164477025733; Wed, 11 Aug 2021 05:39:58 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-20-1XU-C2GrNjmS6M4hrxGMRA-1; Wed, 11 Aug 2021 08:39:55 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E687BC7407; Wed, 11 Aug 2021 12:39:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DDDBB66FFF; Wed, 11 Aug 2021 12:39:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A44CB4A707; Wed, 11 Aug 2021 12:39:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17BCblCu020095 for ; Wed, 11 Aug 2021 08:37:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 162F981F78; Wed, 11 Aug 2021 12:37:47 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9402B81F76 for ; Wed, 11 Aug 2021 12:37:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628685597; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=TvN4oL5mSPVqhGOki7v/FaozEUoB4KGMVJmwSGc97m4=; b=ULIDOHpbhnUmqwXZdMJHUsSPrhHEXm1sW3XvUu05cCRe/clvVfI1KXjktP4ZYE57yztCrH SDgVJDsMeZ7iX7ptvVUoWnto78yjq+O1HyXNnGGzpIdouylrdNLfuQGINCJl4Giiv/EAau hX7lkGDecIUr9ISv42ydEW1B2PG9Xu4= X-MC-Unique: 1XU-C2GrNjmS6M4hrxGMRA-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 5/5] conf: replace validation with variables passed to virXMLParse() Date: Wed, 11 Aug 2021 14:36:48 +0200 Message-Id: <3e441b9a26af1c031072b8f7628f7295a5a8d4f5.1628684959.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628685599805100001 Content-Type: text/plain; charset="utf-8" virXMLParse() now allows to validate xml against schema directly, eliminating the need to do it individually in each function. Signed-off-by: Kristina Hanicova Reviewed-by: J=C3=A1n Tomko --- src/conf/backup_conf.c | 13 ++----------- src/conf/checkpoint_conf.c | 12 ++---------- src/conf/snapshot_conf.c | 15 ++------------- 3 files changed, 6 insertions(+), 34 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index 9307357d84..8e378a5d26 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 =3D NULL; int keepBlanksDefault =3D xmlKeepBlanksDefault(0); =20 - if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_backup)"), NULL, fal= se))) { + if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_backup)"), "domainba= ckup.rng", + !(flags & VIR_DOMAIN_BACKUP_PARSE_INTERNAL)))) { xmlKeepBlanksDefault(keepBlanksDefault); ret =3D virDomainBackupDefParseNode(xml, xmlDocGetRootElement(xml), xmlopt, flags); @@ -306,16 +307,6 @@ virDomainBackupDefParseNode(xmlDocPtr xml, return NULL; } =20 - if (!(flags & VIR_DOMAIN_BACKUP_PARSE_INTERNAL)) { - if (!(schema =3D virFileFindResource("domainbackup.rng", - abs_top_srcdir "/docs/schemas", - PKGDATADIR "/schemas"))) - return NULL; - - if (virXMLValidateAgainstSchema(schema, xml) < 0) - return NULL; - } - if (!(ctxt =3D virXMLXPathContextNew(xml))) return NULL; =20 diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index dd0e6035fa..ccb01b87f9 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -200,15 +200,6 @@ virDomainCheckpointDefParseNode(xmlDocPtr xml, return NULL; } =20 - /* This is a new enough API to make schema validation unconditional */ - schema =3D virFileFindResource("domaincheckpoint.rng", - abs_top_srcdir "/docs/schemas", - PKGDATADIR "/schemas"); - if (!schema) - return NULL; - if (virXMLValidateAgainstSchema(schema, xml) < 0) - return NULL; - if (!(ctxt =3D virXMLXPathContextNew(xml))) return NULL; =20 @@ -226,7 +217,8 @@ virDomainCheckpointDefParseString(const char *xmlStr, xmlDocPtr xml; int keepBlanksDefault =3D xmlKeepBlanksDefault(0); =20 - if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_checkpoint)"), NULL,= false))) { + if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_checkpoint)"), + "domaincheckpoint.rng", true))) { xmlKeepBlanksDefault(keepBlanksDefault); ret =3D 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; } =20 - if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE) { - g_autofree char *schema =3D NULL; - - schema =3D virFileFindResource("domainsnapshot.rng", - abs_top_srcdir "/docs/schemas", - PKGDATADIR "/schemas"); - if (!schema) - return NULL; - if (virXMLValidateAgainstSchema(schema, xml) < 0) - return NULL; - } - if (!(ctxt =3D virXMLXPathContextNew(xml))) return NULL; =20 @@ -462,7 +450,8 @@ virDomainSnapshotDefParseString(const char *xmlStr, xmlDocPtr xml; int keepBlanksDefault =3D xmlKeepBlanksDefault(0); =20 - if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_snapshot)"), NULL, f= alse))) { + if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_snapshot)"), "domain= snapshot.rng", + flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE))) { xmlKeepBlanksDefault(keepBlanksDefault); ret =3D virDomainSnapshotDefParseNode(xml, xmlDocGetRootElement(xm= l), xmlopt, parseOpaque, --=20 2.31.1