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