5
* Copyright (C) 2000, 2001 Const Kaplinsky. All Rights Reserved.
6
* Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
7
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
9
* This is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This software is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this software; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
34
#include <rfb/rfbproto.h>
35
#include <rfb/keysym.h>
36
#ifdef LIBVNCSERVER_WITH_CLIENT_TLS
37
#include <gnutls/gnutls.h>
40
#define rfbClientSwap16IfLE(s) \
41
(*(char *)&client->endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
43
#define rfbClientSwap32IfLE(l) \
44
(*(char *)&client->endianTest ? ((((l) & 0xff000000) >> 24) | \
45
(((l) & 0x00ff0000) >> 8) | \
46
(((l) & 0x0000ff00) << 8) | \
47
(((l) & 0x000000ff) << 24)) : (l))
49
#define rfbClientSwap64IfLE(l) \
50
(*(char *)&client->endianTest ? ((((l) & 0xff00000000000000ULL) >> 56) | \
51
(((l) & 0x00ff000000000000ULL) >> 40) | \
52
(((l) & 0x0000ff0000000000ULL) >> 24) | \
53
(((l) & 0x000000ff00000000ULL) >> 8) | \
54
(((l) & 0x00000000ff000000ULL) << 8) | \
55
(((l) & 0x0000000000ff0000ULL) << 24) | \
56
(((l) & 0x000000000000ff00ULL) << 40) | \
57
(((l) & 0x00000000000000ffULL) << 56)) : (l))
59
#define FLASH_PORT_OFFSET 5400
60
#define LISTEN_PORT_OFFSET 5500
61
#define TUNNEL_PORT_OFFSET 5500
62
#define SERVER_PORT_OFFSET 5900
64
#define DEFAULT_SSH_CMD "/usr/bin/ssh"
65
#define DEFAULT_TUNNEL_CMD \
66
(DEFAULT_SSH_CMD " -f -L %L:localhost:%R %H sleep 20")
67
#define DEFAULT_VIA_CMD \
68
(DEFAULT_SSH_CMD " -f -L %L:%H:%R %G sleep 20")
70
#if(defined __cplusplus)
80
rfbBool readTimestamp;
86
typedef struct rfbClientData {
89
struct rfbClientData* next;
92
/* app data (belongs into rfbClient?) */
98
const char* encodingsString;
102
rfbBool forceOwnCmap;
103
rfbBool forceTrueColour;
109
rfbBool useRemoteCursor;
110
rfbBool palmVNC; /* use palmvnc specific SetScale (vs ultravnc) */
111
int scaleSetting; /* 0 means no scale set, else 1/scaleSetting */
114
/* For GetCredentialProc callback function to return */
115
typedef union _rfbCredential
117
/* X509 (VeNCrypt) */
120
char *x509CACertFile;
122
char *x509ClientCertFile;
123
char *x509ClientKeyFile;
125
/* Plain (VeNCrypt), MSLogon (UltraVNC) */
133
#define rfbCredentialTypeX509 1
134
#define rfbCredentialTypeUser 2
138
typedef void (*HandleTextChatProc)(struct _rfbClient* client, int value, char *text);
139
typedef void (*HandleKeyboardLedStateProc)(struct _rfbClient* client, int value, int pad);
140
typedef rfbBool (*HandleCursorPosProc)(struct _rfbClient* client, int x, int y);
141
typedef void (*SoftCursorLockAreaProc)(struct _rfbClient* client, int x, int y, int w, int h);
142
typedef void (*SoftCursorUnlockScreenProc)(struct _rfbClient* client);
143
typedef void (*GotFrameBufferUpdateProc)(struct _rfbClient* client, int x, int y, int w, int h);
144
typedef void (*FinishedFrameBufferUpdateProc)(struct _rfbClient* client);
145
typedef char* (*GetPasswordProc)(struct _rfbClient* client);
146
typedef rfbCredential* (*GetCredentialProc)(struct _rfbClient* client, int credentialType);
147
typedef rfbBool (*MallocFrameBufferProc)(struct _rfbClient* client);
148
typedef void (*GotXCutTextProc)(struct _rfbClient* client, const char *text, int textlen);
149
typedef void (*BellProc)(struct _rfbClient* client);
151
typedef void (*GotCursorShapeProc)(struct _rfbClient* client, int xhot, int yhot, int width, int height, int bytesPerPixel);
152
typedef void (*GotCopyRectProc)(struct _rfbClient* client, int src_x, int src_y, int w, int h, int dest_x, int dest_y);
154
typedef struct _rfbClient {
155
uint8_t* frameBuffer;
162
const char* programName;
164
int serverPort; /* if -1, then use file recorded by vncrec */
165
rfbBool listenSpecified;
166
int listenPort, flashPort;
172
/* Note that the CoRRE encoding uses this buffer and assumes it is big enough
173
to hold 255 * 255 * 32 bits -> 260100 bytes. 640*480 = 307200 bytes.
174
Hextile also assumes it is big enough to hold 16 * 16 * 32 bits.
175
Tight encoding assumes BUFFER_SIZE is at least 16384 bytes. */
177
#define RFB_BUFFER_SIZE (640*480)
178
char buffer[RFB_BUFFER_SIZE];
184
rfbBool canUseHextile;
186
rfbPixelFormat format;
193
#define RFB_BUF_SIZE 8192
194
char buf[RFB_BUF_SIZE];
198
/* The zlib encoding requires expansion/decompression/deflation of the
199
compressed data in the "buffer" above into another, result buffer.
200
However, the size of the result buffer can be determined precisely
201
based on the bitsPerPixel, height and width of the rectangle. We
202
allocate this buffer one time to be the full size of the buffer. */
204
/* Ultra Encoding uses this buffer too */
206
int ultra_buffer_size;
212
#ifdef LIBVNCSERVER_HAVE_LIBZ
213
z_stream decompStream;
214
rfbBool decompStreamInited;
218
#ifdef LIBVNCSERVER_HAVE_LIBZ
220
* Variables for the ``tight'' encoding implementation.
223
/* Separate buffer for compressed data. */
224
#define ZLIB_BUFFER_SIZE 30000
225
char zlib_buffer[ZLIB_BUFFER_SIZE];
227
/* Four independent compression streams for zlib library. */
228
z_stream zlibStream[4];
229
rfbBool zlibStreamActive[4];
231
/* Filter stuff. Should be initialized by filter initialization code. */
233
int rectWidth, rectColors;
234
char tightPalette[256*4];
235
uint8_t tightPrevRow[2048*3*sizeof(uint16_t)];
237
#ifdef LIBVNCSERVER_HAVE_LIBJPEG
238
/* JPEG decoder state. */
241
struct jpeg_source_mgr* jpegSrcManager;
243
size_t jpegBufferLen;
250
uint8_t *rcSource, *rcMask;
252
/* private data pointer */
253
rfbClientData* clientData;
257
/* Keyboard State support (is 'Caps Lock' set on the remote display???) */
258
int KeyboardLedStateEnabled;
259
int CurrentKeyboardLedState;
261
int canHandleNewFBSize;
264
HandleTextChatProc HandleTextChat;
265
HandleKeyboardLedStateProc HandleKeyboardLedState;
266
HandleCursorPosProc HandleCursorPos;
267
SoftCursorLockAreaProc SoftCursorLockArea;
268
SoftCursorUnlockScreenProc SoftCursorUnlockScreen;
269
GotFrameBufferUpdateProc GotFrameBufferUpdate;
270
FinishedFrameBufferUpdateProc FinishedFrameBufferUpdate;
271
/* the pointer returned by GetPassword will be freed after use! */
272
GetPasswordProc GetPassword;
273
MallocFrameBufferProc MallocFrameBuffer;
274
GotXCutTextProc GotXCutText;
277
GotCursorShapeProc GotCursorShape;
278
GotCopyRectProc GotCopyRect;
280
/* Which messages are supported by the server
281
* This is a *guess* for most servers.
282
* (If we can even detect the type of server)
284
* If the server supports the "rfbEncodingSupportedMessages"
285
* then this will be updated when the encoding is received to
286
* accurately reflect the servers capabilities.
288
rfbSupportedMessages supportedMessages;
290
/* negotiated protocol version */
293
/* The selected security types */
294
uint32_t authScheme, subAuthScheme;
296
#ifdef LIBVNCSERVER_WITH_CLIENT_TLS
297
/* The TLS session for Anonymous TLS and VeNCrypt */
298
gnutls_session_t tlsSession;
301
/* To support security types that requires user input (except VNC password
302
* authentication), for example VeNCrypt and MSLogon, this callback function
303
* must be set before the authentication. Otherwise, it implicates that the
304
* caller application does not support it and related security types should
307
GetCredentialProc GetCredential;
312
extern rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int height, uint32_t enc);
316
extern void listenForIncomingConnections(rfbClient* viewer);
317
extern int listenForIncomingConnectionsNoFork(rfbClient* viewer, int usec_timeout);
321
extern rfbBool rfbEnableClientLogging;
322
typedef void (*rfbClientLogProc)(const char *format, ...);
323
extern rfbClientLogProc rfbClientLog,rfbClientErr;
324
extern rfbBool ConnectToRFBServer(rfbClient* client,const char *hostname, int port);
325
extern rfbBool InitialiseRFBConnection(rfbClient* client);
326
extern rfbBool SetFormatAndEncodings(rfbClient* client);
327
extern rfbBool SendIncrementalFramebufferUpdateRequest(rfbClient* client);
328
extern rfbBool SendFramebufferUpdateRequest(rfbClient* client,
329
int x, int y, int w, int h,
330
rfbBool incremental);
331
extern rfbBool SendScaleSetting(rfbClient* client,int scaleSetting);
332
extern rfbBool SendPointerEvent(rfbClient* client,int x, int y, int buttonMask);
333
extern rfbBool SendKeyEvent(rfbClient* client,uint32_t key, rfbBool down);
334
extern rfbBool SendClientCutText(rfbClient* client,char *str, int len);
335
extern rfbBool HandleRFBServerMessage(rfbClient* client);
337
extern rfbBool TextChatSend(rfbClient* client, char *text);
338
extern rfbBool TextChatOpen(rfbClient* client);
339
extern rfbBool TextChatClose(rfbClient* client);
340
extern rfbBool TextChatFinish(rfbClient* client);
341
extern rfbBool PermitServerInput(rfbClient* client, int enabled);
343
extern void PrintPixelFormat(rfbPixelFormat *format);
345
extern rfbBool SupportsClient2Server(rfbClient* client, int messageType);
346
extern rfbBool SupportsServer2Client(rfbClient* client, int messageType);
350
void rfbClientSetClientData(rfbClient* client, void* tag, void* data);
351
void* rfbClientGetClientData(rfbClient* client, void* tag);
353
/* protocol extensions */
355
typedef struct _rfbClientProtocolExtension {
357
/* returns TRUE if the encoding was handled */
358
rfbBool (*handleEncoding)(rfbClient* cl,
359
rfbFramebufferUpdateRectHeader* rect);
360
/* returns TRUE if it handled the message */
361
rfbBool (*handleMessage)(rfbClient* cl,
362
rfbServerToClientMsg* message);
363
struct _rfbClientProtocolExtension* next;
364
} rfbClientProtocolExtension;
366
void rfbClientRegisterExtension(rfbClientProtocolExtension* e);
370
extern rfbBool errorMessageOnReadFailure;
372
extern rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n);
373
extern rfbBool WriteToRFBServer(rfbClient* client, char *buf, int n);
374
extern int FindFreeTcpPort(void);
375
extern int ListenAtTcpPort(int port);
376
extern int ConnectClientToTcpAddr(unsigned int host, int port);
377
extern int ConnectClientToUnixSock(const char *sockFile);
378
extern int AcceptTcpConnection(int listenSock);
379
extern rfbBool SetNonBlocking(int sock);
381
extern rfbBool StringToIPAddr(const char *str, unsigned int *addr);
382
extern rfbBool SameMachine(int sock);
383
extern int WaitForMessage(rfbClient* client,unsigned int usecs);
386
rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,int bytesPerPixel);
387
rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv);
388
/* rfbClientCleanup() does not touch client->frameBuffer */
389
void rfbClientCleanup(rfbClient* client);
391
#if(defined __cplusplus)