1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
|
/*
* rfb.h - header file for RFB DDX implementation.
*/
/*
* Copyright (C) 2000-2004 Const Kaplinsky. All Rights Reserved.
* Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
#include "scrnintstr.h"
#include "colormapst.h"
#include "gcstruct.h"
#include "osdep.h"
#include <rfbproto.h>
#include <vncauth.h>
#include <zlib.h>
#include <stdarg.h>
#include <stdlib.h>
/* It's a good idea to keep these values a bit greater than required. */
#define MAX_ENCODINGS 10
#define MAX_SECURITY_TYPES 4
#define MAX_TUNNELING_CAPS 16
#define MAX_AUTH_CAPS 16
extern char *display;
/*
* Per-screen (framebuffer) structure. There is only one of these, since we
* don't allow the X server to have multiple screens.
*/
typedef struct
{
int width;
int paddedWidthInBytes;
int height;
int depth;
int bitsPerPixel;
int sizeInBytes;
char *pfbMemory;
Pixel blackPixel;
Pixel whitePixel;
/* The following two members are used to minimise the amount of unnecessary
drawing caused by cursor movement. Whenever any drawing affects the
part of the screen where the cursor is, the cursor is removed first and
then the drawing is done (this is what the sprite routines test for).
Afterwards, however, we do not replace the cursor, even when the cursor
is logically being moved across the screen. We only draw the cursor
again just as we are about to send the client a framebuffer update.
We need to be careful when removing and drawing the cursor because of
their relationship with the normal drawing routines. The drawing
routines can invoke the cursor routines, but also the cursor routines
themselves end up invoking drawing routines.
Removing the cursor (rfbSpriteRemoveCursor) is eventually achieved by
doing a CopyArea from a pixmap to the screen, where the pixmap contains
the saved contents of the screen under the cursor. Before doing this,
however, we set cursorIsDrawn to FALSE. Then, when CopyArea is called,
it sees that cursorIsDrawn is FALSE and so doesn't feel the need to
(recursively!) remove the cursor before doing it.
Putting up the cursor (rfbSpriteRestoreCursor) involves a call to
PushPixels. While this is happening, cursorIsDrawn must be FALSE so
that PushPixels doesn't think it has to remove the cursor first.
Obviously cursorIsDrawn is set to TRUE afterwards.
Another problem we face is that drawing routines sometimes cause a
framebuffer update to be sent to the RFB client. When the RFB client is
already waiting for a framebuffer update and some drawing to the
framebuffer then happens, the drawing routine sees that the client is
ready, so it calls rfbSendFramebufferUpdate. If the cursor is not drawn
at this stage, it must be put up, and so rfbSpriteRestoreCursor is
called. However, if the original drawing routine was actually called
from within rfbSpriteRestoreCursor or rfbSpriteRemoveCursor we don't
want this to happen. So both the cursor routines set
dontSendFramebufferUpdate to TRUE, and all the drawing routines check
this before calling rfbSendFramebufferUpdate. */
Bool cursorIsDrawn; /* TRUE if the cursor is currently drawn */
Bool dontSendFramebufferUpdate; /* TRUE while removing or drawing the
cursor */
/* wrapped screen functions */
CloseScreenProcPtr CloseScreen;
CreateGCProcPtr CreateGC;
PaintWindowBackgroundProcPtr PaintWindowBackground;
PaintWindowBorderProcPtr PaintWindowBorder;
CopyWindowProcPtr CopyWindow;
ClearToBackgroundProcPtr ClearToBackground;
RestoreAreasProcPtr RestoreAreas;
} rfbScreenInfo, *rfbScreenInfoPtr;
/*
* rfbTranslateFnType is the type of translation functions.
*/
struct rfbClientRec;
typedef void (*rfbTranslateFnType)(char *table, rfbPixelFormat *in,
rfbPixelFormat *out,
char *iptr, char *optr,
int bytesBetweenInputLines,
int width, int height);
/*
* Per-client structure.
*/
typedef struct rfbClientRec {
int sock;
char *host;
char *login;
int protocol_minor_ver; /* RFB protocol minor version in use */
Bool protocol_tightvnc; /* TightVNC protocol extensions enabled */
/* Possible client states: */
enum {
RFB_PROTOCOL_VERSION, /* establishing protocol version */
RFB_SECURITY_TYPE, /* negotiating security (RFB v.3.7) */
RFB_TUNNELING_TYPE, /* establishing tunneling (RFB v.3.7t) */
RFB_AUTH_TYPE, /* negotiating authentication (RFB v.3.7t) */
RFB_AUTHENTICATION, /* authenticating (VNC authentication) */
RFB_INITIALISATION, /* sending initialisation messages */
RFB_NORMAL /* normal protocol messages */
} state;
Bool viewOnly; /* Do not accept input from this client. */
Bool reverseConnection;
Bool readyForSetColourMapEntries;
Bool useCopyRect;
int preferredEncoding;
int correMaxWidth, correMaxHeight;
/* The list of security types sent to this client (protocol 3.7).
Note that the first entry is the number of list items following. */
CARD8 securityTypes[MAX_SECURITY_TYPES + 1];
/* Lists of capability codes sent to clients. We remember these
lists to restrict clients from choosing those tunneling and
authentication types that were not advertised. */
int nAuthCaps;
CARD32 authCaps[MAX_AUTH_CAPS];
/* This is not useful while we don't support tunneling:
int nTunnelingCaps;
CARD32 tunnelingCaps[MAX_TUNNELING_CAPS]; */
/* The following member is only used during VNC authentication */
CARD8 authChallenge[CHALLENGESIZE];
/* The following members represent the update needed to get the client's
framebuffer from its present state to the current state of our
framebuffer.
If the client does not accept CopyRect encoding then the update is
simply represented as the region of the screen which has been modified
(modifiedRegion).
If the client does accept CopyRect encoding, then the update consists of
two parts. First we have a single copy from one region of the screen to
another (the destination of the copy is copyRegion), and second we have
the region of the screen which has been modified in some other way
(modifiedRegion).
Although the copy is of a single region, this region may have many
rectangles. When sending an update, the copyRegion is always sent
before the modifiedRegion. This is because the modifiedRegion may
overlap parts of the screen which are in the source of the copy.
In fact during normal processing, the modifiedRegion may even overlap
the destination copyRegion. Just before an update is sent we remove
from the copyRegion anything in the modifiedRegion. */
RegionRec copyRegion; /* the destination region of the copy */
int copyDX, copyDY; /* the translation by which the copy happens */
RegionRec modifiedRegion; /* the region of the screen modified in any
other way */
/* As part of the FramebufferUpdateRequest, a client can express interest
in a subrectangle of the whole framebuffer. This is stored in the
requestedRegion member. In the normal case this is the whole
framebuffer if the client is ready, empty if it's not. */
RegionRec requestedRegion;
/* The following members represent the state of the "deferred update" timer
- when the framebuffer is modified and the client is ready, in most
cases it is more efficient to defer sending the update by a few
milliseconds so that several changes to the framebuffer can be combined
into a single update. */
Bool deferredUpdateScheduled;
OsTimerPtr deferredUpdateTimer;
/* translateFn points to the translation function which is used to copy
and translate a rectangle from the framebuffer to an output buffer. */
rfbTranslateFnType translateFn;
char *translateLookupTable;
rfbPixelFormat format;
/* statistics */
int rfbBytesSent[MAX_ENCODINGS];
int rfbRectanglesSent[MAX_ENCODINGS];
int rfbLastRectMarkersSent;
int rfbLastRectBytesSent;
int rfbCursorShapeBytesSent;
int rfbCursorShapeUpdatesSent;
int rfbCursorPosBytesSent;
int rfbCursorPosUpdatesSent;
int rfbFramebufferUpdateMessagesSent;
int rfbRawBytesEquivalent;
int rfbKeyEventsRcvd;
int rfbPointerEventsRcvd;
/* zlib encoding -- necessary compression state info per client */
struct z_stream_s compStream;
Bool compStreamInited;
CARD32 zlibCompressLevel;
/* tight encoding -- preserve zlib streams' state for each client */
z_stream zsStruct[4];
Bool zsActive[4];
int zsLevel[4];
int tightCompressLevel;
int tightQualityLevel;
Bool enableLastRectEncoding; /* client supports LastRect encoding */
Bool enableCursorShapeUpdates; /* client supports cursor shape updates */
Bool enableCursorPosUpdates; /* client supports PointerPos updates */
Bool useRichCursorEncoding; /* rfbEncodingRichCursor is preferred */
Bool cursorWasChanged; /* cursor shape update should be sent */
Bool cursorWasMoved; /* cursor position update should be sent */
int cursorX, cursorY; /* client's cursor position */
struct rfbClientRec *next;
} rfbClientRec, *rfbClientPtr;
/*
* This macro is used to test whether there is a framebuffer update needing to
* be sent to the client.
*/
#define FB_UPDATE_PENDING(cl) \
((!(cl)->enableCursorShapeUpdates && !rfbScreen.cursorIsDrawn) || \
((cl)->enableCursorShapeUpdates && (cl)->cursorWasChanged) || \
((cl)->enableCursorPosUpdates && (cl)->cursorWasMoved) || \
REGION_NOTEMPTY((pScreen),&(cl)->copyRegion) || \
REGION_NOTEMPTY((pScreen),&(cl)->modifiedRegion))
/*
* This macro creates an empty region (ie. a region with no areas) if it is
* given a rectangle with a width or height of zero. It appears that
* REGION_INTERSECT does not quite do the right thing with zero-width
* rectangles, but it should with completely empty regions.
*/
#define SAFE_REGION_INIT(pscreen, preg, rect, size) \
{ \
if ( ( (rect) ) && \
( ( (rect)->x2 == (rect)->x1 ) || \
( (rect)->y2 == (rect)->y1 ) ) ) { \
REGION_INIT( (pscreen), (preg), NullBox, 0 ); \
} else { \
REGION_INIT( (pscreen), (preg), (rect), (size) ); \
} \
}
/*
* An rfbGCRec is where we store the pointers to the original GC funcs and ops
* which we wrap (NULL means not wrapped).
*/
typedef struct {
GCFuncs *wrapFuncs;
GCOps *wrapOps;
} rfbGCRec, *rfbGCPtr;
/*
* Macros for endian swapping.
*/
#define Swap16(s) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))
#define Swap32(l) (((l) >> 24) | \
(((l) & 0x00ff0000) >> 8) | \
(((l) & 0x0000ff00) << 8) | \
((l) << 24))
static const int rfbEndianTest = 1;
#define Swap16IfLE(s) (*(const char *)&rfbEndianTest ? Swap16(s) : (s))
#define Swap32IfLE(l) (*(const char *)&rfbEndianTest ? Swap32(l) : (l))
/*
* Macro to fill in an rfbCapabilityInfo structure (protocol 3.7t).
* Normally, using macros is no good, but this macro saves us from
* writing constants twice -- it constructs signature names from codes.
* Note that "code_sym" argument should be a single symbol, not an expression.
*/
#define SetCapInfo(cap_ptr, code_sym, vendor) \
{ \
rfbCapabilityInfo *pcap; \
pcap = (cap_ptr); \
pcap->code = Swap32IfLE(code_sym); \
memcpy(pcap->vendorSignature, (vendor), \
sz_rfbCapabilityInfoVendor); \
memcpy(pcap->nameSignature, sig_##code_sym, \
sz_rfbCapabilityInfoName); \
}
/* init.c */
extern char *desktopName;
extern char rfbThisHost[];
extern Atom VNC_LAST_CLIENT_ID;
extern rfbScreenInfo rfbScreen;
extern int rfbGCIndex;
extern int inetdSock;
extern struct in_addr interface;
extern int rfbBitsPerPixel(int depth);
extern void rfbLog(char *format, ...);
extern void rfbLogPerror(char *str);
/* sockets.c */
extern int rfbMaxClientWait;
extern int udpPort;
extern int udpSock;
extern Bool udpSockConnected;
extern int rfbPort;
extern int rfbListenSock;
extern void rfbInitSockets();
extern void rfbDisconnectUDPSock();
extern void rfbCloseSock();
extern void rfbCheckFds();
extern void rfbWaitForClient(int sock);
extern int rfbConnect(char *host, int port);
extern int ReadExact(int sock, char *buf, int len);
extern int WriteExact(int sock, char *buf, int len);
extern int ListenOnTCPPort(int port);
extern int ListenOnUDPPort(int port);
extern int ConnectToTcpAddr(char *host, int port);
/* cmap.c */
extern ColormapPtr rfbInstalledColormap;
extern int rfbListInstalledColormaps(ScreenPtr pScreen, Colormap *pmaps);
extern void rfbInstallColormap(ColormapPtr pmap);
extern void rfbUninstallColormap(ColormapPtr pmap);
extern void rfbStoreColors(ColormapPtr pmap, int ndef, xColorItem *pdefs);
/* draw.c */
extern int rfbDeferUpdateTime;
extern Bool rfbCloseScreen(int,ScreenPtr);
extern Bool rfbCreateGC(GCPtr);
extern void rfbPaintWindowBackground(WindowPtr, RegionPtr, int what);
extern void rfbPaintWindowBorder(WindowPtr, RegionPtr, int what);
extern void rfbCopyWindow(WindowPtr, DDXPointRec, RegionPtr);
extern void rfbClearToBackground(WindowPtr, int x, int y, int w,
int h, Bool generateExposures);
extern RegionPtr rfbRestoreAreas(WindowPtr, RegionPtr);
/* cutpaste.c */
extern void rfbSetXCutText(char *str, int len);
extern void rfbGotXCutText(char *str, int len);
/* kbdptr.c */
extern Bool compatibleKbd;
extern unsigned char ptrAcceleration;
extern void PtrDeviceInit();
extern void PtrDeviceOn();
extern void PtrDeviceOff();
extern void PtrDeviceControl();
extern void PtrAddEvent(int buttonMask, int x, int y, rfbClientPtr cl);
extern void KbdDeviceInit();
extern void KbdDeviceOn();
extern void KbdDeviceOff();
extern void KbdAddEvent(Bool down, KeySym keySym, rfbClientPtr cl);
extern void KbdReleaseAllKeys();
/* rfbserver.c */
/*
* UPDATE_BUF_SIZE must be big enough to send at least one whole line of the
* framebuffer. So for a max screen width of say 2K with 32-bit pixels this
* means 8K minimum.
*/
#define UPDATE_BUF_SIZE 30000
extern char updateBuf[UPDATE_BUF_SIZE];
extern int ublen;
extern rfbClientPtr rfbClientHead;
extern rfbClientPtr pointerClient;
extern Bool rfbAlwaysShared;
extern Bool rfbNeverShared;
extern Bool rfbDontDisconnect;
extern Bool rfbViewOnly; /* run server in view-only mode - Ehud Karni SW */
extern void rfbNewClientConnection(int sock);
extern rfbClientPtr rfbReverseConnection(char *host, int port);
extern void rfbClientConnectionGone(int sock);
extern void rfbProcessClientMessage(int sock);
extern void rfbNewUDPConnection(int sock);
extern void rfbProcessUDPInput(int sock);
extern Bool rfbSendFramebufferUpdate(rfbClientPtr cl);
extern Bool rfbSendRectEncodingRaw(rfbClientPtr cl, int x,int y,int w,int h);
extern Bool rfbSendUpdateBuf(rfbClientPtr cl);
extern Bool rfbSendSetColourMapEntries(rfbClientPtr cl, int firstColour,
int nColours);
extern void rfbSendBell();
extern void rfbSendServerCutText(char *str, int len);
/* translate.c */
extern Bool rfbEconomicTranslate;
extern rfbPixelFormat rfbServerFormat;
extern void rfbTranslateNone(char *table, rfbPixelFormat *in,
rfbPixelFormat *out,
char *iptr, char *optr,
int bytesBetweenInputLines,
int width, int height);
extern Bool rfbSetTranslateFunction(rfbClientPtr cl);
extern void rfbSetClientColourMaps(int firstColour, int nColours);
extern Bool rfbSetClientColourMap(rfbClientPtr cl, int firstColour,
int nColours);
/* httpd.c */
extern int httpPort;
extern char *httpDir;
extern void httpInitSockets();
extern void httpCheckFds();
/* auth.c */
extern char *rfbAuthPasswdFile;
extern void rfbAuthNewClient(rfbClientPtr cl);
extern void rfbProcessClientSecurityType(rfbClientPtr cl);
extern void rfbProcessClientTunnelingType(rfbClientPtr cl);
extern void rfbProcessClientAuthType(rfbClientPtr cl);
extern void rfbVncAuthProcessResponse(rfbClientPtr cl);
extern void rfbClientConnFailed(rfbClientPtr cl, char *reason);
extern void rfbClientAuthFailed(rfbClientPtr cl, char *reason);
extern void rfbClientAuthSucceeded(rfbClientPtr cl, CARD32 authType);
/* Functions to prevent too many successive authentication failures */
extern Bool rfbAuthConsiderBlocking(void);
extern void rfbAuthUnblock(void);
extern Bool rfbAuthIsBlocked(void);
/* rre.c */
extern Bool rfbSendRectEncodingRRE(rfbClientPtr cl, int x,int y,int w,int h);
/* corre.c */
extern Bool rfbSendRectEncodingCoRRE(rfbClientPtr cl, int x,int y,int w,int h);
/* hextile.c */
extern Bool rfbSendRectEncodingHextile(rfbClientPtr cl, int x, int y, int w,
int h);
/* zlib.c */
/* Minimum zlib rectangle size in bytes. Anything smaller will
* not compress well due to overhead.
*/
#define VNC_ENCODE_ZLIB_MIN_COMP_SIZE (17)
/* Set maximum zlib rectangle size in pixels. Always allow at least
* two scan lines.
*/
#define ZLIB_MAX_RECT_SIZE (128*256)
#define ZLIB_MAX_SIZE(min) ((( min * 2 ) > ZLIB_MAX_RECT_SIZE ) ? \
( min * 2 ) : ZLIB_MAX_RECT_SIZE )
extern Bool rfbSendRectEncodingZlib(rfbClientPtr cl, int x, int y, int w,
int h);
/* tight.c */
#define TIGHT_DEFAULT_COMPRESSION 6
extern Bool rfbTightDisableGradient;
extern int rfbNumCodedRectsTight(rfbClientPtr cl, int x,int y,int w,int h);
extern Bool rfbSendRectEncodingTight(rfbClientPtr cl, int x,int y,int w,int h);
/* cursor.c */
extern Bool rfbSendCursorShape(rfbClientPtr cl, ScreenPtr pScreen);
extern Bool rfbSendCursorPos(rfbClientPtr cl, ScreenPtr pScreen);
/* stats.c */
extern void rfbResetStats(rfbClientPtr cl);
extern void rfbPrintStats(rfbClientPtr cl);
|