00001 #ifndef RFBCLIENT_H
00002 #define RFBCLIENT_H
00003
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <string.h>
00037 #include <sys/time.h>
00038 #include <unistd.h>
00039 #include <rfb/rfbproto.h>
00040 #include <rfb/keysym.h>
00041
00042 #define rfbClientSwap16IfLE(s) \
00043 (*(char *)&client->endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
00044
00045 #define rfbClientSwap32IfLE(l) \
00046 (*(char *)&client->endianTest ? ((((l) & 0xff000000) >> 24) | \
00047 (((l) & 0x00ff0000) >> 8) | \
00048 (((l) & 0x0000ff00) << 8) | \
00049 (((l) & 0x000000ff) << 24)) : (l))
00050
00051 #define rfbClientSwap64IfLE(l) \
00052 (*(char *)&client->endianTest ? ((((l) & 0xff00000000000000ULL) >> 56) | \
00053 (((l) & 0x00ff000000000000ULL) >> 40) | \
00054 (((l) & 0x0000ff0000000000ULL) >> 24) | \
00055 (((l) & 0x000000ff00000000ULL) >> 8) | \
00056 (((l) & 0x00000000ff000000ULL) << 8) | \
00057 (((l) & 0x0000000000ff0000ULL) << 24) | \
00058 (((l) & 0x000000000000ff00ULL) << 40) | \
00059 (((l) & 0x00000000000000ffULL) << 56)) : (l))
00060
00061 #define FLASH_PORT_OFFSET 5400
00062 #define LISTEN_PORT_OFFSET 5500
00063 #define TUNNEL_PORT_OFFSET 5500
00064 #define SERVER_PORT_OFFSET 5900
00065
00066 #define DEFAULT_SSH_CMD "/usr/bin/ssh"
00067 #define DEFAULT_TUNNEL_CMD \
00068 (DEFAULT_SSH_CMD " -f -L %L:localhost:%R %H sleep 20")
00069 #define DEFAULT_VIA_CMD \
00070 (DEFAULT_SSH_CMD " -f -L %L:%H:%R %G sleep 20")
00071
00072 #if(defined __cplusplus)
00073 extern "C"
00074 {
00075 #endif
00076
00079 typedef struct {
00080 FILE* file;
00081 struct timeval tv;
00082 rfbBool readTimestamp;
00083 rfbBool doNotSleep;
00084 } rfbVNCRec;
00085
00088 typedef struct rfbClientData {
00089 void* tag;
00090 void* data;
00091 struct rfbClientData* next;
00092 } rfbClientData;
00093
00096 typedef struct {
00097 rfbBool shareDesktop;
00098 rfbBool viewOnly;
00099
00100 const char* encodingsString;
00101
00102 rfbBool useBGR233;
00103 int nColours;
00104 rfbBool forceOwnCmap;
00105 rfbBool forceTrueColour;
00106 int requestedDepth;
00107
00108 int compressLevel;
00109 int qualityLevel;
00110 rfbBool enableJPEG;
00111 rfbBool useRemoteCursor;
00112 rfbBool palmVNC;
00113 int scaleSetting;
00114 } AppData;
00115
00117 typedef union _rfbCredential
00118 {
00120 struct
00121 {
00122 char *x509CACertFile;
00123 char *x509CACrlFile;
00124 char *x509ClientCertFile;
00125 char *x509ClientKeyFile;
00126 } x509Credential;
00128 struct
00129 {
00130 char *username;
00131 char *password;
00132 } userCredential;
00133 } rfbCredential;
00134
00135 #define rfbCredentialTypeX509 1
00136 #define rfbCredentialTypeUser 2
00137
00138 struct _rfbClient;
00139
00150 typedef void (*HandleTextChatProc)(struct _rfbClient* client, int value, char *text);
00160 typedef void (*HandleXvpMsgProc)(struct _rfbClient* client, uint8_t version, uint8_t opcode);
00161 typedef void (*HandleKeyboardLedStateProc)(struct _rfbClient* client, int value, int pad);
00162 typedef rfbBool (*HandleCursorPosProc)(struct _rfbClient* client, int x, int y);
00163 typedef void (*SoftCursorLockAreaProc)(struct _rfbClient* client, int x, int y, int w, int h);
00164 typedef void (*SoftCursorUnlockScreenProc)(struct _rfbClient* client);
00165 typedef void (*GotFrameBufferUpdateProc)(struct _rfbClient* client, int x, int y, int w, int h);
00166 typedef void (*FinishedFrameBufferUpdateProc)(struct _rfbClient* client);
00167 typedef char* (*GetPasswordProc)(struct _rfbClient* client);
00168 typedef rfbCredential* (*GetCredentialProc)(struct _rfbClient* client, int credentialType);
00169 typedef rfbBool (*MallocFrameBufferProc)(struct _rfbClient* client);
00170 typedef void (*GotXCutTextProc)(struct _rfbClient* client, const char *text, int textlen);
00171 typedef void (*BellProc)(struct _rfbClient* client);
00172
00173 typedef void (*GotCursorShapeProc)(struct _rfbClient* client, int xhot, int yhot, int width, int height, int bytesPerPixel);
00174 typedef void (*GotCopyRectProc)(struct _rfbClient* client, int src_x, int src_y, int w, int h, int dest_x, int dest_y);
00175
00176 typedef struct _rfbClient {
00177 uint8_t* frameBuffer;
00178 int width, height;
00179
00180 int endianTest;
00181
00182 AppData appData;
00183
00184 const char* programName;
00185 char* serverHost;
00186 int serverPort;
00187 rfbBool listenSpecified;
00188 int listenPort, flashPort;
00189
00190 struct {
00191 int x, y, w, h;
00192 } updateRect;
00193
00199 #define RFB_BUFFER_SIZE (640*480)
00200 char buffer[RFB_BUFFER_SIZE];
00201
00202
00203
00204 int sock;
00205 rfbBool canUseCoRRE;
00206 rfbBool canUseHextile;
00207 char *desktopName;
00208 rfbPixelFormat format;
00209 rfbServerInitMsg si;
00210
00211
00212 #define RFB_BUF_SIZE 8192
00213 char buf[RFB_BUF_SIZE];
00214 char *bufoutptr;
00215 int buffered;
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 int ultra_buffer_size;
00226 char *ultra_buffer;
00227
00228 int raw_buffer_size;
00229 char *raw_buffer;
00230
00231 #ifdef LIBVNCSERVER_HAVE_LIBZ
00232 z_stream decompStream;
00233 rfbBool decompStreamInited;
00234 #endif
00235
00236
00237 #ifdef LIBVNCSERVER_HAVE_LIBZ
00238
00239
00240
00241
00243 #define ZLIB_BUFFER_SIZE 30000
00244 char zlib_buffer[ZLIB_BUFFER_SIZE];
00245
00246
00247 z_stream zlibStream[4];
00248 rfbBool zlibStreamActive[4];
00249
00250
00251 rfbBool cutZeros;
00252 int rectWidth, rectColors;
00253 char tightPalette[256*4];
00254 uint8_t tightPrevRow[2048*3*sizeof(uint16_t)];
00255
00256 #ifdef LIBVNCSERVER_HAVE_LIBJPEG
00257
00258 rfbBool jpegError;
00259
00260 struct jpeg_source_mgr* jpegSrcManager;
00261 void* jpegBufferPtr;
00262 size_t jpegBufferLen;
00263
00264 #endif
00265 #endif
00266
00267
00268
00269 uint8_t *rcSource, *rcMask;
00270
00272 rfbClientData* clientData;
00273
00274 rfbVNCRec* vncRec;
00275
00276
00277 int KeyboardLedStateEnabled;
00278 int CurrentKeyboardLedState;
00279
00280 int canHandleNewFBSize;
00281
00282
00283 HandleTextChatProc HandleTextChat;
00284 HandleKeyboardLedStateProc HandleKeyboardLedState;
00285 HandleCursorPosProc HandleCursorPos;
00286 SoftCursorLockAreaProc SoftCursorLockArea;
00287 SoftCursorUnlockScreenProc SoftCursorUnlockScreen;
00288 GotFrameBufferUpdateProc GotFrameBufferUpdate;
00290 GetPasswordProc GetPassword;
00291 MallocFrameBufferProc MallocFrameBuffer;
00292 GotXCutTextProc GotXCutText;
00293 BellProc Bell;
00294
00295 GotCursorShapeProc GotCursorShape;
00296 GotCopyRectProc GotCopyRect;
00297
00306 rfbSupportedMessages supportedMessages;
00307
00309 int major, minor;
00310
00312 uint32_t authScheme, subAuthScheme;
00313
00315 void* tlsSession;
00316
00323 GetCredentialProc GetCredential;
00324
00327 uint32_t *clientAuthSchemes;
00328
00330 char *destHost;
00331 int destPort;
00332
00334 int QoS_DSCP;
00335
00337 HandleXvpMsgProc HandleXvpMsg;
00338
00339
00340 int listenSock;
00341
00342 FinishedFrameBufferUpdateProc FinishedFrameBufferUpdate;
00343
00344 char *listenAddress;
00345
00346 int listen6Sock;
00347 char* listen6Address;
00348 int listen6Port;
00349 } rfbClient;
00350
00351
00352
00353 extern rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int height, uint32_t enc);
00354
00355
00356
00357 extern void listenForIncomingConnections(rfbClient* viewer);
00358 extern int listenForIncomingConnectionsNoFork(rfbClient* viewer, int usec_timeout);
00359
00360
00361
00362 extern rfbBool rfbEnableClientLogging;
00363 typedef void (*rfbClientLogProc)(const char *format, ...);
00364 extern rfbClientLogProc rfbClientLog,rfbClientErr;
00365 extern rfbBool ConnectToRFBServer(rfbClient* client,const char *hostname, int port);
00366 extern rfbBool ConnectToRFBRepeater(rfbClient* client,const char *repeaterHost, int repeaterPort, const char *destHost, int destPort);
00367 extern void SetClientAuthSchemes(rfbClient* client,const uint32_t *authSchemes, int size);
00368 extern rfbBool InitialiseRFBConnection(rfbClient* client);
00386 extern rfbBool SetFormatAndEncodings(rfbClient* client);
00387 extern rfbBool SendIncrementalFramebufferUpdateRequest(rfbClient* client);
00408 extern rfbBool SendFramebufferUpdateRequest(rfbClient* client,
00409 int x, int y, int w, int h,
00410 rfbBool incremental);
00411 extern rfbBool SendScaleSetting(rfbClient* client,int scaleSetting);
00432 extern rfbBool SendPointerEvent(rfbClient* client,int x, int y, int buttonMask);
00442 extern rfbBool SendKeyEvent(rfbClient* client,uint32_t key, rfbBool down);
00455 extern rfbBool SendClientCutText(rfbClient* client,char *str, int len);
00466 extern rfbBool HandleRFBServerMessage(rfbClient* client);
00467
00474 extern rfbBool TextChatSend(rfbClient* client, char *text);
00480 extern rfbBool TextChatOpen(rfbClient* client);
00486 extern rfbBool TextChatClose(rfbClient* client);
00487 extern rfbBool TextChatFinish(rfbClient* client);
00488 extern rfbBool PermitServerInput(rfbClient* client, int enabled);
00489 extern rfbBool SendXvpMsg(rfbClient* client, uint8_t version, uint8_t code);
00490
00491 extern void PrintPixelFormat(rfbPixelFormat *format);
00492
00493 extern rfbBool SupportsClient2Server(rfbClient* client, int messageType);
00494 extern rfbBool SupportsServer2Client(rfbClient* client, int messageType);
00495
00496
00497
00511 void rfbClientSetClientData(rfbClient* client, void* tag, void* data);
00520 void* rfbClientGetClientData(rfbClient* client, void* tag);
00521
00522
00523
00524 typedef struct _rfbClientProtocolExtension {
00525 int* encodings;
00527 rfbBool (*handleEncoding)(rfbClient* cl,
00528 rfbFramebufferUpdateRectHeader* rect);
00530 rfbBool (*handleMessage)(rfbClient* cl,
00531 rfbServerToClientMsg* message);
00532 struct _rfbClientProtocolExtension* next;
00533 } rfbClientProtocolExtension;
00534
00535 void rfbClientRegisterExtension(rfbClientProtocolExtension* e);
00536
00537
00538
00539 extern rfbBool errorMessageOnReadFailure;
00540
00541 extern rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n);
00542 extern rfbBool WriteToRFBServer(rfbClient* client, char *buf, int n);
00543 extern int FindFreeTcpPort(void);
00544 extern int ListenAtTcpPort(int port);
00545 extern int ListenAtTcpPortAndAddress(int port, const char *address);
00546 extern int ConnectClientToTcpAddr(unsigned int host, int port);
00547 extern int ConnectClientToTcpAddr6(const char *hostname, int port);
00548 extern int ConnectClientToUnixSock(const char *sockFile);
00549 extern int AcceptTcpConnection(int listenSock);
00550 extern rfbBool SetNonBlocking(int sock);
00551 extern rfbBool SetDSCP(int sock, int dscp);
00552
00553 extern rfbBool StringToIPAddr(const char *str, unsigned int *addr);
00554 extern rfbBool SameMachine(int sock);
00565 extern int WaitForMessage(rfbClient* client,unsigned int usecs);
00566
00567
00592 rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,int bytesPerPixel);
00624 rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv);
00632 void rfbClientCleanup(rfbClient* client);
00633
00634 #if(defined __cplusplus)
00635 }
00636 #endif
00637
00648 #endif