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