LibVNCServer/LibVNCClient
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rfbproto.h
Go to the documentation of this file.
1 #ifndef RFBPROTO_H
2 #define RFBPROTO_H
3 
15 /*
16  * Copyright (C) 2009-2010 D. R. Commander. All Rights Reserved.
17  * Copyright (C) 2005 Rohit Kumar, Johannes E. Schindelin
18  * Copyright (C) 2004-2008 Sun Microsystems, Inc. All Rights Reserved.
19  * Copyright (C) 2000-2002 Constantin Kaplinsky. All Rights Reserved.
20  * Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
21  * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
22  *
23  * This is free software; you can redistribute it and/or modify
24  * it under the terms of the GNU General Public License as published by
25  * the Free Software Foundation; either version 2 of the License, or
26  * (at your option) any later version.
27  *
28  * This software is distributed in the hope that it will be useful,
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31  * GNU General Public License for more details.
32  *
33  * You should have received a copy of the GNU General Public License
34  * along with this software; if not, write to the Free Software
35  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
36  * USA.
37  */
38 
39 /*
40  * rfbproto.h - header file for the RFB protocol version 3.3
41  *
42  * Uses types CARD<n> for an n-bit unsigned integer, INT<n> for an n-bit signed
43  * integer (for n = 8, 16 and 32).
44  *
45  * All multiple byte integers are in big endian (network) order (most
46  * significant byte first). Unless noted otherwise there is no special
47  * alignment of protocol structures.
48  *
49  *
50  * Once the initial handshaking is done, all messages start with a type byte,
51  * (usually) followed by message-specific data. The order of definitions in
52  * this file is as follows:
53  *
54  * (1) Structures used in several types of message.
55  * (2) Structures used in the initial handshaking.
56  * (3) Message types.
57  * (4) Encoding types.
58  * (5) For each message type, the form of the data following the type byte.
59  * Sometimes this is defined by a single structure but the more complex
60  * messages have to be explained by comments.
61  */
62 
63 
64 #if defined(WIN32) && !defined(__MINGW32__)
65 #define LIBVNCSERVER_WORDS_BIGENDIAN
66 #define rfbBool int
67 #include <sys/timeb.h>
68 #include <winsock.h>
69 #undef SOCKET
70 #define SOCKET int
71 #else
72 #include <rfb/rfbconfig.h>
73 #include <rfb/rfbint.h>
74 #endif
75 
76 #ifdef LIBVNCSERVER_HAVE_LIBZ
77 #include <zlib.h>
78 #ifdef __CHECKER__
79 #undef Z_NULL
80 #define Z_NULL NULL
81 #endif
82 #endif
83 
84 /* some autotool versions do not properly prefix
85  WORDS_BIGENDIAN, so do that manually */
86 #ifdef WORDS_BIGENDIAN
87 #define LIBVNCSERVER_WORDS_BIGENDIAN
88 #endif
89 
90 /* MS compilers don't have strncasecmp */
91 #ifdef _MSC_VER
92 #define strncasecmp _strnicmp
93 #endif
94 
95 #if !defined(WIN32) || defined(__MINGW32__)
96 #define max(a,b) (((a)>(b))?(a):(b))
97 #ifdef LIBVNCSERVER_HAVE_SYS_TIME_H
98 #include <sys/time.h>
99 #endif
100 #ifdef LIBVNCSERVER_HAVE_NETINET_IN_H
101 #include <netinet/in.h>
102 #endif
103 #define SOCKET int
104 typedef int8_t rfbBool;
105 #undef FALSE
106 #define FALSE 0
107 #undef TRUE
108 #define TRUE -1
109 #endif
110 
111 typedef uint32_t rfbKeySym;
112 typedef uint32_t rfbPixel;
113 
114 #ifdef LIBVNCSERVER_NEED_INADDR_T
115 typedef uint32_t in_addr_t;
116 #endif
117 
118 #ifndef INADDR_NONE
119 #define INADDR_NONE ((in_addr_t) 0xffffffff)
120 #endif
121 
122 #define MAX_ENCODINGS 21
123 
124 /*****************************************************************************
125  *
126  * Structures used in several messages
127  *
128  *****************************************************************************/
129 
130 /*-----------------------------------------------------------------------------
131  * Structure used to specify a rectangle. This structure is a multiple of 4
132  * bytes so that it can be interspersed with 32-bit pixel data without
133  * affecting alignment.
134  */
135 
136 typedef struct {
137  uint16_t x;
138  uint16_t y;
139  uint16_t w;
140  uint16_t h;
141 } rfbRectangle;
142 
143 #define sz_rfbRectangle 8
144 
145 
146 /*-----------------------------------------------------------------------------
147  * Structure used to specify pixel format.
148  */
149 
150 typedef struct {
151 
152  uint8_t bitsPerPixel; /* 8,16,32 only */
153 
154  uint8_t depth; /* 8 to 32 */
155 
156  uint8_t bigEndian; /* True if multi-byte pixels are interpreted
157  as big endian, or if single-bit-per-pixel
158  has most significant bit of the byte
159  corresponding to first (leftmost) pixel. Of
160  course this is meaningless for 8 bits/pix */
161 
162  uint8_t trueColour; /* If false then we need a "colour map" to
163  convert pixels to RGB. If true, xxxMax and
164  xxxShift specify bits used for red, green
165  and blue */
166 
167  /* the following fields are only meaningful if trueColour is true */
168 
169  uint16_t redMax; /* maximum red value (= 2^n - 1 where n is the
170  number of bits used for red). Note this
171  value is always in big endian order. */
172 
173  uint16_t greenMax; /* similar for green */
174 
175  uint16_t blueMax; /* and blue */
176 
177  uint8_t redShift; /* number of shifts needed to get the red
178  value in a pixel to the least significant
179  bit. To find the red value from a given
180  pixel, do the following:
181  1) Swap pixel value according to bigEndian
182  (e.g. if bigEndian is false and host byte
183  order is big endian, then swap).
184  2) Shift right by redShift.
185  3) AND with redMax (in host byte order).
186  4) You now have the red value between 0 and
187  redMax. */
188 
189  uint8_t greenShift; /* similar for green */
190 
191  uint8_t blueShift; /* and blue */
192 
193  uint8_t pad1;
194  uint16_t pad2;
195 
197 
198 #define sz_rfbPixelFormat 16
199 
200 /* UltraVNC: Color settings values */
201 #define rfbPFFullColors 0
202 #define rfbPF256Colors 1
203 #define rfbPF64Colors 2
204 #define rfbPF8Colors 3
205 #define rfbPF8GreyColors 4
206 #define rfbPF4GreyColors 5
207 #define rfbPF2GreyColors 6
208 
209 
210 /*****************************************************************************
211  *
212  * Initial handshaking messages
213  *
214  *****************************************************************************/
215 
216 /*-----------------------------------------------------------------------------
217  * Protocol Version
218  *
219  * The server always sends 12 bytes to start which identifies the latest RFB
220  * protocol version number which it supports. These bytes are interpreted
221  * as a string of 12 ASCII characters in the format "RFB xxx.yyy\n" where
222  * xxx and yyy are the major and minor version numbers (for version 3.3
223  * this is "RFB 003.003\n").
224  *
225  * The client then replies with a similar 12-byte message giving the version
226  * number of the protocol which should actually be used (which may be different
227  * to that quoted by the server).
228  *
229  * It is intended that both clients and servers may provide some level of
230  * backwards compatibility by this mechanism. Servers in particular should
231  * attempt to provide backwards compatibility, and even forwards compatibility
232  * to some extent. For example if a client demands version 3.1 of the
233  * protocol, a 3.0 server can probably assume that by ignoring requests for
234  * encoding types it doesn't understand, everything will still work OK. This
235  * will probably not be the case for changes in the major version number.
236  *
237  * The format string below can be used in sprintf or sscanf to generate or
238  * decode the version string respectively.
239  */
240 
241 #define rfbProtocolVersionFormat "RFB %03d.%03d\n"
242 #define rfbProtocolMajorVersion 3
243 #define rfbProtocolMinorVersion 8
244 /* UltraVNC Viewer examines rfbProtocolMinorVersion number (4, and 6)
245  * to identify if the server supports File Transfer
246  */
247 
248 typedef char rfbProtocolVersionMsg[13]; /* allow extra byte for null */
249 
250 #define sz_rfbProtocolVersionMsg 12
251 
252 /*
253  * Negotiation of the security type (protocol version 3.7)
254  *
255  * Once the protocol version has been decided, the server either sends a list
256  * of supported security types, or informs the client about an error (when the
257  * number of security types is 0). Security type rfbSecTypeTight is used to
258  * enable TightVNC-specific protocol extensions. The value rfbSecTypeVncAuth
259  * stands for classic VNC authentication.
260  *
261  * The client selects a particular security type from the list provided by the
262  * server.
263  */
264 
265 #define rfbSecTypeInvalid 0
266 #define rfbSecTypeNone 1
267 #define rfbSecTypeVncAuth 2
268 
269 
270 /*-----------------------------------------------------------------------------
271  * Authentication
272  *
273  * Once the protocol version has been decided, the server then sends a 32-bit
274  * word indicating whether any authentication is needed on the connection.
275  * The value of this word determines the authentication scheme in use. For
276  * version 3.0 of the protocol this may have one of the following values:
277  */
278 
279 #define rfbConnFailed 0
280 #define rfbNoAuth 1
281 #define rfbVncAuth 2
282 
283 #define rfbRA2 5
284 #define rfbRA2ne 6
285 #define rfbSSPI 7
286 #define rfbSSPIne 8
287 #define rfbTight 16
288 #define rfbUltra 17
289 #define rfbTLS 18
290 #define rfbVeNCrypt 19
291 #define rfbARD 30
292 #define rfbMSLogon 0xfffffffa
293 
294 #define rfbVeNCryptPlain 256
295 #define rfbVeNCryptTLSNone 257
296 #define rfbVeNCryptTLSVNC 258
297 #define rfbVeNCryptTLSPlain 259
298 #define rfbVeNCryptX509None 260
299 #define rfbVeNCryptX509VNC 261
300 #define rfbVeNCryptX509Plain 262
301 #define rfbVeNCryptX509SASL 263
302 #define rfbVeNCryptTLSSASL 264
303 
304 /*
305  * rfbConnFailed: For some reason the connection failed (e.g. the server
306  * cannot support the desired protocol version). This is
307  * followed by a string describing the reason (where a
308  * string is specified as a 32-bit length followed by that
309  * many ASCII characters).
310  *
311  * rfbNoAuth: No authentication is needed.
312  *
313  * rfbVncAuth: The VNC authentication scheme is to be used. A 16-byte
314  * challenge follows, which the client encrypts as
315  * appropriate using the password and sends the resulting
316  * 16-byte response. If the response is correct, the
317  * server sends the 32-bit word rfbVncAuthOK. If a simple
318  * failure happens, the server sends rfbVncAuthFailed and
319  * closes the connection. If the server decides that too
320  * many failures have occurred, it sends rfbVncAuthTooMany
321  * and closes the connection. In the latter case, the
322  * server should not allow an immediate reconnection by
323  * the client.
324  */
325 
326 #define rfbVncAuthOK 0
327 #define rfbVncAuthFailed 1
328 #define rfbVncAuthTooMany 2
329 
330 
331 /*-----------------------------------------------------------------------------
332  * Client Initialisation Message
333  *
334  * Once the client and server are sure that they're happy to talk to one
335  * another, the client sends an initialisation message. At present this
336  * message only consists of a boolean indicating whether the server should try
337  * to share the desktop by leaving other clients connected, or give exclusive
338  * access to this client by disconnecting all other clients.
339  */
340 
341 typedef struct {
342  uint8_t shared;
344 
345 #define sz_rfbClientInitMsg 1
346 
347 
348 /*-----------------------------------------------------------------------------
349  * Server Initialisation Message
350  *
351  * After the client initialisation message, the server sends one of its own.
352  * This tells the client the width and height of the server's framebuffer,
353  * its pixel format and the name associated with the desktop.
354  */
355 
356 typedef struct {
359  rfbPixelFormat format; /* the server's preferred pixel format */
360  uint32_t nameLength;
361  /* followed by char name[nameLength] */
363 
364 #define sz_rfbServerInitMsg (8 + sz_rfbPixelFormat)
365 
366 
367 /*
368  * Following the server initialisation message it's up to the client to send
369  * whichever protocol messages it wants. Typically it will send a
370  * SetPixelFormat message and a SetEncodings message, followed by a
371  * FramebufferUpdateRequest. From then on the server will send
372  * FramebufferUpdate messages in response to the client's
373  * FramebufferUpdateRequest messages. The client should send
374  * FramebufferUpdateRequest messages with incremental set to true when it has
375  * finished processing one FramebufferUpdate and is ready to process another.
376  * With a fast client, the rate at which FramebufferUpdateRequests are sent
377  * should be regulated to avoid hogging the network.
378  */
379 
380 
381 
382 /*****************************************************************************
383  *
384  * Message types
385  *
386  *****************************************************************************/
387 
388 /* server -> client */
389 
390 #define rfbFramebufferUpdate 0
391 #define rfbSetColourMapEntries 1
392 #define rfbBell 2
393 #define rfbServerCutText 3
394 /* Modif sf@2002 */
395 #define rfbResizeFrameBuffer 4
396 #define rfbPalmVNCReSizeFrameBuffer 0xF
397 
398 /* client -> server */
399 
400 #define rfbSetPixelFormat 0
401 #define rfbFixColourMapEntries 1 /* not currently supported */
402 #define rfbSetEncodings 2
403 #define rfbFramebufferUpdateRequest 3
404 #define rfbKeyEvent 4
405 #define rfbPointerEvent 5
406 #define rfbClientCutText 6
407 /* Modif sf@2002 - actually bidirectionnal */
408 #define rfbFileTransfer 7
409 /* Modif sf@2002 */
410 #define rfbSetScale 8
411 /* Modif rdv@2002 */
412 #define rfbSetServerInput 9
413 /* Modif rdv@2002 */
414 #define rfbSetSW 10
415 /* Modif sf@2002 - TextChat - Bidirectionnal */
416 #define rfbTextChat 11
417 /* Modif cs@2005 */
418 /* PalmVNC 1.4 & 2.0 SetScale Factor message */
419 #define rfbPalmVNCSetScaleFactor 0xF
420 /* Xvp message - bidirectional */
421 #define rfbXvp 250
422 
423 
424 
425 
426 /*****************************************************************************
427  *
428  * Encoding types
429  *
430  *****************************************************************************/
431 
432 #define rfbEncodingRaw 0
433 #define rfbEncodingCopyRect 1
434 #define rfbEncodingRRE 2
435 #define rfbEncodingCoRRE 4
436 #define rfbEncodingHextile 5
437 #define rfbEncodingZlib 6
438 #define rfbEncodingTight 7
439 #define rfbEncodingTightPng 0xFFFFFEFC /* -260 */
440 #define rfbEncodingZlibHex 8
441 #define rfbEncodingUltra 9
442 #define rfbEncodingZRLE 16
443 #define rfbEncodingZYWRLE 17
444 
445 /* Cache & XOR-Zlib - rdv@2002 */
446 #define rfbEncodingCache 0xFFFF0000
447 #define rfbEncodingCacheEnable 0xFFFF0001
448 #define rfbEncodingXOR_Zlib 0xFFFF0002
449 #define rfbEncodingXORMonoColor_Zlib 0xFFFF0003
450 #define rfbEncodingXORMultiColor_Zlib 0xFFFF0004
451 #define rfbEncodingSolidColor 0xFFFF0005
452 #define rfbEncodingXOREnable 0xFFFF0006
453 #define rfbEncodingCacheZip 0xFFFF0007
454 #define rfbEncodingSolMonoZip 0xFFFF0008
455 #define rfbEncodingUltraZip 0xFFFF0009
456 
457 /* Xvp pseudo-encoding */
458 #define rfbEncodingXvp 0xFFFFFECB
459 
460 /*
461  * Special encoding numbers:
462  * 0xFFFFFD00 .. 0xFFFFFD05 -- subsampling level
463  * 0xFFFFFE00 .. 0xFFFFFE64 -- fine-grained quality level (0-100 scale)
464  * 0xFFFFFF00 .. 0xFFFFFF0F -- encoding-specific compression levels;
465  * 0xFFFFFF10 .. 0xFFFFFF1F -- mouse cursor shape data;
466  * 0xFFFFFF20 .. 0xFFFFFF2F -- various protocol extensions;
467  * 0xFFFFFF30 .. 0xFFFFFFDF -- not allocated yet;
468  * 0xFFFFFFE0 .. 0xFFFFFFEF -- quality level for JPEG compressor;
469  * 0xFFFFFFF0 .. 0xFFFFFFFF -- cross-encoding compression levels.
470  */
471 
472 #define rfbEncodingFineQualityLevel0 0xFFFFFE00
473 #define rfbEncodingFineQualityLevel100 0xFFFFFE64
474 #define rfbEncodingSubsamp1X 0xFFFFFD00
475 #define rfbEncodingSubsamp4X 0xFFFFFD01
476 #define rfbEncodingSubsamp2X 0xFFFFFD02
477 #define rfbEncodingSubsampGray 0xFFFFFD03
478 #define rfbEncodingSubsamp8X 0xFFFFFD04
479 #define rfbEncodingSubsamp16X 0xFFFFFD05
480 
481 #define rfbEncodingCompressLevel0 0xFFFFFF00
482 #define rfbEncodingCompressLevel1 0xFFFFFF01
483 #define rfbEncodingCompressLevel2 0xFFFFFF02
484 #define rfbEncodingCompressLevel3 0xFFFFFF03
485 #define rfbEncodingCompressLevel4 0xFFFFFF04
486 #define rfbEncodingCompressLevel5 0xFFFFFF05
487 #define rfbEncodingCompressLevel6 0xFFFFFF06
488 #define rfbEncodingCompressLevel7 0xFFFFFF07
489 #define rfbEncodingCompressLevel8 0xFFFFFF08
490 #define rfbEncodingCompressLevel9 0xFFFFFF09
491 
492 #define rfbEncodingXCursor 0xFFFFFF10
493 #define rfbEncodingRichCursor 0xFFFFFF11
494 #define rfbEncodingPointerPos 0xFFFFFF18
495 
496 #define rfbEncodingLastRect 0xFFFFFF20
497 #define rfbEncodingNewFBSize 0xFFFFFF21
498 
499 #define rfbEncodingQualityLevel0 0xFFFFFFE0
500 #define rfbEncodingQualityLevel1 0xFFFFFFE1
501 #define rfbEncodingQualityLevel2 0xFFFFFFE2
502 #define rfbEncodingQualityLevel3 0xFFFFFFE3
503 #define rfbEncodingQualityLevel4 0xFFFFFFE4
504 #define rfbEncodingQualityLevel5 0xFFFFFFE5
505 #define rfbEncodingQualityLevel6 0xFFFFFFE6
506 #define rfbEncodingQualityLevel7 0xFFFFFFE7
507 #define rfbEncodingQualityLevel8 0xFFFFFFE8
508 #define rfbEncodingQualityLevel9 0xFFFFFFE9
509 
510 
511 /* LibVNCServer additions. We claim 0xFFFE0000 - 0xFFFE00FF */
512 #define rfbEncodingKeyboardLedState 0xFFFE0000
513 #define rfbEncodingSupportedMessages 0xFFFE0001
514 #define rfbEncodingSupportedEncodings 0xFFFE0002
515 #define rfbEncodingServerIdentity 0xFFFE0003
516 
517 
518 /*****************************************************************************
519  *
520  * Server -> client message definitions
521  *
522  *****************************************************************************/
523 
524 
525 /*-----------------------------------------------------------------------------
526  * FramebufferUpdate - a block of rectangles to be copied to the framebuffer.
527  *
528  * This message consists of a header giving the number of rectangles of pixel
529  * data followed by the rectangles themselves. The header is padded so that
530  * together with the type byte it is an exact multiple of 4 bytes (to help
531  * with alignment of 32-bit pixels):
532  */
533 
534 typedef struct {
535  uint8_t type; /* always rfbFramebufferUpdate */
536  uint8_t pad;
537  uint16_t nRects;
538  /* followed by nRects rectangles */
540 
541 #define sz_rfbFramebufferUpdateMsg 4
542 
543 /*
544  * Each rectangle of pixel data consists of a header describing the position
545  * and size of the rectangle and a type word describing the encoding of the
546  * pixel data, followed finally by the pixel data. Note that if the client has
547  * not sent a SetEncodings message then it will only receive raw pixel data.
548  * Also note again that this structure is a multiple of 4 bytes.
549  */
550 
551 typedef struct {
553  uint32_t encoding; /* one of the encoding types rfbEncoding... */
555 
556 #define sz_rfbFramebufferUpdateRectHeader (sz_rfbRectangle + 4)
557 
558 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
559  * Supported Messages Encoding. This encoding does not contain any pixel data.
560  * Instead, it contains 2 sets of bitflags. These bitflags indicate what messages
561  * are supported by the server.
562  * rect->w contains byte count
563  */
564 
565 typedef struct {
566  uint8_t client2server[32]; /* maximum of 256 message types (256/8)=32 */
567  uint8_t server2client[32]; /* maximum of 256 message types (256/8)=32 */
569 
570 #define sz_rfbSupportedMessages 64
571 
572 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
573  * Supported Encodings Encoding. This encoding does not contain any pixel data.
574  * Instead, it contains a list of (uint32_t) Encodings supported by this server.
575  * rect->w contains byte count
576  * rect->h contains encoding count
577  */
578 
579 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
580  * Server Identity Encoding. This encoding does not contain any pixel data.
581  * Instead, it contains a text string containing information about the server.
582  * ie: "x11vnc: 0.8.1 lastmod: 2006-04-25 (libvncserver 0.9pre)\0"
583  * rect->w contains byte count
584  */
585 
586 
587 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
588  * Raw Encoding. Pixels are sent in top-to-bottom scanline order,
589  * left-to-right within a scanline with no padding in between.
590  */
591 
592 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
593  * KeyboardLedState Encoding. The X coordinate contains the Locked Modifiers
594  * so that a remote troubleshooter can identify that the users 'Caps Lock'
595  * is set... (It helps a *lot* when the users are untrained)
596  */
597 #define rfbKeyboardMaskShift 1
598 #define rfbKeyboardMaskCapsLock 2
599 #define rfbKeyboardMaskControl 4
600 #define rfbKeyboardMaskAlt 8
601 #define rfbKeyboardMaskMeta 16
602 #define rfbKeyboardMaskSuper 32
603 #define rfbKeyboardMaskHyper 64
604 #define rfbKeyboardMaskNumLock 128
605 #define rfbKeyboardMaskScrollLock 256
606 #define rfbKeyboardMaskAltGraph 512
607 
608 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
609  * CopyRect Encoding. The pixels are specified simply by the x and y position
610  * of the source rectangle.
611  */
612 
613 typedef struct {
614  uint16_t srcX;
615  uint16_t srcY;
616 } rfbCopyRect;
617 
618 #define sz_rfbCopyRect 4
619 
620 
621 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
622  * RRE - Rise-and-Run-length Encoding. We have an rfbRREHeader structure
623  * giving the number of subrectangles following. Finally the data follows in
624  * the form [<bgpixel><subrect><subrect>...] where each <subrect> is
625  * [<pixel><rfbRectangle>].
626  */
627 
628 typedef struct {
629  uint32_t nSubrects;
630 } rfbRREHeader;
631 
632 #define sz_rfbRREHeader 4
633 
634 
635 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
636  * CoRRE - Compact RRE Encoding. We have an rfbRREHeader structure giving
637  * the number of subrectangles following. Finally the data follows in the form
638  * [<bgpixel><subrect><subrect>...] where each <subrect> is
639  * [<pixel><rfbCoRRERectangle>]. This means that
640  * the whole rectangle must be at most 255x255 pixels.
641  */
642 
643 typedef struct {
644  uint8_t x;
645  uint8_t y;
646  uint8_t w;
647  uint8_t h;
649 
650 #define sz_rfbCoRRERectangle 4
651 
652 
653 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
654  * Hextile Encoding. The rectangle is divided up into "tiles" of 16x16 pixels,
655  * starting at the top left going in left-to-right, top-to-bottom order. If
656  * the width of the rectangle is not an exact multiple of 16 then the width of
657  * the last tile in each row will be correspondingly smaller. Similarly if the
658  * height is not an exact multiple of 16 then the height of each tile in the
659  * final row will also be smaller. Each tile begins with a "subencoding" type
660  * byte, which is a mask made up of a number of bits. If the Raw bit is set
661  * then the other bits are irrelevant; w*h pixel values follow (where w and h
662  * are the width and height of the tile). Otherwise the tile is encoded in a
663  * similar way to RRE, except that the position and size of each subrectangle
664  * can be specified in just two bytes. The other bits in the mask are as
665  * follows:
666  *
667  * BackgroundSpecified - if set, a pixel value follows which specifies
668  * the background colour for this tile. The first non-raw tile in a
669  * rectangle must have this bit set. If this bit isn't set then the
670  * background is the same as the last tile.
671  *
672  * ForegroundSpecified - if set, a pixel value follows which specifies
673  * the foreground colour to be used for all subrectangles in this tile.
674  * If this bit is set then the SubrectsColoured bit must be zero.
675  *
676  * AnySubrects - if set, a single byte follows giving the number of
677  * subrectangles following. If not set, there are no subrectangles (i.e.
678  * the whole tile is just solid background colour).
679  *
680  * SubrectsColoured - if set then each subrectangle is preceded by a pixel
681  * value giving the colour of that subrectangle. If not set, all
682  * subrectangles are the same colour, the foreground colour; if the
683  * ForegroundSpecified bit wasn't set then the foreground is the same as
684  * the last tile.
685  *
686  * The position and size of each subrectangle is specified in two bytes. The
687  * Pack macros below can be used to generate the two bytes from x, y, w, h,
688  * and the Extract macros can be used to extract the x, y, w, h values from
689  * the two bytes.
690  */
691 
692 #define rfbHextileRaw (1 << 0)
693 #define rfbHextileBackgroundSpecified (1 << 1)
694 #define rfbHextileForegroundSpecified (1 << 2)
695 #define rfbHextileAnySubrects (1 << 3)
696 #define rfbHextileSubrectsColoured (1 << 4)
697 
698 #define rfbHextilePackXY(x,y) (((x) << 4) | (y))
699 #define rfbHextilePackWH(w,h) ((((w)-1) << 4) | ((h)-1))
700 #define rfbHextileExtractX(byte) ((byte) >> 4)
701 #define rfbHextileExtractY(byte) ((byte) & 0xf)
702 #define rfbHextileExtractW(byte) (((byte) >> 4) + 1)
703 #define rfbHextileExtractH(byte) (((byte) & 0xf) + 1)
704 
705 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
706  * zlib - zlib compressed Encoding. We have an rfbZlibHeader structure
707  * giving the number of bytes following. Finally the data follows is
708  * zlib compressed version of the raw pixel data as negotiated.
709  * (NOTE: also used by Ultra Encoding)
710  */
711 
712 typedef struct {
713  uint32_t nBytes;
714 } rfbZlibHeader;
715 
716 #define sz_rfbZlibHeader 4
717 
718 #ifdef LIBVNCSERVER_HAVE_LIBZ
719 
720 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
721  * Tight and TightPng Encoding.
722  *
723  *-- TightPng is like Tight but basic compression is not used, instead PNG
724  * data is sent.
725  *
726  *-- The first byte of each Tight-encoded rectangle is a "compression control
727  * byte". Its format is as follows (bit 0 is the least significant one):
728  *
729  * bit 0: if 1, then compression stream 0 should be reset;
730  * bit 1: if 1, then compression stream 1 should be reset;
731  * bit 2: if 1, then compression stream 2 should be reset;
732  * bit 3: if 1, then compression stream 3 should be reset;
733  * bits 7-4: if 1000 (0x08), then the compression type is "fill",
734  * if 1001 (0x09), then the compression type is "jpeg",
735  * (Tight only) if 1010 (0x0A), then the compression type is
736  * "basic" and no Zlib compression was used,
737  * (Tight only) if 1110 (0x0E), then the compression type is
738  * "basic", no Zlib compression was used, and a "filter id" byte
739  * follows this byte,
740  * (TightPng only) if 1010 (0x0A), then the compression type is
741  * "png",
742  * if 0xxx, then the compression type is "basic" and Zlib
743  * compression was used,
744  * values greater than 1010 are not valid.
745  *
746  * If the compression type is "basic" and Zlib compression was used, then bits
747  * 6..4 of the compression control byte (those xxx in 0xxx) specify the
748  * following:
749  *
750  * bits 5-4: decimal representation is the index of a particular zlib
751  * stream which should be used for decompressing the data;
752  * bit 6: if 1, then a "filter id" byte is following this byte.
753  *
754  *-- The data that follows after the compression control byte described
755  * above depends on the compression type ("fill", "jpeg", "png" or "basic").
756  *
757  *-- If the compression type is "fill", then the only pixel value follows, in
758  * client pixel format (see NOTE 1). This value applies to all pixels of the
759  * rectangle.
760  *
761  *-- If the compression type is "jpeg" or "png", the following data stream
762  * looks like this:
763  *
764  * 1..3 bytes: data size (N) in compact representation;
765  * N bytes: JPEG or PNG image.
766  *
767  * Data size is compactly represented in one, two or three bytes, according
768  * to the following scheme:
769  *
770  * 0xxxxxxx (for values 0..127)
771  * 1xxxxxxx 0yyyyyyy (for values 128..16383)
772  * 1xxxxxxx 1yyyyyyy zzzzzzzz (for values 16384..4194303)
773  *
774  * Here each character denotes one bit, xxxxxxx are the least significant 7
775  * bits of the value (bits 0-6), yyyyyyy are bits 7-13, and zzzzzzzz are the
776  * most significant 8 bits (bits 14-21). For example, decimal value 10000
777  * should be represented as two bytes: binary 10010000 01001110, or
778  * hexadecimal 90 4E.
779  *
780  *-- If the compression type is "basic" and bit 6 of the compression control
781  * byte was set to 1, then the next (second) byte specifies "filter id" which
782  * tells the decoder what filter type was used by the encoder to pre-process
783  * pixel data before the compression. The "filter id" byte can be one of the
784  * following:
785  *
786  * 0: no filter ("copy" filter);
787  * 1: "palette" filter;
788  * 2: "gradient" filter.
789  *
790  *-- If bit 6 of the compression control byte is set to 0 (no "filter id"
791  * byte), or if the filter id is 0, then raw pixel values in the client
792  * format (see NOTE 1) will be compressed. See below details on the
793  * compression.
794  *
795  *-- The "gradient" filter pre-processes pixel data with a simple algorithm
796  * which converts each color component to a difference between a "predicted"
797  * intensity and the actual intensity. Such a technique does not affect
798  * uncompressed data size, but helps to compress photo-like images better.
799  * Pseudo-code for converting intensities to differences is the following:
800  *
801  * P[i,j] := V[i-1,j] + V[i,j-1] - V[i-1,j-1];
802  * if (P[i,j] < 0) then P[i,j] := 0;
803  * if (P[i,j] > MAX) then P[i,j] := MAX;
804  * D[i,j] := V[i,j] - P[i,j];
805  *
806  * Here V[i,j] is the intensity of a color component for a pixel at
807  * coordinates (i,j). MAX is the maximum value of intensity for a color
808  * component.
809  *
810  *-- The "palette" filter converts true-color pixel data to indexed colors
811  * and a palette which can consist of 2..256 colors. If the number of colors
812  * is 2, then each pixel is encoded in 1 bit, otherwise 8 bits is used to
813  * encode one pixel. 1-bit encoding is performed such way that the most
814  * significant bits correspond to the leftmost pixels, and each raw of pixels
815  * is aligned to the byte boundary. When "palette" filter is used, the
816  * palette is sent before the pixel data. The palette begins with an unsigned
817  * byte which value is the number of colors in the palette minus 1 (i.e. 1
818  * means 2 colors, 255 means 256 colors in the palette). Then follows the
819  * palette itself which consist of pixel values in client pixel format (see
820  * NOTE 1).
821  *
822  *-- The pixel data is compressed using the zlib library. But if the data
823  * size after applying the filter but before the compression is less then 12,
824  * then the data is sent as is, uncompressed. Four separate zlib streams
825  * (0..3) can be used and the decoder should read the actual stream id from
826  * the compression control byte (see NOTE 2).
827  *
828  * If the compression is not used, then the pixel data is sent as is,
829  * otherwise the data stream looks like this:
830  *
831  * 1..3 bytes: data size (N) in compact representation;
832  * N bytes: zlib-compressed data.
833  *
834  * Data size is compactly represented in one, two or three bytes, just like
835  * in the "jpeg" compression method (see above).
836  *
837  *-- NOTE 1. If the color depth is 24, and all three color components are
838  * 8-bit wide, then one pixel in Tight encoding is always represented by
839  * three bytes, where the first byte is red component, the second byte is
840  * green component, and the third byte is blue component of the pixel color
841  * value. This applies to colors in palettes as well.
842  *
843  *-- NOTE 2. The decoder must reset compression streams' states before
844  * decoding the rectangle, if some of bits 0,1,2,3 in the compression control
845  * byte are set to 1. Note that the decoder must reset zlib streams even if
846  * the compression type is "fill", "jpeg" or "png".
847  *
848  *-- NOTE 3. The "gradient" filter and "jpeg" compression may be used only
849  * when bits-per-pixel value is either 16 or 32, not 8.
850  *
851  *-- NOTE 4. The width of any Tight-encoded rectangle cannot exceed 2048
852  * pixels. If a rectangle is wider, it must be split into several rectangles
853  * and each one should be encoded separately.
854  *
855  */
856 
857 #define rfbTightExplicitFilter 0x04
858 #define rfbTightFill 0x08
859 #define rfbTightJpeg 0x09
860 #define rfbTightNoZlib 0x0A
861 #define rfbTightPng 0x0A
862 #define rfbTightMaxSubencoding 0x0A
863 
864 /* Filters to improve compression efficiency */
865 #define rfbTightFilterCopy 0x00
866 #define rfbTightFilterPalette 0x01
867 #define rfbTightFilterGradient 0x02
868 
869 #endif
870 
871 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
872  * XCursor encoding. This is a special encoding used to transmit X-style
873  * cursor shapes from server to clients. Note that for this encoding,
874  * coordinates in rfbFramebufferUpdateRectHeader structure hold hotspot
875  * position (r.x, r.y) and cursor size (r.w, r.h). If (w * h != 0), two RGB
876  * samples are sent after header in the rfbXCursorColors structure. They
877  * denote foreground and background colors of the cursor. If a client
878  * supports only black-and-white cursors, it should ignore these colors and
879  * assume that foreground is black and background is white. Next, two bitmaps
880  * (1 bits per pixel) follow: first one with actual data (value 0 denotes
881  * background color, value 1 denotes foreground color), second one with
882  * transparency data (bits with zero value mean that these pixels are
883  * transparent). Both bitmaps represent cursor data in a byte stream, from
884  * left to right, from top to bottom, and each row is byte-aligned. Most
885  * significant bits correspond to leftmost pixels. The number of bytes in
886  * each row can be calculated as ((w + 7) / 8). If (w * h == 0), cursor
887  * should be hidden (or default local cursor should be set by the client).
888  */
889 
890 typedef struct {
891  uint8_t foreRed;
892  uint8_t foreGreen;
893  uint8_t foreBlue;
894  uint8_t backRed;
895  uint8_t backGreen;
896  uint8_t backBlue;
898 
899 #define sz_rfbXCursorColors 6
900 
901 
902 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
903  * RichCursor encoding. This is a special encoding used to transmit cursor
904  * shapes from server to clients. It is similar to the XCursor encoding but
905  * uses client pixel format instead of two RGB colors to represent cursor
906  * image. For this encoding, coordinates in rfbFramebufferUpdateRectHeader
907  * structure hold hotspot position (r.x, r.y) and cursor size (r.w, r.h).
908  * After header, two pixmaps follow: first one with cursor image in current
909  * client pixel format (like in raw encoding), second with transparency data
910  * (1 bit per pixel, exactly the same format as used for transparency bitmap
911  * in the XCursor encoding). If (w * h == 0), cursor should be hidden (or
912  * default local cursor should be set by the client).
913  */
914 
915 
916 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
917  * ZRLE - encoding combining Zlib compression, tiling, palettisation and
918  * run-length encoding.
919  */
920 
921 typedef struct {
922  uint32_t length;
923 } rfbZRLEHeader;
924 
925 #define sz_rfbZRLEHeader 4
926 
927 #define rfbZRLETileWidth 64
928 #define rfbZRLETileHeight 64
929 
930 
931 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
932  * ZLIBHEX - zlib compressed Hextile Encoding. Essentially, this is the
933  * hextile encoding with zlib compression on the tiles that can not be
934  * efficiently encoded with one of the other hextile subencodings. The
935  * new zlib subencoding uses two bytes to specify the length of the
936  * compressed tile and then the compressed data follows. As with the
937  * raw sub-encoding, the zlib subencoding invalidates the other
938  * values, if they are also set.
939  */
940 
941 #define rfbHextileZlibRaw (1 << 5)
942 #define rfbHextileZlibHex (1 << 6)
943 #define rfbHextileZlibMono (1 << 7)
944 
945 
946 /*-----------------------------------------------------------------------------
947  * SetColourMapEntries - these messages are only sent if the pixel
948  * format uses a "colour map" (i.e. trueColour false) and the client has not
949  * fixed the entire colour map using FixColourMapEntries. In addition they
950  * will only start being sent after the client has sent its first
951  * FramebufferUpdateRequest. So if the client always tells the server to use
952  * trueColour then it never needs to process this type of message.
953  */
954 
955 typedef struct {
956  uint8_t type; /* always rfbSetColourMapEntries */
957  uint8_t pad;
958  uint16_t firstColour;
959  uint16_t nColours;
960 
961  /* Followed by nColours * 3 * uint16_t
962  r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
963 
965 
966 #define sz_rfbSetColourMapEntriesMsg 6
967 
968 
969 
970 /*-----------------------------------------------------------------------------
971  * Bell - ring a bell on the client if it has one.
972  */
973 
974 typedef struct {
975  uint8_t type; /* always rfbBell */
976 } rfbBellMsg;
977 
978 #define sz_rfbBellMsg 1
979 
980 
981 
982 /*-----------------------------------------------------------------------------
983  * ServerCutText - the server has new text in its cut buffer.
984  */
985 
986 typedef struct {
987  uint8_t type; /* always rfbServerCutText */
988  uint8_t pad1;
989  uint16_t pad2;
990  uint32_t length;
991  /* followed by char text[length] */
993 
994 #define sz_rfbServerCutTextMsg 8
995 
996 
997 /*-----------------------------------------------------------------------------
998  * // Modif sf@2002
999  * FileTransferMsg - The client sends FileTransfer message.
1000  * Bidirectional message - Files can be sent from client to server & vice versa
1001  */
1002 
1003 typedef struct _rfbFileTransferMsg {
1004  uint8_t type; /* always rfbFileTransfer */
1005  uint8_t contentType; /* See defines below */
1006  uint8_t contentParam;/* Other possible content classification (Dir or File name, etc..) */
1007  uint8_t pad; /* It appears that UltraVNC *forgot* to Swap16IfLE(contentParam) */
1008  uint32_t size; /* FileSize or packet index or error or other */
1009 /* uint32_t sizeH; Additional 32Bits params to handle big values. Only for V2 (we want backward compatibility between all V1 versions) */
1010  uint32_t length;
1011  /* followed by data char text[length] */
1013 
1014 #define sz_rfbFileTransferMsg 12
1015 
1016 #define rfbFileTransferVersion 2 /* v1 is the old FT version ( <= 1.0.0 RC18 versions) */
1017 
1018 /* FileTransfer Content types and Params defines */
1019 #define rfbDirContentRequest 1 /* Client asks for the content of a given Server directory */
1020 #define rfbDirPacket 2 /* Full directory name or full file name. */
1021  /* Null content means end of Directory */
1022 #define rfbFileTransferRequest 3 /* Client asks the server for the transfer of a given file */
1023 #define rfbFileHeader 4 /* First packet of a file transfer, containing file's features */
1024 #define rfbFilePacket 5 /* One chunk of the file */
1025 #define rfbEndOfFile 6 /* End of file transfer (the file has been received or error) */
1026 #define rfbAbortFileTransfer 7 /* The file transfer must be aborted, whatever the state */
1027 #define rfbFileTransferOffer 8 /* The client offers to send a file to the server */
1028 #define rfbFileAcceptHeader 9 /* The server accepts or rejects the file */
1029 #define rfbCommand 10 /* The Client sends a simple command (File Delete, Dir create etc...) */
1030 #define rfbCommandReturn 11 /* The Client receives the server's answer about a simple command */
1031 #define rfbFileChecksums 12 /* The zipped checksums of the destination file (Delta Transfer) */
1032 #define rfbFileTransferAccess 14 /* Request FileTransfer authorization */
1033 
1034  /* rfbDirContentRequest client Request - content params */
1035 #define rfbRDirContent 1 /* Request a Server Directory contents */
1036 #define rfbRDrivesList 2 /* Request the server's drives list */
1037 #define rfbRDirRecursiveList 3 /* Request a server directory content recursive sorted list */
1038 #define rfbRDirRecursiveSize 4 /* Request a server directory content recursive size */
1039 
1040  /* rfbDirPacket & rfbCommandReturn server Answer - content params */
1041 #define rfbADirectory 1 /* Reception of a directory name */
1042 #define rfbAFile 2 /* Reception of a file name */
1043 #define rfbADrivesList 3 /* Reception of a list of drives */
1044 #define rfbADirCreate 4 /* Response to a create dir command */
1045 #define rfbADirDelete 5 /* Response to a delete dir command */
1046 #define rfbAFileCreate 6 /* Response to a create file command */
1047 #define rfbAFileDelete 7 /* Response to a delete file command */
1048 #define rfbAFileRename 8 /* Response to a rename file command */
1049 #define rfbADirRename 9 /* Response to a rename dir command */
1050 #define rfbADirRecursiveListItem 10
1051 #define rfbADirRecursiveSize 11
1052 
1053  /* rfbCommand Command - content params */
1054 #define rfbCDirCreate 1 /* Request the server to create the given directory */
1055 #define rfbCDirDelete 2 /* Request the server to delete the given directory */
1056 #define rfbCFileCreate 3 /* Request the server to create the given file */
1057 #define rfbCFileDelete 4 /* Request the server to delete the given file */
1058 #define rfbCFileRename 5 /* Request the server to rename the given file */
1059 #define rfbCDirRename 6 /* Request the server to rename the given directory */
1060 
1061  /* Errors - content params or "size" field */
1062 #define rfbRErrorUnknownCmd 1 /* Unknown FileTransfer command. */
1063 #define rfbRErrorCmd 0xFFFFFFFF/* Error when a command fails on remote side (ret in "size" field) */
1064 
1065 #define sz_rfbBlockSize 8192 /* Size of a File Transfer packet (before compression) */
1066 #define rfbZipDirectoryPrefix "!UVNCDIR-\0" /* Transfered directory are zipped in a file with this prefix. Must end with "-" */
1067 #define sz_rfbZipDirectoryPrefix 9
1068 #define rfbDirPrefix "[ "
1069 #define rfbDirSuffix " ]"
1070 
1071 
1072 
1073 /*-----------------------------------------------------------------------------
1074  * Modif sf@2002
1075  * TextChatMsg - Utilized to order the TextChat mode on server or client
1076  * Bidirectional message
1077  */
1078 
1079 typedef struct _rfbTextChatMsg {
1080  uint8_t type; /* always rfbTextChat */
1081  uint8_t pad1; /* Could be used later as an additionnal param */
1082  uint16_t pad2; /* Could be used later as text offset, for instance */
1083  uint32_t length; /* Specific values for Open, close, finished (-1, -2, -3) */
1084  /* followed by char text[length] */
1085 } rfbTextChatMsg;
1086 
1087 #define sz_rfbTextChatMsg 8
1088 
1089 #define rfbTextMaxSize 4096
1090 #define rfbTextChatOpen 0xFFFFFFFF
1091 #define rfbTextChatClose 0xFFFFFFFE
1092 #define rfbTextChatFinished 0xFFFFFFFD
1093 
1094 
1095 /*-----------------------------------------------------------------------------
1096  * Xvp Message
1097  * Bidirectional message
1098  * A server which supports the xvp extension declares this by sending a message
1099  * with an Xvp_INIT xvp-message-code when it receives a request from the client
1100  * to use the xvp Pseudo-encoding. The server must specify in this message the
1101  * highest xvp-extension-version it supports: the client may assume that the
1102  * server supports all versions from 1 up to this value. The client is then
1103  * free to use any supported version. Currently, only version 1 is defined.
1104  *
1105  * A server which subsequently receives an xvp Client Message requesting an
1106  * operation which it is unable to perform, informs the client of this by
1107  * sending a message with an Xvp_FAIL xvp-message-code, and the same
1108  * xvp-extension-version as included in the client's operation request.
1109  *
1110  * A client supporting the xvp extension sends this to request that the server
1111  * initiate a clean shutdown, clean reboot or abrupt reset of the system whose
1112  * framebuffer the client is displaying.
1113  */
1114 
1115 
1116 typedef struct {
1117  uint8_t type; /* always rfbXvp */
1118  uint8_t pad;
1119  uint8_t version; /* xvp extension version */
1120  uint8_t code; /* xvp message code */
1121 } rfbXvpMsg;
1122 
1123 #define sz_rfbXvpMsg (4)
1124 
1125 /* server message codes */
1126 #define rfbXvp_Fail 0
1127 #define rfbXvp_Init 1
1128 /* client message codes */
1129 #define rfbXvp_Shutdown 2
1130 #define rfbXvp_Reboot 3
1131 #define rfbXvp_Reset 4
1132 
1133 
1134 /*-----------------------------------------------------------------------------
1135  * Modif sf@2002
1136  * ResizeFrameBuffer - The Client must change the size of its framebuffer
1137  */
1138 
1139 typedef struct _rfbResizeFrameBufferMsg {
1140  uint8_t type; /* always rfbResizeFrameBuffer */
1141  uint8_t pad1;
1142  uint16_t framebufferWidth; /* FrameBuffer width */
1143  uint16_t framebufferHeigth; /* FrameBuffer height */
1145 
1146 #define sz_rfbResizeFrameBufferMsg 6
1147 
1148 
1149 /*-----------------------------------------------------------------------------
1150  * Copyright (C) 2001 Harakan Software
1151  * PalmVNC 1.4 & 2.? ResizeFrameBuffer message
1152  * ReSizeFrameBuffer - tell the RFB client to alter its framebuffer, either
1153  * due to a resize of the server desktop or a client-requested scaling factor.
1154  * The pixel format remains unchanged.
1155  */
1156 
1157 typedef struct {
1158  uint8_t type; /* always rfbReSizeFrameBuffer */
1159  uint8_t pad1;
1160  uint16_t desktop_w; /* Desktop width */
1161  uint16_t desktop_h; /* Desktop height */
1162  uint16_t buffer_w; /* FrameBuffer width */
1163  uint16_t buffer_h; /* Framebuffer height */
1164  uint16_t pad2;
1165 
1167 
1168 #define sz_rfbPalmVNCReSizeFrameBufferMsg (12)
1169 
1170 
1171 
1172 
1173 /*-----------------------------------------------------------------------------
1174  * Union of all server->client messages.
1175  */
1176 
1177 typedef union {
1178  uint8_t type;
1189 
1190 
1191 
1192 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1193  * RDV Cache Encoding.
1194  * special is not used at this point, can be used to reset cache or other specials
1195  * just put it to make sure we don't have to change the encoding again.
1196  */
1197 
1198 typedef struct {
1199  uint16_t special;
1200 } rfbCacheRect;
1201 
1202 #define sz_rfbCacheRect 2
1203 
1204 
1205 
1206 
1207 /*****************************************************************************
1208  *
1209  * Message definitions (client -> server)
1210  *
1211  *****************************************************************************/
1212 
1213 
1214 /*-----------------------------------------------------------------------------
1215  * SetPixelFormat - tell the RFB server the format in which the client wants
1216  * pixels sent.
1217  */
1218 
1219 typedef struct {
1220  uint8_t type; /* always rfbSetPixelFormat */
1221  uint8_t pad1;
1222  uint16_t pad2;
1225 
1226 #define sz_rfbSetPixelFormatMsg (sz_rfbPixelFormat + 4)
1227 
1228 
1229 /*-----------------------------------------------------------------------------
1230  * FixColourMapEntries - when the pixel format uses a "colour map", fix
1231  * read-only colour map entries.
1232  *
1233  * ***************** NOT CURRENTLY SUPPORTED *****************
1234  */
1235 
1236 typedef struct {
1237  uint8_t type; /* always rfbFixColourMapEntries */
1238  uint8_t pad;
1239  uint16_t firstColour;
1240  uint16_t nColours;
1241 
1242  /* Followed by nColours * 3 * uint16_t
1243  r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
1244 
1246 
1247 #define sz_rfbFixColourMapEntriesMsg 6
1248 
1249 
1250 /*-----------------------------------------------------------------------------
1251  * SetEncodings - tell the RFB server which encoding types we accept. Put them
1252  * in order of preference, if we have any. We may always receive raw
1253  * encoding, even if we don't specify it here.
1254  */
1255 
1256 typedef struct {
1257  uint8_t type; /* always rfbSetEncodings */
1258  uint8_t pad;
1259  uint16_t nEncodings;
1260  /* followed by nEncodings * uint32_t encoding types */
1262 
1263 #define sz_rfbSetEncodingsMsg 4
1264 
1265 
1266 /*-----------------------------------------------------------------------------
1267  * FramebufferUpdateRequest - request for a framebuffer update. If incremental
1268  * is true then the client just wants the changes since the last update. If
1269  * false then it wants the whole of the specified rectangle.
1270  */
1271 
1272 typedef struct {
1273  uint8_t type; /* always rfbFramebufferUpdateRequest */
1274  uint8_t incremental;
1275  uint16_t x;
1276  uint16_t y;
1277  uint16_t w;
1278  uint16_t h;
1280 
1281 #define sz_rfbFramebufferUpdateRequestMsg 10
1282 
1283 
1284 /*-----------------------------------------------------------------------------
1285  * KeyEvent - key press or release
1286  *
1287  * Keys are specified using the "keysym" values defined by the X Window System.
1288  * For most ordinary keys, the keysym is the same as the corresponding ASCII
1289  * value. Other common keys are:
1290  *
1291  * BackSpace 0xff08
1292  * Tab 0xff09
1293  * Return or Enter 0xff0d
1294  * Escape 0xff1b
1295  * Insert 0xff63
1296  * Delete 0xffff
1297  * Home 0xff50
1298  * End 0xff57
1299  * Page Up 0xff55
1300  * Page Down 0xff56
1301  * Left 0xff51
1302  * Up 0xff52
1303  * Right 0xff53
1304  * Down 0xff54
1305  * F1 0xffbe
1306  * F2 0xffbf
1307  * ... ...
1308  * F12 0xffc9
1309  * Shift 0xffe1
1310  * Control 0xffe3
1311  * Meta 0xffe7
1312  * Alt 0xffe9
1313  */
1314 
1315 typedef struct {
1316  uint8_t type; /* always rfbKeyEvent */
1317  uint8_t down; /* true if down (press), false if up */
1318  uint16_t pad;
1319  uint32_t key; /* key is specified as an X keysym */
1320 } rfbKeyEventMsg;
1321 
1322 #define sz_rfbKeyEventMsg 8
1323 
1324 
1325 /*-----------------------------------------------------------------------------
1326  * PointerEvent - mouse/pen move and/or button press.
1327  */
1328 
1329 typedef struct {
1330  uint8_t type; /* always rfbPointerEvent */
1331  uint8_t buttonMask; /* bits 0-7 are buttons 1-8, 0=up, 1=down */
1332  uint16_t x;
1333  uint16_t y;
1335 
1336 #define rfbButton1Mask 1
1337 #define rfbButton2Mask 2
1338 #define rfbButton3Mask 4
1339 #define rfbButton4Mask 8
1340 #define rfbButton5Mask 16
1341 /* RealVNC 335 method */
1342 #define rfbWheelUpMask rfbButton4Mask
1343 #define rfbWheelDownMask rfbButton5Mask
1344 
1345 #define sz_rfbPointerEventMsg 6
1346 
1347 
1348 
1349 /*-----------------------------------------------------------------------------
1350  * ClientCutText - the client has new text in its cut buffer.
1351  */
1352 
1353 typedef struct {
1354  uint8_t type; /* always rfbClientCutText */
1355  uint8_t pad1;
1356  uint16_t pad2;
1357  uint32_t length;
1358  /* followed by char text[length] */
1360 
1361 #define sz_rfbClientCutTextMsg 8
1362 
1363 
1364 
1365 /*-----------------------------------------------------------------------------
1366  * sf@2002 - Set Server Scale
1367  * SetServerScale - Server must change the scale of the client buffer.
1368  */
1369 
1370 typedef struct _rfbSetScaleMsg {
1371  uint8_t type; /* always rfbSetScale */
1372  uint8_t scale; /* Scale value 1<sv<n */
1373  uint16_t pad;
1374 } rfbSetScaleMsg;
1375 
1376 #define sz_rfbSetScaleMsg 4
1377 
1378 
1379 /*-----------------------------------------------------------------------------
1380  * Copyright (C) 2001 Harakan Software
1381  * PalmVNC 1.4 & 2.? SetScale Factor message
1382  * SetScaleFactor - tell the RFB server to alter the scale factor for the
1383  * client buffer.
1384  */
1385 typedef struct {
1386  uint8_t type; /* always rfbPalmVNCSetScaleFactor */
1387 
1388  uint8_t scale; /* Scale factor (positive non-zero integer) */
1389  uint16_t pad2;
1391 
1392 #define sz_rfbPalmVNCSetScaleFactorMsg (4)
1393 
1394 
1395 /*-----------------------------------------------------------------------------
1396  * rdv@2002 - Set input status
1397  * SetServerInput - Server input is dis/enabled
1398  */
1399 
1400 typedef struct _rfbSetServerInputMsg {
1401  uint8_t type; /* always rfbSetScale */
1402  uint8_t status; /* Scale value 1<sv<n */
1403  uint16_t pad;
1405 
1406 #define sz_rfbSetServerInputMsg 4
1407 
1408 /*-----------------------------------------------------------------------------
1409  * rdv@2002 - Set SW
1410  * SetSW - Server SW/full desktop
1411  */
1412 
1413 typedef struct _rfbSetSWMsg {
1414  uint8_t type; /* always rfbSetSW */
1415  uint8_t status;
1416  uint16_t x;
1417  uint16_t y;
1418 } rfbSetSWMsg;
1419 
1420 #define sz_rfbSetSWMsg 6
1421 
1422 
1423 
1424 /*-----------------------------------------------------------------------------
1425  * Union of all client->server messages.
1426  */
1427 
1428 typedef union {
1429  uint8_t type;
1445 
1446 /*
1447  * vncauth.h - describes the functions provided by the vncauth library.
1448  */
1449 
1450 #define MAXPWLEN 8
1451 #define CHALLENGESIZE 16
1452 
1453 extern int rfbEncryptAndStorePasswd(char *passwd, char *fname);
1454 extern char *rfbDecryptPasswdFromFile(char *fname);
1455 extern void rfbRandomBytes(unsigned char *bytes);
1456 extern void rfbEncryptBytes(unsigned char *bytes, char *passwd);
1457 
1458 
1459 #endif