Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/vncdll/winvnc/rfbproto.h
Views: 11777
/*1* Copyright (C) 2000-2006 Constantin Kaplinsky. All Rights Reserved.2* Copyright (C) 2000 Tridia Corporation. All Rights Reserved.3* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.4*5* This is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* This software is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this software; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,18* USA.19*/2021/*22* rfbproto.h - header file for the RFB protocol, versions 3.3, 3.7 and 3.7t,23* 3.8 and 3.8t ("t" suffix denotes TightVNC protocol extensions enabled)24*25* Uses types CARD<n> for an n-bit unsigned integer, INT<n> for an n-bit signed26* integer (for n = 8, 16 and 32).27*28* All multiple byte integers are in big endian (network) order (most29* significant byte first). Unless noted otherwise there is no special30* alignment of protocol structures.31*32*33* Once the initial handshaking is done, all messages start with a type byte,34* (usually) followed by message-specific data. The order of definitions in35* this file is as follows:36*37* (1) Structures used in several types of message.38* (2) Structures used in the initial handshaking.39* (3) Message types.40* (4) Encoding types.41* (5) For each message type, the form of the data following the type byte.42* Sometimes this is defined by a single structure but the more complex43* messages have to be explained by comments.44*/454647/*****************************************************************************48*49* Structures used in several messages50*51*****************************************************************************/5253/*-----------------------------------------------------------------------------54* Structure used to specify a rectangle. This structure is a multiple of 455* bytes so that it can be interspersed with 32-bit pixel data without56* affecting alignment.57*/5859typedef struct _rfbRectangle {60CARD16 x;61CARD16 y;62CARD16 w;63CARD16 h;64} rfbRectangle;6566#define sz_rfbRectangle 8676869/*-----------------------------------------------------------------------------70* Structure used to specify pixel format.71*/7273typedef struct _rfbPixelFormat {7475CARD8 bitsPerPixel; /* 8,16,32 only */7677CARD8 depth; /* 8 to 32 */7879CARD8 bigEndian; /* True if multi-byte pixels are interpreted80as big endian, or if single-bit-per-pixel81has most significant bit of the byte82corresponding to first (leftmost) pixel. Of83course this is meaningless for 8 bits/pix */8485CARD8 trueColour; /* If false then we need a "colour map" to86convert pixels to RGB. If true, xxxMax and87xxxShift specify bits used for red, green88and blue */8990/* the following fields are only meaningful if trueColour is true */9192CARD16 redMax; /* maximum red value (= 2^n - 1 where n is the93number of bits used for red). Note this94value is always in big endian order. */9596CARD16 greenMax; /* similar for green */9798CARD16 blueMax; /* and blue */99100CARD8 redShift; /* number of shifts needed to get the red101value in a pixel to the least significant102bit. To find the red value from a given103pixel, do the following:1041) Swap pixel value according to bigEndian105(e.g. if bigEndian is false and host byte106order is big endian, then swap).1072) Shift right by redShift.1083) AND with redMax (in host byte order).1094) You now have the red value between 0 and110redMax. */111112CARD8 greenShift; /* similar for green */113114CARD8 blueShift; /* and blue */115116CARD8 pad1;117CARD16 pad2;118119} rfbPixelFormat;120121#define sz_rfbPixelFormat 16122123124/*-----------------------------------------------------------------------------125* Structure used to describe protocol options such as tunneling methods,126* authentication schemes and message types (protocol versions 3.7t, 3.8t).127*/128129typedef struct _rfbCapabilityInfo {130131CARD32 code; /* numeric identifier */132CARD8 vendorSignature[4]; /* vendor identification */133CARD8 nameSignature[8]; /* abbreviated option name */134135} rfbCapabilityInfo;136137#define sz_rfbCapabilityInfoVendor 4138#define sz_rfbCapabilityInfoName 8139#define sz_rfbCapabilityInfo 16140141/*142* Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC.143*/144145#define rfbStandardVendor "STDV"146#define rfbTridiaVncVendor "TRDV"147#define rfbTightVncVendor "TGHT"148149150/*****************************************************************************151*152* Initial handshaking messages153*154*****************************************************************************/155156/*-----------------------------------------------------------------------------157* Protocol Version158*159* The server always sends 12 bytes to start which identifies the latest RFB160* protocol version number which it supports. These bytes are interpreted161* as a string of 12 ASCII characters in the format "RFB xxx.yyy\n" where162* xxx and yyy are the major and minor version numbers (e.g. for version 3.8163* this is "RFB 003.008\n").164*165* The client then replies with a similar 12-byte message giving the version166* number of the protocol which should actually be used (which may be different167* to that quoted by the server).168*169* It is intended that both clients and servers may provide some level of170* backwards compatibility by this mechanism. Servers in particular should171* attempt to provide backwards compatibility, and even forwards compatibility172* to some extent. For example if a client demands version 3.1 of the173* protocol, a 3.0 server can probably assume that by ignoring requests for174* encoding types it doesn't understand, everything will still work OK. This175* will probably not be the case for changes in the major version number.176*177* The format string below can be used in sprintf or sscanf to generate or178* decode the version string respectively.179*/180181#define rfbProtocolVersionFormat "RFB %03d.%03d\n"182183typedef char rfbProtocolVersionMsg[13]; /* allow extra byte for null */184185#define sz_rfbProtocolVersionMsg 12186187188/*189* Negotiation of the security type (protocol versions 3.7, 3.8)190*191* Once the protocol version has been decided, the server either sends a list192* of supported security types, or informs the client about an error (when the193* number of security types is 0). Security type rfbSecTypeTight is used to194* enable TightVNC-specific protocol extensions. The value rfbSecTypeVncAuth195* stands for classic VNC authentication.196*197* The client selects a particular security type from the list provided by the198* server.199*/200201#define rfbSecTypeInvalid 0202#define rfbSecTypeNone 1203#define rfbSecTypeVncAuth 2204#define rfbSecTypeTight 16205206207/*-----------------------------------------------------------------------------208* Negotiation of Tunneling Capabilities (protocol versions 3.7t, 3.8t)209*210* If the chosen security type is rfbSecTypeTight, the server sends a list of211* supported tunneling methods ("tunneling" refers to any additional layer of212* data transformation, such as encryption or external compression.)213*214* nTunnelTypes specifies the number of following rfbCapabilityInfo structures215* that list all supported tunneling methods in the order of preference.216*217* NOTE: If nTunnelTypes is 0, that tells the client that no tunneling can be218* used, and the client should not send a response requesting a tunneling219* method.220*/221222typedef struct _rfbTunnelingCapsMsg {223CARD32 nTunnelTypes;224/* followed by nTunnelTypes * rfbCapabilityInfo structures */225} rfbTunnelingCapsMsg;226227#define sz_rfbTunnelingCapsMsg 4228229/*-----------------------------------------------------------------------------230* Tunneling Method Request (protocol versions 3.7t, 3.8t)231*232* If the list of tunneling capabilities sent by the server was not empty, the233* client should reply with a 32-bit code specifying a particular tunneling234* method. The following code should be used for no tunneling.235*/236237#define rfbNoTunneling 0238#define sig_rfbNoTunneling "NOTUNNEL"239240241/*-----------------------------------------------------------------------------242* Negotiation of Authentication Capabilities (protocol versions 3.7t, 3.8t)243*244* After setting up tunneling, the server sends a list of supported245* authentication schemes.246*247* nAuthTypes specifies the number of following rfbCapabilityInfo structures248* that list all supported authentication schemes in the order of preference.249*250* NOTE: If nAuthTypes is 0, that tells the client that no authentication is251* necessary, and the client should not send a response requesting an252* authentication scheme.253*/254255typedef struct _rfbAuthenticationCapsMsg {256CARD32 nAuthTypes;257/* followed by nAuthTypes * rfbCapabilityInfo structures */258} rfbAuthenticationCapsMsg;259260#define sz_rfbAuthenticationCapsMsg 4261262/*-----------------------------------------------------------------------------263* Authentication Scheme Request (protocol versions 3.7t, 3.8t)264*265* If the list of authentication capabilities sent by the server was not empty,266* the client should reply with a 32-bit code specifying a particular267* authentication scheme. The following codes are supported.268*/269270/* Standard authentication methods. */271#define rfbAuthNone 1272#define rfbAuthVNC 2273274#define sig_rfbAuthNone "NOAUTH__"275#define sig_rfbAuthVNC "VNCAUTH_"276277/* These two are not used in the mainstream version. */278#define rfbAuthUnixLogin 129279#define rfbAuthExternal 130280281#define sig_rfbAuthUnixLogin "ULGNAUTH"282#define sig_rfbAuthExternal "XTRNAUTH"283284285/*-----------------------------------------------------------------------------286* Authentication result codes (all protocol versions, but rfbAuthTooMany is287* not used in protocol versions above 3.3)288*289* In the protocol version 3.8 and above, rfbAuthFailed is followed by a text290* string describing the reason of failure. The text string is preceded with a291* 32-bit counter of bytes in the string.292*/293294#define rfbAuthOK 0295#define rfbAuthFailed 1296#define rfbAuthTooMany 2297298299/*-----------------------------------------------------------------------------300* Client Initialisation Message301*302* Once the client and server are sure that they're happy to talk to one303* another, the client sends an initialisation message. At present this304* message only consists of a boolean indicating whether the server should try305* to share the desktop by leaving other clients connected, or give exclusive306* access to this client by disconnecting all other clients.307*/308309typedef struct _rfbClientInitMsg {310CARD8 shared;311} rfbClientInitMsg;312313#define sz_rfbClientInitMsg 1314315316/*-----------------------------------------------------------------------------317* Server Initialisation Message318*319* After the client initialisation message, the server sends one of its own.320* This tells the client the width and height of the server's framebuffer,321* its pixel format and the name associated with the desktop.322*/323324typedef struct _rfbServerInitMsg {325CARD16 framebufferWidth;326CARD16 framebufferHeight;327rfbPixelFormat format; /* the server's preferred pixel format */328CARD32 nameLength;329/* followed by char name[nameLength] */330} rfbServerInitMsg;331332#define sz_rfbServerInitMsg (8 + sz_rfbPixelFormat)333334335/*-----------------------------------------------------------------------------336* Server Interaction Capabilities Message (protocol versions 3.7t, 3.8t)337*338* If TightVNC protocol extensions are enabled, the server informs the client339* what message types it supports in addition to ones defined in the standard340* RFB protocol.341* Also, the server sends the list of all supported encodings (note that it's342* not necessary to advertise the "raw" encoding sinse it MUST be supported in343* RFB 3.x protocols).344*345* This data immediately follows the server initialisation message.346*/347348typedef struct _rfbInteractionCapsMsg {349CARD16 nServerMessageTypes;350CARD16 nClientMessageTypes;351CARD16 nEncodingTypes;352CARD16 pad; /* reserved, must be 0 */353/* followed by nServerMessageTypes * rfbCapabilityInfo structures */354/* followed by nClientMessageTypes * rfbCapabilityInfo structures */355} rfbInteractionCapsMsg;356357#define sz_rfbInteractionCapsMsg 8358359360/*361* Following the server initialisation message it's up to the client to send362* whichever protocol messages it wants. Typically it will send a363* SetPixelFormat message and a SetEncodings message, followed by a364* FramebufferUpdateRequest. From then on the server will send365* FramebufferUpdate messages in response to the client's366* FramebufferUpdateRequest messages. The client should send367* FramebufferUpdateRequest messages with incremental set to true when it has368* finished processing one FramebufferUpdate and is ready to process another.369* With a fast client, the rate at which FramebufferUpdateRequests are sent370* should be regulated to avoid hogging the network.371*/372373374375/*****************************************************************************376*377* Message types378*379*****************************************************************************/380381/* server -> client */382383#define rfbFramebufferUpdate 0384#define rfbSetColourMapEntries 1385#define rfbBell 2386#define rfbServerCutText 3387388#define rfbFileListData 130389#define rfbFileDownloadData 131390#define rfbFileUploadCancel 132391#define rfbFileDownloadFailed 133392393/* signatures for non-standard messages */394#define sig_rfbFileListData "FTS_LSDT"395#define sig_rfbFileDownloadData "FTS_DNDT"396#define sig_rfbFileUploadCancel "FTS_UPCN"397#define sig_rfbFileDownloadFailed "FTS_DNFL"398399400/* client -> server */401402#define rfbSetPixelFormat 0403#define rfbFixColourMapEntries 1 /* not currently supported */404#define rfbSetEncodings 2405#define rfbFramebufferUpdateRequest 3406#define rfbKeyEvent 4407#define rfbPointerEvent 5408#define rfbClientCutText 6409410#define rfbFileListRequest 130411#define rfbFileDownloadRequest 131412#define rfbFileUploadRequest 132413#define rfbFileUploadData 133414#define rfbFileDownloadCancel 134415#define rfbFileUploadFailed 135416#define rfbFileCreateDirRequest 136417418/* signatures for non-standard messages */419#define sig_rfbFileListRequest "FTC_LSRQ"420#define sig_rfbFileDownloadRequest "FTC_DNRQ"421#define sig_rfbFileUploadRequest "FTC_UPRQ"422#define sig_rfbFileUploadData "FTC_UPDT"423#define sig_rfbFileDownloadCancel "FTC_DNCN"424#define sig_rfbFileUploadFailed "FTC_UPFL"425#define sig_rfbFileCreateDirRequest "FTC_FCDR"426427/*****************************************************************************428*429* Encoding types430*431*****************************************************************************/432433#define rfbEncodingRaw 0434#define rfbEncodingCopyRect 1435#define rfbEncodingRRE 2436#define rfbEncodingCoRRE 4437#define rfbEncodingHextile 5438#define rfbEncodingZlib 6439#define rfbEncodingTight 7440#define rfbEncodingZlibHex 8441#define rfbEncodingZRLE 16442443/* signatures for basic encoding types */444#define sig_rfbEncodingRaw "RAW_____"445#define sig_rfbEncodingCopyRect "COPYRECT"446#define sig_rfbEncodingRRE "RRE_____"447#define sig_rfbEncodingCoRRE "CORRE___"448#define sig_rfbEncodingHextile "HEXTILE_"449#define sig_rfbEncodingZlib "ZLIB____"450#define sig_rfbEncodingTight "TIGHT___"451#define sig_rfbEncodingZlibHex "ZLIBHEX_"452#define sig_rfbEncodingZRLE "ZRLE____"453454/*455* Special encoding numbers:456* 0xFFFFFF00 .. 0xFFFFFF0F -- encoding-specific compression levels;457* 0xFFFFFF10 .. 0xFFFFFF1F -- mouse cursor shape data;458* 0xFFFFFF20 .. 0xFFFFFF2F -- various protocol extensions;459* 0xFFFFFF30 .. 0xFFFFFFDF -- not allocated yet;460* 0xFFFFFFE0 .. 0xFFFFFFEF -- quality level for JPEG compressor;461* 0xFFFFFFF0 .. 0xFFFFFFFF -- not allocated yet.462*/463464#define rfbEncodingCompressLevel0 0xFFFFFF00465#define rfbEncodingCompressLevel1 0xFFFFFF01466#define rfbEncodingCompressLevel2 0xFFFFFF02467#define rfbEncodingCompressLevel3 0xFFFFFF03468#define rfbEncodingCompressLevel4 0xFFFFFF04469#define rfbEncodingCompressLevel5 0xFFFFFF05470#define rfbEncodingCompressLevel6 0xFFFFFF06471#define rfbEncodingCompressLevel7 0xFFFFFF07472#define rfbEncodingCompressLevel8 0xFFFFFF08473#define rfbEncodingCompressLevel9 0xFFFFFF09474475#define rfbEncodingXCursor 0xFFFFFF10476#define rfbEncodingRichCursor 0xFFFFFF11477#define rfbEncodingPointerPos 0xFFFFFF18478479#define rfbEncodingLastRect 0xFFFFFF20480#define rfbEncodingNewFBSize 0xFFFFFF21481482#define rfbEncodingQualityLevel0 0xFFFFFFE0483#define rfbEncodingQualityLevel1 0xFFFFFFE1484#define rfbEncodingQualityLevel2 0xFFFFFFE2485#define rfbEncodingQualityLevel3 0xFFFFFFE3486#define rfbEncodingQualityLevel4 0xFFFFFFE4487#define rfbEncodingQualityLevel5 0xFFFFFFE5488#define rfbEncodingQualityLevel6 0xFFFFFFE6489#define rfbEncodingQualityLevel7 0xFFFFFFE7490#define rfbEncodingQualityLevel8 0xFFFFFFE8491#define rfbEncodingQualityLevel9 0xFFFFFFE9492493/* signatures for "fake" encoding types */494#define sig_rfbEncodingCompressLevel0 "COMPRLVL"495#define sig_rfbEncodingXCursor "X11CURSR"496#define sig_rfbEncodingRichCursor "RCHCURSR"497#define sig_rfbEncodingPointerPos "POINTPOS"498#define sig_rfbEncodingLastRect "LASTRECT"499#define sig_rfbEncodingNewFBSize "NEWFBSIZ"500#define sig_rfbEncodingQualityLevel0 "JPEGQLVL"501502503/*****************************************************************************504*505* Server -> client message definitions506*507*****************************************************************************/508509510/*-----------------------------------------------------------------------------511* FramebufferUpdate - a block of rectangles to be copied to the framebuffer.512*513* This message consists of a header giving the number of rectangles of pixel514* data followed by the rectangles themselves. The header is padded so that515* together with the type byte it is an exact multiple of 4 bytes (to help516* with alignment of 32-bit pixels):517*/518519typedef struct _rfbFramebufferUpdateMsg {520CARD8 type; /* always rfbFramebufferUpdate */521CARD8 pad;522CARD16 nRects;523/* followed by nRects rectangles */524} rfbFramebufferUpdateMsg;525526#define sz_rfbFramebufferUpdateMsg 4527528/*529* Each rectangle of pixel data consists of a header describing the position530* and size of the rectangle and a type word describing the encoding of the531* pixel data, followed finally by the pixel data. Note that if the client has532* not sent a SetEncodings message then it will only receive raw pixel data.533* Also note again that this structure is a multiple of 4 bytes.534*/535536typedef struct _rfbFramebufferUpdateRectHeader {537rfbRectangle r;538CARD32 encoding; /* one of the encoding types rfbEncoding... */539} rfbFramebufferUpdateRectHeader;540541#define sz_rfbFramebufferUpdateRectHeader (sz_rfbRectangle + 4)542543544/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -545* Raw Encoding. Pixels are sent in top-to-bottom scanline order,546* left-to-right within a scanline with no padding in between.547*/548549550/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -551* CopyRect Encoding. The pixels are specified simply by the x and y position552* of the source rectangle.553*/554555typedef struct _rfbCopyRect {556CARD16 srcX;557CARD16 srcY;558} rfbCopyRect;559560#define sz_rfbCopyRect 4561562563/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -564* RRE - Rise-and-Run-length Encoding. We have an rfbRREHeader structure565* giving the number of subrectangles following. Finally the data follows in566* the form [<bgpixel><subrect><subrect>...] where each <subrect> is567* [<pixel><rfbRectangle>].568*/569570typedef struct _rfbRREHeader {571CARD32 nSubrects;572} rfbRREHeader;573574#define sz_rfbRREHeader 4575576577/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -578* CoRRE - Compact RRE Encoding. We have an rfbRREHeader structure giving579* the number of subrectangles following. Finally the data follows in the form580* [<bgpixel><subrect><subrect>...] where each <subrect> is581* [<pixel><rfbCoRRERectangle>]. This means that582* the whole rectangle must be at most 255x255 pixels.583*/584585typedef struct _rfbCoRRERectangle {586CARD8 x;587CARD8 y;588CARD8 w;589CARD8 h;590} rfbCoRRERectangle;591592#define sz_rfbCoRRERectangle 4593594595/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -596* Hextile Encoding. The rectangle is divided up into "tiles" of 16x16 pixels,597* starting at the top left going in left-to-right, top-to-bottom order. If598* the width of the rectangle is not an exact multiple of 16 then the width of599* the last tile in each row will be correspondingly smaller. Similarly if the600* height is not an exact multiple of 16 then the height of each tile in the601* final row will also be smaller. Each tile begins with a "subencoding" type602* byte, which is a mask made up of a number of bits. If the Raw bit is set603* then the other bits are irrelevant; w*h pixel values follow (where w and h604* are the width and height of the tile). Otherwise the tile is encoded in a605* similar way to RRE, except that the position and size of each subrectangle606* can be specified in just two bytes. The other bits in the mask are as607* follows:608*609* BackgroundSpecified - if set, a pixel value follows which specifies610* the background colour for this tile. The first non-raw tile in a611* rectangle must have this bit set. If this bit isn't set then the612* background is the same as the last tile.613*614* ForegroundSpecified - if set, a pixel value follows which specifies615* the foreground colour to be used for all subrectangles in this tile.616* If this bit is set then the SubrectsColoured bit must be zero.617*618* AnySubrects - if set, a single byte follows giving the number of619* subrectangles following. If not set, there are no subrectangles (i.e.620* the whole tile is just solid background colour).621*622* SubrectsColoured - if set then each subrectangle is preceded by a pixel623* value giving the colour of that subrectangle. If not set, all624* subrectangles are the same colour, the foreground colour; if the625* ForegroundSpecified bit wasn't set then the foreground is the same as626* the last tile.627*628* The position and size of each subrectangle is specified in two bytes. The629* Pack macros below can be used to generate the two bytes from x, y, w, h,630* and the Extract macros can be used to extract the x, y, w, h values from631* the two bytes.632*/633634#define rfbHextileRaw (1 << 0)635#define rfbHextileBackgroundSpecified (1 << 1)636#define rfbHextileForegroundSpecified (1 << 2)637#define rfbHextileAnySubrects (1 << 3)638#define rfbHextileSubrectsColoured (1 << 4)639640#define rfbHextilePackXY(x,y) (((x) << 4) | (y))641#define rfbHextilePackWH(w,h) ((((w)-1) << 4) | ((h)-1))642#define rfbHextileExtractX(byte) ((byte) >> 4)643#define rfbHextileExtractY(byte) ((byte) & 0xf)644#define rfbHextileExtractW(byte) (((byte) >> 4) + 1)645#define rfbHextileExtractH(byte) (((byte) & 0xf) + 1)646647/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -648* ZLIB - zlib compression Encoding. We have an rfbZlibHeader structure649* giving the number of bytes to follow. Finally the data follows in650* zlib compressed format.651*/652653typedef struct _rfbZlibHeader {654CARD32 nBytes;655} rfbZlibHeader;656657#define sz_rfbZlibHeader 4658659660/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -661* Tight Encoding.662*663*-- The first byte of each Tight-encoded rectangle is a "compression control664* byte". Its format is as follows (bit 0 is the least significant one):665*666* bit 0: if 1, then compression stream 0 should be reset;667* bit 1: if 1, then compression stream 1 should be reset;668* bit 2: if 1, then compression stream 2 should be reset;669* bit 3: if 1, then compression stream 3 should be reset;670* bits 7-4: if 1000 (0x08), then the compression type is "fill",671* if 1001 (0x09), then the compression type is "jpeg",672* if 0xxx, then the compression type is "basic",673* values greater than 1001 are not valid.674*675* If the compression type is "basic", then bits 6..4 of the676* compression control byte (those xxx in 0xxx) specify the following:677*678* bits 5-4: decimal representation is the index of a particular zlib679* stream which should be used for decompressing the data;680* bit 6: if 1, then a "filter id" byte is following this byte.681*682*-- The data that follows after the compression control byte described683* above depends on the compression type ("fill", "jpeg" or "basic").684*685*-- If the compression type is "fill", then the only pixel value follows, in686* client pixel format (see NOTE 1). This value applies to all pixels of the687* rectangle.688*689*-- If the compression type is "jpeg", the following data stream looks like690* this:691*692* 1..3 bytes: data size (N) in compact representation;693* N bytes: JPEG image.694*695* Data size is compactly represented in one, two or three bytes, according696* to the following scheme:697*698* 0xxxxxxx (for values 0..127)699* 1xxxxxxx 0yyyyyyy (for values 128..16383)700* 1xxxxxxx 1yyyyyyy zzzzzzzz (for values 16384..4194303)701*702* Here each character denotes one bit, xxxxxxx are the least significant 7703* bits of the value (bits 0-6), yyyyyyy are bits 7-13, and zzzzzzzz are the704* most significant 8 bits (bits 14-21). For example, decimal value 10000705* should be represented as two bytes: binary 10010000 01001110, or706* hexadecimal 90 4E.707*708*-- If the compression type is "basic" and bit 6 of the compression control709* byte was set to 1, then the next (second) byte specifies "filter id" which710* tells the decoder what filter type was used by the encoder to pre-process711* pixel data before the compression. The "filter id" byte can be one of the712* following:713*714* 0: no filter ("copy" filter);715* 1: "palette" filter;716* 2: "gradient" filter.717*718*-- If bit 6 of the compression control byte is set to 0 (no "filter id"719* byte), or if the filter id is 0, then raw pixel values in the client720* format (see NOTE 1) will be compressed. See below details on the721* compression.722*723*-- The "gradient" filter pre-processes pixel data with a simple algorithm724* which converts each color component to a difference between a "predicted"725* intensity and the actual intensity. Such a technique does not affect726* uncompressed data size, but helps to compress photo-like images better.727* Pseudo-code for converting intensities to differences is the following:728*729* P[i,j] := V[i-1,j] + V[i,j-1] - V[i-1,j-1];730* if (P[i,j] < 0) then P[i,j] := 0;731* if (P[i,j] > MAX) then P[i,j] := MAX;732* D[i,j] := V[i,j] - P[i,j];733*734* Here V[i,j] is the intensity of a color component for a pixel at735* coordinates (i,j). MAX is the maximum value of intensity for a color736* component.737*738*-- The "palette" filter converts true-color pixel data to indexed colors739* and a palette which can consist of 2..256 colors. If the number of colors740* is 2, then each pixel is encoded in 1 bit, otherwise 8 bits is used to741* encode one pixel. 1-bit encoding is performed such way that the most742* significant bits correspond to the leftmost pixels, and each raw of pixels743* is aligned to the byte boundary. When "palette" filter is used, the744* palette is sent before the pixel data. The palette begins with an unsigned745* byte which value is the number of colors in the palette minus 1 (i.e. 1746* means 2 colors, 255 means 256 colors in the palette). Then follows the747* palette itself which consist of pixel values in client pixel format (see748* NOTE 1).749*750*-- The pixel data is compressed using the zlib library. But if the data751* size after applying the filter but before the compression is less then 12,752* then the data is sent as is, uncompressed. Four separate zlib streams753* (0..3) can be used and the decoder should read the actual stream id from754* the compression control byte (see NOTE 2).755*756* If the compression is not used, then the pixel data is sent as is,757* otherwise the data stream looks like this:758*759* 1..3 bytes: data size (N) in compact representation;760* N bytes: zlib-compressed data.761*762* Data size is compactly represented in one, two or three bytes, just like763* in the "jpeg" compression method (see above).764*765*-- NOTE 1. If the color depth is 24, and all three color components are766* 8-bit wide, then one pixel in Tight encoding is always represented by767* three bytes, where the first byte is red component, the second byte is768* green component, and the third byte is blue component of the pixel color769* value. This applies to colors in palettes as well.770*771*-- NOTE 2. The decoder must reset compression streams' states before772* decoding the rectangle, if some of bits 0,1,2,3 in the compression control773* byte are set to 1. Note that the decoder must reset zlib streams even if774* the compression type is "fill" or "jpeg".775*776*-- NOTE 3. The "gradient" filter and "jpeg" compression may be used only777* when bits-per-pixel value is either 16 or 32, not 8.778*779*-- NOTE 4. The width of any Tight-encoded rectangle cannot exceed 2048780* pixels. If a rectangle is wider, it must be split into several rectangles781* and each one should be encoded separately.782*783*/784785#define rfbTightExplicitFilter 0x04786#define rfbTightFill 0x08787#define rfbTightJpeg 0x09788#define rfbTightMaxSubencoding 0x09789790/* Filters to improve compression efficiency */791#define rfbTightFilterCopy 0x00792#define rfbTightFilterPalette 0x01793#define rfbTightFilterGradient 0x02794795796/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -797* ZLIBHEX - zlib compressed Hextile Encoding. Essentially, this is the798* hextile encoding with zlib compression on the tiles that can not be799* efficiently encoded with one of the other hextile subencodings. The800* new zlib subencoding uses two bytes to specify the length of the801* compressed tile and then the compressed data follows. As with the802* raw sub-encoding, the zlib subencoding invalidates the other803* values, if they are also set.804*/805806#define rfbHextileZlibRaw (1 << 5)807#define rfbHextileZlibHex (1 << 6)808809810/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -811* XCursor encoding. This is a special encoding used to transmit X-style812* cursor shapes from server to clients. Note that for this encoding,813* coordinates in rfbFramebufferUpdateRectHeader structure hold hotspot814* position (r.x, r.y) and cursor size (r.w, r.h). If (w * h != 0), two RGB815* samples are sent after header in the rfbXCursorColors structure. They816* denote foreground and background colors of the cursor. If a client817* supports only black-and-white cursors, it should ignore these colors and818* assume that foreground is black and background is white. Next, two bitmaps819* (1 bits per pixel) follow: first one with actual data (value 0 denotes820* background color, value 1 denotes foreground color), second one with821* transparency data (bits with zero value mean that these pixels are822* transparent). Both bitmaps represent cursor data in a byte stream, from823* left to right, from top to bottom, and each row is byte-aligned. Most824* significant bits correspond to leftmost pixels. The number of bytes in825* each row can be calculated as ((w + 7) / 8). If (w * h == 0), cursor826* should be hidden (or default local cursor should be set by the client).827*/828829typedef struct _rfbXCursorColors {830CARD8 foreRed;831CARD8 foreGreen;832CARD8 foreBlue;833CARD8 backRed;834CARD8 backGreen;835CARD8 backBlue;836} rfbXCursorColors;837838#define sz_rfbXCursorColors 6839840841/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -842* RichCursor encoding. This is a special encoding used to transmit cursor843* shapes from server to clients. It is similar to the XCursor encoding but844* uses client pixel format instead of two RGB colors to represent cursor845* image. For this encoding, coordinates in rfbFramebufferUpdateRectHeader846* structure hold hotspot position (r.x, r.y) and cursor size (r.w, r.h).847* After header, two pixmaps follow: first one with cursor image in current848* client pixel format (like in raw encoding), second with transparency data849* (1 bit per pixel, exactly the same format as used for transparency bitmap850* in the XCursor encoding). If (w * h == 0), cursor should be hidden (or851* default local cursor should be set by the client).852*/853854855/*-----------------------------------------------------------------------------856* SetColourMapEntries - these messages are only sent if the pixel857* format uses a "colour map" (i.e. trueColour false) and the client has not858* fixed the entire colour map using FixColourMapEntries. In addition they859* will only start being sent after the client has sent its first860* FramebufferUpdateRequest. So if the client always tells the server to use861* trueColour then it never needs to process this type of message.862*/863864typedef struct _rfbSetColourMapEntriesMsg {865CARD8 type; /* always rfbSetColourMapEntries */866CARD8 pad;867CARD16 firstColour;868CARD16 nColours;869870/* Followed by nColours * 3 * CARD16871r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */872873} rfbSetColourMapEntriesMsg;874875#define sz_rfbSetColourMapEntriesMsg 6876877878879/*-----------------------------------------------------------------------------880* Bell - ring a bell on the client if it has one.881*/882883typedef struct _rfbBellMsg {884CARD8 type; /* always rfbBell */885} rfbBellMsg;886887#define sz_rfbBellMsg 1888889890891/*-----------------------------------------------------------------------------892* ServerCutText - the server has new text in its cut buffer.893*/894895typedef struct _rfbServerCutTextMsg {896CARD8 type; /* always rfbServerCutText */897CARD8 pad1;898CARD16 pad2;899CARD32 length;900/* followed by char text[length] */901} rfbServerCutTextMsg;902903#define sz_rfbServerCutTextMsg 8904905/*-----------------------------------------------------------------------------906* FileListData907*/908909typedef struct _rfbFileListDataMsg {910CARD8 type;911CARD8 flags;912CARD16 numFiles;913CARD16 dataSize;914CARD16 compressedSize;915/* Followed by SizeData[numFiles] */916/* Followed by Filenames[compressedSize] */917} rfbFileListDataMsg;918919#define sz_rfbFileListDataMsg 8920921/*-----------------------------------------------------------------------------922* FileDownloadData923*/924925typedef struct _rfbFileDownloadDataMsg {926CARD8 type;927CARD8 compressLevel;928CARD16 realSize;929CARD16 compressedSize;930/* Followed by File[copressedSize],931but if (realSize = compressedSize = 0) followed by CARD32 modTime */932} rfbFileDownloadDataMsg;933934#define sz_rfbFileDownloadDataMsg 6935936937/*-----------------------------------------------------------------------------938* FileUploadCancel939*/940941typedef struct _rfbFileUploadCancelMsg {942CARD8 type;943CARD8 unused;944CARD16 reasonLen;945/* Followed by reason[reasonLen] */946} rfbFileUploadCancelMsg;947948#define sz_rfbFileUploadCancelMsg 4949950/*-----------------------------------------------------------------------------951* FileDownloadFailed952*/953954typedef struct _rfbFileDownloadFailedMsg {955CARD8 type;956CARD8 unused;957CARD16 reasonLen;958/* Followed by reason[reasonLen] */959} rfbFileDownloadFailedMsg;960961#define sz_rfbFileDownloadFailedMsg 4962963/*-----------------------------------------------------------------------------964* Union of all server->client messages.965*/966967typedef union _rfbServerToClientMsg {968CARD8 type;969rfbFramebufferUpdateMsg fu;970rfbSetColourMapEntriesMsg scme;971rfbBellMsg b;972rfbServerCutTextMsg sct;973rfbFileListDataMsg fld;974rfbFileDownloadDataMsg fdd;975rfbFileUploadCancelMsg fuc;976rfbFileDownloadFailedMsg fdf;977} rfbServerToClientMsg;978979980981/*****************************************************************************982*983* Message definitions (client -> server)984*985*****************************************************************************/986987988/*-----------------------------------------------------------------------------989* SetPixelFormat - tell the RFB server the format in which the client wants990* pixels sent.991*/992993typedef struct _rfbSetPixelFormatMsg {994CARD8 type; /* always rfbSetPixelFormat */995CARD8 pad1;996CARD16 pad2;997rfbPixelFormat format;998} rfbSetPixelFormatMsg;9991000#define sz_rfbSetPixelFormatMsg (sz_rfbPixelFormat + 4)100110021003/*-----------------------------------------------------------------------------1004* FixColourMapEntries - when the pixel format uses a "colour map", fix1005* read-only colour map entries.1006*1007* ***************** NOT CURRENTLY SUPPORTED *****************1008*/10091010typedef struct _rfbFixColourMapEntriesMsg {1011CARD8 type; /* always rfbFixColourMapEntries */1012CARD8 pad;1013CARD16 firstColour;1014CARD16 nColours;10151016/* Followed by nColours * 3 * CARD161017r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */10181019} rfbFixColourMapEntriesMsg;10201021#define sz_rfbFixColourMapEntriesMsg 6102210231024/*-----------------------------------------------------------------------------1025* SetEncodings - tell the RFB server which encoding types we accept. Put them1026* in order of preference, if we have any. We may always receive raw1027* encoding, even if we don't specify it here.1028*/10291030typedef struct _rfbSetEncodingsMsg {1031CARD8 type; /* always rfbSetEncodings */1032CARD8 pad;1033CARD16 nEncodings;1034/* followed by nEncodings * CARD32 encoding types */1035} rfbSetEncodingsMsg;10361037#define sz_rfbSetEncodingsMsg 4103810391040/*-----------------------------------------------------------------------------1041* FramebufferUpdateRequest - request for a framebuffer update. If incremental1042* is true then the client just wants the changes since the last update. If1043* false then it wants the whole of the specified rectangle.1044*/10451046typedef struct _rfbFramebufferUpdateRequestMsg {1047CARD8 type; /* always rfbFramebufferUpdateRequest */1048CARD8 incremental;1049CARD16 x;1050CARD16 y;1051CARD16 w;1052CARD16 h;1053} rfbFramebufferUpdateRequestMsg;10541055#define sz_rfbFramebufferUpdateRequestMsg 10105610571058/*-----------------------------------------------------------------------------1059* KeyEvent - key press or release1060*1061* Keys are specified using the "keysym" values defined by the X Window System.1062* For most ordinary keys, the keysym is the same as the corresponding ASCII1063* value. Other common keys are:1064*1065* BackSpace 0xff081066* Tab 0xff091067* Return or Enter 0xff0d1068* Escape 0xff1b1069* Insert 0xff631070* Delete 0xffff1071* Home 0xff501072* End 0xff571073* Page Up 0xff551074* Page Down 0xff561075* Left 0xff511076* Up 0xff521077* Right 0xff531078* Down 0xff541079* F1 0xffbe1080* F2 0xffbf1081* ... ...1082* F12 0xffc91083* Shift 0xffe11084* Control 0xffe31085* Meta 0xffe71086* Alt 0xffe91087*/10881089typedef struct _rfbKeyEventMsg {1090CARD8 type; /* always rfbKeyEvent */1091CARD8 down; /* true if down (press), false if up */1092CARD16 pad;1093CARD32 key; /* key is specified as an X keysym */1094} rfbKeyEventMsg;10951096#define sz_rfbKeyEventMsg 8109710981099/*-----------------------------------------------------------------------------1100* PointerEvent - mouse/pen move and/or button press.1101*/11021103typedef struct _rfbPointerEventMsg {1104CARD8 type; /* always rfbPointerEvent */1105CARD8 buttonMask; /* bits 0-7 are buttons 1-8, 0=up, 1=down */1106CARD16 x;1107CARD16 y;1108} rfbPointerEventMsg;11091110#define rfbButton1Mask 11111#define rfbButton2Mask 21112#define rfbButton3Mask 41113#define rfbButton4Mask 81114#define rfbButton5Mask 1611151116#define sz_rfbPointerEventMsg 61117111811191120/*-----------------------------------------------------------------------------1121* ClientCutText - the client has new text in its cut buffer.1122*/11231124typedef struct _rfbClientCutTextMsg {1125CARD8 type; /* always rfbClientCutText */1126CARD8 pad1;1127CARD16 pad2;1128CARD32 length;1129/* followed by char text[length] */1130} rfbClientCutTextMsg;11311132#define sz_rfbClientCutTextMsg 811331134/*-----------------------------------------------------------------------------1135* FileListRequest1136*/11371138typedef struct _rfbFileListRequestMsg {1139CARD8 type;1140CARD8 flags;1141CARD16 dirNameSize;1142/* Followed by char Dirname[dirNameSize] */1143} rfbFileListRequestMsg;11441145#define sz_rfbFileListRequestMsg 411461147/*-----------------------------------------------------------------------------1148* FileDownloadRequest1149*/11501151typedef struct _rfbFileDownloadRequestMsg {1152CARD8 type;1153CARD8 compressedLevel;1154CARD16 fNameSize;1155CARD32 position;1156/* Followed by char Filename[fNameSize] */1157} rfbFileDownloadRequestMsg;11581159#define sz_rfbFileDownloadRequestMsg 811601161/*-----------------------------------------------------------------------------1162* FileUploadRequest1163*/11641165typedef struct _rfbFileUploadRequestMsg {1166CARD8 type;1167CARD8 compressedLevel;1168CARD16 fNameSize;1169CARD32 position;1170/* Followed by char Filename[fNameSize] */1171} rfbFileUploadRequestMsg;11721173#define sz_rfbFileUploadRequestMsg 8117411751176/*-----------------------------------------------------------------------------1177* FileUploadData1178*/11791180typedef struct _rfbFileUploadDataMsg {1181CARD8 type;1182CARD8 compressedLevel;1183CARD16 realSize;1184CARD16 compressedSize;1185/* Followed by File[compressedSize],1186but if (realSize = compressedSize = 0) followed by CARD32 modTime */1187} rfbFileUploadDataMsg;11881189#define sz_rfbFileUploadDataMsg 611901191/*-----------------------------------------------------------------------------1192* FileDownloadCancel1193*/11941195typedef struct _rfbFileDownloadCancelMsg {1196CARD8 type;1197CARD8 unused;1198CARD16 reasonLen;1199/* Followed by reason[reasonLen] */1200} rfbFileDownloadCancelMsg;12011202#define sz_rfbFileDownloadCancelMsg 412031204/*-----------------------------------------------------------------------------1205* FileUploadFailed1206*/12071208typedef struct _rfbFileUploadFailedMsg {1209CARD8 type;1210CARD8 unused;1211CARD16 reasonLen;1212/* Followed by reason[reasonLen] */1213} rfbFileUploadFailedMsg;12141215#define sz_rfbFileUploadFailedMsg 412161217/*-----------------------------------------------------------------------------1218* FileCreateDirRequest1219*/12201221typedef struct _rfbFileCreateDirRequestMsg {1222CARD8 type;1223CARD8 unused;1224CARD16 dNameLen;1225/* Followed by dName[dNameLen] */1226} rfbFileCreateDirRequestMsg;12271228#define sz_rfbFileCreateDirRequestMsg 412291230/*-----------------------------------------------------------------------------1231* Union of all client->server messages.1232*/12331234typedef union _rfbClientToServerMsg {1235CARD8 type;1236rfbSetPixelFormatMsg spf;1237rfbFixColourMapEntriesMsg fcme;1238rfbSetEncodingsMsg se;1239rfbFramebufferUpdateRequestMsg fur;1240rfbKeyEventMsg ke;1241rfbPointerEventMsg pe;1242rfbClientCutTextMsg cct;1243rfbFileListRequestMsg flr;1244rfbFileDownloadRequestMsg fdr;1245rfbFileUploadRequestMsg fupr;1246rfbFileUploadDataMsg fud;1247rfbFileDownloadCancelMsg fdc;1248rfbFileUploadFailedMsg fuf;1249rfbFileCreateDirRequestMsg fcdr;1250} rfbClientToServerMsg;125112521253