qemuMigrationCookieGraphicsXMLFormat: Use 'virXMLFormatElement'

Switch to the two buffer approach to simplify the logic for terminating
the element.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2020-09-30 15:24:19 +02:00
parent 600c1b5202
commit 592a9a859a

View File

@ -578,20 +578,19 @@ static void
qemuMigrationCookieGraphicsXMLFormat(virBufferPtr buf, qemuMigrationCookieGraphicsXMLFormat(virBufferPtr buf,
qemuMigrationCookieGraphicsPtr grap) qemuMigrationCookieGraphicsPtr grap)
{ {
virBufferAsprintf(buf, "<graphics type='%s' port='%d' listen='%s'", g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
virBufferAsprintf(&attrBuf, " type='%s' port='%d' listen='%s'",
virDomainGraphicsTypeToString(grap->type), virDomainGraphicsTypeToString(grap->type),
grap->port, grap->listen); grap->port, grap->listen);
if (grap->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) if (grap->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE)
virBufferAsprintf(buf, " tlsPort='%d'", grap->tlsPort); virBufferAsprintf(&attrBuf, " tlsPort='%d'", grap->tlsPort);
if (grap->tlsSubject) {
virBufferAddLit(buf, ">\n"); virBufferEscapeString(&childBuf, "<cert info='subject' value='%s'/>\n", grap->tlsSubject);
virBufferAdjustIndent(buf, 2);
virBufferEscapeString(buf, "<cert info='subject' value='%s'/>\n", grap->tlsSubject); virXMLFormatElement(buf, "graphics", &attrBuf, &childBuf);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</graphics>\n");
} else {
virBufferAddLit(buf, "/>\n");
}
} }