2 * QEMU VNC display driver: Websockets support
4 * Copyright (C) 2010 Joel Martin
5 * Copyright (C) 2012 Tim Hardeck
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.
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.
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/>.
21 #include "qemu/osdep.h"
23 #include "io/channel-websock.h"
25 static void vncws_tls_handshake_done(Object
*source
,
29 VncState
*vs
= user_data
;
32 VNC_DEBUG("Handshake failed %s\n", error_get_pretty(err
));
35 VNC_DEBUG("TLS handshake complete, starting websocket handshake\n");
36 vs
->ioc_tag
= qio_channel_add_watch(
37 QIO_CHANNEL(vs
->ioc
), G_IO_IN
, vncws_handshake_io
, vs
, NULL
);
42 gboolean
vncws_tls_handshake_io(QIOChannel
*ioc G_GNUC_UNUSED
,
43 GIOCondition condition G_GNUC_UNUSED
,
46 VncState
*vs
= opaque
;
50 VNC_DEBUG("TLS Websocket connection required\n");
52 g_source_remove(vs
->ioc_tag
);
56 tls
= qio_channel_tls_new_server(
62 VNC_DEBUG("Failed to setup TLS %s\n", error_get_pretty(err
));
68 VNC_DEBUG("Start TLS WS handshake process\n");
69 object_unref(OBJECT(vs
->ioc
));
70 vs
->ioc
= QIO_CHANNEL(tls
);
71 vs
->tls
= qio_channel_tls_get_session(tls
);
73 qio_channel_tls_handshake(tls
,
74 vncws_tls_handshake_done
,
82 static void vncws_handshake_done(Object
*source
,
86 VncState
*vs
= user_data
;
89 VNC_DEBUG("Websock handshake failed %s\n", error_get_pretty(err
));
92 VNC_DEBUG("Websock handshake complete, starting VNC protocol\n");
94 vs
->ioc_tag
= qio_channel_add_watch(
95 vs
->ioc
, G_IO_IN
, vnc_client_io
, vs
, NULL
);
100 gboolean
vncws_handshake_io(QIOChannel
*ioc G_GNUC_UNUSED
,
101 GIOCondition condition G_GNUC_UNUSED
,
104 VncState
*vs
= opaque
;
105 QIOChannelWebsock
*wioc
;
107 VNC_DEBUG("Websocket negotiate starting\n");
109 g_source_remove(vs
->ioc_tag
);
113 wioc
= qio_channel_websock_new_server(vs
->ioc
);
115 object_unref(OBJECT(vs
->ioc
));
116 vs
->ioc
= QIO_CHANNEL(wioc
);
118 qio_channel_websock_handshake(wioc
,
119 vncws_handshake_done
,