virDomainLoaderDefFormat: Use modern XML formatting approach

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-03-28 15:18:39 +02:00
parent 68d1056392
commit 3dd6f0e3de

View File

@ -26949,34 +26949,30 @@ static void
virDomainLoaderDefFormat(virBuffer *buf, virDomainLoaderDefFormat(virBuffer *buf,
virDomainLoaderDef *loader) virDomainLoaderDef *loader)
{ {
const char *readonly = virTristateBoolTypeToString(loader->readonly); g_auto(virBuffer) loaderAttrBuf = VIR_BUFFER_INITIALIZER;
const char *secure = virTristateBoolTypeToString(loader->secure); g_auto(virBuffer) loaderChildBuf = VIR_BUFFER_INITIALIZER;
const char *type = virDomainLoaderTypeToString(loader->type); g_auto(virBuffer) nvramAttrBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) nvramChildBuf = VIR_BUFFER_INITIALIZER;
virBufferAddLit(buf, "<loader"); if (loader->readonly != VIR_TRISTATE_BOOL_ABSENT)
virBufferAsprintf(&loaderAttrBuf, " readonly='%s'",
virTristateBoolTypeToString(loader->readonly));
if (loader->readonly) if (loader->secure != VIR_TRISTATE_BOOL_ABSENT)
virBufferAsprintf(buf, " readonly='%s'", readonly); virBufferAsprintf(&loaderAttrBuf, " secure='%s'",
virTristateBoolTypeToString(loader->secure));
if (loader->secure)
virBufferAsprintf(buf, " secure='%s'", secure);
if (loader->type != VIR_DOMAIN_LOADER_TYPE_NONE) if (loader->type != VIR_DOMAIN_LOADER_TYPE_NONE)
virBufferAsprintf(buf, " type='%s'", type); virBufferAsprintf(&loaderAttrBuf, " type='%s'",
virDomainLoaderTypeToString(loader->type));
if (loader->path) virBufferEscapeString(&loaderChildBuf, "%s", loader->path);
virBufferEscapeString(buf, ">%s</loader>\n", loader->path);
else
virBufferAddLit(buf, "/>\n");
if (loader->nvram || loader->nvramTemplate) { virXMLFormatElementInternal(buf, "loader", &loaderAttrBuf, &loaderChildBuf, false, false);
virBufferAddLit(buf, "<nvram");
virBufferEscapeString(buf, " template='%s'", loader->nvramTemplate); virBufferEscapeString(&nvramAttrBuf, " template='%s'", loader->nvramTemplate);
if (loader->nvram) virBufferEscapeString(&nvramChildBuf, "%s", loader->nvram);
virBufferEscapeString(buf, ">%s</nvram>\n", loader->nvram); virXMLFormatElementInternal(buf, "nvram", &nvramAttrBuf, &nvramChildBuf, false, false);
else
virBufferAddLit(buf, "/>\n");
}
} }
static void static void