cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

rfbproto.h (55088B)


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