virt-viewer: Allow TLS-only SPICE connections

When trying to connect to a VM which uses SPICE with only a tls port
set:
<graphics type='spice' tlsPort='-1' autoport='no' listen='0' keymap='en-us'>
    <listen type='address' address='0'/>
</graphics>
the connection will fail with
"Cannot determine the graphic address for the guest spice"

virt_viewer_extract_connect_info() indeed assumes that if no
non-TLS port is set, then this means we are trying to connect through
an already open socket, and otherwise the connection fails.
The presence of a TLS port is only checked when a non-TLS port is set.

This commit reworks that logic to start by extracting both the non-TLS
and TLS ports (only when using SPICE for the latter), and by only trying
to parse the socket to use if none of these 2 ports is set

This fixes rhbz#982840
This commit is contained in:
Christophe Fergeau 2013-07-10 18:20:09 +02:00
parent ac4c71a3f0
commit 59ca6bd8a7

View File

@ -335,24 +335,24 @@ virt_viewer_extract_connect_info(VirtViewer *self,
goto cleanup;
xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@port)", type);
if ((gport = virt_viewer_extract_xpath_string(xmldesc, xpath)) == NULL) {
free(xpath);
gport = virt_viewer_extract_xpath_string(xmldesc, xpath);
g_free(xpath);
if (g_str_equal(type, "spice")) {
xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@tlsPort)", type);
gtlsport = virt_viewer_extract_xpath_string(xmldesc, xpath);
g_free(xpath);
}
if (gport || gtlsport) {
xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@listen)", type);
ghost = virt_viewer_extract_xpath_string(xmldesc, xpath);
} else {
xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@socket)", type);
if ((unixsock = virt_viewer_extract_xpath_string(xmldesc, xpath)) == NULL) {
virt_viewer_app_simple_message_dialog(app, _("Cannot determine the graphic address for the guest %s"),
priv->domkey);
goto cleanup;
}
} else {
if (g_str_equal(type, "spice")) {
free(xpath);
xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@tlsPort)", type);
gtlsport = virt_viewer_extract_xpath_string(xmldesc, xpath);
}
free(xpath);
xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@listen)", type);
ghost = virt_viewer_extract_xpath_string(xmldesc, xpath);
}
if (ghost && gport)