Switch to the two buffer approach to simplify the logic for terminating
the element.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_migration_cookie.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c
index 052d8e311b..accf3c5efb 100644
--- a/src/qemu/qemu_migration_cookie.c
+++ b/src/qemu/qemu_migration_cookie.c
@@ -581,20 +581,19 @@ static void
qemuMigrationCookieGraphicsXMLFormat(virBufferPtr buf,
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),
grap->port, grap->listen);
+
if (grap->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE)
- virBufferAsprintf(buf, " tlsPort='%d'", grap->tlsPort);
- if (grap->tlsSubject) {
- virBufferAddLit(buf, ">\n");
- virBufferAdjustIndent(buf, 2);
- virBufferEscapeString(buf, "<cert info='subject'
value='%s'/>\n", grap->tlsSubject);
- virBufferAdjustIndent(buf, -2);
- virBufferAddLit(buf, "</graphics>\n");
- } else {
- virBufferAddLit(buf, "/>\n");
- }
+ virBufferAsprintf(&attrBuf, " tlsPort='%d'",
grap->tlsPort);
+
+ virBufferEscapeString(&childBuf, "<cert info='subject'
value='%s'/>\n", grap->tlsSubject);
+
+ virXMLFormatElement(buf, "graphics", &attrBuf, &childBuf);
}
--
2.26.2