5 * rfb.h - header file for RFB DDX implementation.
9 * Copyright (C) 2005 Rohit Kumar <rokumar@novell.com>,
10 * Johannes E. Schindelin <johannes.schindelin@gmx.de>
11 * Copyright (C) 2002 RealVNC Ltd.
12 * OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
13 * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.
14 * All Rights Reserved.
16 * This is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This software is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this software; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
32 #if(defined __cplusplus)
40 #include <rfb/rfbproto.h>
42 #ifdef LIBVNCSERVER_HAVE_SYS_TYPES_H
43 #include <sys/types.h>
50 #ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
53 #define LOCK(mutex) (rfbLog("%s:%d LOCK(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_lock(&(mutex)))
54 #define UNLOCK(mutex) (rfbLog("%s:%d UNLOCK(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_unlock(&(mutex)))
55 #define MUTEX(mutex) pthread_mutex_t (mutex)
56 #define INIT_MUTEX(mutex) (rfbLog("%s:%d INIT_MUTEX(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_init(&(mutex),NULL))
57 #define TINI_MUTEX(mutex) (rfbLog("%s:%d TINI_MUTEX(%s)\n",__FILE__,__LINE__,#mutex), pthread_mutex_destroy(&(mutex)))
58 #define TSIGNAL(cond) (rfbLog("%s:%d TSIGNAL(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_signal(&(cond)))
59 #define WAIT(cond,mutex) (rfbLog("%s:%d WAIT(%s,%s)\n",__FILE__,__LINE__,#cond,#mutex), pthread_cond_wait(&(cond),&(mutex)))
60 #define COND(cond) pthread_cond_t (cond)
61 #define INIT_COND(cond) (rfbLog("%s:%d INIT_COND(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_init(&(cond),NULL))
62 #define TINI_COND(cond) (rfbLog("%s:%d TINI_COND(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_destroy(&(cond)))
63 #define IF_PTHREADS(x) x
66 #define LOCK(mutex) pthread_mutex_lock(&(mutex));
67 #define UNLOCK(mutex) pthread_mutex_unlock(&(mutex));
69 #define MUTEX(mutex) pthread_mutex_t (mutex)
70 #define INIT_MUTEX(mutex) pthread_mutex_init(&(mutex),NULL)
71 #define TINI_MUTEX(mutex) pthread_mutex_destroy(&(mutex))
72 #define TSIGNAL(cond) pthread_cond_signal(&(cond))
73 #define WAIT(cond,mutex) pthread_cond_wait(&(cond),&(mutex))
74 #define COND(cond) pthread_cond_t (cond)
75 #define INIT_COND(cond) pthread_cond_init(&(cond),NULL)
76 #define TINI_COND(cond) pthread_cond_destroy(&(cond))
77 #define IF_PTHREADS(x) x
83 #define INIT_MUTEX(mutex)
84 #define TINI_MUTEX(mutex)
86 #define WAIT(cond,mutex) this_is_unsupported
88 #define INIT_COND(cond)
89 #define TINI_COND(cond)
90 #define IF_PTHREADS(x)
93 /* end of stuff for autoconf */
95 /* if you use pthreads, but don't define LIBVNCSERVER_HAVE_LIBPTHREAD, the structs
96 get all mixed up. So this gives a linker error reminding you to compile
97 the library and your application (at least the parts including rfb.h)
98 with the same support for pthreads. */
99 #ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
100 #ifdef LIBVNCSERVER_HAVE_LIBZ
101 #define rfbInitServer rfbInitServerWithPthreadsAndZRLE
103 #define rfbInitServer rfbInitServerWithPthreadsButWithoutZRLE
106 #ifdef LIBVNCSERVER_HAVE_LIBZ
107 #define rfbInitServer rfbInitServerWithoutPthreadsButWithZRLE
109 #define rfbInitServer rfbInitServerWithoutPthreadsAndZRLE
113 struct _rfbClientRec;
114 struct _rfbScreenInfo;
117 enum rfbNewClientAction {
123 enum rfbSocketState {
129 typedef void (*rfbKbdAddEventProcPtr) (rfbBool down, rfbKeySym keySym, struct _rfbClientRec* cl);
130 typedef void (*rfbKbdReleaseAllKeysProcPtr) (struct _rfbClientRec* cl);
131 typedef void (*rfbPtrAddEventProcPtr) (int buttonMask, int x, int y, struct _rfbClientRec* cl);
132 typedef void (*rfbSetXCutTextProcPtr) (char* str,int len, struct _rfbClientRec* cl);
133 typedef struct rfbCursor* (*rfbGetCursorProcPtr) (struct _rfbClientRec* pScreen);
134 typedef rfbBool (*rfbSetTranslateFunctionProcPtr)(struct _rfbClientRec* cl);
135 typedef rfbBool (*rfbPasswordCheckProcPtr)(struct _rfbClientRec* cl,const char* encryptedPassWord,int len);
136 typedef enum rfbNewClientAction (*rfbNewClientHookPtr)(struct _rfbClientRec* cl);
137 typedef void (*rfbDisplayHookPtr)(struct _rfbClientRec* cl);
138 /* support the capability to view the caps/num/scroll states of the X server */
139 typedef int (*rfbGetKeyboardLedStateHookPtr)(struct _rfbScreenInfo* screen);
140 /* If x==1 and y==1 then set the whole display
141 * else find the window underneath x and y and set the framebuffer to the dimensions
144 typedef void (*rfbSetSingleWindowProcPtr) (struct _rfbClientRec* cl, int x, int y);
145 /* Status determines if the X11 server permits input from the local user
148 typedef void (*rfbSetServerInputProcPtr) (struct _rfbClientRec* cl, int status);
149 /* Permit the server to allow or deny filetransfers. This is defaulted to deny
150 * It is called when a client initiates a connection to determine if it is permitted.
152 typedef int (*rfbFileTransferPermitted) (struct _rfbClientRec* cl);
153 /* Handle the textchat messages */
154 typedef void (*rfbSetTextChat) (struct _rfbClientRec* cl, int length, char *string);
158 rfbBool is16; /* is the data format short? */
162 } data; /* there have to be count*3 entries */
166 * Security handling (RFB protocol version 3.7)
169 typedef struct _rfbSecurity {
171 void (*handler)(struct _rfbClientRec* cl);
172 struct _rfbSecurity* next;
173 } rfbSecurityHandler;
176 * Protocol extension handling.
179 typedef struct _rfbProtocolExtension {
180 /* returns FALSE if extension should be deactivated for client.
181 if newClient == NULL, it is always deactivated. */
182 rfbBool (*newClient)(struct _rfbClientRec* client, void** data);
183 /* returns FALSE if extension should be deactivated for client.
184 if init == NULL, it stays activated. */
185 rfbBool (*init)(struct _rfbClientRec* client, void* data);
186 /* if pseudoEncodings is not NULL, it contains a 0 terminated
187 list of the pseudo encodings handled by this extension. */
188 int *pseudoEncodings;
189 /* returns TRUE if that pseudo encoding is handled by the extension.
190 encodingNumber==0 means "reset encodings". */
191 rfbBool (*enablePseudoEncoding)(struct _rfbClientRec* client,
192 void** data, int encodingNumber);
193 /* returns TRUE if message was handled */
194 rfbBool (*handleMessage)(struct _rfbClientRec* client,
196 const rfbClientToServerMsg* message);
197 void (*close)(struct _rfbClientRec* client, void* data);
199 /* processArguments returns the number of handled arguments */
200 int (*processArgument)(int argc, char *argv[]);
201 struct _rfbProtocolExtension* next;
202 } rfbProtocolExtension;
204 typedef struct _rfbExtensionData {
205 rfbProtocolExtension* extension;
207 struct _rfbExtensionData* next;
211 * Per-screen (framebuffer) structure. There can be as many as you wish,
212 * each serving different clients. However, you have to call
213 * rfbProcessEvents for each of these.
216 typedef struct _rfbScreenInfo
218 /* this structure has children that are scaled versions of this screen */
219 struct _rfbScreenInfo *scaledScreenNext;
220 int scaledScreenRefCount;
223 int paddedWidthInBytes;
232 /* some screen specific data can be put into a struct where screenData
233 * points to. You need this if you have more than one screen at the
234 * same time while using the same functions.
238 /* additions by libvncserver */
240 rfbPixelFormat serverFormat;
241 rfbColourMap colourMap; /* set this if rfbServerFormat.trueColour==FALSE */
242 const char* desktopName;
251 struct fd_set allFds;
256 enum rfbSocketState socketState;
258 rfbBool inetdInitDone;
262 struct _rfbClientRec* udpClient;
263 rfbBool udpSockConnected;
264 struct sockaddr_in udpRemoteAddr;
269 rfbBool httpInitDone;
270 rfbBool httpEnableProxyConnect;
273 SOCKET httpListenSock;
276 rfbPasswordCheckProcPtr passwordCheck;
277 void* authPasswdData;
278 /* If rfbAuthPasswdData is given a list, this is the first
279 view only password. */
280 int authPasswdFirstViewOnly;
282 /* send only this many rectangles in one update */
283 int maxRectsPerUpdate;
284 /* this is the amount of milliseconds to wait at least before sending
290 rfbBool alwaysShared;
292 rfbBool dontDisconnect;
293 struct _rfbClientRec* clientHead;
294 struct _rfbClientRec* pointerClient; /* "Mutex" for pointer events */
298 int cursorX, cursorY,underCursorBufferLen;
299 char* underCursorBuffer;
300 rfbBool dontConvertRichCursorToXCursor;
301 struct rfbCursor* cursor;
303 /* the frameBufferhas to be supplied by the serving process.
304 * The buffer will not be freed by
307 rfbKbdAddEventProcPtr kbdAddEvent;
308 rfbKbdReleaseAllKeysProcPtr kbdReleaseAllKeys;
309 rfbPtrAddEventProcPtr ptrAddEvent;
310 rfbSetXCutTextProcPtr setXCutText;
311 rfbGetCursorProcPtr getCursorPtr;
312 rfbSetTranslateFunctionProcPtr setTranslateFunction;
313 rfbSetSingleWindowProcPtr setSingleWindow;
314 rfbSetServerInputProcPtr setServerInput;
315 rfbFileTransferPermitted getFileTransferPermission;
316 rfbSetTextChat setTextChat;
318 /* newClientHook is called just after a new client is created */
319 rfbNewClientHookPtr newClientHook;
320 /* displayHook is called just before a frame buffer update */
321 rfbDisplayHookPtr displayHook;
323 /* These hooks are called to pass keyboard state back to the client */
324 rfbGetKeyboardLedStateHookPtr getKeyboardLedStateHook;
326 #ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
328 rfbBool backgroundLoop;
331 /* if TRUE, an ignoring signal handler is installed for SIGPIPE */
332 rfbBool ignoreSIGPIPE;
334 /* if not zero, only a slice of this height is processed every time
335 * an update should be sent. This should make working on a slow
336 * link more interactive. */
337 int progressiveSliceHeight;
339 in_addr_t listenInterface;
340 int deferPtrUpdateTime;
342 /* handle as many input events as possible (default off) */
343 rfbBool handleEventsEagerly;
345 /* rfbEncodingServerIdentity */
348 /* What does the server tell the new clients which version it supports */
349 int protocolMajorVersion;
350 int protocolMinorVersion;
352 /* command line authorization of file transfers */
353 rfbBool permitFileTransfer;
354 } rfbScreenInfo, *rfbScreenInfoPtr;
358 * rfbTranslateFnType is the type of translation functions.
361 typedef void (*rfbTranslateFnType)(char *table, rfbPixelFormat *in,
363 char *iptr, char *optr,
364 int bytesBetweenInputLines,
365 int width, int height);
371 typedef struct sraRegion* sraRegionPtr;
374 * Per-client structure.
377 typedef void (*ClientGoneHookPtr)(struct _rfbClientRec* cl);
379 typedef struct _rfbFileTransferData {
381 int compressionEnabled;
386 } rfbFileTransferData;
389 typedef struct _rfbStatList {
393 uint32_t bytesSentIfRaw;
396 uint32_t bytesRcvdIfRaw;
397 struct _rfbStatList *Next;
400 typedef struct _rfbClientRec {
402 /* back pointer to the screen */
403 rfbScreenInfoPtr screen;
405 /* points to a scaled version of the screen buffer in cl->scaledScreenList */
406 rfbScreenInfoPtr scaledScreen;
407 /* how did the client tell us it wanted the screen changed? Ultra style or palm style? */
411 /* private data. You should put any application client specific data
412 * into a struct and let clientData point to it. Don't forget to
413 * free the struct via clientGoneHook!
415 * This is useful if the IO functions have to behave client specific.
418 ClientGoneHookPtr clientGoneHook;
423 /* RFB protocol minor version number */
424 int protocolMajorVersion;
425 int protocolMinorVersion;
427 #ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
428 pthread_t client_thread;
430 /* Possible client states: */
432 RFB_PROTOCOL_VERSION, /* establishing protocol version */
433 RFB_SECURITY_TYPE, /* negotiating security (RFB v.3.7) */
434 RFB_AUTHENTICATION, /* authenticating */
435 RFB_INITIALISATION, /* sending initialisation messages */
436 RFB_NORMAL /* normal protocol messages */
439 rfbBool reverseConnection;
441 rfbBool readyForSetColourMapEntries;
443 int preferredEncoding;
444 int correMaxWidth, correMaxHeight;
448 /* The following member is only used during VNC authentication */
449 uint8_t authChallenge[CHALLENGESIZE];
451 /* The following members represent the update needed to get the client's
452 framebuffer from its present state to the current state of our
455 If the client does not accept CopyRect encoding then the update is
456 simply represented as the region of the screen which has been modified
459 If the client does accept CopyRect encoding, then the update consists of
460 two parts. First we have a single copy from one region of the screen to
461 another (the destination of the copy is copyRegion), and second we have
462 the region of the screen which has been modified in some other way
465 Although the copy is of a single region, this region may have many
466 rectangles. When sending an update, the copyRegion is always sent
467 before the modifiedRegion. This is because the modifiedRegion may
468 overlap parts of the screen which are in the source of the copy.
470 In fact during normal processing, the modifiedRegion may even overlap
471 the destination copyRegion. Just before an update is sent we remove
472 from the copyRegion anything in the modifiedRegion. */
474 sraRegionPtr copyRegion; /* the destination region of the copy */
475 int copyDX, copyDY; /* the translation by which the copy happens */
477 sraRegionPtr modifiedRegion;
479 /* As part of the FramebufferUpdateRequest, a client can express interest
480 in a subrectangle of the whole framebuffer. This is stored in the
481 requestedRegion member. In the normal case this is the whole
482 framebuffer if the client is ready, empty if it's not. */
484 sraRegionPtr requestedRegion;
486 /* The following member represents the state of the "deferred update" timer
487 - when the framebuffer is modified and the client is ready, in most
488 cases it is more efficient to defer sending the update by a few
489 milliseconds so that several changes to the framebuffer can be combined
490 into a single update. */
492 struct timeval startDeferring;
493 struct timeval startPtrDeferring;
498 /* translateFn points to the translation function which is used to copy
499 and translate a rectangle from the framebuffer to an output buffer. */
501 rfbTranslateFnType translateFn;
502 char *translateLookupTable;
503 rfbPixelFormat format;
506 * UPDATE_BUF_SIZE must be big enough to send at least one whole line of the
507 * framebuffer. So for a max screen width of say 2K with 32-bit pixels this
511 #define UPDATE_BUF_SIZE 30000
513 char updateBuf[UPDATE_BUF_SIZE];
517 struct _rfbStatList *statEncList;
518 struct _rfbStatList *statMsgList;
519 int rawBytesEquivalent;
522 #ifdef LIBVNCSERVER_HAVE_LIBZ
523 /* zlib encoding -- necessary compression state info per client */
525 struct z_stream_s compStream;
526 rfbBool compStreamInited;
527 uint32_t zlibCompressLevel;
528 /* the quality level is also used by ZYWRLE */
529 int tightQualityLevel;
531 #ifdef LIBVNCSERVER_HAVE_LIBJPEG
532 /* tight encoding -- preserve zlib streams' state for each client */
533 z_stream zsStruct[4];
536 int tightCompressLevel;
540 /* Ultra Encoding support */
541 rfbBool compStreamInitedLZO;
544 rfbFileTransferData fileTransfer;
546 int lastKeyboardLedState; /* keep track of last value so we can send *change* events */
547 rfbBool enableSupportedMessages; /* client supports SupportedMessages encoding */
548 rfbBool enableSupportedEncodings; /* client supports SupportedEncodings encoding */
549 rfbBool enableServerIdentity; /* client supports ServerIdentity encoding */
550 rfbBool enableKeyboardLedState; /* client supports KeyboardState encoding */
551 rfbBool enableLastRectEncoding; /* client supports LastRect encoding */
552 rfbBool enableCursorShapeUpdates; /* client supports cursor shape updates */
553 rfbBool enableCursorPosUpdates; /* client supports cursor position updates */
554 rfbBool useRichCursorEncoding; /* rfbEncodingRichCursor is preferred */
555 rfbBool cursorWasChanged; /* cursor shape update should be sent */
556 rfbBool cursorWasMoved; /* cursor position update should be sent */
557 int cursorX,cursorY; /* the coordinates of the cursor,
558 if enableCursorShapeUpdates = FALSE */
560 rfbBool useNewFBSize; /* client supports NewFBSize encoding */
561 rfbBool newFBSizePending; /* framebuffer size was changed */
563 struct _rfbClientRec *prev;
564 struct _rfbClientRec *next;
566 #ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
567 /* whenever a client is referenced, the refCount has to be incremented
568 and afterwards decremented, so that the client is not cleaned up
569 while being referenced.
570 Use the functions rfbIncrClientRef(cl) and rfbDecrClientRef(cl);
573 MUTEX(refCountMutex);
581 #ifdef LIBVNCSERVER_HAVE_LIBZ
584 int zywrleBuf[rfbZRLETileWidth * rfbZRLETileHeight];
587 /* if progressive updating is on, this variable holds the current
588 * y coordinate of the progressive slice. */
589 int progressiveSliceY;
591 rfbExtensionData* extensions;
592 } rfbClientRec, *rfbClientPtr;
595 * This macro is used to test whether there is a framebuffer update needing to
596 * be sent to the client.
599 #define FB_UPDATE_PENDING(cl) \
600 (((cl)->enableCursorShapeUpdates && (cl)->cursorWasChanged) || \
601 (((cl)->enableCursorShapeUpdates == FALSE && \
602 ((cl)->cursorX != (cl)->screen->cursorX || \
603 (cl)->cursorY != (cl)->screen->cursorY))) || \
604 ((cl)->useNewFBSize && (cl)->newFBSizePending) || \
605 ((cl)->enableCursorPosUpdates && (cl)->cursorWasMoved) || \
606 !sraRgnEmpty((cl)->copyRegion) || !sraRgnEmpty((cl)->modifiedRegion))
609 * Macros for endian swapping.
612 #define Swap16(s) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))
614 #define Swap24(l) ((((l) & 0xff) << 16) | (((l) >> 16) & 0xff) | \
617 #define Swap32(l) (((l) >> 24) | \
618 (((l) & 0x00ff0000) >> 8) | \
619 (((l) & 0x0000ff00) << 8) | \
623 extern char rfbEndianTest;
625 #define Swap16IfLE(s) (rfbEndianTest ? Swap16(s) : (s))
626 #define Swap24IfLE(l) (rfbEndianTest ? Swap24(l) : (l))
627 #define Swap32IfLE(l) (rfbEndianTest ? Swap32(l) : (l))
629 /* UltraVNC uses some windows structures unmodified, so the viewer expects LittleEndian Data */
630 #define Swap16IfBE(s) (rfbEndianTest ? (s) : Swap16(s))
631 #define Swap24IfBE(l) (rfbEndianTest ? (l) : Swap24(l))
632 #define Swap32IfBE(l) (rfbEndianTest ? (l) : Swap32(l))
636 extern int rfbMaxClientWait;
638 extern void rfbInitSockets(rfbScreenInfoPtr rfbScreen);
639 extern void rfbShutdownSockets(rfbScreenInfoPtr rfbScreen);
640 extern void rfbDisconnectUDPSock(rfbScreenInfoPtr rfbScreen);
641 extern void rfbCloseClient(rfbClientPtr cl);
642 extern int rfbReadExact(rfbClientPtr cl, char *buf, int len);
643 extern int rfbReadExactTimeout(rfbClientPtr cl, char *buf, int len,int timeout);
644 extern int rfbWriteExact(rfbClientPtr cl, const char *buf, int len);
645 extern int rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec);
646 extern int rfbConnect(rfbScreenInfoPtr rfbScreen, char* host, int port);
647 extern int rfbConnectToTcpAddr(char* host, int port);
648 extern int rfbListenOnTCPPort(int port, in_addr_t iface);
649 extern int rfbListenOnUDPPort(int port, in_addr_t iface);
650 extern int rfbStringToAddr(char* string,in_addr_t* addr);
654 /* Routines to iterate over the client list in a thread-safe way.
655 Only a single iterator can be in use at a time process-wide. */
656 typedef struct rfbClientIterator *rfbClientIteratorPtr;
658 extern void rfbClientListInit(rfbScreenInfoPtr rfbScreen);
659 extern rfbClientIteratorPtr rfbGetClientIterator(rfbScreenInfoPtr rfbScreen);
660 extern rfbClientPtr rfbClientIteratorNext(rfbClientIteratorPtr iterator);
661 extern void rfbReleaseClientIterator(rfbClientIteratorPtr iterator);
662 extern void rfbIncrClientRef(rfbClientPtr cl);
663 extern void rfbDecrClientRef(rfbClientPtr cl);
665 extern void rfbNewClientConnection(rfbScreenInfoPtr rfbScreen,int sock);
666 extern rfbClientPtr rfbNewClient(rfbScreenInfoPtr rfbScreen,int sock);
667 extern rfbClientPtr rfbNewUDPClient(rfbScreenInfoPtr rfbScreen);
668 extern rfbClientPtr rfbReverseConnection(rfbScreenInfoPtr rfbScreen,char *host, int port);
669 extern void rfbClientConnectionGone(rfbClientPtr cl);
670 extern void rfbProcessClientMessage(rfbClientPtr cl);
671 extern void rfbClientConnFailed(rfbClientPtr cl, char *reason);
672 extern void rfbNewUDPConnection(rfbScreenInfoPtr rfbScreen,int sock);
673 extern void rfbProcessUDPInput(rfbScreenInfoPtr rfbScreen);
674 extern rfbBool rfbSendFramebufferUpdate(rfbClientPtr cl, sraRegionPtr updateRegion);
675 extern rfbBool rfbSendRectEncodingRaw(rfbClientPtr cl, int x,int y,int w,int h);
676 extern rfbBool rfbSendUpdateBuf(rfbClientPtr cl);
677 extern void rfbSendServerCutText(rfbScreenInfoPtr rfbScreen,char *str, int len);
678 extern rfbBool rfbSendCopyRegion(rfbClientPtr cl,sraRegionPtr reg,int dx,int dy);
679 extern rfbBool rfbSendLastRectMarker(rfbClientPtr cl);
680 extern rfbBool rfbSendNewFBSize(rfbClientPtr cl, int w, int h);
681 extern rfbBool rfbSendSetColourMapEntries(rfbClientPtr cl, int firstColour, int nColours);
682 extern void rfbSendBell(rfbScreenInfoPtr rfbScreen);
684 extern char *rfbProcessFileTransferReadBuffer(rfbClientPtr cl, uint32_t length);
685 extern rfbBool rfbSendFileTransferChunk(rfbClientPtr cl);
686 extern rfbBool rfbSendDirContent(rfbClientPtr cl, int length, char *buffer);
687 extern rfbBool rfbSendFileTransferMessage(rfbClientPtr cl, uint8_t contentType, uint8_t contentParam, uint32_t size, uint32_t length, char *buffer);
688 extern char *rfbProcessFileTransferReadBuffer(rfbClientPtr cl, uint32_t length);
689 extern rfbBool rfbProcessFileTransfer(rfbClientPtr cl, uint8_t contentType, uint8_t contentParam, uint32_t size, uint32_t length);
691 void rfbGotXCutText(rfbScreenInfoPtr rfbScreen, char *str, int len);
695 extern rfbBool rfbEconomicTranslate;
697 extern void rfbTranslateNone(char *table, rfbPixelFormat *in,
699 char *iptr, char *optr,
700 int bytesBetweenInputLines,
701 int width, int height);
702 extern rfbBool rfbSetTranslateFunction(rfbClientPtr cl);
703 extern rfbBool rfbSetClientColourMap(rfbClientPtr cl, int firstColour, int nColours);
704 extern void rfbSetClientColourMaps(rfbScreenInfoPtr rfbScreen, int firstColour, int nColours);
708 extern void rfbHttpInitSockets(rfbScreenInfoPtr rfbScreen);
709 extern void rfbHttpShutdownSockets(rfbScreenInfoPtr rfbScreen);
710 extern void rfbHttpCheckFds(rfbScreenInfoPtr rfbScreen);
716 extern void rfbAuthNewClient(rfbClientPtr cl);
717 extern void rfbProcessClientSecurityType(rfbClientPtr cl);
718 extern void rfbAuthProcessClientMessage(rfbClientPtr cl);
719 extern void rfbRegisterSecurityHandler(rfbSecurityHandler* handler);
720 extern void rfbUnregisterSecurityHandler(rfbSecurityHandler* handler);
724 extern rfbBool rfbSendRectEncodingRRE(rfbClientPtr cl, int x,int y,int w,int h);
729 extern rfbBool rfbSendRectEncodingCoRRE(rfbClientPtr cl, int x,int y,int w,int h);
734 extern rfbBool rfbSendRectEncodingHextile(rfbClientPtr cl, int x, int y, int w,
739 /* Set maximum ultra rectangle size in pixels. Always allow at least
742 #define ULTRA_MAX_RECT_SIZE (128*256)
743 #define ULTRA_MAX_SIZE(min) ((( min * 2 ) > ULTRA_MAX_RECT_SIZE ) ? \
744 ( min * 2 ) : ULTRA_MAX_RECT_SIZE )
746 extern rfbBool rfbSendRectEncodingUltra(rfbClientPtr cl, int x,int y,int w,int h);
749 #ifdef LIBVNCSERVER_HAVE_LIBZ
752 /* Minimum zlib rectangle size in bytes. Anything smaller will
753 * not compress well due to overhead.
755 #define VNC_ENCODE_ZLIB_MIN_COMP_SIZE (17)
757 /* Set maximum zlib rectangle size in pixels. Always allow at least
760 #define ZLIB_MAX_RECT_SIZE (128*256)
761 #define ZLIB_MAX_SIZE(min) ((( min * 2 ) > ZLIB_MAX_RECT_SIZE ) ? \
762 ( min * 2 ) : ZLIB_MAX_RECT_SIZE )
764 extern rfbBool rfbSendRectEncodingZlib(rfbClientPtr cl, int x, int y, int w,
767 #ifdef LIBVNCSERVER_HAVE_LIBJPEG
770 #define TIGHT_DEFAULT_COMPRESSION 6
772 extern rfbBool rfbTightDisableGradient;
774 extern int rfbNumCodedRectsTight(rfbClientPtr cl, int x,int y,int w,int h);
775 extern rfbBool rfbSendRectEncodingTight(rfbClientPtr cl, int x,int y,int w,int h);
783 typedef struct rfbCursor {
784 /* set this to true if LibVNCServer has to free this cursor */
785 rfbBool cleanup, cleanupSource, cleanupMask, cleanupRichSource;
786 unsigned char *source; /* points to bits */
787 unsigned char *mask; /* points to bits */
788 unsigned short width, height, xhot, yhot; /* metrics */
789 unsigned short foreRed, foreGreen, foreBlue; /* device-independent colour */
790 unsigned short backRed, backGreen, backBlue; /* device-independent colour */
791 unsigned char *richSource; /* source bytes for a rich cursor */
792 unsigned char *alphaSource; /* source for alpha blending info */
793 rfbBool alphaPreMultiplied; /* if richSource already has alpha applied */
794 } rfbCursor, *rfbCursorPtr;
795 extern unsigned char rfbReverseByte[0x100];
797 extern rfbBool rfbSendCursorShape(rfbClientPtr cl/*, rfbScreenInfoPtr pScreen*/);
798 extern rfbBool rfbSendCursorPos(rfbClientPtr cl);
799 extern void rfbConvertLSBCursorBitmapOrMask(int width,int height,unsigned char* bitmap);
800 extern rfbCursorPtr rfbMakeXCursor(int width,int height,char* cursorString,char* maskString);
801 extern char* rfbMakeMaskForXCursor(int width,int height,char* cursorString);
802 extern char* rfbMakeMaskFromAlphaSource(int width,int height,unsigned char* alphaSource);
803 extern void rfbMakeXCursorFromRichCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor);
804 extern void rfbMakeRichCursorFromXCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor);
805 extern void rfbFreeCursor(rfbCursorPtr cursor);
806 extern void rfbSetCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr c);
808 /* cursor handling for the pointer */
809 extern void rfbDefaultPtrAddEvent(int buttonMask,int x,int y,rfbClientPtr cl);
812 #ifdef LIBVNCSERVER_HAVE_LIBZ
813 extern rfbBool rfbSendRectEncodingZRLE(rfbClientPtr cl, int x, int y, int w,int h);
818 extern void rfbResetStats(rfbClientPtr cl);
819 extern void rfbPrintStats(rfbClientPtr cl);
823 typedef struct rfbFontData {
826 metaData is a 256*5 array:
828 (offset,width,height,x,y)
831 } rfbFontData,* rfbFontDataPtr;
833 int rfbDrawChar(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,int x,int y,unsigned char c,rfbPixel colour);
834 void rfbDrawString(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,int x,int y,const char* string,rfbPixel colour);
835 /* if colour==backColour, background is transparent */
836 int rfbDrawCharWithClip(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,int x,int y,unsigned char c,int x1,int y1,int x2,int y2,rfbPixel colour,rfbPixel backColour);
837 void rfbDrawStringWithClip(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,int x,int y,const char* string,int x1,int y1,int x2,int y2,rfbPixel colour,rfbPixel backColour);
838 int rfbWidthOfString(rfbFontDataPtr font,const char* string);
839 int rfbWidthOfChar(rfbFontDataPtr font,unsigned char c);
840 void rfbFontBBox(rfbFontDataPtr font,unsigned char c,int* x1,int* y1,int* x2,int* y2);
841 /* this returns the smallest box enclosing any character of font. */
842 void rfbWholeFontBBox(rfbFontDataPtr font,int *x1, int *y1, int *x2, int *y2);
844 /* dynamically load a linux console font (4096 bytes, 256 glyphs a 8x16 */
845 rfbFontDataPtr rfbLoadConsoleFont(char *filename);
846 /* free a dynamically loaded font */
847 void rfbFreeFont(rfbFontDataPtr font);
851 void rfbFillRect(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2,rfbPixel col);
852 void rfbDrawPixel(rfbScreenInfoPtr s,int x,int y,rfbPixel col);
853 void rfbDrawLine(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2,rfbPixel col);
857 /* this opens a modal select box. list is an array of strings, the end marked
859 It returns the index in the list or -1 if cancelled or something else
861 typedef void (*SelectionChangedHookPtr)(int _index);
862 extern int rfbSelectBox(rfbScreenInfoPtr rfbScreen,
863 rfbFontDataPtr font, char** list,
864 int x1, int y1, int x2, int y2,
865 rfbPixel foreColour, rfbPixel backColour,
866 int border,SelectionChangedHookPtr selChangedHook);
870 extern void rfbUsage(void);
871 extern void rfbPurgeArguments(int* argc,int* position,int count,char *argv[]);
872 extern rfbBool rfbProcessArguments(rfbScreenInfoPtr rfbScreen,int* argc, char *argv[]);
873 extern rfbBool rfbProcessSizeArguments(int* width,int* height,int* bpp,int* argc, char *argv[]);
877 extern void rfbLogEnable(int enabled);
878 typedef void (*rfbLogProc)(const char *format, ...);
879 extern rfbLogProc rfbLog, rfbErr;
880 extern void rfbLogPerror(const char *str);
882 void rfbScheduleCopyRect(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y2,int dx,int dy);
883 void rfbScheduleCopyRegion(rfbScreenInfoPtr rfbScreen,sraRegionPtr copyRegion,int dx,int dy);
885 void rfbDoCopyRect(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y2,int dx,int dy);
886 void rfbDoCopyRegion(rfbScreenInfoPtr rfbScreen,sraRegionPtr copyRegion,int dx,int dy);
888 void rfbMarkRectAsModified(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y2);
889 void rfbMarkRegionAsModified(rfbScreenInfoPtr rfbScreen,sraRegionPtr modRegion);
890 void rfbDoNothingWithClient(rfbClientPtr cl);
891 enum rfbNewClientAction defaultNewClientHook(rfbClientPtr cl);
892 void rfbRegisterProtocolExtension(rfbProtocolExtension* extension);
893 void rfbUnregisterProtocolExtension(rfbProtocolExtension* extension);
894 struct _rfbProtocolExtension* rfbGetExtensionIterator();
895 void rfbReleaseExtensionIterator();
896 rfbBool rfbEnableExtension(rfbClientPtr cl, rfbProtocolExtension* extension,
898 rfbBool rfbDisableExtension(rfbClientPtr cl, rfbProtocolExtension* extension);
899 void* rfbGetExtensionClientData(rfbClientPtr cl, rfbProtocolExtension* extension);
901 /* to check against plain passwords */
902 rfbBool rfbCheckPasswordByList(rfbClientPtr cl,const char* response,int len);
904 /* functions to make a vnc server */
905 extern rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv,
906 int width,int height,int bitsPerSample,int samplesPerPixel,
908 extern void rfbInitServer(rfbScreenInfoPtr rfbScreen);
909 extern void rfbShutdownServer(rfbScreenInfoPtr rfbScreen,rfbBool disconnectClients);
910 extern void rfbNewFramebuffer(rfbScreenInfoPtr rfbScreen,char *framebuffer,
911 int width,int height, int bitsPerSample,int samplesPerPixel,
914 extern void rfbScreenCleanup(rfbScreenInfoPtr screenInfo);
915 extern void rfbSetServerVersionIdentity(rfbScreenInfoPtr screen, char *fmt, ...);
917 /* functions to accept/refuse a client that has been put on hold
918 by a NewClientHookPtr function. Must not be called in other
920 extern void rfbStartOnHoldClient(rfbClientPtr cl);
921 extern void rfbRefuseOnHoldClient(rfbClientPtr cl);
923 /* call one of these two functions to service the vnc clients.
924 usec are the microseconds the select on the fds waits.
925 if you are using the event loop, set this to some value > 0, so the
926 server doesn't get a high load just by listening.
927 rfbProcessEvents() returns TRUE if an update was pending. */
929 extern void rfbRunEventLoop(rfbScreenInfoPtr screenInfo, long usec, rfbBool runInBackground);
930 extern rfbBool rfbProcessEvents(rfbScreenInfoPtr screenInfo,long usec);
931 extern rfbBool rfbIsActive(rfbScreenInfoPtr screenInfo);
933 /* TightVNC file transfer extension */
934 void rfbRegisterTightVNCFileTransferExtension();
935 void rfbUnregisterTightVNCFileTransferExtension();
938 extern char *messageNameServer2Client(uint32_t type, char *buf, int len);
939 extern char *messageNameClient2Server(uint32_t type, char *buf, int len);
940 extern char *encodingName(uint32_t enc, char *buf, int len);
942 extern rfbStatList *rfbStatLookupEncoding(rfbClientPtr cl, uint32_t type);
943 extern rfbStatList *rfbStatLookupMessage(rfbClientPtr cl, uint32_t type);
945 /* Each call to rfbStatRecord* adds one to the rect count for that type */
946 extern void rfbStatRecordEncodingSent(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
947 extern void rfbStatRecordEncodingSentAdd(rfbClientPtr cl, uint32_t type, int byteCount); /* Specifically for tight encoding */
948 extern void rfbStatRecordEncodingRcvd(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
949 extern void rfbStatRecordMessageSent(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
950 extern void rfbStatRecordMessageRcvd(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
951 extern void rfbResetStats(rfbClientPtr cl);
952 extern void rfbPrintStats(rfbClientPtr cl);
954 extern int rfbStatGetSentBytes(rfbClientPtr cl);
955 extern int rfbStatGetSentBytesIfRaw(rfbClientPtr cl);
956 extern int rfbStatGetRcvdBytes(rfbClientPtr cl);
957 extern int rfbStatGetRcvdBytesIfRaw(rfbClientPtr cl);
958 extern int rfbStatGetMessageCountSent(rfbClientPtr cl, uint32_t type);
959 extern int rfbStatGetMessageCountRcvd(rfbClientPtr cl, uint32_t type);
960 extern int rfbStatGetEncodingCountSent(rfbClientPtr cl, uint32_t type);
961 extern int rfbStatGetEncodingCountRcvd(rfbClientPtr cl, uint32_t type);
963 /* Set which version you want to advertise 3.3, 3.6, 3.7 and 3.8 are currently supported*/
964 extern void rfbSetProtocolVersion(rfbScreenInfoPtr rfbScreen, int major_, int minor_);
966 /* send a TextChat message to a client */
967 extern rfbBool rfbSendTextChatMessage(rfbClientPtr cl, uint32_t length, char *buffer);
972 #if(defined __cplusplus)