LibVNCServer/LibVNCClient
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rfbclient.h
Go to the documentation of this file.
1 #ifndef RFBCLIENT_H
2 #define RFBCLIENT_H
3 
9 /*
10  * Copyright (C) 2000, 2001 Const Kaplinsky. All Rights Reserved.
11  * Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
12  * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
13  *
14  * This is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This software is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this software; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27  * USA.
28  */
29 
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <sys/time.h>
38 #include <unistd.h>
39 #include <rfb/rfbproto.h>
40 #include <rfb/keysym.h>
41 
42 #define rfbClientSwap16IfLE(s) \
43  (*(char *)&client->endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
44 
45 #define rfbClientSwap32IfLE(l) \
46  (*(char *)&client->endianTest ? ((((l) & 0xff000000) >> 24) | \
47  (((l) & 0x00ff0000) >> 8) | \
48  (((l) & 0x0000ff00) << 8) | \
49  (((l) & 0x000000ff) << 24)) : (l))
50 
51 #define rfbClientSwap64IfLE(l) \
52  (*(char *)&client->endianTest ? ((((l) & 0xff00000000000000ULL) >> 56) | \
53  (((l) & 0x00ff000000000000ULL) >> 40) | \
54  (((l) & 0x0000ff0000000000ULL) >> 24) | \
55  (((l) & 0x000000ff00000000ULL) >> 8) | \
56  (((l) & 0x00000000ff000000ULL) << 8) | \
57  (((l) & 0x0000000000ff0000ULL) << 24) | \
58  (((l) & 0x000000000000ff00ULL) << 40) | \
59  (((l) & 0x00000000000000ffULL) << 56)) : (l))
60 
61 #define FLASH_PORT_OFFSET 5400
62 #define LISTEN_PORT_OFFSET 5500
63 #define TUNNEL_PORT_OFFSET 5500
64 #define SERVER_PORT_OFFSET 5900
65 
66 #define DEFAULT_SSH_CMD "/usr/bin/ssh"
67 #define DEFAULT_TUNNEL_CMD \
68  (DEFAULT_SSH_CMD " -f -L %L:localhost:%R %H sleep 20")
69 #define DEFAULT_VIA_CMD \
70  (DEFAULT_SSH_CMD " -f -L %L:%H:%R %G sleep 20")
71 
72 #if(defined __cplusplus)
73 extern "C"
74 {
75 #endif
76 
79 typedef struct {
80  FILE* file;
81  struct timeval tv;
84 } rfbVNCRec;
85 
88 typedef struct rfbClientData {
89  void* tag;
90  void* data;
93 
96 typedef struct {
99 
100  const char* encodingsString;
101 
103  int nColours;
107 
114 } AppData;
115 
117 typedef union _rfbCredential
118 {
120  struct
121  {
126  } x509Credential;
128  struct
129  {
130  char *username;
131  char *password;
132  } userCredential;
133 } rfbCredential;
134 
135 #define rfbCredentialTypeX509 1
136 #define rfbCredentialTypeUser 2
137 
138 struct _rfbClient;
139 
150 typedef void (*HandleTextChatProc)(struct _rfbClient* client, int value, char *text);
160 typedef void (*HandleXvpMsgProc)(struct _rfbClient* client, uint8_t version, uint8_t opcode);
161 typedef void (*HandleKeyboardLedStateProc)(struct _rfbClient* client, int value, int pad);
162 typedef rfbBool (*HandleCursorPosProc)(struct _rfbClient* client, int x, int y);
163 typedef void (*SoftCursorLockAreaProc)(struct _rfbClient* client, int x, int y, int w, int h);
164 typedef void (*SoftCursorUnlockScreenProc)(struct _rfbClient* client);
165 typedef void (*GotFrameBufferUpdateProc)(struct _rfbClient* client, int x, int y, int w, int h);
166 typedef void (*FinishedFrameBufferUpdateProc)(struct _rfbClient* client);
167 typedef char* (*GetPasswordProc)(struct _rfbClient* client);
168 typedef rfbCredential* (*GetCredentialProc)(struct _rfbClient* client, int credentialType);
169 typedef rfbBool (*MallocFrameBufferProc)(struct _rfbClient* client);
170 typedef void (*GotXCutTextProc)(struct _rfbClient* client, const char *text, int textlen);
171 typedef void (*BellProc)(struct _rfbClient* client);
172 
173 typedef void (*GotCursorShapeProc)(struct _rfbClient* client, int xhot, int yhot, int width, int height, int bytesPerPixel);
174 typedef void (*GotCopyRectProc)(struct _rfbClient* client, int src_x, int src_y, int w, int h, int dest_x, int dest_y);
175 
176 typedef struct _rfbClient {
177  uint8_t* frameBuffer;
178  int width, height;
179 
181 
183 
184  const char* programName;
185  char* serverHost;
188  int listenPort, flashPort;
189 
190  struct {
191  int x, y, w, h;
192  } updateRect;
193 
199 #define RFB_BUFFER_SIZE (640*480)
200  char buffer[RFB_BUFFER_SIZE];
201 
202  /* rfbproto.c */
203 
204  int sock;
207  char *desktopName;
210 
211  /* sockets.c */
212 #define RFB_BUF_SIZE 8192
213  char buf[RFB_BUF_SIZE];
214  char *bufoutptr;
215  int buffered;
216 
217  /* The zlib encoding requires expansion/decompression/deflation of the
218  compressed data in the "buffer" above into another, result buffer.
219  However, the size of the result buffer can be determined precisely
220  based on the bitsPerPixel, height and width of the rectangle. We
221  allocate this buffer one time to be the full size of the buffer. */
222 
223  /* Ultra Encoding uses this buffer too */
224 
227 
229  char *raw_buffer;
230 
231 #ifdef LIBVNCSERVER_HAVE_LIBZ
232  z_stream decompStream;
233  rfbBool decompStreamInited;
234 #endif
235 
236 
237 #ifdef LIBVNCSERVER_HAVE_LIBZ
238  /*
239  * Variables for the ``tight'' encoding implementation.
240  */
241 
243 #define ZLIB_BUFFER_SIZE 30000
244  char zlib_buffer[ZLIB_BUFFER_SIZE];
245 
246  /* Four independent compression streams for zlib library. */
247  z_stream zlibStream[4];
248  rfbBool zlibStreamActive[4];
249 
250  /* Filter stuff. Should be initialized by filter initialization code. */
251  rfbBool cutZeros;
252  int rectWidth, rectColors;
253  char tightPalette[256*4];
254  uint8_t tightPrevRow[2048*3*sizeof(uint16_t)];
255 
256 #ifdef LIBVNCSERVER_HAVE_LIBJPEG
257 
258  rfbBool jpegError;
259 
260  struct jpeg_source_mgr* jpegSrcManager;
261  void* jpegBufferPtr;
262  size_t jpegBufferLen;
263 
264 #endif
265 #endif
266 
267 
268  /* cursor.c */
269  uint8_t *rcSource, *rcMask;
270 
273 
275 
276  /* Keyboard State support (is 'Caps Lock' set on the remote display???) */
279 
281 
282  /* hooks */
294 
297 
307 
309  int major, minor;
310 
312  uint32_t authScheme, subAuthScheme;
313 
315  void* tlsSession;
316 
324 
327  uint32_t *clientAuthSchemes;
328 
330  char *destHost;
331  int destPort;
332 
334  int QoS_DSCP;
335 
338 
339  /* listen.c */
341 
343 
345  /* IPv6 listen socket, address and port*/
349 } rfbClient;
350 
351 /* cursor.c */
352 
353 extern rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int height, uint32_t enc);
354 
355 /* listen.c */
356 
357 extern void listenForIncomingConnections(rfbClient* viewer);
358 extern int listenForIncomingConnectionsNoFork(rfbClient* viewer, int usec_timeout);
359 
360 /* rfbproto.c */
361 
363 typedef void (*rfbClientLogProc)(const char *format, ...);
365 extern rfbBool ConnectToRFBServer(rfbClient* client,const char *hostname, int port);
366 extern rfbBool ConnectToRFBRepeater(rfbClient* client,const char *repeaterHost, int repeaterPort, const char *destHost, int destPort);
367 extern void SetClientAuthSchemes(rfbClient* client,const uint32_t *authSchemes, int size);
386 extern rfbBool SetFormatAndEncodings(rfbClient* client);
409  int x, int y, int w, int h,
410  rfbBool incremental);
411 extern rfbBool SendScaleSetting(rfbClient* client,int scaleSetting);
432 extern rfbBool SendPointerEvent(rfbClient* client,int x, int y, int buttonMask);
442 extern rfbBool SendKeyEvent(rfbClient* client,uint32_t key, rfbBool down);
455 extern rfbBool SendClientCutText(rfbClient* client,char *str, int len);
467 
474 extern rfbBool TextChatSend(rfbClient* client, char *text);
480 extern rfbBool TextChatOpen(rfbClient* client);
486 extern rfbBool TextChatClose(rfbClient* client);
487 extern rfbBool TextChatFinish(rfbClient* client);
488 extern rfbBool PermitServerInput(rfbClient* client, int enabled);
489 extern rfbBool SendXvpMsg(rfbClient* client, uint8_t version, uint8_t code);
490 
491 extern void PrintPixelFormat(rfbPixelFormat *format);
492 
493 extern rfbBool SupportsClient2Server(rfbClient* client, int messageType);
494 extern rfbBool SupportsServer2Client(rfbClient* client, int messageType);
495 
496 /* client data */
497 
511 void rfbClientSetClientData(rfbClient* client, void* tag, void* data);
520 void* rfbClientGetClientData(rfbClient* client, void* tag);
521 
522 /* protocol extensions */
523 
524 typedef struct _rfbClientProtocolExtension {
525  int* encodings;
527  rfbBool (*handleEncoding)(rfbClient* cl,
530  rfbBool (*handleMessage)(rfbClient* cl,
531  rfbServerToClientMsg* message);
532  struct _rfbClientProtocolExtension* next;
534 
536 
537 /* sockets.c */
538 
540 
541 extern rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n);
542 extern rfbBool WriteToRFBServer(rfbClient* client, char *buf, int n);
543 extern int FindFreeTcpPort(void);
544 extern int ListenAtTcpPort(int port);
545 extern int ListenAtTcpPortAndAddress(int port, const char *address);
546 extern int ConnectClientToTcpAddr(unsigned int host, int port);
547 extern int ConnectClientToTcpAddr6(const char *hostname, int port);
548 extern int ConnectClientToUnixSock(const char *sockFile);
549 extern int AcceptTcpConnection(int listenSock);
550 extern rfbBool SetNonBlocking(int sock);
551 extern rfbBool SetDSCP(int sock, int dscp);
552 
553 extern rfbBool StringToIPAddr(const char *str, unsigned int *addr);
554 extern rfbBool SameMachine(int sock);
565 extern int WaitForMessage(rfbClient* client,unsigned int usecs);
566 
567 /* vncviewer.c */
592 rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,int bytesPerPixel);
624 rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv);
632 void rfbClientCleanup(rfbClient* client);
633 
634 #if(defined __cplusplus)
635 }
636 #endif
637 
648 #endif