[PATCH 0/6] Adapt to libxml2-2.12.0

There is a new release of libxml2 and we have a technical debt we need to address before we can compile with it cleanly. Michal Prívozník (6): vbox_snapshot_conf: Parse XMLs without net access vbox_snapshot_conf: Keep indent in snapshot XML virxml: include <libxml/xmlsave.h> for xmlIndentTreeOutput declaration virXMLParseHelper: Store XML parsing flags in a variable virxml: Introduce parsing APIs that keep indentation lib: Replace xmlKeepBlanksDefault() with virXMLParseWithIndent() src/conf/backup_conf.c | 8 +++----- src/conf/checkpoint_conf.c | 8 +++----- src/conf/domain_conf.c | 11 +++-------- src/conf/network_conf.c | 6 ++---- src/conf/snapshot_conf.c | 8 +++----- src/util/virxml.c | 24 +++++++++++++++++------- src/util/virxml.h | 29 +++++++++++++++++++++++++---- src/vbox/vbox_snapshot_conf.c | 27 +++++++++++++++++++-------- tools/virsh-util.c | 5 +---- 9 files changed, 76 insertions(+), 50 deletions(-) -- 2.41.0

When working with VirtualBox's snapshots, the snapshot XML is firstly parsed, stored in memory (with some parts being stored as verbatim XML snippets, strings), requested changes are made and then this modified XML is formatted via virVBoxSnapshotConfSaveVboxFile() which calls xmlParseInNodeContext() to format those previously stored XML snippets. The first parse of whole VirtualBox snapshot file is done using virXMLParse() (in virVBoxSnapshotConfLoadVboxFile()) and thus with XML_PARSE_NONET specified. But those ad-hoc parsings when formatting the XML back pass zero flags mask: xmlParseInNodeContext(..., options = 0, ...); This is potentially dangerous. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/vbox/vbox_snapshot_conf.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index 84f7aceac2..467255f77f 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -369,6 +369,7 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node, int firstRegexResult = 0; g_auto(GStrv) secondRegex = NULL; int secondRegexResult = 0; + const int parseFlags = XML_PARSE_NONET; uuid = g_strdup_printf("{%s}", snapshot->uuid); @@ -406,7 +407,7 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node, parseError = xmlParseInNodeContext(node, snapshot->hardware, (int)strlen(snapshot->hardware), - 0, + parseFlags, &hardwareNode); if (parseError != XML_ERR_OK) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -418,7 +419,7 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node, /* storageController */ if (xmlParseInNodeContext(node, snapshot->storageController, (int)strlen(snapshot->storageController), - 0, + parseFlags, &storageControllerNode) != XML_ERR_OK) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Unable to add the snapshot storageController")); @@ -944,6 +945,7 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine, int firstRegexResult = 0; g_auto(GStrv) secondRegex = NULL; int secondRegexResult = 0; + const int parseFlags = XML_PARSE_NONET; if (machine == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1051,7 +1053,7 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine, parseError = xmlParseInNodeContext(mediaRegistryNode, machine->mediaRegistry->otherMedia[i], (int)strlen(machine->mediaRegistry->otherMedia[i]), - 0, + parseFlags, &cur); if (parseError != XML_ERR_OK) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -1071,7 +1073,7 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine, parseError = xmlParseInNodeContext(machineNode, machine->hardware, (int)strlen(machine->hardware), - 0, + parseFlags, &cur); if (parseError != XML_ERR_OK) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -1084,7 +1086,7 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine, parseError = xmlParseInNodeContext(xmlDocGetRootElement(xml), machine->extraData, (int)strlen(machine->extraData), - 0, + parseFlags, &cur); if (parseError != XML_ERR_OK) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -1097,7 +1099,7 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine, parseError = xmlParseInNodeContext(machineNode, machine->storageController, (int)strlen(machine->storageController), - 0, + parseFlags, &cur); if (parseError != XML_ERR_OK) { virReportError(VIR_ERR_XML_ERROR, "%s", -- 2.41.0

On a Tuesday in 2023, Michal Privoznik wrote:
When working with VirtualBox's snapshots, the snapshot XML is firstly parsed, stored in memory (with some parts being stored as verbatim XML snippets, strings), requested changes are made and then this modified XML is formatted via virVBoxSnapshotConfSaveVboxFile() which calls xmlParseInNodeContext() to format those previously stored XML snippets.
The first parse of whole VirtualBox snapshot file is done using virXMLParse() (in virVBoxSnapshotConfLoadVboxFile()) and thus with XML_PARSE_NONET specified.
But those ad-hoc parsings when formatting the XML back pass zero flags mask: xmlParseInNodeContext(..., options = 0, ...);
This is potentially dangerous.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/vbox/vbox_snapshot_conf.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

As mentioned in previous commit, VirtualBox has its own snapshot XML which we parse, change and then format back. During this, we ought to keep the indentation to produce better looking result (especially when we want to compare the output in tests later on, like we do in vboxsnapshotxmltest). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/vbox/vbox_snapshot_conf.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index 467255f77f..9a10b08c3c 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -25,6 +25,7 @@ #include "virstring.h" #include "virxml.h" +#include <libxml/xmlsave.h> #include <libxml/xpathInternals.h> #define VIR_FROM_THIS VIR_FROM_VBOX @@ -364,12 +365,14 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node, xmlParserErrors parseError = XML_ERR_OK; char *uuid = NULL; char *timeStamp = NULL; - g_auto(GStrv) firstRegex = NULL; int firstRegexResult = 0; g_auto(GStrv) secondRegex = NULL; int secondRegexResult = 0; - const int parseFlags = XML_PARSE_NONET; + const int parseFlags = XML_PARSE_NONET | XML_PARSE_NOBLANKS; + int oldIndentTreeOutput = xmlIndentTreeOutput; + + xmlIndentTreeOutput = 1; uuid = g_strdup_printf("{%s}", snapshot->uuid); @@ -440,6 +443,8 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node, result = 0; cleanup: + xmlIndentTreeOutput = oldIndentTreeOutput; + if (result < 0) { xmlFreeNode(descriptionNode); xmlUnlinkNode(snapshotsNode); @@ -940,12 +945,14 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine, xmlParserErrors parseError = XML_ERR_OK; char *currentSnapshot = NULL; char *timeStamp = NULL; - g_auto(GStrv) firstRegex = NULL; int firstRegexResult = 0; g_auto(GStrv) secondRegex = NULL; int secondRegexResult = 0; - const int parseFlags = XML_PARSE_NONET; + const int parseFlags = XML_PARSE_NONET | XML_PARSE_NOBLANKS; + int oldIndentTreeOutput = xmlIndentTreeOutput; + + xmlIndentTreeOutput = 1; if (machine == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1127,6 +1134,8 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine, ret = 0; cleanup: + xmlIndentTreeOutput = oldIndentTreeOutput; + VIR_FREE(currentSnapshot); VIR_FREE(timeStamp); -- 2.41.0

On a Tuesday in 2023, Michal Privoznik wrote:
As mentioned in previous commit, VirtualBox has its own snapshot XML which we parse, change and then format back. During this, we ought to keep the indentation to produce better looking result (especially when we want to compare the output in tests later on, like we do in vboxsnapshotxmltest).
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/vbox/vbox_snapshot_conf.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index 467255f77f..9a10b08c3c 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -25,6 +25,7 @@ #include "virstring.h" #include "virxml.h"
+#include <libxml/xmlsave.h> #include <libxml/xpathInternals.h>
#define VIR_FROM_THIS VIR_FROM_VBOX @@ -364,12 +365,14 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node, xmlParserErrors parseError = XML_ERR_OK; char *uuid = NULL; char *timeStamp = NULL; - g_auto(GStrv) firstRegex = NULL; int firstRegexResult = 0; g_auto(GStrv) secondRegex = NULL; int secondRegexResult = 0; - const int parseFlags = XML_PARSE_NONET; + const int parseFlags = XML_PARSE_NONET | XML_PARSE_NOBLANKS; + int oldIndentTreeOutput = xmlIndentTreeOutput; + + xmlIndentTreeOutput = 1;
uuid = g_strdup_printf("{%s}", snapshot->uuid);
@@ -440,6 +443,8 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node, result = 0;
cleanup: + xmlIndentTreeOutput = oldIndentTreeOutput; + if (result < 0) { xmlFreeNode(descriptionNode); xmlUnlinkNode(snapshotsNode);
The changes to virVBoxSnapshotConfSerializeSnapshot seem unnecessary: 1) it only does parsing, not formatting 2) its only caller (other than itself) gets the IdentTreeOutput set below:
@@ -940,12 +945,14 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine, xmlParserErrors parseError = XML_ERR_OK; char *currentSnapshot = NULL; char *timeStamp = NULL; - g_auto(GStrv) firstRegex = NULL; int firstRegexResult = 0; g_auto(GStrv) secondRegex = NULL; int secondRegexResult = 0; - const int parseFlags = XML_PARSE_NONET; + const int parseFlags = XML_PARSE_NONET | XML_PARSE_NOBLANKS; + int oldIndentTreeOutput = xmlIndentTreeOutput; + + xmlIndentTreeOutput = 1;
if (machine == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1127,6 +1134,8 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine, ret = 0;
cleanup: + xmlIndentTreeOutput = oldIndentTreeOutput; + VIR_FREE(currentSnapshot); VIR_FREE(timeStamp);
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

After libxml2's commit of v2.12.0~101 we no longer get xmlIndentTreeOutput declaration by us including just libxml/xpathInternals.h and libxml2's header files leakage. Resolves: https://bugs.gentoo.org/917516 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virxml.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/virxml.c b/src/util/virxml.c index 0c1eae8c3c..4f215a0e59 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -24,6 +24,7 @@ #include <math.h> /* for isnan() */ #include <sys/stat.h> +#include <libxml/xmlsave.h> #include <libxml/xpathInternals.h> #include "virerror.h" -- 2.41.0

On a Tuesday in 2023, Michal Privoznik wrote:
After libxml2's commit of v2.12.0~101 we no longer get xmlIndentTreeOutput declaration by us including just libxml/xpathInternals.h and libxml2's header files leakage.
Resolves: https://bugs.gentoo.org/917516 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virxml.c | 1 + 1 file changed, 1 insertion(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

The virXMLParseHelper() can work in two modes: either it parses a file or a string. Either way, the same set of flags is specified in call of corresponding function. Save flags in a local variable instead. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virxml.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 4f215a0e59..31685cddde 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1136,6 +1136,8 @@ virXMLParseHelper(int domcode, g_autoptr(xmlDoc) xml = NULL; xmlNodePtr rootnode; const char *docname; + const int parseFlags = XML_PARSE_NONET | + XML_PARSE_NOWARNING; if (filename) docname = filename; @@ -1154,13 +1156,9 @@ virXMLParseHelper(int domcode, pctxt->sax->error = catchXMLError; if (filename) { - xml = xmlCtxtReadFile(pctxt, filename, NULL, - XML_PARSE_NONET | - XML_PARSE_NOWARNING); + xml = xmlCtxtReadFile(pctxt, filename, NULL, parseFlags); } else { - xml = xmlCtxtReadDoc(pctxt, BAD_CAST xmlStr, url, NULL, - XML_PARSE_NONET | - XML_PARSE_NOWARNING); + xml = xmlCtxtReadDoc(pctxt, BAD_CAST xmlStr, url, NULL, parseFlags); } if (!xml) { -- 2.41.0

On a Tuesday in 2023, Michal Privoznik wrote:
The virXMLParseHelper() can work in two modes: either it parses a file or a string. Either way, the same set of flags is specified in call of corresponding function. Save flags in a local variable instead.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virxml.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/util/virxml.c b/src/util/virxml.c index 4f215a0e59..31685cddde 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1136,6 +1136,8 @@ virXMLParseHelper(int domcode, g_autoptr(xmlDoc) xml = NULL; xmlNodePtr rootnode; const char *docname; + const int parseFlags = XML_PARSE_NONET | + XML_PARSE_NOWARNING;
This can fit on a single line.
if (filename) docname = filename;
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

When parsing an XML it may be important to keep indentation to produce a better looking result when formatting the XML back. Just look at all those xmlKeepBlanksDefault() calls just before virXMLParse() is called. Anyway, as of libxml2 commit v2.12.0~108 xmlKeepBlanksDefault() is deprecated. Therefore, introduce virXMLParse...WithIndent() variants which would do exactly xmlKeepBlanksDefault() did but with non-deprecated APIs. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virxml.c | 15 +++++++++++++-- src/util/virxml.h | 29 +++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 31685cddde..e94708448a 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1129,14 +1129,16 @@ virXMLParseHelper(int domcode, const char *rootelement, xmlXPathContextPtr *ctxt, const char *schemafile, - bool validate) + bool validate, + bool keepindent) { struct virParserData private; g_autoptr(xmlParserCtxt) pctxt = NULL; g_autoptr(xmlDoc) xml = NULL; xmlNodePtr rootnode; const char *docname; - const int parseFlags = XML_PARSE_NONET | + int oldIndentTreeOutput = 0; + int parseFlags = XML_PARSE_NONET | XML_PARSE_NOWARNING; if (filename) @@ -1155,12 +1157,21 @@ virXMLParseHelper(int domcode, pctxt->_private = &private; pctxt->sax->error = catchXMLError; + if (keepindent) { + parseFlags |= XML_PARSE_NOBLANKS; + xmlIndentTreeOutput = 1; + } + if (filename) { xml = xmlCtxtReadFile(pctxt, filename, NULL, parseFlags); } else { xml = xmlCtxtReadDoc(pctxt, BAD_CAST xmlStr, url, NULL, parseFlags); } + if (keepindent) { + xmlIndentTreeOutput = oldIndentTreeOutput; + } + if (!xml) { if (virGetLastErrorCode() == VIR_ERR_OK) { virGenericReportError(domcode, VIR_ERR_XML_ERROR, diff --git a/src/util/virxml.h b/src/util/virxml.h index 7af47437bd..03a85bfb25 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -199,7 +199,8 @@ virXMLParseHelper(int domcode, const char *rootelement, xmlXPathContextPtr *ctxt, const char *schemafile, - bool validate); + bool validate, + bool keepindent); const char * virXMLPickShellSafeComment(const char *str1, @@ -219,7 +220,17 @@ virXMLPickShellSafeComment(const char *str1, * Return the parsed document object, or NULL on failure. */ #define virXMLParse(filename, xmlStr, url, rootelement, ctxt, schemafile, validate) \ - virXMLParseHelper(VIR_FROM_THIS, filename, xmlStr, url, rootelement, ctxt, schemafile, validate) + virXMLParseHelper(VIR_FROM_THIS, filename, xmlStr, url, rootelement, ctxt, schemafile, validate, false) + +/** + * virXMLParseWithIndent: + * + * Just like virXMLParse, except indentation is preserved. Should be used when + * facing an user provided XML which may be formatted back and keeping verbatim + * spacing is necessary (e.g. due to <metadata/>). + */ +#define virXMLParseWithIndent(filename, xmlStr, url, rootelement, ctxt, schemafile, validate) \ + virXMLParseHelper(VIR_FROM_THIS, filename, xmlStr, url, rootelement, ctxt, schemafile, validate, true) /** * virXMLParseStringCtxt: @@ -233,7 +244,17 @@ 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, NULL, false) + virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, NULL, pctxt, NULL, false, false) + +/** + * virXMLParseStringCtxtWithIndent: + * + * Just like virXMLParseStringCtxt, except indentation is preserved. Should be + * used when facing an user provided XML which may be formatted back and + * keeping verbatim spacing is necessary (e.g. due to <metadata/>). + */ +#define virXMLParseStringCtxtWithIndent(xmlStr, url, pctxt) \ + virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, NULL, pctxt, NULL, false, true) /** * virXMLParseFileCtxt: @@ -246,7 +267,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, NULL, false) + virXMLParseHelper(VIR_FROM_THIS, filename, NULL, NULL, NULL, pctxt, NULL, false, false) int virXMLSaveFile(const char *path, -- 2.41.0

On a Tuesday in 2023, Michal Privoznik wrote:
When parsing an XML it may be important to keep indentation to produce a better looking result when formatting the XML back. Just look at all those xmlKeepBlanksDefault() calls just before virXMLParse() is called.
Anyway, as of libxml2 commit v2.12.0~108 xmlKeepBlanksDefault() is deprecated. Therefore, introduce virXMLParse...WithIndent() variants which would do exactly xmlKeepBlanksDefault() did but with non-deprecated APIs.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virxml.c | 15 +++++++++++++-- src/util/virxml.h | 29 +++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/src/util/virxml.c b/src/util/virxml.c index 31685cddde..e94708448a 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1129,14 +1129,16 @@ virXMLParseHelper(int domcode, const char *rootelement, xmlXPathContextPtr *ctxt, const char *schemafile, - bool validate) + bool validate, + bool keepindent) { struct virParserData private; g_autoptr(xmlParserCtxt) pctxt = NULL; g_autoptr(xmlDoc) xml = NULL; xmlNodePtr rootnode; const char *docname; - const int parseFlags = XML_PARSE_NONET | + int oldIndentTreeOutput = 0; + int parseFlags = XML_PARSE_NONET | XML_PARSE_NOWARNING;
if (filename) @@ -1155,12 +1157,21 @@ virXMLParseHelper(int domcode, pctxt->_private = &private; pctxt->sax->error = catchXMLError;
+ if (keepindent) { + parseFlags |= XML_PARSE_NOBLANKS; + xmlIndentTreeOutput = 1; + } + if (filename) { xml = xmlCtxtReadFile(pctxt, filename, NULL, parseFlags); } else { xml = xmlCtxtReadDoc(pctxt, BAD_CAST xmlStr, url, NULL, parseFlags); }
+ if (keepindent) { + xmlIndentTreeOutput = oldIndentTreeOutput; + } +
Touching xmlIndentTreeOutput is not necessary. 1) it does not affect parsing, which is what we're doing here 2) xmlIndentTreeOutput = 1 is the default All we need here is the XML_PARSE_NOBLANKS flag. (Also, we did revert to the original value of xmlKeepBlanksDefaultValue by calling xmlKeepBlanksDefault, but xmlIndentTreeOutput is always set to 1 by xmlKeepBlanksDefault and never reset)
if (!xml) { if (virGetLastErrorCode() == VIR_ERR_OK) { virGenericReportError(domcode, VIR_ERR_XML_ERROR,
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Now that we have virXMLParseWithIndent() and virXMLParseStringCtxtWithIndent(), we can use them directly and drop calls to xmlKeepBlanksDefault(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/backup_conf.c | 8 +++----- src/conf/checkpoint_conf.c | 8 +++----- src/conf/domain_conf.c | 11 +++-------- src/conf/network_conf.c | 6 ++---- src/conf/snapshot_conf.c | 8 +++----- tools/virsh-util.c | 5 +---- 6 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index e151c29738..1fea6a2be7 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -276,13 +276,11 @@ virDomainBackupDefParseString(const char *xmlStr, { g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - int keepBlanksDefault = xmlKeepBlanksDefault(0); bool validate = !(flags & VIR_DOMAIN_BACKUP_PARSE_INTERNAL); - xml = virXMLParse(NULL, xmlStr, _("(domain_backup)"), - "domainbackup", &ctxt, "domainbackup.rng", validate); - - xmlKeepBlanksDefault(keepBlanksDefault); + xml = virXMLParseWithIndent(NULL, xmlStr, _("(domain_backup)"), + "domainbackup", &ctxt, "domainbackup.rng", + validate); if (!xml) return NULL; diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 89f8675235..3c797f0f5b 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -192,12 +192,10 @@ virDomainCheckpointDefParseString(const char *xmlStr, { g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - int keepBlanksDefault = xmlKeepBlanksDefault(0); - xml = virXMLParse(NULL, xmlStr, _("(domain_checkpoint)"), - "domaincheckpoint", &ctxt, "domaincheckpoint.rng", true); - - xmlKeepBlanksDefault(keepBlanksDefault); + xml = virXMLParseWithIndent(NULL, xmlStr, _("(domain_checkpoint)"), + "domaincheckpoint", &ctxt, + "domaincheckpoint.rng", true); if (!xml) return NULL; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bef76f46aa..428147fe44 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19503,13 +19503,10 @@ virDomainDefParse(const char *xmlStr, { g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - int keepBlanksDefault = xmlKeepBlanksDefault(0); bool validate = flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; - xml = virXMLParse(filename, xmlStr, _("(domain_definition)"), - "domain", &ctxt, "domain.rng", validate); - - xmlKeepBlanksDefault(keepBlanksDefault); + xml = virXMLParseWithIndent(filename, xmlStr, _("(domain_definition)"), + "domain", &ctxt, "domain.rng", validate); if (!xml) return NULL; @@ -19566,10 +19563,8 @@ virDomainObjParseFile(const char *filename, { g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - int keepBlanksDefault = xmlKeepBlanksDefault(0); - xml = virXMLParse(filename, NULL, NULL, "domstatus", &ctxt, NULL, false); - xmlKeepBlanksDefault(keepBlanksDefault); + xml = virXMLParseWithIndent(filename, NULL, NULL, "domstatus", &ctxt, NULL, false); if (!xml) return NULL; diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 1a6fd86180..0449b6f07c 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1962,11 +1962,9 @@ virNetworkDefParse(const char *xmlStr, { g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - int keepBlanksDefault = xmlKeepBlanksDefault(0); - xml = virXMLParse(filename, xmlStr, _("(network_definition)"), - "network", &ctxt, "network.rng", validate); - xmlKeepBlanksDefault(keepBlanksDefault); + xml = virXMLParseWithIndent(filename, xmlStr, _("(network_definition)"), + "network", &ctxt, "network.rng", validate); if (!xml) return NULL; diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 4b0555eb8c..d7fcded302 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -426,13 +426,11 @@ virDomainSnapshotDefParseString(const char *xmlStr, { g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlDoc) xml = NULL; - int keepBlanksDefault = xmlKeepBlanksDefault(0); bool validate = flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE; - xml = virXMLParse(NULL, xmlStr, _("(domain_snapshot)"), - "domainsnapshot", &ctxt, "domainsnapshot.rng", validate); - - xmlKeepBlanksDefault(keepBlanksDefault); + xml = virXMLParseWithIndent(NULL, xmlStr, _("(domain_snapshot)"), + "domainsnapshot", &ctxt, "domainsnapshot.rng", + validate); if (!xml) return NULL; diff --git a/tools/virsh-util.c b/tools/virsh-util.c index fb6327613a..a6026eed53 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -474,16 +474,13 @@ virshDumpXML(vshControl *ctl, g_autofree xmlNodePtr *nodes = NULL; int nnodes = 0; size_t i; - int oldblanks; if (xpath == NULL) { vshPrint(ctl, "%s", xml); return true; } - oldblanks = xmlKeepBlanksDefault(0); - doc = virXMLParseStringCtxt(xml, url, &ctxt); - xmlKeepBlanksDefault(oldblanks); + doc = virXMLParseStringCtxtWithIndent(xml, url, &ctxt); if (!doc) return false; -- 2.41.0

On a Tuesday in 2023, Michal Privoznik wrote:
Now that we have virXMLParseWithIndent() and virXMLParseStringCtxtWithIndent(), we can use them directly and drop calls to xmlKeepBlanksDefault().
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/backup_conf.c | 8 +++----- src/conf/checkpoint_conf.c | 8 +++----- src/conf/domain_conf.c | 11 +++-------- src/conf/network_conf.c | 6 ++---- src/conf/snapshot_conf.c | 8 +++----- tools/virsh-util.c | 5 +---- 6 files changed, 15 insertions(+), 31 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Michal Privoznik