[PATCH 15/23] virshGetOneDisplay: Refactor formatting of URI params

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Unconditionally format the start of the query ('?') and make delimiters
('&') part of the arguments. At the end we can trim off 1 char from the
end of the buffer unconditionally.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tools/virsh-domain.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index d0f78798b5..ca1145428f 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -11678,7 +11678,6 @@ virshGetOneDisplay(vshControl *ctl,
     g_autofree char *type_conn = NULL;
     g_autofree char *sockpath = NULL;
     g_autofree char *passwd = NULL;
-    bool params = false;

     /* Attempt to get the port number for the current graphics scheme */
     xpathPort = g_strdup_printf(xpath_fmt, scheme, "@port");
@@ -11781,22 +11780,20 @@ virshGetOneDisplay(vshControl *ctl,
         virBufferAsprintf(&buf, ":%d", port);
     }

+    /* format the parameters part of the uri */
+    virBufferAddLit(&buf, "?");
+
     /* TLS Port */
     if (tls_port) {
-        virBufferAsprintf(&buf,
-                          "?tls-port=%d",
-                          tls_port);
-        params = true;
+        virBufferAsprintf(&buf, "tls-port=%d&", tls_port);
     }

     if (STREQ(scheme, "spice") && passwd) {
-        virBufferAsprintf(&buf,
-                          "%spassword=%s",
-                          params ? "&" : "?",
-                          passwd);
-        params = true;
+        virBufferAsprintf(&buf, "password=%s&", passwd);
     }

+    virBufferTrimLen(&buf, 1);
+
     return virBufferContentAndReset(&buf);
 }

-- 
2.35.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux