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