LibVNCServer/LibVNCClient
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rfb.h
Go to the documentation of this file.
1 #ifndef RFB_H
2 #define RFB_H
3 
12 /*
13  * Copyright (C) 2005 Rohit Kumar <rokumar@novell.com>,
14  * Johannes E. Schindelin <johannes.schindelin@gmx.de>
15  * Copyright (C) 2002 RealVNC Ltd.
16  * OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
17  * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.
18  * All Rights Reserved.
19  *
20  * This is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation; either version 2 of the License, or
23  * (at your option) any later version.
24  *
25  * This software is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this software; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
33  * USA.
34  */
35 
36 #if(defined __cplusplus)
37 extern "C"
38 {
39 #endif
40 
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <rfb/rfbproto.h>
45 
46 #if defined(ANDROID) || defined(LIBVNCSERVER_HAVE_ANDROID)
47 #include <arpa/inet.h>
48 #include <sys/select.h>
49 #endif
50 
51 #ifdef LIBVNCSERVER_HAVE_SYS_TYPES_H
52 #include <sys/types.h>
53 #endif
54 
55 #ifdef __MINGW32__
56 #undef SOCKET
57 #include <winsock2.h>
58 #ifdef LIBVNCSERVER_HAVE_WS2TCPIP_H
59 #undef socklen_t
60 #include <ws2tcpip.h>
61 #endif
62 #endif
63 
64 #ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
65 #include <pthread.h>
66 #if 0 /* debugging */
67 #define LOCK(mutex) (rfbLog("%s:%d LOCK(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_lock(&(mutex)))
68 #define UNLOCK(mutex) (rfbLog("%s:%d UNLOCK(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_unlock(&(mutex)))
69 #define MUTEX(mutex) pthread_mutex_t (mutex)
70 #define INIT_MUTEX(mutex) (rfbLog("%s:%d INIT_MUTEX(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_init(&(mutex),NULL))
71 #define TINI_MUTEX(mutex) (rfbLog("%s:%d TINI_MUTEX(%s)\n",__FILE__,__LINE__,#mutex), pthread_mutex_destroy(&(mutex)))
72 #define TSIGNAL(cond) (rfbLog("%s:%d TSIGNAL(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_signal(&(cond)))
73 #define WAIT(cond,mutex) (rfbLog("%s:%d WAIT(%s,%s)\n",__FILE__,__LINE__,#cond,#mutex), pthread_cond_wait(&(cond),&(mutex)))
74 #define COND(cond) pthread_cond_t (cond)
75 #define INIT_COND(cond) (rfbLog("%s:%d INIT_COND(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_init(&(cond),NULL))
76 #define TINI_COND(cond) (rfbLog("%s:%d TINI_COND(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_destroy(&(cond)))
77 #define IF_PTHREADS(x) x
78 #else
79 #if !NONETWORK
80 #define LOCK(mutex) pthread_mutex_lock(&(mutex));
81 #define UNLOCK(mutex) pthread_mutex_unlock(&(mutex));
82 #endif
83 #define MUTEX(mutex) pthread_mutex_t (mutex)
84 #define INIT_MUTEX(mutex) pthread_mutex_init(&(mutex),NULL)
85 #define TINI_MUTEX(mutex) pthread_mutex_destroy(&(mutex))
86 #define TSIGNAL(cond) pthread_cond_signal(&(cond))
87 #define WAIT(cond,mutex) pthread_cond_wait(&(cond),&(mutex))
88 #define COND(cond) pthread_cond_t (cond)
89 #define INIT_COND(cond) pthread_cond_init(&(cond),NULL)
90 #define TINI_COND(cond) pthread_cond_destroy(&(cond))
91 #define IF_PTHREADS(x) x
92 #endif
93 #else
94 #define LOCK(mutex)
95 #define UNLOCK(mutex)
96 #define MUTEX(mutex)
97 #define INIT_MUTEX(mutex)
98 #define TINI_MUTEX(mutex)
99 #define TSIGNAL(cond)
100 #define WAIT(cond,mutex) this_is_unsupported
101 #define COND(cond)
102 #define INIT_COND(cond)
103 #define TINI_COND(cond)
104 #define IF_PTHREADS(x)
105 #endif
106 
107 /* end of stuff for autoconf */
108 
109 /* if you use pthreads, but don't define LIBVNCSERVER_HAVE_LIBPTHREAD, the structs
110  get all mixed up. So this gives a linker error reminding you to compile
111  the library and your application (at least the parts including rfb.h)
112  with the same support for pthreads. */
113 #ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
114 #ifdef LIBVNCSERVER_HAVE_LIBZ
115 #define rfbInitServer rfbInitServerWithPthreadsAndZRLE
116 #else
117 #define rfbInitServer rfbInitServerWithPthreadsButWithoutZRLE
118 #endif
119 #else
120 #ifdef LIBVNCSERVER_HAVE_LIBZ
121 #define rfbInitServer rfbInitServerWithoutPthreadsButWithZRLE
122 #else
123 #define rfbInitServer rfbInitServerWithoutPthreadsAndZRLE
124 #endif
125 #endif
126 
127 struct _rfbClientRec;
128 struct _rfbScreenInfo;
129 struct rfbCursor;
130 
135 };
136 
141 };
142 
143 typedef void (*rfbKbdAddEventProcPtr) (rfbBool down, rfbKeySym keySym, struct _rfbClientRec* cl);
144 typedef void (*rfbKbdReleaseAllKeysProcPtr) (struct _rfbClientRec* cl);
145 typedef void (*rfbPtrAddEventProcPtr) (int buttonMask, int x, int y, struct _rfbClientRec* cl);
146 typedef void (*rfbSetXCutTextProcPtr) (char* str,int len, struct _rfbClientRec* cl);
147 typedef struct rfbCursor* (*rfbGetCursorProcPtr) (struct _rfbClientRec* pScreen);
148 typedef rfbBool (*rfbSetTranslateFunctionProcPtr)(struct _rfbClientRec* cl);
149 typedef rfbBool (*rfbPasswordCheckProcPtr)(struct _rfbClientRec* cl,const char* encryptedPassWord,int len);
150 typedef enum rfbNewClientAction (*rfbNewClientHookPtr)(struct _rfbClientRec* cl);
151 typedef void (*rfbDisplayHookPtr)(struct _rfbClientRec* cl);
152 typedef void (*rfbDisplayFinishedHookPtr)(struct _rfbClientRec* cl, int result);
154 typedef int (*rfbGetKeyboardLedStateHookPtr)(struct _rfbScreenInfo* screen);
155 typedef rfbBool (*rfbXvpHookPtr)(struct _rfbClientRec* cl, uint8_t, uint8_t);
161 typedef void (*rfbSetSingleWindowProcPtr) (struct _rfbClientRec* cl, int x, int y);
166 typedef void (*rfbSetServerInputProcPtr) (struct _rfbClientRec* cl, int status);
171 typedef int (*rfbFileTransferPermitted) (struct _rfbClientRec* cl);
173 typedef void (*rfbSetTextChat) (struct _rfbClientRec* cl, int length, char *string);
174 
175 typedef struct {
176  uint32_t count;
178  union {
179  uint8_t* bytes;
180  uint16_t* shorts;
181  } data;
182 } rfbColourMap;
183 
188 typedef struct _rfbSecurity {
189  uint8_t type;
190  void (*handler)(struct _rfbClientRec* cl);
191  struct _rfbSecurity* next;
193 
198 typedef struct _rfbProtocolExtension {
201  rfbBool (*newClient)(struct _rfbClientRec* client, void** data);
204  rfbBool (*init)(struct _rfbClientRec* client, void* data);
210  rfbBool (*enablePseudoEncoding)(struct _rfbClientRec* client,
211  void** data, int encodingNumber);
213  rfbBool (*handleMessage)(struct _rfbClientRec* client,
214  void* data,
215  const rfbClientToServerMsg* message);
216  void (*close)(struct _rfbClientRec* client, void* data);
217  void (*usage)(void);
219  int (*processArgument)(int argc, char *argv[]);
220  struct _rfbProtocolExtension* next;
222 
223 typedef struct _rfbExtensionData {
225  void* data;
226  struct _rfbExtensionData* next;
228 
235 typedef struct _rfbScreenInfo
236 {
238  struct _rfbScreenInfo *scaledScreenNext;
240 
241  int width;
243  int height;
244  int depth;
247 
250 
256  void* screenData;
257 
258  /* additions by libvncserver */
259 
262  const char* desktopName;
263  char thisHost[255];
264 
266  int port;
268  int maxSock;
269  int maxFd;
270 #ifdef __MINGW32__
271  struct fd_set allFds;
272 #else
273  fd_set allFds;
274 #endif
275 
276  enum rfbSocketState socketState;
279 
280  int udpPort;
282  struct _rfbClientRec* udpClient;
284  struct sockaddr_in udpRemoteAddr;
285 
287 
288  /* http stuff */
291  int httpPort;
292  char* httpDir;
295 
301 
307 #ifdef TODELETE
308  char* screen;
309 #endif
313  struct _rfbClientRec* clientHead;
314  struct _rfbClientRec* pointerClient;
317  /* cursor */
318  int cursorX, cursorY,underCursorBufferLen;
321  struct rfbCursor* cursor;
322 
327  char* frameBuffer;
332  rfbGetCursorProcPtr getCursorPtr;
338 
343 
346 
347 #ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
348  MUTEX(cursorMutex);
349  rfbBool backgroundLoop;
350 #endif
351 
354 
359 
360  in_addr_t listenInterface;
362 
365 
368 
372 
375 
380 #ifdef LIBVNCSERVER_WITH_WEBSOCKETS
381  char *sslkeyfile;
382  char *sslcertfile;
383 #endif
384  int ipv6port;
386  /* We have an additional IPv6 listen socket since there are systems that
387  don't support dual binding sockets under *any* circumstances, for
388  instance OpenBSD */
392 } rfbScreenInfo, *rfbScreenInfoPtr;
393 
394 
399 typedef void (*rfbTranslateFnType)(char *table, rfbPixelFormat *in,
400  rfbPixelFormat *out,
401  char *iptr, char *optr,
402  int bytesBetweenInputLines,
403  int width, int height);
404 
405 
406 /* region stuff */
407 
408 struct sraRegion;
409 typedef struct sraRegion* sraRegionPtr;
410 
411 /*
412  * Per-client structure.
413  */
414 
415 typedef void (*ClientGoneHookPtr)(struct _rfbClientRec* cl);
416 
417 typedef struct _rfbFileTransferData {
418  int fd;
420  int fileSize;
423  int sending;
425 
426 
427 typedef struct _rfbStatList {
428  uint32_t type;
429  uint32_t sentCount;
430  uint32_t bytesSent;
431  uint32_t bytesSentIfRaw;
432  uint32_t rcvdCount;
433  uint32_t bytesRcvd;
434  uint32_t bytesRcvdIfRaw;
435  struct _rfbStatList *Next;
436 } rfbStatList;
437 
438 typedef struct _rfbSslCtx rfbSslCtx;
439 typedef struct _wsCtx wsCtx;
440 
441 typedef struct _rfbClientRec {
442 
444  rfbScreenInfoPtr screen;
445 
447  rfbScreenInfoPtr scaledScreen;
450 
451 
458  void* clientData;
460 
462  char *host;
463 
464  /* RFB protocol minor version number */
467 
468 #ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
469  pthread_t client_thread;
470 #endif
471 
472  /* Note that the RFB_INITIALISATION_SHARED state is provided to support
473  clients that under some circumstances do not send a ClientInit message.
474  In particular the Mac OS X built-in VNC client (with protocolMinorVersion
475  == 889) is one of those. However, it only requires this support under
476  special circumstances that can only be determined during the initial
477  authentication. If the right conditions are met this state will be
478  set (see the auth.c file) when rfbProcessClientInitMessage is called.
479 
480  If the state is RFB_INITIALISATION_SHARED we should not expect to recieve
481  any ClientInit message, but instead should proceed to the next stage
482  of initialisation as though an implicit ClientInit message was received
483  with a shared-flag of true. (There is currently no corresponding
484  RFB_INITIALISATION_NOTSHARED state to represent an implicit ClientInit
485  message with a shared-flag of false because no known existing client
486  requires such support at this time.)
487 
488  Note that software using LibVNCServer to provide a VNC server will only
489  ever have a chance to see the state field set to
490  RFB_INITIALISATION_SHARED if the software is multi-threaded and manages
491  to examine the state field during the extremely brief window after the
492  'None' authentication type selection has been received from the built-in
493  OS X VNC client and before the rfbProcessClientInitMessage function is
494  called -- control cannot return to the caller during this brief window
495  while the state field is set to RFB_INITIALISATION_SHARED. */
496 
498  enum {
505  /* Ephemeral internal-use states that will never be seen by software
506  * using LibVNCServer to provide services: */
507 
508  RFB_INITIALISATION_SHARED
509  } state;
510 
516  int correMaxWidth, correMaxHeight;
517 
519 
520  /* The following member is only used during VNC authentication */
521  uint8_t authChallenge[CHALLENGESIZE];
522 
523  /* The following members represent the update needed to get the client's
524  framebuffer from its present state to the current state of our
525  framebuffer.
526 
527  If the client does not accept CopyRect encoding then the update is
528  simply represented as the region of the screen which has been modified
529  (modifiedRegion).
530 
531  If the client does accept CopyRect encoding, then the update consists of
532  two parts. First we have a single copy from one region of the screen to
533  another (the destination of the copy is copyRegion), and second we have
534  the region of the screen which has been modified in some other way
535  (modifiedRegion).
536 
537  Although the copy is of a single region, this region may have many
538  rectangles. When sending an update, the copyRegion is always sent
539  before the modifiedRegion. This is because the modifiedRegion may
540  overlap parts of the screen which are in the source of the copy.
541 
542  In fact during normal processing, the modifiedRegion may even overlap
543  the destination copyRegion. Just before an update is sent we remove
544  from the copyRegion anything in the modifiedRegion. */
545 
546  sraRegionPtr copyRegion;
547  int copyDX, copyDY;
549  sraRegionPtr modifiedRegion;
550 
556  sraRegionPtr requestedRegion;
557 
564  struct timeval startDeferring;
565  struct timeval startPtrDeferring;
566  int lastPtrX;
567  int lastPtrY;
569 
576 
583 #define UPDATE_BUF_SIZE 30000
584 
585  char updateBuf[UPDATE_BUF_SIZE];
586  int ublen;
587 
588  /* statistics */
589  struct _rfbStatList *statEncList;
590  struct _rfbStatList *statMsgList;
593 
594 #ifdef LIBVNCSERVER_HAVE_LIBZ
595  /* zlib encoding -- necessary compression state info per client */
596 
597  struct z_stream_s compStream;
598  rfbBool compStreamInited;
599  uint32_t zlibCompressLevel;
600 #endif
601 #if defined(LIBVNCSERVER_HAVE_LIBZ) || defined(LIBVNCSERVER_HAVE_LIBPNG)
602 
603  int tightQualityLevel;
604 
605 #ifdef LIBVNCSERVER_HAVE_LIBJPEG
606  /* tight encoding -- preserve zlib streams' state for each client */
607  z_stream zsStruct[4];
608  rfbBool zsActive[4];
609  int zsLevel[4];
610  int tightCompressLevel;
611 #endif
612 #endif
613 
614  /* Ultra Encoding support */
616  char *lzoWrkMem;
617 
619 
631  int cursorX,cursorY;
637  struct _rfbClientRec *prev;
638  struct _rfbClientRec *next;
639 
640 #ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
641 
646  int refCount;
647  MUTEX(refCountMutex);
648  COND(deleteCond);
649 
650  MUTEX(outputMutex);
651  MUTEX(updateMutex);
652  COND(updateCond);
653 #endif
654 
655 #ifdef LIBVNCSERVER_HAVE_LIBZ
656  void* zrleData;
657  int zywrleLevel;
658  int zywrleBuf[rfbZRLETileWidth * rfbZRLETileHeight];
659 #endif
660 
664 
666 
670 
672 #ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
673 #define LIBVNCSERVER_SEND_MUTEX
674  MUTEX(sendMutex);
675 #endif
676 
677  /* buffers to hold pixel data before and after encoding.
678  per-client for thread safety */
681  char *afterEncBuf;
684 #if defined(LIBVNCSERVER_HAVE_LIBZ) || defined(LIBVNCSERVER_HAVE_LIBPNG)
685  uint32_t tightEncoding; /* rfbEncodingTight or rfbEncodingTightPng */
686 #ifdef LIBVNCSERVER_HAVE_LIBJPEG
687  /* TurboVNC Encoding support (extends TightVNC) */
688  int turboSubsampLevel;
689  int turboQualityLevel; // 1-100 scale
690 #endif
691 #endif
692 
693 #ifdef LIBVNCSERVER_WITH_WEBSOCKETS
694  rfbSslCtx *sslctx;
695  wsCtx *wsctx;
696  char *wspath; /* Requests path component */
697 #endif
698 } rfbClientRec, *rfbClientPtr;
699 
705 #define FB_UPDATE_PENDING(cl) \
706  (((cl)->enableCursorShapeUpdates && (cl)->cursorWasChanged) || \
707  (((cl)->enableCursorShapeUpdates == FALSE && \
708  ((cl)->cursorX != (cl)->screen->cursorX || \
709  (cl)->cursorY != (cl)->screen->cursorY))) || \
710  ((cl)->useNewFBSize && (cl)->newFBSizePending) || \
711  ((cl)->enableCursorPosUpdates && (cl)->cursorWasMoved) || \
712  !sraRgnEmpty((cl)->copyRegion) || !sraRgnEmpty((cl)->modifiedRegion))
713 
714 /*
715  * Macros for endian swapping.
716  */
717 
718 #define Swap16(s) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))
719 
720 #define Swap24(l) ((((l) & 0xff) << 16) | (((l) >> 16) & 0xff) | \
721  (((l) & 0x00ff00)))
722 
723 #define Swap32(l) (((l) >> 24) | \
724  (((l) & 0x00ff0000) >> 8) | \
725  (((l) & 0x0000ff00) << 8) | \
726  ((l) << 24))
727 
728 
729 extern char rfbEndianTest;
730 
731 #define Swap16IfLE(s) (rfbEndianTest ? Swap16(s) : (s))
732 #define Swap24IfLE(l) (rfbEndianTest ? Swap24(l) : (l))
733 #define Swap32IfLE(l) (rfbEndianTest ? Swap32(l) : (l))
734 
735 /* UltraVNC uses some windows structures unmodified, so the viewer expects LittleEndian Data */
736 #define Swap16IfBE(s) (rfbEndianTest ? (s) : Swap16(s))
737 #define Swap24IfBE(l) (rfbEndianTest ? (l) : Swap24(l))
738 #define Swap32IfBE(l) (rfbEndianTest ? (l) : Swap32(l))
739 
740 /* sockets.c */
741 
742 extern int rfbMaxClientWait;
743 
744 extern void rfbInitSockets(rfbScreenInfoPtr rfbScreen);
745 extern void rfbShutdownSockets(rfbScreenInfoPtr rfbScreen);
746 extern void rfbDisconnectUDPSock(rfbScreenInfoPtr rfbScreen);
747 extern void rfbCloseClient(rfbClientPtr cl);
748 extern int rfbReadExact(rfbClientPtr cl, char *buf, int len);
749 extern int rfbReadExactTimeout(rfbClientPtr cl, char *buf, int len,int timeout);
750 extern int rfbPeekExactTimeout(rfbClientPtr cl, char *buf, int len,int timeout);
751 extern int rfbWriteExact(rfbClientPtr cl, const char *buf, int len);
752 extern int rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec);
753 extern int rfbConnect(rfbScreenInfoPtr rfbScreen, char* host, int port);
754 extern int rfbConnectToTcpAddr(char* host, int port);
755 extern int rfbListenOnTCPPort(int port, in_addr_t iface);
756 extern int rfbListenOnTCP6Port(int port, const char* iface);
757 extern int rfbListenOnUDPPort(int port, in_addr_t iface);
758 extern int rfbStringToAddr(char* string,in_addr_t* addr);
759 extern rfbBool rfbSetNonBlocking(int sock);
760 
761 #ifdef LIBVNCSERVER_WITH_WEBSOCKETS
762 /* websockets.c */
763 
764 extern rfbBool webSocketsCheck(rfbClientPtr cl);
765 extern rfbBool webSocketCheckDisconnect(rfbClientPtr cl);
766 extern int webSocketsEncode(rfbClientPtr cl, const char *src, int len, char **dst);
767 extern int webSocketsDecode(rfbClientPtr cl, char *dst, int len);
768 #endif
769 
770 /* rfbserver.c */
771 
772 /* Routines to iterate over the client list in a thread-safe way.
773  Only a single iterator can be in use at a time process-wide. */
774 typedef struct rfbClientIterator *rfbClientIteratorPtr;
775 
776 extern void rfbClientListInit(rfbScreenInfoPtr rfbScreen);
777 extern rfbClientIteratorPtr rfbGetClientIterator(rfbScreenInfoPtr rfbScreen);
778 extern rfbClientPtr rfbClientIteratorNext(rfbClientIteratorPtr iterator);
779 extern void rfbReleaseClientIterator(rfbClientIteratorPtr iterator);
780 extern void rfbIncrClientRef(rfbClientPtr cl);
781 extern void rfbDecrClientRef(rfbClientPtr cl);
782 
783 extern void rfbNewClientConnection(rfbScreenInfoPtr rfbScreen,int sock);
784 extern rfbClientPtr rfbNewClient(rfbScreenInfoPtr rfbScreen,int sock);
785 extern rfbClientPtr rfbNewUDPClient(rfbScreenInfoPtr rfbScreen);
786 extern rfbClientPtr rfbReverseConnection(rfbScreenInfoPtr rfbScreen,char *host, int port);
787 extern void rfbClientConnectionGone(rfbClientPtr cl);
788 extern void rfbProcessClientMessage(rfbClientPtr cl);
789 extern void rfbClientConnFailed(rfbClientPtr cl, const char *reason);
790 extern void rfbNewUDPConnection(rfbScreenInfoPtr rfbScreen,int sock);
791 extern void rfbProcessUDPInput(rfbScreenInfoPtr rfbScreen);
792 extern rfbBool rfbSendFramebufferUpdate(rfbClientPtr cl, sraRegionPtr updateRegion);
793 extern rfbBool rfbSendRectEncodingRaw(rfbClientPtr cl, int x,int y,int w,int h);
794 extern rfbBool rfbSendUpdateBuf(rfbClientPtr cl);
795 extern void rfbSendServerCutText(rfbScreenInfoPtr rfbScreen,char *str, int len);
796 extern rfbBool rfbSendCopyRegion(rfbClientPtr cl,sraRegionPtr reg,int dx,int dy);
797 extern rfbBool rfbSendLastRectMarker(rfbClientPtr cl);
798 extern rfbBool rfbSendNewFBSize(rfbClientPtr cl, int w, int h);
799 extern rfbBool rfbSendSetColourMapEntries(rfbClientPtr cl, int firstColour, int nColours);
800 extern void rfbSendBell(rfbScreenInfoPtr rfbScreen);
801 
802 extern char *rfbProcessFileTransferReadBuffer(rfbClientPtr cl, uint32_t length);
803 extern rfbBool rfbSendFileTransferChunk(rfbClientPtr cl);
804 extern rfbBool rfbSendDirContent(rfbClientPtr cl, int length, char *buffer);
805 extern rfbBool rfbSendFileTransferMessage(rfbClientPtr cl, uint8_t contentType, uint8_t contentParam, uint32_t size, uint32_t length, const char *buffer);
806 extern char *rfbProcessFileTransferReadBuffer(rfbClientPtr cl, uint32_t length);
807 extern rfbBool rfbProcessFileTransfer(rfbClientPtr cl, uint8_t contentType, uint8_t contentParam, uint32_t size, uint32_t length);
808 
809 void rfbGotXCutText(rfbScreenInfoPtr rfbScreen, char *str, int len);
810 
811 /* translate.c */
812 
814 
815 extern void rfbTranslateNone(char *table, rfbPixelFormat *in,
816  rfbPixelFormat *out,
817  char *iptr, char *optr,
818  int bytesBetweenInputLines,
819  int width, int height);
820 extern rfbBool rfbSetTranslateFunction(rfbClientPtr cl);
821 extern rfbBool rfbSetClientColourMap(rfbClientPtr cl, int firstColour, int nColours);
822 extern void rfbSetClientColourMaps(rfbScreenInfoPtr rfbScreen, int firstColour, int nColours);
823 
824 /* httpd.c */
825 
826 extern void rfbHttpInitSockets(rfbScreenInfoPtr rfbScreen);
827 extern void rfbHttpShutdownSockets(rfbScreenInfoPtr rfbScreen);
828 extern void rfbHttpCheckFds(rfbScreenInfoPtr rfbScreen);
829 
830 
831 
832 /* auth.c */
833 
834 extern void rfbAuthNewClient(rfbClientPtr cl);
835 extern void rfbProcessClientSecurityType(rfbClientPtr cl);
836 extern void rfbAuthProcessClientMessage(rfbClientPtr cl);
837 extern void rfbRegisterSecurityHandler(rfbSecurityHandler* handler);
839 
840 /* rre.c */
841 
842 extern rfbBool rfbSendRectEncodingRRE(rfbClientPtr cl, int x,int y,int w,int h);
843 
844 
845 /* corre.c */
846 
847 extern rfbBool rfbSendRectEncodingCoRRE(rfbClientPtr cl, int x,int y,int w,int h);
848 
849 
850 /* hextile.c */
851 
852 extern rfbBool rfbSendRectEncodingHextile(rfbClientPtr cl, int x, int y, int w,
853  int h);
854 
855 /* ultra.c */
856 
857 /* Set maximum ultra rectangle size in pixels. Always allow at least
858  * two scan lines.
859  */
860 #define ULTRA_MAX_RECT_SIZE (128*256)
861 #define ULTRA_MAX_SIZE(min) ((( min * 2 ) > ULTRA_MAX_RECT_SIZE ) ? \
862  ( min * 2 ) : ULTRA_MAX_RECT_SIZE )
863 
864 extern rfbBool rfbSendRectEncodingUltra(rfbClientPtr cl, int x,int y,int w,int h);
865 
866 
867 #ifdef LIBVNCSERVER_HAVE_LIBZ
868 /* zlib.c */
869 
873 #define VNC_ENCODE_ZLIB_MIN_COMP_SIZE (17)
874 
875 /* Set maximum zlib rectangle size in pixels. Always allow at least
876  * two scan lines.
877  */
878 #define ZLIB_MAX_RECT_SIZE (128*256)
879 #define ZLIB_MAX_SIZE(min) ((( min * 2 ) > ZLIB_MAX_RECT_SIZE ) ? \
880  ( min * 2 ) : ZLIB_MAX_RECT_SIZE )
881 
882 extern rfbBool rfbSendRectEncodingZlib(rfbClientPtr cl, int x, int y, int w,
883  int h);
884 
885 #ifdef LIBVNCSERVER_HAVE_LIBJPEG
886 /* tight.c */
887 
888 #define TIGHT_DEFAULT_COMPRESSION 6
889 #define TURBO_DEFAULT_SUBSAMP 0
890 
891 extern rfbBool rfbTightDisableGradient;
892 
893 extern int rfbNumCodedRectsTight(rfbClientPtr cl, int x,int y,int w,int h);
894 
895 extern rfbBool rfbSendRectEncodingTight(rfbClientPtr cl, int x,int y,int w,int h);
896 
897 #if defined(LIBVNCSERVER_HAVE_LIBPNG)
898 extern rfbBool rfbSendRectEncodingTightPng(rfbClientPtr cl, int x,int y,int w,int h);
899 #endif
900 
901 #endif
902 #endif
903 
904 
905 /* cursor.c */
906 
907 typedef struct rfbCursor {
910  unsigned char *source;
911  unsigned char *mask;
912  unsigned short width, height, xhot, yhot;
913  unsigned short foreRed, foreGreen, foreBlue;
914  unsigned short backRed, backGreen, backBlue;
915  unsigned char *richSource;
916  unsigned char *alphaSource;
918 } rfbCursor, *rfbCursorPtr;
919 extern unsigned char rfbReverseByte[0x100];
920 
921 extern rfbBool rfbSendCursorShape(rfbClientPtr cl/*, rfbScreenInfoPtr pScreen*/);
922 extern rfbBool rfbSendCursorPos(rfbClientPtr cl);
923 extern void rfbConvertLSBCursorBitmapOrMask(int width,int height,unsigned char* bitmap);
924 extern rfbCursorPtr rfbMakeXCursor(int width,int height,char* cursorString,char* maskString);
925 extern char* rfbMakeMaskForXCursor(int width,int height,char* cursorString);
926 extern char* rfbMakeMaskFromAlphaSource(int width,int height,unsigned char* alphaSource);
927 extern void rfbMakeXCursorFromRichCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor);
928 extern void rfbMakeRichCursorFromXCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor);
929 extern void rfbFreeCursor(rfbCursorPtr cursor);
930 extern void rfbSetCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr c);
931 
933 extern void rfbDefaultPtrAddEvent(int buttonMask,int x,int y,rfbClientPtr cl);
934 
935 /* zrle.c */
936 #ifdef LIBVNCSERVER_HAVE_LIBZ
937 extern rfbBool rfbSendRectEncodingZRLE(rfbClientPtr cl, int x, int y, int w,int h);
938 #endif
939 
940 /* stats.c */
941 
942 extern void rfbResetStats(rfbClientPtr cl);
943 extern void rfbPrintStats(rfbClientPtr cl);
944 
945 /* font.c */
946 
947 typedef struct rfbFontData {
948  unsigned char* data;
954  int* metaData;
955 } rfbFontData,* rfbFontDataPtr;
956 
957 int rfbDrawChar(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,int x,int y,unsigned char c,rfbPixel colour);
958 void rfbDrawString(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,int x,int y,const char* string,rfbPixel colour);
960 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);
961 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);
962 int rfbWidthOfString(rfbFontDataPtr font,const char* string);
963 int rfbWidthOfChar(rfbFontDataPtr font,unsigned char c);
964 void rfbFontBBox(rfbFontDataPtr font,unsigned char c,int* x1,int* y1,int* x2,int* y2);
966 void rfbWholeFontBBox(rfbFontDataPtr font,int *x1, int *y1, int *x2, int *y2);
967 
969 rfbFontDataPtr rfbLoadConsoleFont(char *filename);
971 void rfbFreeFont(rfbFontDataPtr font);
972 
973 /* draw.c */
974 
975 void rfbFillRect(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2,rfbPixel col);
976 void rfbDrawPixel(rfbScreenInfoPtr s,int x,int y,rfbPixel col);
977 void rfbDrawLine(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2,rfbPixel col);
978 
979 /* selbox.c */
980 
985 typedef void (*SelectionChangedHookPtr)(int _index);
986 extern int rfbSelectBox(rfbScreenInfoPtr rfbScreen,
987  rfbFontDataPtr font, char** list,
988  int x1, int y1, int x2, int y2,
989  rfbPixel foreColour, rfbPixel backColour,
990  int border,SelectionChangedHookPtr selChangedHook);
991 
992 /* cargs.c */
993 
994 extern void rfbUsage(void);
995 extern void rfbPurgeArguments(int* argc,int* position,int count,char *argv[]);
996 extern rfbBool rfbProcessArguments(rfbScreenInfoPtr rfbScreen,int* argc, char *argv[]);
997 extern rfbBool rfbProcessSizeArguments(int* width,int* height,int* bpp,int* argc, char *argv[]);
998 
999 /* main.c */
1000 
1001 extern void rfbLogEnable(int enabled);
1002 typedef void (*rfbLogProc)(const char *format, ...);
1003 extern rfbLogProc rfbLog, rfbErr;
1004 extern void rfbLogPerror(const char *str);
1005 
1006 void rfbScheduleCopyRect(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y2,int dx,int dy);
1007 void rfbScheduleCopyRegion(rfbScreenInfoPtr rfbScreen,sraRegionPtr copyRegion,int dx,int dy);
1008 
1009 void rfbDoCopyRect(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y2,int dx,int dy);
1010 void rfbDoCopyRegion(rfbScreenInfoPtr rfbScreen,sraRegionPtr copyRegion,int dx,int dy);
1011 
1012 void rfbMarkRectAsModified(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y2);
1013 void rfbMarkRegionAsModified(rfbScreenInfoPtr rfbScreen,sraRegionPtr modRegion);
1014 void rfbDoNothingWithClient(rfbClientPtr cl);
1015 enum rfbNewClientAction defaultNewClientHook(rfbClientPtr cl);
1018 struct _rfbProtocolExtension* rfbGetExtensionIterator();
1020 rfbBool rfbEnableExtension(rfbClientPtr cl, rfbProtocolExtension* extension,
1021  void* data);
1022 rfbBool rfbDisableExtension(rfbClientPtr cl, rfbProtocolExtension* extension);
1023 void* rfbGetExtensionClientData(rfbClientPtr cl, rfbProtocolExtension* extension);
1024 
1026 rfbBool rfbCheckPasswordByList(rfbClientPtr cl,const char* response,int len);
1027 
1028 /* functions to make a vnc server */
1029 extern rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv,
1030  int width,int height,int bitsPerSample,int samplesPerPixel,
1031  int bytesPerPixel);
1032 extern void rfbInitServer(rfbScreenInfoPtr rfbScreen);
1033 extern void rfbShutdownServer(rfbScreenInfoPtr rfbScreen,rfbBool disconnectClients);
1034 extern void rfbNewFramebuffer(rfbScreenInfoPtr rfbScreen,char *framebuffer,
1035  int width,int height, int bitsPerSample,int samplesPerPixel,
1036  int bytesPerPixel);
1037 
1038 extern void rfbScreenCleanup(rfbScreenInfoPtr screenInfo);
1039 extern void rfbSetServerVersionIdentity(rfbScreenInfoPtr screen, char *fmt, ...);
1040 
1041 /* functions to accept/refuse a client that has been put on hold
1042  by a NewClientHookPtr function. Must not be called in other
1043  situations. */
1044 extern void rfbStartOnHoldClient(rfbClientPtr cl);
1045 extern void rfbRefuseOnHoldClient(rfbClientPtr cl);
1046 
1047 /* call one of these two functions to service the vnc clients.
1048  usec are the microseconds the select on the fds waits.
1049  if you are using the event loop, set this to some value > 0, so the
1050  server doesn't get a high load just by listening.
1051  rfbProcessEvents() returns TRUE if an update was pending. */
1052 
1053 extern void rfbRunEventLoop(rfbScreenInfoPtr screenInfo, long usec, rfbBool runInBackground);
1054 extern rfbBool rfbProcessEvents(rfbScreenInfoPtr screenInfo,long usec);
1055 extern rfbBool rfbIsActive(rfbScreenInfoPtr screenInfo);
1056 
1057 /* TightVNC file transfer extension */
1060 
1061 /* Statistics */
1062 extern char *messageNameServer2Client(uint32_t type, char *buf, int len);
1063 extern char *messageNameClient2Server(uint32_t type, char *buf, int len);
1064 extern char *encodingName(uint32_t enc, char *buf, int len);
1065 
1066 extern rfbStatList *rfbStatLookupEncoding(rfbClientPtr cl, uint32_t type);
1067 extern rfbStatList *rfbStatLookupMessage(rfbClientPtr cl, uint32_t type);
1068 
1069 /* Each call to rfbStatRecord* adds one to the rect count for that type */
1070 extern void rfbStatRecordEncodingSent(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
1071 extern void rfbStatRecordEncodingSentAdd(rfbClientPtr cl, uint32_t type, int byteCount); /* Specifically for tight encoding */
1072 extern void rfbStatRecordEncodingRcvd(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
1073 extern void rfbStatRecordMessageSent(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
1074 extern void rfbStatRecordMessageRcvd(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
1075 extern void rfbResetStats(rfbClientPtr cl);
1076 extern void rfbPrintStats(rfbClientPtr cl);
1077 
1078 extern int rfbStatGetSentBytes(rfbClientPtr cl);
1079 extern int rfbStatGetSentBytesIfRaw(rfbClientPtr cl);
1080 extern int rfbStatGetRcvdBytes(rfbClientPtr cl);
1081 extern int rfbStatGetRcvdBytesIfRaw(rfbClientPtr cl);
1082 extern int rfbStatGetMessageCountSent(rfbClientPtr cl, uint32_t type);
1083 extern int rfbStatGetMessageCountRcvd(rfbClientPtr cl, uint32_t type);
1084 extern int rfbStatGetEncodingCountSent(rfbClientPtr cl, uint32_t type);
1085 extern int rfbStatGetEncodingCountRcvd(rfbClientPtr cl, uint32_t type);
1086 
1088 extern void rfbSetProtocolVersion(rfbScreenInfoPtr rfbScreen, int major_, int minor_);
1089 
1091 extern rfbBool rfbSendTextChatMessage(rfbClientPtr cl, uint32_t length, char *buffer);
1092 
1093 
1094 /*
1095  * Additions for Qt event loop integration
1096  * Original idea taken from vino.
1097  */
1098 rfbBool rfbProcessNewConnection(rfbScreenInfoPtr rfbScreen);
1099 rfbBool rfbUpdateClient(rfbClientPtr cl);
1100 
1101 
1102 #if(defined __cplusplus)
1103 }
1104 #endif
1105 
1276 #endif