~ubuntu-branches/debian/lenny/italc/lenny

« back to all changes in this revision

Viewing changes to master/icv/include/rfbproto.h

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-06-17 13:46:54 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20080617134654-2y5m7ki93r5c1ysf
Tags: upstream-1.0.9~rc3
ImportĀ upstreamĀ versionĀ 1.0.9~rc3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (C) 2000-2002 Constantin Kaplinsky.  All Rights Reserved.
3
 
 *  Copyright (C) 2000 Tridia Corporation.  All Rights Reserved.
4
 
 *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
5
 
 *
6
 
 *  This is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This software is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this software; if not, write to the Free Software
18
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
19
 
 *  USA.
20
 
 */
21
 
 
22
 
/*
23
 
 * rfbproto.h - header file for the RFB protocol version 3.3
24
 
 *
25
 
 * Uses types CARD<n> for an n-bit unsigned integer, INT<n> for an n-bit signed
26
 
 * integer (for n = 8, 16 and 32).
27
 
 *
28
 
 * All multiple byte integers are in big endian (network) order (most
29
 
 * significant byte first).  Unless noted otherwise there is no special
30
 
 * 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 in
35
 
 * 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 complex
43
 
 *      messages have to be explained by comments.
44
 
 */
45
 
 
46
 
#include "vnctypes.h"
47
 
#include "rsa_crypt_lib.h"
48
 
 
49
 
#define LONG64
50
 
 
51
 
#include <X11/Xmd.h>
52
 
 
53
 
/*****************************************************************************
54
 
 *
55
 
 * Structures used in several messages
56
 
 *
57
 
 *****************************************************************************/
58
 
 
59
 
/*-----------------------------------------------------------------------------
60
 
 * Structure used to specify a rectangle.  This structure is a multiple of 4
61
 
 * bytes so that it can be interspersed with 32-bit pixel data without
62
 
 * affecting alignment.
63
 
 */
64
 
 
65
 
typedef struct {
66
 
    CARD16 x;
67
 
    CARD16 y;
68
 
    CARD16 w;
69
 
    CARD16 h;
70
 
} rfbRectangle;
71
 
 
72
 
#define sz_rfbRectangle 8
73
 
 
74
 
 
75
 
/*-----------------------------------------------------------------------------
76
 
 * Structure used to specify pixel format.
77
 
 */
78
 
 
79
 
typedef struct {
80
 
 
81
 
    CARD8 bitsPerPixel;         /* 8,16,32 only */
82
 
 
83
 
    CARD8 depth;                /* 8 to 32 */
84
 
 
85
 
    CARD8 bigEndian;            /* True if multi-byte pixels are interpreted
86
 
                                   as big endian, or if single-bit-per-pixel
87
 
                                   has most significant bit of the byte
88
 
                                   corresponding to first (leftmost) pixel. Of
89
 
                                   course this is meaningless for 8 bits/pix */
90
 
 
91
 
    CARD8 trueColour;           /* If false then we need a "colour map" to
92
 
                                   convert pixels to RGB.  If true, xxxMax and
93
 
                                   xxxShift specify bits used for red, green
94
 
                                   and blue */
95
 
 
96
 
    /* the following fields are only meaningful if trueColour is true */
97
 
 
98
 
    CARD16 redMax;              /* maximum red value (= 2^n - 1 where n is the
99
 
                                   number of bits used for red). Note this
100
 
                                   value is always in big endian order. */
101
 
 
102
 
    CARD16 greenMax;            /* similar for green */
103
 
 
104
 
    CARD16 blueMax;             /* and blue */
105
 
 
106
 
    CARD8 redShift;             /* number of shifts needed to get the red
107
 
                                   value in a pixel to the least significant
108
 
                                   bit. To find the red value from a given
109
 
                                   pixel, do the following:
110
 
                                   1) Swap pixel value according to bigEndian
111
 
                                      (e.g. if bigEndian is false and host byte
112
 
                                      order is big endian, then swap).
113
 
                                   2) Shift right by redShift.
114
 
                                   3) AND with redMax (in host byte order).
115
 
                                   4) You now have the red value between 0 and
116
 
                                      redMax. */
117
 
 
118
 
    CARD8 greenShift;           /* similar for green */
119
 
 
120
 
    CARD8 blueShift;            /* and blue */
121
 
 
122
 
    CARD8 pad1;
123
 
    CARD16 pad2;
124
 
 
125
 
} rfbPixelFormat;
126
 
 
127
 
#define sz_rfbPixelFormat 16
128
 
 
129
 
 
130
 
 
131
 
/*****************************************************************************
132
 
 *
133
 
 * Initial handshaking messages
134
 
 *
135
 
 *****************************************************************************/
136
 
 
137
 
/*-----------------------------------------------------------------------------
138
 
 * Protocol Version
139
 
 *
140
 
 * The server always sends 12 bytes to start which identifies the latest RFB
141
 
 * protocol version number which it supports.  These bytes are interpreted
142
 
 * as a string of 12 ASCII characters in the format "RFB xxx.yyy\n" where
143
 
 * xxx and yyy are the major and minor version numbers (for version 3.3
144
 
 * this is "RFB 003.003\n").
145
 
 *
146
 
 * The client then replies with a similar 12-byte message giving the version
147
 
 * number of the protocol which should actually be used (which may be different
148
 
 * to that quoted by the server).
149
 
 *
150
 
 * It is intended that both clients and servers may provide some level of
151
 
 * backwards compatibility by this mechanism.  Servers in particular should
152
 
 * attempt to provide backwards compatibility, and even forwards compatibility
153
 
 * to some extent.  For example if a client demands version 3.1 of the
154
 
 * protocol, a 3.0 server can probably assume that by ignoring requests for
155
 
 * encoding types it doesn't understand, everything will still work OK.  This
156
 
 * will probably not be the case for changes in the major version number.
157
 
 *
158
 
 * The format string below can be used in sprintf or sscanf to generate or
159
 
 * decode the version string respectively.
160
 
 */
161
 
 
162
 
#define rfbProtocolVersionFormat "RFB %03d.%03d\n"
163
 
#define rfbProtocolMajorVersion 3
164
 
#define rfbProtocolMinorVersion 3
165
 
 
166
 
typedef char rfbProtocolVersionMsg[13]; /* allow extra byte for null */
167
 
 
168
 
#define sz_rfbProtocolVersionMsg 12
169
 
 
170
 
 
171
 
/*-----------------------------------------------------------------------------
172
 
 * Authentication
173
 
 *
174
 
 * Once the protocol version has been decided, the server then sends a 32-bit
175
 
 * word indicating whether any authentication is needed on the connection.
176
 
 * The value of this word determines the authentication scheme in use.  For
177
 
 * version 3.0 of the protocol this may have one of the following values:
178
 
 */
179
 
 
180
 
#define rfbConnFailed 0
181
 
#define rfbNoAuth 1
182
 
#define rfbVncAuth 2
183
 
 
184
 
/*
185
 
 * rfbConnFailed:       For some reason the connection failed (e.g. the server
186
 
 *                      cannot support the desired protocol version).  This is
187
 
 *                      followed by a string describing the reason (where a
188
 
 *                      string is specified as a 32-bit length followed by that
189
 
 *                      many ASCII characters).
190
 
 *
191
 
 * rfbNoAuth:           No authentication is needed.
192
 
 *
193
 
 * rfbVncAuth:          The VNC authentication scheme is to be used.  A 16-byte
194
 
 *                      challenge follows, which the client encrypts as
195
 
 *                      appropriate using the password and sends the resulting
196
 
 *                      16-byte response.  If the response is correct, the
197
 
 *                      server sends the 32-bit word rfbVncAuthOK.  If a simple
198
 
 *                      failure happens, the server sends rfbVncAuthFailed and
199
 
 *                      closes the connection. If the server decides that too
200
 
 *                      many failures have occurred, it sends rfbVncAuthTooMany
201
 
 *                      and closes the connection.  In the latter case, the
202
 
 *                      server should not allow an immediate reconnection by
203
 
 *                      the client.
204
 
 */
205
 
 
206
 
#define rfbVncAuthOK 0
207
 
#define rfbVncAuthFailed 1
208
 
#define rfbVncAuthTooMany 2
209
 
 
210
 
 
211
 
/*-----------------------------------------------------------------------------
212
 
 * Client Initialisation Message
213
 
 *
214
 
 * Once the client and server are sure that they're happy to talk to one
215
 
 * another, the client sends an initialisation message.  At present this
216
 
 * message only consists of a boolean indicating whether the server should try
217
 
 * to share the desktop by leaving other clients connected, or give exclusive
218
 
 * access to this client by disconnecting all other clients.
219
 
 */
220
 
 
221
 
typedef struct {
222
 
    CARD8 shared;
223
 
} rfbClientInitMsg;
224
 
 
225
 
#define sz_rfbClientInitMsg 1
226
 
 
227
 
 
228
 
/*-----------------------------------------------------------------------------
229
 
 * Server Initialisation Message
230
 
 *
231
 
 * After the client initialisation message, the server sends one of its own.
232
 
 * This tells the client the width and height of the server's framebuffer,
233
 
 * its pixel format and the name associated with the desktop.
234
 
 */
235
 
 
236
 
typedef struct {
237
 
    CARD16 framebufferWidth;
238
 
    CARD16 framebufferHeight;
239
 
    rfbPixelFormat format;      /* the server's preferred pixel format */
240
 
    CARD32 nameLength;
241
 
    /* followed by char name[nameLength] */
242
 
} rfbServerInitMsg;
243
 
 
244
 
#define sz_rfbServerInitMsg (8 + sz_rfbPixelFormat)
245
 
 
246
 
 
247
 
/*
248
 
 * Following the server initialisation message it's up to the client to send
249
 
 * whichever protocol messages it wants.  Typically it will send a
250
 
 * SetPixelFormat message and a SetEncodings message, followed by a
251
 
 * FramebufferUpdateRequest.  From then on the server will send
252
 
 * FramebufferUpdate messages in response to the client's
253
 
 * FramebufferUpdateRequest messages.  The client should send
254
 
 * FramebufferUpdateRequest messages with incremental set to true when it has
255
 
 * finished processing one FramebufferUpdate and is ready to process another.
256
 
 * With a fast client, the rate at which FramebufferUpdateRequests are sent
257
 
 * should be regulated to avoid hogging the network.
258
 
 */
259
 
 
260
 
 
261
 
 
262
 
/*****************************************************************************
263
 
 *
264
 
 * Message types
265
 
 *
266
 
 *****************************************************************************/
267
 
 
268
 
/* server -> client */
269
 
 
270
 
#define rfbFramebufferUpdate 0
271
 
#define rfbSetColourMapEntries 1
272
 
#define rfbBell 2
273
 
#define rfbServerCutText 3
274
 
 
275
 
 
276
 
/* client -> server */
277
 
 
278
 
#define rfbSetPixelFormat 0
279
 
#define rfbFixColourMapEntries 1        /* not currently supported */
280
 
#define rfbSetEncodings 2
281
 
#define rfbFramebufferUpdateRequest 3
282
 
#define rfbKeyEvent 4
283
 
#define rfbPointerEvent 5
284
 
#define rfbClientCutText 6
285
 
 
286
 
 
287
 
 
288
 
 
289
 
/*****************************************************************************
290
 
 *
291
 
 * Encoding types
292
 
 *
293
 
 *****************************************************************************/
294
 
 
295
 
#define rfbEncodingRaw 0
296
 
#define rfbEncodingCopyRect 1
297
 
#define rfbEncodingRRE 2
298
 
#define rfbEncodingCoRRE 4
299
 
#define rfbEncodingHextile 5
300
 
#define rfbEncodingZlib 6
301
 
#define rfbEncodingTight 7
302
 
#define rfbEncodingZlibHex 8
303
 
 
304
 
/*
305
 
 * Special encoding numbers:
306
 
 *   0xFFFFFF00 .. 0xFFFFFF0F -- encoding-specific compression levels;
307
 
 *   0xFFFFFF10 .. 0xFFFFFF1F -- mouse cursor shape data;
308
 
 *   0xFFFFFF20 .. 0xFFFFFF2F -- various protocol extensions;
309
 
 *   0xFFFFFF30 .. 0xFFFFFFDF -- not allocated yet;
310
 
 *   0xFFFFFFE0 .. 0xFFFFFFEF -- quality level for JPEG compressor;
311
 
 *   0xFFFFFFF0 .. 0xFFFFFFFF -- cross-encoding compression levels.
312
 
 */
313
 
 
314
 
#define rfbEncodingCompressLevel0  0xFFFFFF00
315
 
#define rfbEncodingCompressLevel1  0xFFFFFF01
316
 
#define rfbEncodingCompressLevel2  0xFFFFFF02
317
 
#define rfbEncodingCompressLevel3  0xFFFFFF03
318
 
#define rfbEncodingCompressLevel4  0xFFFFFF04
319
 
#define rfbEncodingCompressLevel5  0xFFFFFF05
320
 
#define rfbEncodingCompressLevel6  0xFFFFFF06
321
 
#define rfbEncodingCompressLevel7  0xFFFFFF07
322
 
#define rfbEncodingCompressLevel8  0xFFFFFF08
323
 
#define rfbEncodingCompressLevel9  0xFFFFFF09
324
 
 
325
 
#define rfbEncodingXCursor         0xFFFFFF10
326
 
#define rfbEncodingRichCursor      0xFFFFFF11
327
 
#define rfbEncodingSoftCursor      0xFFFFFF12
328
 
#define rfbEncodingPointerPos      0xFFFFFF18
329
 
 
330
 
#define rfbEncodingLastRect        0xFFFFFF20
331
 
#define rfbEncodingBackground      0xFFFFFF25
332
 
 
333
 
#define rfbEncodingQualityLevel0   0xFFFFFFE0
334
 
#define rfbEncodingQualityLevel1   0xFFFFFFE1
335
 
#define rfbEncodingQualityLevel2   0xFFFFFFE2
336
 
#define rfbEncodingQualityLevel3   0xFFFFFFE3
337
 
#define rfbEncodingQualityLevel4   0xFFFFFFE4
338
 
#define rfbEncodingQualityLevel5   0xFFFFFFE5
339
 
#define rfbEncodingQualityLevel6   0xFFFFFFE6
340
 
#define rfbEncodingQualityLevel7   0xFFFFFFE7
341
 
#define rfbEncodingQualityLevel8   0xFFFFFFE8
342
 
#define rfbEncodingQualityLevel9   0xFFFFFFE9
343
 
 
344
 
 
345
 
/*****************************************************************************
346
 
 *
347
 
 * Server -> client message definitions
348
 
 *
349
 
 *****************************************************************************/
350
 
 
351
 
 
352
 
/*-----------------------------------------------------------------------------
353
 
 * FramebufferUpdate - a block of rectangles to be copied to the framebuffer.
354
 
 *
355
 
 * This message consists of a header giving the number of rectangles of pixel
356
 
 * data followed by the rectangles themselves.  The header is padded so that
357
 
 * together with the type byte it is an exact multiple of 4 bytes (to help
358
 
 * with alignment of 32-bit pixels):
359
 
 */
360
 
 
361
 
typedef struct {
362
 
    CARD8 type;                 /* always rfbFramebufferUpdate */
363
 
    CARD8 pad;
364
 
    CARD16 nRects;
365
 
    /* followed by nRects rectangles */
366
 
} rfbFramebufferUpdateMsg;
367
 
 
368
 
#define sz_rfbFramebufferUpdateMsg 4
369
 
 
370
 
/*
371
 
 * Each rectangle of pixel data consists of a header describing the position
372
 
 * and size of the rectangle and a type word describing the encoding of the
373
 
 * pixel data, followed finally by the pixel data.  Note that if the client has
374
 
 * not sent a SetEncodings message then it will only receive raw pixel data.
375
 
 * Also note again that this structure is a multiple of 4 bytes.
376
 
 */
377
 
 
378
 
typedef struct {
379
 
    rfbRectangle r;
380
 
    CARD32 encoding;    /* one of the encoding types rfbEncoding... */
381
 
} rfbFramebufferUpdateRectHeader;
382
 
 
383
 
#define sz_rfbFramebufferUpdateRectHeader (sz_rfbRectangle + 4)
384
 
 
385
 
 
386
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
387
 
 * Raw Encoding.  Pixels are sent in top-to-bottom scanline order,
388
 
 * left-to-right within a scanline with no padding in between.
389
 
 */
390
 
 
391
 
 
392
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
393
 
 * CopyRect Encoding.  The pixels are specified simply by the x and y position
394
 
 * of the source rectangle.
395
 
 */
396
 
 
397
 
typedef struct {
398
 
    CARD16 srcX;
399
 
    CARD16 srcY;
400
 
} rfbCopyRect;
401
 
 
402
 
#define sz_rfbCopyRect 4
403
 
 
404
 
 
405
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
406
 
 * RRE - Rise-and-Run-length Encoding.  We have an rfbRREHeader structure
407
 
 * giving the number of subrectangles following.  Finally the data follows in
408
 
 * the form [<bgpixel><subrect><subrect>...] where each <subrect> is
409
 
 * [<pixel><rfbRectangle>].
410
 
 */
411
 
 
412
 
typedef struct {
413
 
    CARD32 nSubrects;
414
 
} rfbRREHeader;
415
 
 
416
 
#define sz_rfbRREHeader 4
417
 
 
418
 
 
419
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
420
 
 * CoRRE - Compact RRE Encoding.  We have an rfbRREHeader structure giving
421
 
 * the number of subrectangles following.  Finally the data follows in the form
422
 
 * [<bgpixel><subrect><subrect>...] where each <subrect> is
423
 
 * [<pixel><rfbCoRRERectangle>].  This means that
424
 
 * the whole rectangle must be at most 255x255 pixels.
425
 
 */
426
 
 
427
 
typedef struct {
428
 
    CARD8 x;
429
 
    CARD8 y;
430
 
    CARD8 w;
431
 
    CARD8 h;
432
 
} rfbCoRRERectangle;
433
 
 
434
 
#define sz_rfbCoRRERectangle 4
435
 
 
436
 
 
437
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
438
 
 * Hextile Encoding.  The rectangle is divided up into "tiles" of 16x16 pixels,
439
 
 * starting at the top left going in left-to-right, top-to-bottom order.  If
440
 
 * the width of the rectangle is not an exact multiple of 16 then the width of
441
 
 * the last tile in each row will be correspondingly smaller.  Similarly if the
442
 
 * height is not an exact multiple of 16 then the height of each tile in the
443
 
 * final row will also be smaller.  Each tile begins with a "subencoding" type
444
 
 * byte, which is a mask made up of a number of bits.  If the Raw bit is set
445
 
 * then the other bits are irrelevant; w*h pixel values follow (where w and h
446
 
 * are the width and height of the tile).  Otherwise the tile is encoded in a
447
 
 * similar way to RRE, except that the position and size of each subrectangle
448
 
 * can be specified in just two bytes.  The other bits in the mask are as
449
 
 * follows:
450
 
 *
451
 
 * BackgroundSpecified - if set, a pixel value follows which specifies
452
 
 *    the background colour for this tile.  The first non-raw tile in a
453
 
 *    rectangle must have this bit set.  If this bit isn't set then the
454
 
 *    background is the same as the last tile.
455
 
 *
456
 
 * ForegroundSpecified - if set, a pixel value follows which specifies
457
 
 *    the foreground colour to be used for all subrectangles in this tile.
458
 
 *    If this bit is set then the SubrectsColoured bit must be zero.
459
 
 *
460
 
 * AnySubrects - if set, a single byte follows giving the number of
461
 
 *    subrectangles following.  If not set, there are no subrectangles (i.e.
462
 
 *    the whole tile is just solid background colour).
463
 
 *
464
 
 * SubrectsColoured - if set then each subrectangle is preceded by a pixel
465
 
 *    value giving the colour of that subrectangle.  If not set, all
466
 
 *    subrectangles are the same colour, the foreground colour;  if the
467
 
 *    ForegroundSpecified bit wasn't set then the foreground is the same as
468
 
 *    the last tile.
469
 
 *
470
 
 * The position and size of each subrectangle is specified in two bytes.  The
471
 
 * Pack macros below can be used to generate the two bytes from x, y, w, h,
472
 
 * and the Extract macros can be used to extract the x, y, w, h values from
473
 
 * the two bytes.
474
 
 */
475
 
 
476
 
#define rfbHextileRaw                   (1 << 0)
477
 
#define rfbHextileBackgroundSpecified   (1 << 1)
478
 
#define rfbHextileForegroundSpecified   (1 << 2)
479
 
#define rfbHextileAnySubrects           (1 << 3)
480
 
#define rfbHextileSubrectsColoured      (1 << 4)
481
 
 
482
 
#define rfbHextilePackXY(x,y) (((x) << 4) | (y))
483
 
#define rfbHextilePackWH(w,h) ((((w)-1) << 4) | ((h)-1))
484
 
#define rfbHextileExtractX(byte) ((byte) >> 4)
485
 
#define rfbHextileExtractY(byte) ((byte) & 0xf)
486
 
#define rfbHextileExtractW(byte) (((byte) >> 4) + 1)
487
 
#define rfbHextileExtractH(byte) (((byte) & 0xf) + 1)
488
 
 
489
 
 
490
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
491
 
 * zlib - zlib compressed Encoding.  We have an rfbZlibHeader structure
492
 
 * giving the number of bytes following.  Finally the data follows is
493
 
 * zlib compressed version of the raw pixel data as negotiated.
494
 
 */
495
 
 
496
 
typedef struct {
497
 
    CARD32 nBytes;
498
 
} rfbZlibHeader;
499
 
 
500
 
#define sz_rfbZlibHeader 4
501
 
 
502
 
 
503
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
504
 
 * Tight Encoding.
505
 
 *
506
 
 *-- The first byte of each Tight-encoded rectangle is a "compression control
507
 
 *   byte". Its format is as follows (bit 0 is the least significant one):
508
 
 *
509
 
 *   bit 0:    if 1, then compression stream 0 should be reset;
510
 
 *   bit 1:    if 1, then compression stream 1 should be reset;
511
 
 *   bit 2:    if 1, then compression stream 2 should be reset;
512
 
 *   bit 3:    if 1, then compression stream 3 should be reset;
513
 
 *   bits 7-4: if 1000 (0x08), then the compression type is "fill",
514
 
 *             if 1001 (0x09), then the compression type is "jpeg",
515
 
 *             if 0xxx, then the compression type is "basic",
516
 
 *             values greater than 1001 are not valid.
517
 
 *
518
 
 * If the compression type is "basic", then bits 6..4 of the
519
 
 * compression control byte (those xxx in 0xxx) specify the following:
520
 
 *
521
 
 *   bits 5-4:  decimal representation is the index of a particular zlib
522
 
 *              stream which should be used for decompressing the data;
523
 
 *   bit 6:     if 1, then a "filter id" byte is following this byte.
524
 
 *
525
 
 *-- The data that follows after the compression control byte described
526
 
 * above depends on the compression type ("fill", "jpeg" or "basic").
527
 
 *
528
 
 *-- If the compression type is "fill", then the only pixel value follows, in
529
 
 * client pixel format (see NOTE 1). This value applies to all pixels of the
530
 
 * rectangle.
531
 
 *
532
 
 *-- If the compression type is "jpeg", the following data stream looks like
533
 
 * this:
534
 
 *
535
 
 *   1..3 bytes:  data size (N) in compact representation;
536
 
 *   N bytes:     JPEG image.
537
 
 *
538
 
 * Data size is compactly represented in one, two or three bytes, according
539
 
 * to the following scheme:
540
 
 *
541
 
 *  0xxxxxxx                    (for values 0..127)
542
 
 *  1xxxxxxx 0yyyyyyy           (for values 128..16383)
543
 
 *  1xxxxxxx 1yyyyyyy zzzzzzzz  (for values 16384..4194303)
544
 
 *
545
 
 * Here each character denotes one bit, xxxxxxx are the least significant 7
546
 
 * bits of the value (bits 0-6), yyyyyyy are bits 7-13, and zzzzzzzz are the
547
 
 * most significant 8 bits (bits 14-21). For example, decimal value 10000
548
 
 * should be represented as two bytes: binary 10010000 01001110, or
549
 
 * hexadecimal 90 4E.
550
 
 *
551
 
 *-- If the compression type is "basic" and bit 6 of the compression control
552
 
 * byte was set to 1, then the next (second) byte specifies "filter id" which
553
 
 * tells the decoder what filter type was used by the encoder to pre-process
554
 
 * pixel data before the compression. The "filter id" byte can be one of the
555
 
 * following:
556
 
 *
557
 
 *   0:  no filter ("copy" filter);
558
 
 *   1:  "palette" filter;
559
 
 *   2:  "gradient" filter.
560
 
 *
561
 
 *-- If bit 6 of the compression control byte is set to 0 (no "filter id"
562
 
 * byte), or if the filter id is 0, then raw pixel values in the client
563
 
 * format (see NOTE 1) will be compressed. See below details on the
564
 
 * compression.
565
 
 *
566
 
 *-- The "gradient" filter pre-processes pixel data with a simple algorithm
567
 
 * which converts each color component to a difference between a "predicted"
568
 
 * intensity and the actual intensity. Such a technique does not affect
569
 
 * uncompressed data size, but helps to compress photo-like images better. 
570
 
 * Pseudo-code for converting intensities to differences is the following:
571
 
 *
572
 
 *   P[i,j] := V[i-1,j] + V[i,j-1] - V[i-1,j-1];
573
 
 *   if (P[i,j] < 0) then P[i,j] := 0;
574
 
 *   if (P[i,j] > MAX) then P[i,j] := MAX;
575
 
 *   D[i,j] := V[i,j] - P[i,j];
576
 
 *
577
 
 * Here V[i,j] is the intensity of a color component for a pixel at
578
 
 * coordinates (i,j). MAX is the maximum value of intensity for a color
579
 
 * component.
580
 
 *
581
 
 *-- The "palette" filter converts true-color pixel data to indexed colors
582
 
 * and a palette which can consist of 2..256 colors. If the number of colors
583
 
 * is 2, then each pixel is encoded in 1 bit, otherwise 8 bits is used to
584
 
 * encode one pixel. 1-bit encoding is performed such way that the most
585
 
 * significant bits correspond to the leftmost pixels, and each raw of pixels
586
 
 * is aligned to the byte boundary. When "palette" filter is used, the
587
 
 * palette is sent before the pixel data. The palette begins with an unsigned
588
 
 * byte which value is the number of colors in the palette minus 1 (i.e. 1
589
 
 * means 2 colors, 255 means 256 colors in the palette). Then follows the
590
 
 * palette itself which consist of pixel values in client pixel format (see
591
 
 * NOTE 1).
592
 
 *
593
 
 *-- The pixel data is compressed using the zlib library. But if the data
594
 
 * size after applying the filter but before the compression is less then 12,
595
 
 * then the data is sent as is, uncompressed. Four separate zlib streams
596
 
 * (0..3) can be used and the decoder should read the actual stream id from
597
 
 * the compression control byte (see NOTE 2).
598
 
 *
599
 
 * If the compression is not used, then the pixel data is sent as is,
600
 
 * otherwise the data stream looks like this:
601
 
 *
602
 
 *   1..3 bytes:  data size (N) in compact representation;
603
 
 *   N bytes:     zlib-compressed data.
604
 
 *
605
 
 * Data size is compactly represented in one, two or three bytes, just like
606
 
 * in the "jpeg" compression method (see above).
607
 
 *
608
 
 *-- NOTE 1. If the color depth is 24, and all three color components are
609
 
 * 8-bit wide, then one pixel in Tight encoding is always represented by
610
 
 * three bytes, where the first byte is red component, the second byte is
611
 
 * green component, and the third byte is blue component of the pixel color
612
 
 * value. This applies to colors in palettes as well.
613
 
 *
614
 
 *-- NOTE 2. The decoder must reset compression streams' states before
615
 
 * decoding the rectangle, if some of bits 0,1,2,3 in the compression control
616
 
 * byte are set to 1. Note that the decoder must reset zlib streams even if
617
 
 * the compression type is "fill" or "jpeg".
618
 
 *
619
 
 *-- NOTE 3. The "gradient" filter and "jpeg" compression may be used only
620
 
 * when bits-per-pixel value is either 16 or 32, not 8.
621
 
 *
622
 
 *-- NOTE 4. The width of any Tight-encoded rectangle cannot exceed 2048
623
 
 * pixels. If a rectangle is wider, it must be split into several rectangles
624
 
 * and each one should be encoded separately.
625
 
 *
626
 
 */
627
 
 
628
 
#define rfbTightExplicitFilter         0x04
629
 
#define rfbTightFill                   0x08
630
 
#define rfbTightJpeg                   0x09
631
 
#define rfbTightMaxSubencoding         0x09
632
 
 
633
 
/* Filters to improve compression efficiency */
634
 
#define rfbTightFilterCopy             0x00
635
 
#define rfbTightFilterPalette          0x01
636
 
#define rfbTightFilterGradient         0x02
637
 
 
638
 
 
639
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
640
 
 * XCursor encoding. This is a special encoding used to transmit X-style
641
 
 * cursor shapes from server to clients. Note that for this encoding,
642
 
 * coordinates in rfbFramebufferUpdateRectHeader structure hold hotspot
643
 
 * position (r.x, r.y) and cursor size (r.w, r.h). If (w * h != 0), two RGB
644
 
 * samples are sent after header in the rfbXCursorColors structure. They
645
 
 * denote foreground and background colors of the cursor. If a client
646
 
 * supports only black-and-white cursors, it should ignore these colors and
647
 
 * assume that foreground is black and background is white. Next, two bitmaps
648
 
 * (1 bits per pixel) follow: first one with actual data (value 0 denotes
649
 
 * background color, value 1 denotes foreground color), second one with
650
 
 * transparency data (bits with zero value mean that these pixels are
651
 
 * transparent). Both bitmaps represent cursor data in a byte stream, from
652
 
 * left to right, from top to bottom, and each row is byte-aligned. Most
653
 
 * significant bits correspond to leftmost pixels. The number of bytes in
654
 
 * each row can be calculated as ((w + 7) / 8). If (w * h == 0), cursor
655
 
 * should be hidden (or default local cursor should be set by the client).
656
 
 */
657
 
 
658
 
typedef struct {
659
 
    CARD8 foreRed;
660
 
    CARD8 foreGreen;
661
 
    CARD8 foreBlue;
662
 
    CARD8 backRed;
663
 
    CARD8 backGreen;
664
 
    CARD8 backBlue;
665
 
} rfbXCursorColors;
666
 
 
667
 
#define sz_rfbXCursorColors 6
668
 
 
669
 
 
670
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
671
 
 * RichCursor encoding. This is a special encoding used to transmit cursor
672
 
 * shapes from server to clients. It is similar to the XCursor encoding but
673
 
 * uses client pixel format instead of two RGB colors to represent cursor
674
 
 * image. For this encoding, coordinates in rfbFramebufferUpdateRectHeader
675
 
 * structure hold hotspot position (r.x, r.y) and cursor size (r.w, r.h).
676
 
 * After header, two pixmaps follow: first one with cursor image in current
677
 
 * client pixel format (like in raw encoding), second with transparency data
678
 
 * (1 bit per pixel, exactly the same format as used for transparency bitmap
679
 
 * in the XCursor encoding). If (w * h == 0), cursor should be hidden (or
680
 
 * default local cursor should be set by the client).
681
 
 */
682
 
 
683
 
 
684
 
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
685
 
 * SoftCursor encoding. This encoding is used to transmit image and position 
686
 
 * of the remote cursor. It has two sub-messages: SetImage is used to upload
687
 
 * one of 16 images, and Move selects the image and sets the position of the
688
 
 * cursor. 
689
 
 * Each SoftCursor message starts with a CARD8. If it is in the 0-15 range
690
 
 * it specifies the number of the cursor image and is followed by the 
691
 
 * rfbSoftCursorMove message. If the given cursor has not been set yet the 
692
 
 * message will be ignored. If the first CARD8 is in the 128-143 range it 
693
 
 * specifies the cursor that will be set in the following 
694
 
 * rfbSoftCursorSetImage message. To hide the cursor send a SetImage
695
 
 * message with width and height 0 and imageLength 0.
696
 
 * SetImage transmits the hotspot coordinates in the x/y fields of the
697
 
 * rfbFramebufferUpdateRectHeader, width and height of the image are in the
698
 
 * header's width and height fields.
699
 
 * Move transmits the pointer coordinates in the w/h fields of the
700
 
 * header, x/y are always 0.
701
 
 */
702
 
 
703
 
typedef struct {
704
 
  CARD8 imageIndex;
705
 
  CARD8 buttonMask; /* bits 0-7 are buttons 1-8, 0=up, 1=down */
706
 
} rfbSoftCursorMove;
707
 
 
708
 
typedef struct {
709
 
  CARD8 imageIndex;
710
 
  CARD8 padding;
711
 
  CARD16 imageLength;
712
 
  /* 
713
 
   * Followed by an image of the cursor in the client's image format
714
 
   * with the following RLE mask compression. It begins with CARD8 that
715
 
   * specifies the number of mask'ed pixels that will be NOT transmitted.
716
 
   * Then follows a CARD8 that specified by the number of unmask'd pixels 
717
 
   * that will be transmitted next. Then a CARD8 with the number of mask'd 
718
 
   * pixels and so on. 
719
 
   */
720
 
} rfbSoftCursorSetImage;
721
 
 
722
 
typedef union {
723
 
  CARD8 type;
724
 
  rfbSoftCursorMove move;
725
 
  rfbSoftCursorSetImage setImage;
726
 
} rfbSoftCursorMsg;
727
 
 
728
 
#define rfbSoftCursorMaxImages    16
729
 
#define rfbSoftCursorSetIconOffset    128
730
 
 
731
 
/*-----------------------------------------------------------------------------
732
 
 * SetColourMapEntries - these messages are only sent if the pixel
733
 
 * format uses a "colour map" (i.e. trueColour false) and the client has not
734
 
 * fixed the entire colour map using FixColourMapEntries.  In addition they
735
 
 * will only start being sent after the client has sent its first
736
 
 * FramebufferUpdateRequest.  So if the client always tells the server to use
737
 
 * trueColour then it never needs to process this type of message.
738
 
 */
739
 
 
740
 
typedef struct {
741
 
    CARD8 type;                 /* always rfbSetColourMapEntries */
742
 
    CARD8 pad;
743
 
    CARD16 firstColour;
744
 
    CARD16 nColours;
745
 
 
746
 
    /* Followed by nColours * 3 * CARD16
747
 
       r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
748
 
 
749
 
} rfbSetColourMapEntriesMsg;
750
 
 
751
 
#define sz_rfbSetColourMapEntriesMsg 6
752
 
 
753
 
 
754
 
 
755
 
/*-----------------------------------------------------------------------------
756
 
 * Bell - ring a bell on the client if it has one.
757
 
 */
758
 
 
759
 
typedef struct {
760
 
    CARD8 type;                 /* always rfbBell */
761
 
} rfbBellMsg;
762
 
 
763
 
#define sz_rfbBellMsg 1
764
 
 
765
 
 
766
 
 
767
 
/*-----------------------------------------------------------------------------
768
 
 * ServerCutText - the server has new text in its cut buffer.
769
 
 */
770
 
 
771
 
typedef struct {
772
 
    CARD8 type;                 /* always rfbServerCutText */
773
 
    CARD8 pad1;
774
 
    CARD16 pad2;
775
 
    CARD32 length;
776
 
    /* followed by char text[length] */
777
 
} rfbServerCutTextMsg;
778
 
 
779
 
#define sz_rfbServerCutTextMsg 8
780
 
 
781
 
 
782
 
/*-----------------------------------------------------------------------------
783
 
 * Union of all server->client messages.
784
 
 */
785
 
 
786
 
typedef union {
787
 
    CARD8 type;
788
 
    rfbFramebufferUpdateMsg fu;
789
 
    rfbSetColourMapEntriesMsg scme;
790
 
    rfbBellMsg b;
791
 
    rfbServerCutTextMsg sct;
792
 
} rfbServerToClientMsg;
793
 
 
794
 
 
795
 
 
796
 
/*****************************************************************************
797
 
 *
798
 
 * Message definitions (client -> server)
799
 
 *
800
 
 *****************************************************************************/
801
 
 
802
 
 
803
 
/*-----------------------------------------------------------------------------
804
 
 * SetPixelFormat - tell the RFB server the format in which the client wants
805
 
 * pixels sent.
806
 
 */
807
 
 
808
 
typedef struct {
809
 
    CARD8 type;                 /* always rfbSetPixelFormat */
810
 
    CARD8 pad1;
811
 
    CARD16 pad2;
812
 
    rfbPixelFormat format;
813
 
} rfbSetPixelFormatMsg;
814
 
 
815
 
#define sz_rfbSetPixelFormatMsg (sz_rfbPixelFormat + 4)
816
 
 
817
 
 
818
 
/*-----------------------------------------------------------------------------
819
 
 * FixColourMapEntries - when the pixel format uses a "colour map", fix
820
 
 * read-only colour map entries.
821
 
 *
822
 
 *    ***************** NOT CURRENTLY SUPPORTED *****************
823
 
 */
824
 
 
825
 
typedef struct {
826
 
    CARD8 type;                 /* always rfbFixColourMapEntries */
827
 
    CARD8 pad;
828
 
    CARD16 firstColour;
829
 
    CARD16 nColours;
830
 
 
831
 
    /* Followed by nColours * 3 * CARD16
832
 
       r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
833
 
 
834
 
} rfbFixColourMapEntriesMsg;
835
 
 
836
 
#define sz_rfbFixColourMapEntriesMsg 6
837
 
 
838
 
 
839
 
/*-----------------------------------------------------------------------------
840
 
 * SetEncodings - tell the RFB server which encoding types we accept.  Put them
841
 
 * in order of preference, if we have any.  We may always receive raw
842
 
 * encoding, even if we don't specify it here.
843
 
 */
844
 
 
845
 
typedef struct {
846
 
    CARD8 type;                 /* always rfbSetEncodings */
847
 
    CARD8 pad;
848
 
    CARD16 nEncodings;
849
 
    /* followed by nEncodings * CARD32 encoding types */
850
 
} rfbSetEncodingsMsg;
851
 
 
852
 
#define sz_rfbSetEncodingsMsg 4
853
 
 
854
 
 
855
 
/*-----------------------------------------------------------------------------
856
 
 * FramebufferUpdateRequest - request for a framebuffer update.  If incremental
857
 
 * is true then the client just wants the changes since the last update.  If
858
 
 * false then it wants the whole of the specified rectangle.
859
 
 */
860
 
 
861
 
typedef struct {
862
 
    CARD8 type;                 /* always rfbFramebufferUpdateRequest */
863
 
    CARD8 incremental;
864
 
    CARD16 x;
865
 
    CARD16 y;
866
 
    CARD16 w;
867
 
    CARD16 h;
868
 
} rfbFramebufferUpdateRequestMsg;
869
 
 
870
 
#define sz_rfbFramebufferUpdateRequestMsg 10
871
 
 
872
 
 
873
 
/*-----------------------------------------------------------------------------
874
 
 * KeyEvent - key press or release
875
 
 *
876
 
 * Keys are specified using the "keysym" values defined by the X Window System.
877
 
 * For most ordinary keys, the keysym is the same as the corresponding ASCII
878
 
 * value.  Other common keys are:
879
 
 *
880
 
 * BackSpace            0xff08
881
 
 * Tab                  0xff09
882
 
 * Return or Enter      0xff0d
883
 
 * Escape               0xff1b
884
 
 * Insert               0xff63
885
 
 * Delete               0xffff
886
 
 * Home                 0xff50
887
 
 * End                  0xff57
888
 
 * Page Up              0xff55
889
 
 * Page Down            0xff56
890
 
 * Left                 0xff51
891
 
 * Up                   0xff52
892
 
 * Right                0xff53
893
 
 * Down                 0xff54
894
 
 * F1                   0xffbe
895
 
 * F2                   0xffbf
896
 
 * ...                  ...
897
 
 * F12                  0xffc9
898
 
 * Shift                0xffe1
899
 
 * Control              0xffe3
900
 
 * Meta                 0xffe7
901
 
 * Alt                  0xffe9
902
 
 */
903
 
 
904
 
typedef struct {
905
 
    CARD8 type;                 /* always rfbKeyEvent */
906
 
    CARD8 down;                 /* true if down (press), false if up */
907
 
    CARD16 pad;
908
 
    CARD32 key;                 /* key is specified as an X keysym */
909
 
} rfbKeyEventMsg;
910
 
 
911
 
#define sz_rfbKeyEventMsg 8
912
 
 
913
 
 
914
 
/*-----------------------------------------------------------------------------
915
 
 * PointerEvent - mouse/pen move and/or button press.
916
 
 */
917
 
 
918
 
typedef struct {
919
 
    CARD8 type;                 /* always rfbPointerEvent */
920
 
    CARD8 buttonMask;           /* bits 0-7 are buttons 1-8, 0=up, 1=down */
921
 
    CARD16 x;
922
 
    CARD16 y;
923
 
} rfbPointerEventMsg;
924
 
 
925
 
#define rfbButton1Mask 1
926
 
#define rfbButton2Mask 2
927
 
#define rfbButton3Mask 4
928
 
 
929
 
#define sz_rfbPointerEventMsg 6
930
 
 
931
 
 
932
 
 
933
 
/*-----------------------------------------------------------------------------
934
 
 * ClientCutText - the client has new text in its cut buffer.
935
 
 */
936
 
 
937
 
typedef struct {
938
 
    CARD8 type;                 /* always rfbClientCutText */
939
 
    CARD8 pad1;
940
 
    CARD16 pad2;
941
 
    CARD32 length;
942
 
    /* followed by char text[length] */
943
 
} rfbClientCutTextMsg;
944
 
 
945
 
#define sz_rfbClientCutTextMsg 8
946
 
 
947
 
 
948
 
 
949
 
/*-----------------------------------------------------------------------------
950
 
 * Union of all client->server messages.
951
 
 */
952
 
 
953
 
typedef union {
954
 
    CARD8 type;
955
 
    rfbSetPixelFormatMsg spf;
956
 
    rfbFixColourMapEntriesMsg fcme;
957
 
    rfbSetEncodingsMsg se;
958
 
    rfbFramebufferUpdateRequestMsg fur;
959
 
    rfbKeyEventMsg ke;
960
 
    rfbPointerEventMsg pe;
961
 
    rfbClientCutTextMsg cct;
962
 
} rfbClientToServerMsg;