]> git.proxmox.com Git - mirror_qemu.git/blame - ui/vnc-ws.c
block: Declare blockdev-add and blockdev-del supported
[mirror_qemu.git] / ui / vnc-ws.c
CommitLineData
7536ee4b
TH
1/*
2 * QEMU VNC display driver: Websockets support
3 *
4 * Copyright (C) 2010 Joel Martin
5 * Copyright (C) 2012 Tim Hardeck
6 *
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this software; if not, see <http://www.gnu.org/licenses/>.
19 */
20
e16f4c87 21#include "qemu/osdep.h"
da34e65c 22#include "qapi/error.h"
7536ee4b 23#include "vnc.h"
d5f04223 24#include "io/channel-websock.h"
58369e22 25#include "qemu/bswap.h"
0057a0d5 26
60e705c5 27static void vncws_tls_handshake_done(QIOTask *task,
2cc45228
DB
28 gpointer user_data)
29{
30 VncState *vs = user_data;
60e705c5 31 Error *err = NULL;
4a48aaa9 32
60e705c5 33 if (qio_task_propagate_error(task, &err)) {
2cc45228
DB
34 VNC_DEBUG("Handshake failed %s\n", error_get_pretty(err));
35 vnc_client_error(vs);
60e705c5 36 error_free(err);
2cc45228 37 } else {
d5f04223 38 VNC_DEBUG("TLS handshake complete, starting websocket handshake\n");
04d2529d 39 vs->ioc_tag = qio_channel_add_watch(
2cc45228 40 QIO_CHANNEL(vs->ioc), G_IO_IN, vncws_handshake_io, vs, NULL);
3e305e4a 41 }
0057a0d5
TH
42}
43
2cc45228 44
04d2529d
DB
45gboolean vncws_tls_handshake_io(QIOChannel *ioc G_GNUC_UNUSED,
46 GIOCondition condition G_GNUC_UNUSED,
47 void *opaque)
0057a0d5 48{
2cc45228
DB
49 VncState *vs = opaque;
50 QIOChannelTLS *tls;
3e305e4a 51 Error *err = NULL;
0057a0d5 52
2cc45228
DB
53 VNC_DEBUG("TLS Websocket connection required\n");
54 if (vs->ioc_tag) {
55 g_source_remove(vs->ioc_tag);
56 vs->ioc_tag = 0;
57 }
58
59 tls = qio_channel_tls_new_server(
60 vs->ioc,
61 vs->vd->tlscreds,
62 vs->vd->tlsaclname,
63 &err);
64 if (!tls) {
65 VNC_DEBUG("Failed to setup TLS %s\n", error_get_pretty(err));
3e305e4a
DB
66 error_free(err);
67 vnc_client_error(vs);
04d2529d 68 return TRUE;
0057a0d5 69 }
3e305e4a 70
10bcfe58
DB
71 qio_channel_set_name(QIO_CHANNEL(tls), "vnc-ws-server-tls");
72
3e305e4a 73 VNC_DEBUG("Start TLS WS handshake process\n");
2cc45228
DB
74 object_unref(OBJECT(vs->ioc));
75 vs->ioc = QIO_CHANNEL(tls);
76 vs->tls = qio_channel_tls_get_session(tls);
77
78 qio_channel_tls_handshake(tls,
79 vncws_tls_handshake_done,
80 vs,
81 NULL);
82
04d2529d 83 return TRUE;
0057a0d5 84}
0057a0d5 85
7536ee4b 86
60e705c5 87static void vncws_handshake_done(QIOTask *task,
d5f04223
DB
88 gpointer user_data)
89{
90 VncState *vs = user_data;
60e705c5 91 Error *err = NULL;
7536ee4b 92
60e705c5 93 if (qio_task_propagate_error(task, &err)) {
d5f04223
DB
94 VNC_DEBUG("Websock handshake failed %s\n", error_get_pretty(err));
95 vnc_client_error(vs);
60e705c5 96 error_free(err);
d5f04223
DB
97 } else {
98 VNC_DEBUG("Websock handshake complete, starting VNC protocol\n");
dbee9897 99 vnc_start_protocol(vs);
04d2529d
DB
100 vs->ioc_tag = qio_channel_add_watch(
101 vs->ioc, G_IO_IN, vnc_client_io, vs, NULL);
7536ee4b
TH
102 }
103}
104
105
04d2529d
DB
106gboolean vncws_handshake_io(QIOChannel *ioc G_GNUC_UNUSED,
107 GIOCondition condition G_GNUC_UNUSED,
108 void *opaque)
109{
110 VncState *vs = opaque;
d5f04223 111 QIOChannelWebsock *wioc;
7536ee4b 112
d5f04223
DB
113 VNC_DEBUG("Websocket negotiate starting\n");
114 if (vs->ioc_tag) {
115 g_source_remove(vs->ioc_tag);
116 vs->ioc_tag = 0;
7536ee4b
TH
117 }
118
d5f04223 119 wioc = qio_channel_websock_new_server(vs->ioc);
10bcfe58 120 qio_channel_set_name(QIO_CHANNEL(wioc), "vnc-ws-server-websock");
7536ee4b 121
d5f04223
DB
122 object_unref(OBJECT(vs->ioc));
123 vs->ioc = QIO_CHANNEL(wioc);
7536ee4b 124
d5f04223
DB
125 qio_channel_websock_handshake(wioc,
126 vncws_handshake_done,
127 vs,
128 NULL);
7536ee4b 129
d5f04223 130 return TRUE;
7536ee4b 131}