]> git.ipfire.org Git - thirdparty/qemu.git/blame - ui/vnc-ws.c
include/qemu/osdep.h: Don't include qapi/error.h
[thirdparty/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"
0057a0d5 25
2cc45228
DB
26static void vncws_tls_handshake_done(Object *source,
27 Error *err,
28 gpointer user_data)
29{
30 VncState *vs = user_data;
4a48aaa9 31
2cc45228
DB
32 if (err) {
33 VNC_DEBUG("Handshake failed %s\n", error_get_pretty(err));
34 vnc_client_error(vs);
35 } else {
d5f04223 36 VNC_DEBUG("TLS handshake complete, starting websocket handshake\n");
04d2529d 37 vs->ioc_tag = qio_channel_add_watch(
2cc45228 38 QIO_CHANNEL(vs->ioc), G_IO_IN, vncws_handshake_io, vs, NULL);
3e305e4a 39 }
0057a0d5
TH
40}
41
2cc45228 42
04d2529d
DB
43gboolean vncws_tls_handshake_io(QIOChannel *ioc G_GNUC_UNUSED,
44 GIOCondition condition G_GNUC_UNUSED,
45 void *opaque)
0057a0d5 46{
2cc45228
DB
47 VncState *vs = opaque;
48 QIOChannelTLS *tls;
3e305e4a 49 Error *err = NULL;
0057a0d5 50
2cc45228
DB
51 VNC_DEBUG("TLS Websocket connection required\n");
52 if (vs->ioc_tag) {
53 g_source_remove(vs->ioc_tag);
54 vs->ioc_tag = 0;
55 }
56
57 tls = qio_channel_tls_new_server(
58 vs->ioc,
59 vs->vd->tlscreds,
60 vs->vd->tlsaclname,
61 &err);
62 if (!tls) {
63 VNC_DEBUG("Failed to setup TLS %s\n", error_get_pretty(err));
3e305e4a
DB
64 error_free(err);
65 vnc_client_error(vs);
04d2529d 66 return TRUE;
0057a0d5 67 }
3e305e4a 68
3e305e4a 69 VNC_DEBUG("Start TLS WS handshake process\n");
2cc45228
DB
70 object_unref(OBJECT(vs->ioc));
71 vs->ioc = QIO_CHANNEL(tls);
72 vs->tls = qio_channel_tls_get_session(tls);
73
74 qio_channel_tls_handshake(tls,
75 vncws_tls_handshake_done,
76 vs,
77 NULL);
78
04d2529d 79 return TRUE;
0057a0d5 80}
0057a0d5 81
7536ee4b 82
d5f04223
DB
83static void vncws_handshake_done(Object *source,
84 Error *err,
85 gpointer user_data)
86{
87 VncState *vs = user_data;
7536ee4b 88
d5f04223
DB
89 if (err) {
90 VNC_DEBUG("Websock handshake failed %s\n", error_get_pretty(err));
91 vnc_client_error(vs);
92 } else {
93 VNC_DEBUG("Websock handshake complete, starting VNC protocol\n");
94 vnc_init_state(vs);
04d2529d
DB
95 vs->ioc_tag = qio_channel_add_watch(
96 vs->ioc, G_IO_IN, vnc_client_io, vs, NULL);
7536ee4b
TH
97 }
98}
99
100
04d2529d
DB
101gboolean vncws_handshake_io(QIOChannel *ioc G_GNUC_UNUSED,
102 GIOCondition condition G_GNUC_UNUSED,
103 void *opaque)
104{
105 VncState *vs = opaque;
d5f04223 106 QIOChannelWebsock *wioc;
7536ee4b 107
d5f04223
DB
108 VNC_DEBUG("Websocket negotiate starting\n");
109 if (vs->ioc_tag) {
110 g_source_remove(vs->ioc_tag);
111 vs->ioc_tag = 0;
7536ee4b
TH
112 }
113
d5f04223 114 wioc = qio_channel_websock_new_server(vs->ioc);
7536ee4b 115
d5f04223
DB
116 object_unref(OBJECT(vs->ioc));
117 vs->ioc = QIO_CHANNEL(wioc);
7536ee4b 118
d5f04223
DB
119 qio_channel_websock_handshake(wioc,
120 vncws_handshake_done,
121 vs,
122 NULL);
7536ee4b 123
d5f04223 124 return TRUE;
7536ee4b 125}