]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMigrationCookieGraphicsXMLFormat: Use 'virXMLFormatElement'
authorPeter Krempa <pkrempa@redhat.com>
Wed, 30 Sep 2020 13:24:19 +0000 (15:24 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 5 Oct 2020 13:58:52 +0000 (15:58 +0200)
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>
src/qemu/qemu_migration_cookie.c

index 97a14c66187aa166380e6fd7089e69c8aba9d505..7f8772968f4d993055a0a3ead72cb8c74d00ca8c 100644 (file)
@@ -578,20 +578,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);
 }