target/mips: Clean up handling of CP0 register 25
[qemu/ar7.git] / ui / vnc-ws.c
blob95c9703c72401e7f84a742510bb37b173004f3a3
1 /*
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"
22 #include "qapi/error.h"
23 #include "vnc.h"
24 #include "io/channel-websock.h"
25 #include "qemu/bswap.h"
26 #include "trace.h"
28 static void vncws_tls_handshake_done(QIOTask *task,
29 gpointer user_data)
31 VncState *vs = user_data;
32 Error *err = NULL;
34 if (qio_task_propagate_error(task, &err)) {
35 VNC_DEBUG("Handshake failed %s\n", error_get_pretty(err));
36 vnc_client_error(vs);
37 error_free(err);
38 } else {
39 VNC_DEBUG("TLS handshake complete, starting websocket handshake\n");
40 if (vs->ioc_tag) {
41 g_source_remove(vs->ioc_tag);
43 vs->ioc_tag = qio_channel_add_watch(
44 QIO_CHANNEL(vs->ioc), G_IO_IN, vncws_handshake_io, vs, NULL);
49 gboolean vncws_tls_handshake_io(QIOChannel *ioc G_GNUC_UNUSED,
50 GIOCondition condition G_GNUC_UNUSED,
51 void *opaque)
53 VncState *vs = opaque;
54 QIOChannelTLS *tls;
55 Error *err = NULL;
57 if (vs->ioc_tag) {
58 g_source_remove(vs->ioc_tag);
59 vs->ioc_tag = 0;
62 tls = qio_channel_tls_new_server(
63 vs->ioc,
64 vs->vd->tlscreds,
65 vs->vd->tlsauthzid,
66 &err);
67 if (!tls) {
68 VNC_DEBUG("Failed to setup TLS %s\n", error_get_pretty(err));
69 error_free(err);
70 vnc_client_error(vs);
71 return TRUE;
74 qio_channel_set_name(QIO_CHANNEL(tls), "vnc-ws-server-tls");
76 object_unref(OBJECT(vs->ioc));
77 vs->ioc = QIO_CHANNEL(tls);
78 trace_vnc_client_io_wrap(vs, vs->ioc, "tls");
79 vs->tls = qio_channel_tls_get_session(tls);
81 qio_channel_tls_handshake(tls,
82 vncws_tls_handshake_done,
83 vs,
84 NULL,
85 NULL);
87 return TRUE;
91 static void vncws_handshake_done(QIOTask *task,
92 gpointer user_data)
94 VncState *vs = user_data;
95 Error *err = NULL;
97 if (qio_task_propagate_error(task, &err)) {
98 VNC_DEBUG("Websock handshake failed %s\n", error_get_pretty(err));
99 vnc_client_error(vs);
100 error_free(err);
101 } else {
102 VNC_DEBUG("Websock handshake complete, starting VNC protocol\n");
103 vnc_start_protocol(vs);
104 if (vs->ioc_tag) {
105 g_source_remove(vs->ioc_tag);
107 vs->ioc_tag = qio_channel_add_watch(
108 vs->ioc, G_IO_IN, vnc_client_io, vs, NULL);
113 gboolean vncws_handshake_io(QIOChannel *ioc G_GNUC_UNUSED,
114 GIOCondition condition G_GNUC_UNUSED,
115 void *opaque)
117 VncState *vs = opaque;
118 QIOChannelWebsock *wioc;
120 if (vs->ioc_tag) {
121 g_source_remove(vs->ioc_tag);
122 vs->ioc_tag = 0;
125 wioc = qio_channel_websock_new_server(vs->ioc);
126 qio_channel_set_name(QIO_CHANNEL(wioc), "vnc-ws-server-websock");
128 object_unref(OBJECT(vs->ioc));
129 vs->ioc = QIO_CHANNEL(wioc);
130 trace_vnc_client_io_wrap(vs, vs->ioc, "websock");
132 qio_channel_websock_handshake(wioc,
133 vncws_handshake_done,
135 NULL);
137 return TRUE;