1 /*
2  * GTK VNC Widget
3  *
4  * Copyright (C) 2006  Anthony Liguori <anthony@codemonkey.ws>
5  * Copyright (C) 2009-2010 Daniel P. Berrange <dan@berrange.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.0 of the License, or (at your option) any later version.
11  *
12  * This library 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 GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21 
22 #ifndef VNC_CONNECTION_H
23 #define VNC_CONNECTION_H
24 
25 #include <glib.h>
26 #include <gio/gio.h>
27 
28 #include <vncframebuffer.h>
29 #include <vnccursor.h>
30 #include <vncutil.h>
31 #include <vncaudio.h>
32 
33 G_BEGIN_DECLS
34 
35 #define VNC_TYPE_CONNECTION            (vnc_connection_get_type ())
36 #define VNC_CONNECTION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), VNC_TYPE_CONNECTION, VncConnection))
37 #define VNC_CONNECTION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), VNC_TYPE_CONNECTION, VncConnectionClass))
38 #define VNC_IS_CONNECTION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VNC_TYPE_CONNECTION))
39 #define VNC_IS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VNC_TYPE_CONNECTION))
40 #define VNC_CONNECTION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), VNC_TYPE_CONNECTION, VncConnectionClass))
41 
42 /* identical to the ledstate bits */
43 #define VNC_LEDSTATE_SCROLL_LOCK (1 << 0)
44 #define VNC_LEDSTATE_NUM_LOCK    (1 << 1)
45 #define VNC_LEDSTATE_CAPS_LOCK   (1 << 2)
46 
47 
48 typedef struct _VncConnection VncConnection;
49 typedef struct _VncConnectionPrivate VncConnectionPrivate;
50 typedef struct _VncConnectionClass VncConnectionClass;
51 
52 struct _VncConnection
53 {
54     GObject parent;
55 
56     VncConnectionPrivate *priv;
57 
58     /* Do not add fields to this struct */
59 };
60 
61 struct _VncConnectionClass
62 {
63     GObjectClass parent_class;
64 
65     /* Signals */
66     void (*vnc_cursor_changed)(VncConnection *conn, VncCursor *cursor);
67     void (*vnc_pointer_mode_changed)(VncConnection *conn, gboolean absPointer);
68     void (*vnc_bell)(VncConnection *conn);
69     void (*vnc_server_cut_text)(VncConnection *conn, const GString *text);
70     void (*vnc_framebuffer_update)(VncConnection *conn, guint16 x, guint16 y, guint16 width, guint16 height);
71     void (*vnc_desktop_resize)(VncConnection *conn, guint16 width, guint16 height);
72     void (*vnc_pixel_format_changed)(VncConnection *conn, VncPixelFormat *format);
73     void (*vnc_auth_failure)(VncConnection *conn, const char *reason);
74     void (*vnc_auth_unsupported)(VncConnection *conn, unsigned int authType);
75     void (*vnc_auth_credential)(VncConnection *conn, GValueArray *creds);
76     void (*vnc_auth_choose_type)(VncConnection *conn, GValueArray *types);
77     void (*vnc_auth_choose_subtype)(VncConnection *conn, unsigned int type, GValueArray *subtypes);
78     void (*vnc_connected)(VncConnection *conn);
79     void (*vnc_initialized)(VncConnection *conn);
80     void (*vnc_disconnected)(VncConnection *conn);
81     void (*vnc_led_state)(VncConnection *conn);
82     void (*vnc_error)(VncConnection *conn, const char *message);
83 
84     /*
85      * If adding fields to this struct, remove corresponding
86      * amount of padding to avoid changing overall struct size
87      */
88     gpointer _vnc_reserved[VNC_PADDING_LARGE - 2];
89 };
90 
91 
92 typedef enum {
93     VNC_CONNECTION_ENCODING_RAW = 0,
94     VNC_CONNECTION_ENCODING_COPY_RECT = 1,
95     VNC_CONNECTION_ENCODING_RRE = 2,
96     VNC_CONNECTION_ENCODING_CORRE = 4,
97     VNC_CONNECTION_ENCODING_HEXTILE = 5,
98     VNC_CONNECTION_ENCODING_TIGHT = 7,
99     VNC_CONNECTION_ENCODING_ZRLE = 16,
100 
101     /* Tight JPEG quality levels */
102     VNC_CONNECTION_ENCODING_TIGHT_JPEG0 = -32,
103     VNC_CONNECTION_ENCODING_TIGHT_JPEG1 = -31,
104     VNC_CONNECTION_ENCODING_TIGHT_JPEG2 = -30,
105     VNC_CONNECTION_ENCODING_TIGHT_JPEG3 = -29,
106     VNC_CONNECTION_ENCODING_TIGHT_JPEG4 = -28,
107     VNC_CONNECTION_ENCODING_TIGHT_JPEG5 = -27,
108     VNC_CONNECTION_ENCODING_TIGHT_JPEG6 = -26,
109     VNC_CONNECTION_ENCODING_TIGHT_JPEG7 = -25,
110     VNC_CONNECTION_ENCODING_TIGHT_JPEG8 = -24,
111     VNC_CONNECTION_ENCODING_TIGHT_JPEG9 = -23,
112 
113     /* Pseudo encodings */
114     VNC_CONNECTION_ENCODING_DESKTOP_RESIZE = -223,
115     VNC_CONNECTION_ENCODING_WMVi = 0x574D5669,
116 
117     VNC_CONNECTION_ENCODING_CURSOR_POS = -232,
118     VNC_CONNECTION_ENCODING_RICH_CURSOR = -239,
119     VNC_CONNECTION_ENCODING_XCURSOR = -240,
120 
121     VNC_CONNECTION_ENCODING_POINTER_CHANGE = -257,
122     VNC_CONNECTION_ENCODING_EXT_KEY_EVENT = -258,
123     VNC_CONNECTION_ENCODING_AUDIO = -259,
124     VNC_CONNECTION_ENCODING_LED_STATE = -261,
125 } VncConnectionEncoding;
126 
127 typedef enum {
128     VNC_CONNECTION_AUTH_INVALID = 0,
129     VNC_CONNECTION_AUTH_NONE = 1,
130     VNC_CONNECTION_AUTH_VNC = 2,
131     VNC_CONNECTION_AUTH_RA2 = 5,
132     VNC_CONNECTION_AUTH_RA2NE = 6,
133     VNC_CONNECTION_AUTH_TIGHT = 16,
134     VNC_CONNECTION_AUTH_ULTRA = 17,
135     VNC_CONNECTION_AUTH_TLS = 18,  /* Used by VINO */
136     VNC_CONNECTION_AUTH_VENCRYPT = 19, /* Used by VeNCrypt and QEMU */
137     VNC_CONNECTION_AUTH_SASL = 20, /* SASL type used by VINO and QEMU */
138     VNC_CONNECTION_AUTH_ARD = 30, /* Apple remote desktop (screen sharing) */
139     VNC_CONNECTION_AUTH_MSLOGON = 0xfffffffa, /* Used by UltraVNC */
140 } VncConnectionAuth;
141 
142 typedef enum {
143     VNC_CONNECTION_AUTH_VENCRYPT_PLAIN = 256,
144     VNC_CONNECTION_AUTH_VENCRYPT_TLSNONE = 257,
145     VNC_CONNECTION_AUTH_VENCRYPT_TLSVNC = 258,
146     VNC_CONNECTION_AUTH_VENCRYPT_TLSPLAIN = 259,
147     VNC_CONNECTION_AUTH_VENCRYPT_X509NONE = 260,
148     VNC_CONNECTION_AUTH_VENCRYPT_X509VNC = 261,
149     VNC_CONNECTION_AUTH_VENCRYPT_X509PLAIN = 262,
150     VNC_CONNECTION_AUTH_VENCRYPT_X509SASL = 263,
151     VNC_CONNECTION_AUTH_VENCRYPT_TLSSASL = 264,
152 } VncConnectionAuthVencrypt;
153 
154 typedef enum {
155     VNC_CONNECTION_CREDENTIAL_PASSWORD,
156     VNC_CONNECTION_CREDENTIAL_USERNAME,
157     VNC_CONNECTION_CREDENTIAL_CLIENTNAME,
158 } VncConnectionCredential;
159 
160 GType vnc_connection_get_type(void) G_GNUC_CONST;
161 
162 VncConnection *vnc_connection_new(void);
163 
164 gboolean vnc_connection_open_fd(VncConnection *conn, int fd);
165 gboolean vnc_connection_open_fd_with_hostname(VncConnection *conn, int fd, const char *hostname);
166 gboolean vnc_connection_open_host(VncConnection *conn, const char *host, const char *port);
167 gboolean vnc_connection_open_addr(VncConnection *conn, GSocketAddress *addr, const char *hostname);
168 gboolean vnc_connection_is_open(VncConnection *conn);
169 void vnc_connection_shutdown(VncConnection *conn);
170 
171 gboolean vnc_connection_set_auth_type(VncConnection *conn, unsigned int type);
172 gboolean vnc_connection_set_auth_subtype(VncConnection *conn, unsigned int type);
173 gboolean vnc_connection_set_credential(VncConnection *conn, int type, const gchar *data);
174 
175 gboolean vnc_connection_is_initialized(VncConnection *conn);
176 
177 gboolean vnc_connection_client_cut_text(VncConnection *conn,
178                                         const void *data, size_t length);
179 
180 gboolean vnc_connection_pointer_event(VncConnection *conn, guint8 button_mask,
181                                       guint16 x, guint16 y);
182 
183 gboolean vnc_connection_key_event(VncConnection *conn, gboolean down_flag,
184                                   guint32 key, guint16 scancode);
185 
186 gboolean vnc_connection_framebuffer_update_request(VncConnection *conn,
187                                                    gboolean incremental,
188                                                    guint16 x, guint16 y,
189                                                    guint16 width, guint16 height);
190 
191 gboolean vnc_connection_set_encodings(VncConnection *conn, int n_encoding, gint32 *encoding);
192 
193 gboolean vnc_connection_set_pixel_format(VncConnection *conn,
194                                          const VncPixelFormat *fmt);
195 
196 const VncPixelFormat *vnc_connection_get_pixel_format(VncConnection *conn);
197 
198 gboolean vnc_connection_set_shared(VncConnection *conn, gboolean sharedFlag);
199 gboolean vnc_connection_get_shared(VncConnection *conn);
200 
201 gboolean vnc_connection_has_error(VncConnection *conn);
202 
203 gboolean vnc_connection_set_framebuffer(VncConnection *conn,
204                                         VncFramebuffer *fb);
205 
206 const char *vnc_connection_get_name(VncConnection *conn);
207 int vnc_connection_get_width(VncConnection *conn);
208 int vnc_connection_get_height(VncConnection *conn);
209 
210 VncCursor *vnc_connection_get_cursor(VncConnection *conn);
211 
212 gboolean vnc_connection_get_abs_pointer(VncConnection *conn);
213 gboolean vnc_connection_get_ext_key_event(VncConnection *conn);
214 int vnc_connection_get_ledstate(VncConnection *conn);
215 
216 gboolean vnc_connection_set_audio(VncConnection *conn,
217                                   VncAudio *audio);
218 
219 gboolean vnc_connection_set_audio_format(VncConnection *conn,
220                                          const VncAudioFormat *fmt);
221 const VncAudioFormat *vnc_connection_get_audio_format(VncConnection *conn);
222 
223 gboolean vnc_connection_audio_enable(VncConnection *conn);
224 gboolean vnc_connection_audio_disable(VncConnection *conn);
225 
226 
227 G_END_DECLS
228 
229 #endif /* VNC_CONNECTION_H */
230 /*
231  * Local variables:
232  *  c-indent-level: 4
233  *  c-basic-offset: 4
234  *  indent-tabs-mode: nil
235  * End:
236  */
237