~vanvugt/+junk/remmina-ppa

« back to all changes in this revision

Viewing changes to libvncserver/rfb/rfbclient.h

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2010-07-11 23:40:47 UTC
  • mfrom: (1.2.1 upstream) (8.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100711234047-id2bdu1gb59e34n4
* New upstream release.
* debian/control:
  - Bump Standards-Version to 3.9.0, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef RFBCLIENT_H
2
 
#define RFBCLIENT_H
3
 
 
4
 
/*
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.
8
 
 *
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.
13
 
 *
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.
18
 
 *
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,
22
 
 *  USA.
23
 
 */
24
 
 
25
 
/*
26
 
 * vncviewer.h
27
 
 */
28
 
 
29
 
#include <stdio.h>
30
 
#include <stdlib.h>
31
 
#include <string.h>
32
 
#include <sys/time.h>
33
 
#include <unistd.h>
34
 
#include <rfb/rfbproto.h>
35
 
#include <rfb/keysym.h>
36
 
#ifdef LIBVNCSERVER_WITH_CLIENT_TLS
37
 
#include <gnutls/gnutls.h>
38
 
#endif
39
 
 
40
 
#define rfbClientSwap16IfLE(s) \
41
 
    (*(char *)&client->endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
42
 
 
43
 
#define rfbClientSwap32IfLE(l) \
44
 
    (*(char *)&client->endianTest ? ((((l) & 0xff000000) >> 24) | \
45
 
                             (((l) & 0x00ff0000) >> 8)  | \
46
 
                             (((l) & 0x0000ff00) << 8)  | \
47
 
                             (((l) & 0x000000ff) << 24))  : (l))
48
 
 
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))
58
 
 
59
 
#define FLASH_PORT_OFFSET 5400
60
 
#define LISTEN_PORT_OFFSET 5500
61
 
#define TUNNEL_PORT_OFFSET 5500
62
 
#define SERVER_PORT_OFFSET 5900
63
 
 
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")
69
 
 
70
 
#if(defined __cplusplus)
71
 
extern "C"
72
 
{
73
 
#endif
74
 
 
75
 
/* vncrec */
76
 
 
77
 
typedef struct {
78
 
  FILE* file;
79
 
  struct timeval tv;
80
 
  rfbBool readTimestamp;
81
 
  rfbBool doNotSleep;
82
 
} rfbVNCRec;
83
 
 
84
 
/* client data */
85
 
 
86
 
typedef struct rfbClientData {
87
 
        void* tag;
88
 
        void* data;
89
 
        struct rfbClientData* next;
90
 
} rfbClientData;
91
 
 
92
 
/* app data (belongs into rfbClient?) */
93
 
 
94
 
typedef struct {
95
 
  rfbBool shareDesktop;
96
 
  rfbBool viewOnly;
97
 
 
98
 
  const char* encodingsString;
99
 
 
100
 
  rfbBool useBGR233;
101
 
  int nColours;
102
 
  rfbBool forceOwnCmap;
103
 
  rfbBool forceTrueColour;
104
 
  int requestedDepth;
105
 
 
106
 
  int compressLevel;
107
 
  int qualityLevel;
108
 
  rfbBool enableJPEG;
109
 
  rfbBool useRemoteCursor;
110
 
  rfbBool palmVNC;  /* use palmvnc specific SetScale (vs ultravnc) */
111
 
  int scaleSetting; /* 0 means no scale set, else 1/scaleSetting */
112
 
} AppData;
113
 
 
114
 
/* For GetCredentialProc callback function to return */
115
 
typedef union _rfbCredential
116
 
{
117
 
  /* X509 (VeNCrypt) */
118
 
  struct
119
 
  {
120
 
    char *x509CACertFile;
121
 
    char *x509CACrlFile;
122
 
    char *x509ClientCertFile;
123
 
    char *x509ClientKeyFile;
124
 
  } x509Credential;
125
 
  /* Plain (VeNCrypt), MSLogon (UltraVNC) */
126
 
  struct
127
 
  {
128
 
    char *username;
129
 
    char *password;
130
 
  } userCredential;
131
 
} rfbCredential;
132
 
 
133
 
#define rfbCredentialTypeX509 1
134
 
#define rfbCredentialTypeUser 2
135
 
 
136
 
struct _rfbClient;
137
 
 
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);
150
 
 
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);
153
 
 
154
 
typedef struct _rfbClient {
155
 
        uint8_t* frameBuffer;
156
 
        int width, height;
157
 
 
158
 
        int endianTest;
159
 
 
160
 
        AppData appData;
161
 
 
162
 
        const char* programName;
163
 
        char* serverHost;
164
 
        int serverPort; /* if -1, then use file recorded by vncrec */
165
 
        rfbBool listenSpecified;
166
 
        int listenPort, flashPort;
167
 
 
168
 
        struct {
169
 
                int x, y, w, h;
170
 
        } updateRect;
171
 
 
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. */
176
 
 
177
 
#define RFB_BUFFER_SIZE (640*480)
178
 
        char buffer[RFB_BUFFER_SIZE];
179
 
 
180
 
        /* rfbproto.c */
181
 
 
182
 
        int sock;
183
 
        rfbBool canUseCoRRE;
184
 
        rfbBool canUseHextile;
185
 
        char *desktopName;
186
 
        rfbPixelFormat format;
187
 
        rfbServerInitMsg si;
188
 
 
189
 
        /* listen.c */
190
 
        int listenSock;
191
 
 
192
 
        /* sockets.c */
193
 
#define RFB_BUF_SIZE 8192
194
 
        char buf[RFB_BUF_SIZE];
195
 
        char *bufoutptr;
196
 
        int buffered;
197
 
 
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. */
203
 
 
204
 
        /* Ultra Encoding uses this buffer too */
205
 
        
206
 
        int ultra_buffer_size;
207
 
        char *ultra_buffer;
208
 
 
209
 
        int raw_buffer_size;
210
 
        char *raw_buffer;
211
 
 
212
 
#ifdef LIBVNCSERVER_HAVE_LIBZ
213
 
        z_stream decompStream;
214
 
        rfbBool decompStreamInited;
215
 
#endif
216
 
 
217
 
 
218
 
#ifdef LIBVNCSERVER_HAVE_LIBZ
219
 
        /*
220
 
         * Variables for the ``tight'' encoding implementation.
221
 
         */
222
 
 
223
 
        /* Separate buffer for compressed data. */
224
 
#define ZLIB_BUFFER_SIZE 30000
225
 
        char zlib_buffer[ZLIB_BUFFER_SIZE];
226
 
 
227
 
        /* Four independent compression streams for zlib library. */
228
 
        z_stream zlibStream[4];
229
 
        rfbBool zlibStreamActive[4];
230
 
 
231
 
        /* Filter stuff. Should be initialized by filter initialization code. */
232
 
        rfbBool cutZeros;
233
 
        int rectWidth, rectColors;
234
 
        char tightPalette[256*4];
235
 
        uint8_t tightPrevRow[2048*3*sizeof(uint16_t)];
236
 
 
237
 
#ifdef LIBVNCSERVER_HAVE_LIBJPEG
238
 
        /* JPEG decoder state. */
239
 
        rfbBool jpegError;
240
 
 
241
 
        struct jpeg_source_mgr* jpegSrcManager;
242
 
        void* jpegBufferPtr;
243
 
        size_t jpegBufferLen;
244
 
 
245
 
#endif
246
 
#endif
247
 
 
248
 
 
249
 
        /* cursor.c */
250
 
        uint8_t *rcSource, *rcMask;
251
 
 
252
 
        /* private data pointer */
253
 
        rfbClientData* clientData;
254
 
 
255
 
        rfbVNCRec* vncRec;
256
 
 
257
 
        /* Keyboard State support (is 'Caps Lock' set on the remote display???) */
258
 
        int KeyboardLedStateEnabled;
259
 
        int CurrentKeyboardLedState;
260
 
 
261
 
        int canHandleNewFBSize;
262
 
 
263
 
        /* hooks */
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;
275
 
        BellProc Bell;
276
 
 
277
 
        GotCursorShapeProc GotCursorShape;
278
 
        GotCopyRectProc GotCopyRect;
279
 
 
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)
283
 
         *
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.
287
 
         */
288
 
        rfbSupportedMessages supportedMessages;
289
 
 
290
 
        /* negotiated protocol version */
291
 
        int major, minor;
292
 
 
293
 
        /* The selected security types */
294
 
        uint32_t authScheme, subAuthScheme;
295
 
 
296
 
#ifdef LIBVNCSERVER_WITH_CLIENT_TLS
297
 
        /* The TLS session for Anonymous TLS and VeNCrypt */
298
 
        gnutls_session_t tlsSession;
299
 
#endif
300
 
 
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
305
 
         * be bypassed.
306
 
         */
307
 
        GetCredentialProc GetCredential;
308
 
} rfbClient;
309
 
 
310
 
/* cursor.c */
311
 
 
312
 
extern rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int height, uint32_t enc);
313
 
 
314
 
/* listen.c */
315
 
 
316
 
extern void listenForIncomingConnections(rfbClient* viewer);
317
 
extern int listenForIncomingConnectionsNoFork(rfbClient* viewer, int usec_timeout);
318
 
 
319
 
/* rfbproto.c */
320
 
 
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);
336
 
 
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);
342
 
 
343
 
extern void PrintPixelFormat(rfbPixelFormat *format);
344
 
 
345
 
extern rfbBool SupportsClient2Server(rfbClient* client, int messageType);
346
 
extern rfbBool SupportsServer2Client(rfbClient* client, int messageType);
347
 
 
348
 
/* client data */
349
 
 
350
 
void rfbClientSetClientData(rfbClient* client, void* tag, void* data);
351
 
void* rfbClientGetClientData(rfbClient* client, void* tag);
352
 
 
353
 
/* protocol extensions */
354
 
 
355
 
typedef struct _rfbClientProtocolExtension {
356
 
        int* encodings;
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;
365
 
 
366
 
void rfbClientRegisterExtension(rfbClientProtocolExtension* e);
367
 
 
368
 
/* sockets.c */
369
 
 
370
 
extern rfbBool errorMessageOnReadFailure;
371
 
 
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);
380
 
 
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);
384
 
 
385
 
/* vncviewer.c */
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);
390
 
 
391
 
#if(defined __cplusplus)
392
 
}
393
 
#endif
394
 
 
395
 
#endif
396