rfbclient.h 24.8 KB
Newer Older
1 2 3
#ifndef RFBCLIENT_H
#define RFBCLIENT_H

4 5 6 7 8
/**
 * @defgroup libvncclient_api LibVNCClient API Reference
 * @{
 */

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 *  Copyright (C) 2000, 2001 Const Kaplinsky.  All Rights Reserved.
 *  Copyright (C) 2000 Tridia Corporation.  All Rights Reserved.
 *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
 *
 *  This is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This software is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this software; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 *  USA.
 */

30 31
/**
 * @file rfbclient.h
32 33 34 35 36 37 38 39 40 41
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include <rfb/rfbproto.h>
#include <rfb/keysym.h>

42
#define rfbClientSwap16IfLE(s) \
43 44
    (*(char *)&client->endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))

45
#define rfbClientSwap32IfLE(l) \
46 47 48 49 50
    (*(char *)&client->endianTest ? ((((l) & 0xff000000) >> 24) | \
			     (((l) & 0x00ff0000) >> 8)  | \
			     (((l) & 0x0000ff00) << 8)  | \
			     (((l) & 0x000000ff) << 24))  : (l))

Vic Lee's avatar
Vic Lee committed
51 52 53 54 55 56 57 58 59 60
#define rfbClientSwap64IfLE(l) \
    (*(char *)&client->endianTest ? ((((l) & 0xff00000000000000ULL) >> 56) | \
			     (((l) & 0x00ff000000000000ULL) >> 40)  | \
			     (((l) & 0x0000ff0000000000ULL) >> 24)  | \
			     (((l) & 0x000000ff00000000ULL) >> 8)  | \
			     (((l) & 0x00000000ff000000ULL) << 8)  | \
			     (((l) & 0x0000000000ff0000ULL) << 24)  | \
			     (((l) & 0x000000000000ff00ULL) << 40)  | \
			     (((l) & 0x00000000000000ffULL) << 56))  : (l))

61 62 63 64 65 66 67 68 69 70 71
#define FLASH_PORT_OFFSET 5400
#define LISTEN_PORT_OFFSET 5500
#define TUNNEL_PORT_OFFSET 5500
#define SERVER_PORT_OFFSET 5900

#define DEFAULT_SSH_CMD "/usr/bin/ssh"
#define DEFAULT_TUNNEL_CMD  \
  (DEFAULT_SSH_CMD " -f -L %L:localhost:%R %H sleep 20")
#define DEFAULT_VIA_CMD     \
  (DEFAULT_SSH_CMD " -f -L %L:%H:%R %G sleep 20")

72 73 74 75 76
#if(defined __cplusplus)
extern "C"
{
#endif

77
/** vncrec */
78 79 80 81 82 83 84 85

typedef struct {
  FILE* file;
  struct timeval tv;
  rfbBool readTimestamp;
  rfbBool doNotSleep;
} rfbVNCRec;

86
/** client data */
87 88 89 90 91 92 93

typedef struct rfbClientData {
	void* tag;
	void* data;
	struct rfbClientData* next;
} rfbClientData;

94
/** app data (belongs into rfbClient?) */
95 96

typedef struct {
97 98
  rfbBool shareDesktop;
  rfbBool viewOnly;
99 100 101

  const char* encodingsString;

102
  rfbBool useBGR233;
103
  int nColours;
104 105
  rfbBool forceOwnCmap;
  rfbBool forceTrueColour;
106 107 108 109
  int requestedDepth;

  int compressLevel;
  int qualityLevel;
110 111
  rfbBool enableJPEG;
  rfbBool useRemoteCursor;
112 113
  rfbBool palmVNC;  /**< use palmvnc specific SetScale (vs ultravnc) */
  int scaleSetting; /**< 0 means no scale set, else 1/scaleSetting */
114 115
} AppData;

116
/** For GetCredentialProc callback function to return */
117 118
typedef union _rfbCredential
{
119
  /** X509 (VeNCrypt) */
120 121 122 123 124 125 126
  struct
  {
    char *x509CACertFile;
    char *x509CACrlFile;
    char *x509ClientCertFile;
    char *x509ClientKeyFile;
  } x509Credential;
127
  /** Plain (VeNCrypt), MSLogon (UltraVNC) */
128 129 130 131 132 133
  struct
  {
    char *username;
    char *password;
  } userCredential;
} rfbCredential;
134

135 136
#define rfbCredentialTypeX509 1
#define rfbCredentialTypeUser 2
137 138 139

struct _rfbClient;

Peter Watkins's avatar
Peter Watkins committed
140 141 142 143 144 145
/**
 * Handles a text chat message. If your application should accept text messages
 * from the server, define a function with this prototype and set
 * client->HandleTextChat to a pointer to that function subsequent to your
 * rfbGetClient() call.
 * @param client The client which called the text chat handler
146 147
 * @param value  text length if text != NULL, or one of rfbTextChatOpen,
 * rfbTextChatClose, rfbTextChatFinished if text == NULL
Peter Watkins's avatar
Peter Watkins committed
148 149
 * @param text The text message from the server
 */
150
typedef void (*HandleTextChatProc)(struct _rfbClient* client, int value, char *text);
Peter Watkins's avatar
Peter Watkins committed
151 152 153 154 155 156 157 158 159
/**
 * Handles XVP server messages. If your application sends XVP messages to the
 * server, you'll want to handle the server's XVP_FAIL and XVP_INIT responses.
 * Define a function with this prototype and set client->HandleXvpMsg to a
 * pointer to that function subsequent to your rfbGetClient() call.
 * @param client The client which called the XVP message handler
 * @param version The highest XVP extension version that the server supports
 * @param opcode The opcode. 0 is XVP_FAIL, 1 is XVP_INIT
 */
160
typedef void (*HandleXvpMsgProc)(struct _rfbClient* client, uint8_t version, uint8_t opcode);
dscho's avatar
dscho committed
161
typedef void (*HandleKeyboardLedStateProc)(struct _rfbClient* client, int value, int pad);
162
typedef rfbBool (*HandleCursorPosProc)(struct _rfbClient* client, int x, int y);
163 164
typedef void (*SoftCursorLockAreaProc)(struct _rfbClient* client, int x, int y, int w, int h);
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 172
typedef void (*BellProc)(struct _rfbClient* client);

173 174 175
typedef void (*GotCursorShapeProc)(struct _rfbClient* client, int xhot, int yhot, int width, int height, int bytesPerPixel);
typedef void (*GotCopyRectProc)(struct _rfbClient* client, int src_x, int src_y, int w, int h, int dest_x, int dest_y);

176 177 178 179 180 181 182 183 184
typedef struct _rfbClient {
	uint8_t* frameBuffer;
	int width, height;

	int endianTest;

	AppData appData;

	const char* programName;
185
	char* serverHost;
186
	int serverPort; /**< if -1, then use file recorded by vncrec */
187
	rfbBool listenSpecified;
188 189
	int listenPort, flashPort;

190 191 192 193
	struct {
		int x, y, w, h;
	} updateRect;

194
	/** Note that the CoRRE encoding uses this buffer and assumes it is big enough
195 196 197 198
	   to hold 255 * 255 * 32 bits -> 260100 bytes.  640*480 = 307200 bytes.
	   Hextile also assumes it is big enough to hold 16 * 16 * 32 bits.
	   Tight encoding assumes BUFFER_SIZE is at least 16384 bytes. */

199 200
#define RFB_BUFFER_SIZE (640*480)
	char buffer[RFB_BUFFER_SIZE];
201 202 203 204

	/* rfbproto.c */

	int sock;
205 206
	rfbBool canUseCoRRE;
	rfbBool canUseHextile;
207 208 209 210
	char *desktopName;
	rfbPixelFormat format;
	rfbServerInitMsg si;

211 212 213 214 215 216
	/* sockets.c */
#define RFB_BUF_SIZE 8192
	char buf[RFB_BUF_SIZE];
	char *bufoutptr;
	int buffered;

217 218 219 220 221 222
	/* The zlib encoding requires expansion/decompression/deflation of the
	   compressed data in the "buffer" above into another, result buffer.
	   However, the size of the result buffer can be determined precisely
	   based on the bitsPerPixel, height and width of the rectangle.  We
	   allocate this buffer one time to be the full size of the buffer. */

223 224 225 226 227
	/* Ultra Encoding uses this buffer too */
	
	int ultra_buffer_size;
	char *ultra_buffer;

228 229 230
	int raw_buffer_size;
	char *raw_buffer;

231
#ifdef LIBVNCSERVER_HAVE_LIBZ
232 233 234 235 236
	z_stream decompStream;
	rfbBool decompStreamInited;
#endif


237
#ifdef LIBVNCSERVER_HAVE_LIBZ
238 239 240 241
	/*
	 * Variables for the ``tight'' encoding implementation.
	 */

242
	/** Separate buffer for compressed data. */
243 244 245 246 247 248 249 250 251 252 253 254 255
#define ZLIB_BUFFER_SIZE 30000
	char zlib_buffer[ZLIB_BUFFER_SIZE];

	/* Four independent compression streams for zlib library. */
	z_stream zlibStream[4];
	rfbBool zlibStreamActive[4];

	/* Filter stuff. Should be initialized by filter initialization code. */
	rfbBool cutZeros;
	int rectWidth, rectColors;
	char tightPalette[256*4];
	uint8_t tightPrevRow[2048*3*sizeof(uint16_t)];

256
#ifdef LIBVNCSERVER_HAVE_LIBJPEG
257
	/** JPEG decoder state. */
258 259 260 261 262 263
	rfbBool jpegError;

	struct jpeg_source_mgr* jpegSrcManager;
	void* jpegBufferPtr;
	size_t jpegBufferLen;

264
#endif
265 266
#endif

267

268 269 270
	/* cursor.c */
	uint8_t *rcSource, *rcMask;

271
	/** private data pointer */
272
	rfbClientData* clientData;
273

274 275
	rfbVNCRec* vncRec;

dscho's avatar
dscho committed
276 277 278 279
	/* Keyboard State support (is 'Caps Lock' set on the remote display???) */
	int KeyboardLedStateEnabled;
	int CurrentKeyboardLedState;

280 281
	int canHandleNewFBSize;

282
	/* hooks */
283
	HandleTextChatProc         HandleTextChat;
dscho's avatar
dscho committed
284
	HandleKeyboardLedStateProc HandleKeyboardLedState;
285 286 287
	HandleCursorPosProc HandleCursorPos;
	SoftCursorLockAreaProc SoftCursorLockArea;
	SoftCursorUnlockScreenProc SoftCursorUnlockScreen;
288
	GotFrameBufferUpdateProc GotFrameBufferUpdate;
289
	/** the pointer returned by GetPassword will be freed after use! */
290 291
	GetPasswordProc GetPassword;
	MallocFrameBufferProc MallocFrameBuffer;
292
	GotXCutTextProc GotXCutText;
293
	BellProc Bell;
294

295 296 297
	GotCursorShapeProc GotCursorShape;
	GotCopyRectProc GotCopyRect;

298
	/** Which messages are supported by the server
299 300 301 302 303 304 305 306 307
	 * This is a *guess* for most servers.
	 * (If we can even detect the type of server)
	 *
	 * If the server supports the "rfbEncodingSupportedMessages"
	 * then this will be updated when the encoding is received to
	 * accurately reflect the servers capabilities.
	 */
	rfbSupportedMessages supportedMessages;

308
	/** negotiated protocol version */
309
	int major, minor;
310

311
	/** The selected security types */
312 313
	uint32_t authScheme, subAuthScheme;

314
	/** The TLS session for Anonymous TLS and VeNCrypt */
315
	void* tlsSession;
316

317
	/** To support security types that requires user input (except VNC password
318 319 320 321 322 323
	 * authentication), for example VeNCrypt and MSLogon, this callback function
	 * must be set before the authentication. Otherwise, it implicates that the
	 * caller application does not support it and related security types should
	 * be bypassed.
	 */
	GetCredentialProc GetCredential;
324

325
	/** The 0-terminated security types supported by the client.
326 327
	 * Set by function SetClientAuthSchemes() */
	uint32_t *clientAuthSchemes;
328

329
	/** When the server is a repeater, this specifies the final destination */
330 331
	char *destHost;
	int destPort;
332

333
        /** the QoS IP DSCP for this client */
334
        int QoS_DSCP;
335

336
        /** hook to handle xvp server messages */
337
	HandleXvpMsgProc           HandleXvpMsg;
338 339 340 341 342

	/* listen.c */
        int listenSock;

	FinishedFrameBufferUpdateProc FinishedFrameBufferUpdate;
343 344

	char *listenAddress;
345 346 347 348
        /* IPv6 listen socket, address and port*/
        int listen6Sock;
        char* listen6Address;
        int listen6Port;
349 350 351 352

        /* Output Window ID. When set, client application enables libvncclient to perform direct rendering in its window */
        unsigned long outputWindow;

353 354 355 356
} rfbClient;

/* cursor.c */

357
extern rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int height, uint32_t enc);
358 359 360 361

/* listen.c */

extern void listenForIncomingConnections(rfbClient* viewer);
362
extern int listenForIncomingConnectionsNoFork(rfbClient* viewer, int usec_timeout);
363 364 365

/* rfbproto.c */

366
extern rfbBool rfbEnableClientLogging;
367 368
typedef void (*rfbClientLogProc)(const char *format, ...);
extern rfbClientLogProc rfbClientLog,rfbClientErr;
369
extern rfbBool ConnectToRFBServer(rfbClient* client,const char *hostname, int port);
370
extern rfbBool ConnectToRFBRepeater(rfbClient* client,const char *repeaterHost, int repeaterPort, const char *destHost, int destPort);
371
extern void SetClientAuthSchemes(rfbClient* client,const uint32_t *authSchemes, int size);
372
extern rfbBool InitialiseRFBConnection(rfbClient* client);
Peter Watkins's avatar
Peter Watkins committed
373 374 375 376 377
/**
 * Sends format and encoding parameters to the server. Your application can
 * modify the 'client' data structure directly. However some changes to this
 * structure must be communicated back to the server. For instance, if you
 * change the encoding to hextile, the server needs to know that it should send
378 379 380 381
 * framebuffer updates in hextile format. Likewise if you change the pixel
 * format of the framebuffer, the server must be notified about this as well.
 * Call this function to propagate your changes of the local 'client' structure
 * over to the server.
Peter Watkins's avatar
Peter Watkins committed
382
 * @li Encoding type
383 384
 * @li RFB protocol extensions announced via pseudo-encodings
 * @li Framebuffer pixel format (like RGB vs ARGB)
Peter Watkins's avatar
Peter Watkins committed
385 386 387 388 389
 * @li Remote cursor support
 * @param client The client in which the format or encodings have been changed
 * @return true if the format or encodings were sent to the server successfully,
 * false otherwise
 */
390 391
extern rfbBool SetFormatAndEncodings(rfbClient* client);
extern rfbBool SendIncrementalFramebufferUpdateRequest(rfbClient* client);
Peter Watkins's avatar
Peter Watkins committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
/**
 * Sends a framebuffer update request to the server. A VNC client may request an
 * update from the server at any time. You can also specify which portions of
 * the screen you want updated. This can be handy if a pointer is at certain
 * location and the user pressed a mouse button, for instance. Then you can
 * immediately request an update of the region around the pointer from the
 * server.
 * @note The coordinate system is a left-handed Cartesian coordinate system with
 * the Z axis (unused) pointing out of the screen. Alternately you can think of
 * it as a right-handed Cartesian coordinate system with the Z axis pointing
 * into the screen. The origin is at the upper left corner of the framebuffer.
 * @param client The client through which to send the request
 * @param x The horizontal position of the update request rectangle
 * @param y The vertical position of the update request rectangle
 * @param w The width of the update request rectangle
 * @param h The height of the update request rectangle
408 409
 * @param incremental false: server sends rectangle even if nothing changed.
 * true: server only sends changed parts of rectangle.
Peter Watkins's avatar
Peter Watkins committed
410 411
 * @return true if the update request was sent successfully, false otherwise
 */
412
extern rfbBool SendFramebufferUpdateRequest(rfbClient* client,
413
					 int x, int y, int w, int h,
414
					 rfbBool incremental);
415
extern rfbBool SendScaleSetting(rfbClient* client,int scaleSetting);
Peter Watkins's avatar
Peter Watkins committed
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
/**
 * Sends a pointer event to the server. A pointer event includes a cursor
 * location and a button mask. The button mask indicates which buttons on the
 * pointing device are pressed. Each button is represented by a bit in the
 * button mask. A 1 indicates the button is pressed while a 0 indicates that it
 * is not pressed. You may use these pre-defined button masks by ORing them
 * together: rfbButton1Mask, rfbButton2Mask, rfbButton3Mask, rfbButton4Mask
 * rfbButton5Mask
 * @note  The cursor location is relative to the client's framebuffer, not the
 * client's screen itself.
 * @note The coordinate system is a left-handed Cartesian coordinate system with
 * the Z axis (unused) pointing out of the screen. Alternately you can think of
 * it as a right-handed Cartesian coordinate system with the Z axis pointing
 * into the screen. The origin is at the upper left corner of the screen.
 * @param client The client through which to send the pointer event
 * @param x the horizontal location of the cursor
 * @param y the vertical location of the cursor
 * @param buttonMask the button mask indicating which buttons are pressed
 * @return true if the pointer event was sent successfully, false otherwise
 */
436
extern rfbBool SendPointerEvent(rfbClient* client,int x, int y, int buttonMask);
Peter Watkins's avatar
Peter Watkins committed
437 438 439 440 441
/**
 * Sends a key event to the server. If your application is not merely a VNC
 * viewer (i.e. it controls the server), you'll want to send the keys that the
 * user presses to the server. Use this function to do that.
 * @param client The client through which to send the key event
442
 * @param key An rfbKeySym defined in rfb/keysym.h
Peter Watkins's avatar
Peter Watkins committed
443 444 445
 * @param down true if this was a key down event, false otherwise
 * @return true if the key event was send successfully, false otherwise
 */
446
extern rfbBool SendKeyEvent(rfbClient* client,uint32_t key, rfbBool down);
Peter Watkins's avatar
Peter Watkins committed
447 448 449 450 451 452 453 454 455 456 457 458
/**
 * Places a string on the server's clipboard. Use this function if you want to
 * be able to copy and paste between the server and your application. For
 * instance, when your application is notified that the user copied some text
 * onto the clipboard, you would call this function to synchronize the server's
 * clipboard with your local clipboard.
 * @param client The client structure through which to send the client cut text
 * message
 * @param str The string to send (doesn't need to be NULL terminated)
 * @param len The length of the string
 * @return true if the client cut message was sent successfully, false otherwise
 */
459
extern rfbBool SendClientCutText(rfbClient* client,char *str, int len);
Peter Watkins's avatar
Peter Watkins committed
460 461
/**
 * Handles messages from the RFB server. You must call this function
462
 * intermittently so LibVNCClient can parse messages from the server. For
Peter Watkins's avatar
Peter Watkins committed
463 464 465 466 467 468 469
 * example, if your app has a draw loop, you could place a call to this
 * function within that draw loop.
 * @note You must call WaitForMessage() before you call this function.
 * @param client The client which will handle the RFB server messages
 * @return true if the client was able to handle the RFB server messages, false
 * otherwise
 */
470
extern rfbBool HandleRFBServerMessage(rfbClient* client);
471

Peter Watkins's avatar
Peter Watkins committed
472 473 474 475 476 477
/**
 * Sends a text chat message to the server.
 * @param client The client through which to send the message
 * @param text The text to send
 * @return true if the text was sent successfully, false otherwise
 */
478
extern rfbBool TextChatSend(rfbClient* client, char *text);
Peter Watkins's avatar
Peter Watkins committed
479 480 481 482 483
/**
 * Opens a text chat window on the server.
 * @param client The client through which to send the message
 * @return true if the window was opened successfully, false otherwise
 */
484
extern rfbBool TextChatOpen(rfbClient* client);
Peter Watkins's avatar
Peter Watkins committed
485 486 487 488 489
/**
 * Closes the text chat window on the server.
 * @param client The client through which to send the message
 * @return true if the window was closed successfully, false otherwise
 */
490 491 492
extern rfbBool TextChatClose(rfbClient* client);
extern rfbBool TextChatFinish(rfbClient* client);
extern rfbBool PermitServerInput(rfbClient* client, int enabled);
493
extern rfbBool SendXvpMsg(rfbClient* client, uint8_t version, uint8_t code);
494

495 496
extern void PrintPixelFormat(rfbPixelFormat *format);

497 498 499
extern rfbBool SupportsClient2Server(rfbClient* client, int messageType);
extern rfbBool SupportsServer2Client(rfbClient* client, int messageType);

500 501
/* client data */

Peter Watkins's avatar
Peter Watkins committed
502
/**
503
 * Associates a client data tag with the given pointer. LibVNCClient has
Peter Watkins's avatar
Peter Watkins committed
504 505 506 507 508 509 510 511 512 513 514
 * several events to which you can associate your own handlers. These handlers
 * have the client structure as one of their parameters. Sometimes, you may want
 * to make data from elsewhere in your application available to these handlers
 * without using a global variable. To do this, you call
 * rfbClientSetClientData() and associate the data with a tag. Then, your
 * handler can call rfbClientGetClientData() and get the a pointer to the data
 * associated with that tag.
 * @param client The client in which to set the client data
 * @param tag A unique tag which identifies the data
 * @param data A pointer to the data to associate with the tag
 */
515
void rfbClientSetClientData(rfbClient* client, void* tag, void* data);
Peter Watkins's avatar
Peter Watkins committed
516 517 518 519 520 521 522 523
/**
 * Returns a pointer to the client data associated with the given tag. See the
 * the documentation for rfbClientSetClientData() for a discussion of how you
 * can use client data.
 * @param client The client from which to get the client data
 * @param tag The tag which identifies the client data
 * @return a pointer to the client data
 */
524 525 526 527 528 529
void* rfbClientGetClientData(rfbClient* client, void* tag);

/* protocol extensions */

typedef struct _rfbClientProtocolExtension {
	int* encodings;
530
	/** returns TRUE if the encoding was handled */
531 532
	rfbBool (*handleEncoding)(rfbClient* cl,
		rfbFramebufferUpdateRectHeader* rect);
533
	/** returns TRUE if it handled the message */
534 535 536 537 538 539 540
	rfbBool (*handleMessage)(rfbClient* cl,
		 rfbServerToClientMsg* message);
	struct _rfbClientProtocolExtension* next;
} rfbClientProtocolExtension;

void rfbClientRegisterExtension(rfbClientProtocolExtension* e);

541 542
/* sockets.c */

543
extern rfbBool errorMessageOnReadFailure;
544

545 546
extern rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n);
extern rfbBool WriteToRFBServer(rfbClient* client, char *buf, int n);
547 548
extern int FindFreeTcpPort(void);
extern int ListenAtTcpPort(int port);
549
extern int ListenAtTcpPortAndAddress(int port, const char *address);
550
extern int ConnectClientToTcpAddr(unsigned int host, int port);
Vic Lee's avatar
Vic Lee committed
551
extern int ConnectClientToTcpAddr6(const char *hostname, int port);
552
extern int ConnectClientToUnixSock(const char *sockFile);
553
extern int AcceptTcpConnection(int listenSock);
554
extern rfbBool SetNonBlocking(int sock);
555
extern rfbBool SetDSCP(int sock, int dscp);
556

557 558
extern rfbBool StringToIPAddr(const char *str, unsigned int *addr);
extern rfbBool SameMachine(int sock);
Peter Watkins's avatar
Peter Watkins committed
559 560 561 562 563 564 565 566 567 568
/**
 * Waits for an RFB message to arrive from the server. Before handling a message
 * with HandleRFBServerMessage(), you must wait for your client to receive one.
 * This function blocks until a message is received. You may specify a timeout
 * in microseconds. Once this number of microseconds have elapsed, the function
 * will return.
 * @param client The client to cause to wait until a message is received
 * @param usecs The timeout in microseconds
 * @return the return value of the underlying select() call
 */
569
extern int WaitForMessage(rfbClient* client,unsigned int usecs);
570

571
/* vncviewer.c */
Peter Watkins's avatar
Peter Watkins committed
572 573
/**
 * Allocates and returns a pointer to an rfbClient structure. This will probably
574
 * be the first LibVNCClient function your client code calls. Most libVNCClient
Peter Watkins's avatar
Peter Watkins committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
 * functions operate on an rfbClient structure, and this function allocates
 * memory for that structure. When you're done with the rfbClient structure
 * pointer this function returns, you should free the memory rfbGetClient()
 * allocated by calling rfbClientCleanup().
 *
 * A pixel is one dot on the screen. The number of bytes in a pixel will depend
 * on the number of samples in that pixel and the number of bits in each sample.
 * A sample represents one of the primary colors in a color model. The RGB
 * color model uses red, green, and blue samples respectively. Suppose you
 * wanted to use 16-bit RGB color: You would have three samples per pixel (one
 * for each primary color), five bits per sample (the quotient of 16 RGB bits
 * divided by three samples), and two bytes per pixel (the smallest multiple of
 * eight bits in which the 16-bit pixel will fit). If you wanted 32-bit RGB
 * color, you would have three samples per pixel again, eight bits per sample
 * (since that's how 32-bit color is defined), and four bytes per pixel (the
 * smallest multiple of eight bits in which the 32-bit pixel will fit.
 * @param bitsPerSample The number of bits in a sample
 * @param samplesPerPixel The number of samples in a pixel
 * @param bytesPerPixel The number of bytes in a pixel
 * @return a pointer to the allocated rfbClient structure
 */
596
rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,int bytesPerPixel);
Peter Watkins's avatar
Peter Watkins committed
597 598 599 600 601 602
/**
 * Initializes the client. The format is {PROGRAM_NAME, [OPTIONS]..., HOST}. This
 * function does not initialize the program name if the rfbClient's program
 * name is set already. The options are as follows:
 * <table>
 * <tr><th>Option</th><th>Description</th></tr>
603 604
 * <tr><td>-listen</td><td>Listen for incoming connections.</td></tr>
 * <tr><td>-listennofork</td><td>Listen for incoming connections without forking.
Peter Watkins's avatar
Peter Watkins committed
605
 * </td></tr>
606
 * <tr><td>-play</td><td>Set this client to replay a previously recorded session.</td></tr>
Peter Watkins's avatar
Peter Watkins committed
607
 * <tr><td>-encodings</td><td>Set the encodings to use. The next item in the
608
 * argv array is the encodings string, consisting of comma separated encodings like 'tight,ultra,raw'.</td></tr>
Peter Watkins's avatar
Peter Watkins committed
609
 * <tr><td>-compress</td><td>Set the compression level. The next item in the
610
 * argv array is the compression level as an integer. Ranges from 0 (lowest) to 9 (highest).
Peter Watkins's avatar
Peter Watkins committed
611 612
 * </td></tr>
 * <tr><td>-scale</td><td>Set the scaling level. The next item in the
613
 * argv array is the scaling level as an integer. The screen will be scaled down by this factor.</td></tr>
Peter Watkins's avatar
Peter Watkins committed
614 615
 * <tr><td>-qosdscp</td><td>Set the Quality of Service Differentiated Services
 * Code Point (QoS DSCP). The next item in the argv array is the code point as
616 617 618
 * an integer.</td></tr>
 * <tr><td>-repeaterdest</td><td>Set a VNC repeater address. The next item in the argv array is
 * the repeater's address as a string.</td></tr>
Peter Watkins's avatar
Peter Watkins committed
619 620 621 622 623 624 625 626 627
 * </table>
 *
 * The host may include a port number (delimited by a ':').
 * @param client The client to initialize
 * @param argc The number of arguments to the initializer
 * @param argv The arguments to the initializer as an array of NULL terminated
 * strings
 * @return true if the client was initialized successfully, false otherwise.
 */
628
rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv);
Peter Watkins's avatar
Peter Watkins committed
629 630 631 632 633 634 635
/**
 * Cleans up the client structure and releases the memory allocated for it. You
 * should call this when you're done with the rfbClient structure that you
 * allocated with rfbGetClient().
 * @note rfbClientCleanup() does not touch client->frameBuffer.
 * @param client The client to clean up
 */
636
void rfbClientCleanup(rfbClient* client);
637

638 639 640 641
#if(defined __cplusplus)
}
#endif

642 643 644
/**
 * @}
 */
645

646 647 648 649 650 651 652
/**
 @page libvncclient_doc LibVNCClient Documentation
 @section example_code Example Code
 See SDLvncviewer.c for a rather complete client example.
*/

#endif