mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virshGetOneDisplay: Refactor formatting of URI params
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@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
3c73ed7300
commit
82217a2c7b
@ -11678,7 +11678,6 @@ virshGetOneDisplay(vshControl *ctl,
|
|||||||
g_autofree char *type_conn = NULL;
|
g_autofree char *type_conn = NULL;
|
||||||
g_autofree char *sockpath = NULL;
|
g_autofree char *sockpath = NULL;
|
||||||
g_autofree char *passwd = NULL;
|
g_autofree char *passwd = NULL;
|
||||||
bool params = false;
|
|
||||||
|
|
||||||
/* Attempt to get the port number for the current graphics scheme */
|
/* Attempt to get the port number for the current graphics scheme */
|
||||||
xpathPort = g_strdup_printf(xpath_fmt, scheme, "@port");
|
xpathPort = g_strdup_printf(xpath_fmt, scheme, "@port");
|
||||||
@ -11781,22 +11780,20 @@ virshGetOneDisplay(vshControl *ctl,
|
|||||||
virBufferAsprintf(&buf, ":%d", port);
|
virBufferAsprintf(&buf, ":%d", port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* format the parameters part of the uri */
|
||||||
|
virBufferAddLit(&buf, "?");
|
||||||
|
|
||||||
/* TLS Port */
|
/* TLS Port */
|
||||||
if (tls_port) {
|
if (tls_port) {
|
||||||
virBufferAsprintf(&buf,
|
virBufferAsprintf(&buf, "tls-port=%d&", tls_port);
|
||||||
"?tls-port=%d",
|
|
||||||
tls_port);
|
|
||||||
params = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STREQ(scheme, "spice") && passwd) {
|
if (STREQ(scheme, "spice") && passwd) {
|
||||||
virBufferAsprintf(&buf,
|
virBufferAsprintf(&buf, "password=%s&", passwd);
|
||||||
"%spassword=%s",
|
|
||||||
params ? "&" : "?",
|
|
||||||
passwd);
|
|
||||||
params = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virBufferTrimLen(&buf, 1);
|
||||||
|
|
||||||
return virBufferContentAndReset(&buf);
|
return virBufferContentAndReset(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user