Skip to content

Commit

Permalink
vnc: drop display+ws_display from VncDisplay
Browse files Browse the repository at this point in the history
Nobody cares about those strings, they are only used to check whenever
the vnc server / websocket support is enabled or not.  Add bools for
this and drop the strings.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
  • Loading branch information
kraxel committed Mar 12, 2015
1 parent 9159eb9 commit bf7aa45
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 35 deletions.
2 changes: 1 addition & 1 deletion ui/vnc-auth-sasl.c
Expand Up @@ -555,7 +555,7 @@ void start_auth_sasl(VncState *vs)

memset (&secprops, 0, sizeof secprops);
/* Inform SASL that we've got an external SSF layer from TLS */
if (strncmp(vs->vd->display, "unix:", 5) == 0
if (vs->vd->is_unix
#ifdef CONFIG_VNC_TLS
/* Disable SSF, if using TLS+x509+SASL only. TLS without x509
is not sufficiently strong */
Expand Down
54 changes: 23 additions & 31 deletions ui/vnc.c
Expand Up @@ -407,7 +407,7 @@ VncInfo *qmp_query_vnc(Error **errp)
VncInfo *info = g_malloc0(sizeof(*info));
VncDisplay *vd = vnc_display_find(NULL);

if (vd == NULL || vd->display == NULL) {
if (vd == NULL || !vd->enabled) {
info->enabled = false;
} else {
struct sockaddr_storage sa;
Expand Down Expand Up @@ -3190,16 +3190,15 @@ static void vnc_display_close(VncDisplay *vs)
{
if (!vs)
return;
g_free(vs->display);
vs->display = NULL;
vs->enabled = false;
vs->is_unix = false;
if (vs->lsock != -1) {
qemu_set_fd_handler2(vs->lsock, NULL, NULL, NULL, NULL);
close(vs->lsock);
vs->lsock = -1;
}
#ifdef CONFIG_VNC_WS
g_free(vs->ws_display);
vs->ws_display = NULL;
vs->ws_enabled = false;
if (vs->lwebsock != -1) {
qemu_set_fd_handler2(vs->lwebsock, NULL, NULL, NULL, NULL);
close(vs->lwebsock);
Expand Down Expand Up @@ -3329,7 +3328,7 @@ void vnc_display_open(const char *id, Error **errp)
bool reverse = false;
const char *vnc;
const char *has_to;
char *display, *to = NULL;
char *display, *ws_display = NULL, *to = NULL;
bool has_ipv4 = false;
bool has_ipv6 = false;
#ifdef CONFIG_VNC_WS
Expand Down Expand Up @@ -3369,10 +3368,9 @@ void vnc_display_open(const char *id, Error **errp)
has_ipv4 = qemu_opt_get_bool(opts, "ipv4", false);
has_ipv6 = qemu_opt_get_bool(opts, "ipv6", false);
display = g_strdup_printf("%s%s%s%s", vnc,
has_to ? to : "",
has_ipv4 ? ",ipv4" : "",
has_ipv6 ? ",ipv6" : "");
vs->display = g_strdup(display);
has_to ? to : "",
has_ipv4 ? ",ipv4" : "",
has_ipv6 ? ",ipv6" : "");

password = qemu_opt_get_bool(opts, "password", false);
if (password && fips_get_state()) {
Expand Down Expand Up @@ -3427,7 +3425,7 @@ void vnc_display_open(const char *id, Error **errp)
if (websocket) {
/* extract the host specification from display */
char *host = NULL, *host_end = NULL;
vs->websocket = 1;
vs->ws_enabled = true;

/* ipv6 hosts have colons */
host_end = strrchr(display, ':');
Expand All @@ -3436,7 +3434,7 @@ void vnc_display_open(const char *id, Error **errp)
} else {
host = g_strdup(":");
}
vs->ws_display = g_strconcat(host, websocket, NULL);
ws_display = g_strconcat(host, websocket, NULL);
g_free(host);
}
#endif /* CONFIG_VNC_WS */
Expand Down Expand Up @@ -3618,47 +3616,42 @@ void vnc_display_open(const char *id, Error **errp)
vnc_connect(vs, csock, false, false);
} else {
/* listen for connects */
char *dpy;
dpy = g_malloc(256);
if (strncmp(display, "unix:", 5) == 0) {
pstrcpy(dpy, 256, "unix:");
vs->lsock = unix_listen(display+5, dpy+5, 256-5, errp);
vs->lsock = unix_listen(display+5, NULL, 0, errp);
vs->is_unix = true;
} else {
vs->lsock = inet_listen(display, dpy, 256,
vs->lsock = inet_listen(display, NULL, 0,
SOCK_STREAM, 5900, errp);
if (vs->lsock < 0) {
g_free(dpy);
goto fail;
}
#ifdef CONFIG_VNC_WS
if (vs->websocket) {
if (vs->ws_display) {
vs->lwebsock = inet_listen(vs->ws_display, NULL, 256,
if (vs->ws_enabled) {
if (ws_display) {
vs->lwebsock = inet_listen(ws_display, NULL, 0,
SOCK_STREAM, 0, errp);
} else {
vs->lwebsock = inet_listen(vs->display, NULL, 256,
vs->lwebsock = inet_listen(display, NULL, 0,
SOCK_STREAM, 5700, errp);
}

if (vs->lwebsock < 0) {
if (vs->lsock) {
close(vs->lsock);
vs->lsock = -1;
}
g_free(dpy);
goto fail;
}
}
#endif /* CONFIG_VNC_WS */
}
g_free(to);
g_free(display);
g_free(vs->display);
vs->display = dpy;
vs->enabled = true;
qemu_set_fd_handler2(vs->lsock, NULL,
vnc_listen_regular_read, NULL, vs);
#ifdef CONFIG_VNC_WS
if (vs->websocket) {
g_free(ws_display);
if (vs->ws_enabled) {
qemu_set_fd_handler2(vs->lwebsock, NULL,
vnc_listen_websocket_read, NULL, vs);
}
Expand All @@ -3669,11 +3662,10 @@ void vnc_display_open(const char *id, Error **errp)
fail:
g_free(to);
g_free(display);
g_free(vs->display);
vs->display = NULL;
vs->enabled = false;
#ifdef CONFIG_VNC_WS
g_free(vs->ws_display);
vs->ws_display = NULL;
g_free(ws_display);
vs->ws_enabled = false;
#endif /* CONFIG_VNC_WS */
}

Expand Down
6 changes: 3 additions & 3 deletions ui/vnc.h
Expand Up @@ -158,8 +158,7 @@ struct VncDisplay
int lsock;
#ifdef CONFIG_VNC_WS
int lwebsock;
bool websocket;
char *ws_display;
bool ws_enabled;
#endif
DisplaySurface *ds;
DisplayChangeListener dcl;
Expand All @@ -176,7 +175,8 @@ struct VncDisplay

const char *id;
QTAILQ_ENTRY(VncDisplay) next;
char *display;
bool enabled;
bool is_unix;
char *password;
time_t expires;
int auth;
Expand Down

0 comments on commit bf7aa45

Please sign in to comment.