PageRenderTime 54ms CodeModel.GetById 37ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 1ms

/apps/desktop/libvncserver/rfb/rfbclient.h

http://ftk.googlecode.com/
C++ Header | 335 lines | 191 code | 75 blank | 69 comment | 0 complexity | 883a70f799af2237d14b25c27356dba1 MD5 | raw file
  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
 37#define rfbClientSwap16IfLE(s) \
 38    (*(char *)&client->endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
 39
 40#define rfbClientSwap32IfLE(l) \
 41    (*(char *)&client->endianTest ? ((((l) & 0xff000000) >> 24) | \
 42			     (((l) & 0x00ff0000) >> 8)  | \
 43			     (((l) & 0x0000ff00) << 8)  | \
 44			     (((l) & 0x000000ff) << 24))  : (l))
 45
 46#define FLASH_PORT_OFFSET 5400
 47#define LISTEN_PORT_OFFSET 5500
 48#define TUNNEL_PORT_OFFSET 5500
 49#define SERVER_PORT_OFFSET 5900
 50
 51#define DEFAULT_SSH_CMD "/usr/bin/ssh"
 52#define DEFAULT_TUNNEL_CMD  \
 53  (DEFAULT_SSH_CMD " -f -L %L:localhost:%R %H sleep 20")
 54#define DEFAULT_VIA_CMD     \
 55  (DEFAULT_SSH_CMD " -f -L %L:%H:%R %G sleep 20")
 56
 57#if(defined __cplusplus)
 58extern "C"
 59{
 60#endif
 61
 62/* vncrec */
 63
 64typedef struct {
 65  FILE* file;
 66  struct timeval tv;
 67  rfbBool readTimestamp;
 68  rfbBool doNotSleep;
 69} rfbVNCRec;
 70
 71/* client data */
 72
 73typedef struct rfbClientData {
 74	void* tag;
 75	void* data;
 76	struct rfbClientData* next;
 77} rfbClientData;
 78
 79/* app data (belongs into rfbClient?) */
 80
 81typedef struct {
 82  rfbBool shareDesktop;
 83  rfbBool viewOnly;
 84
 85  const char* encodingsString;
 86
 87  rfbBool useBGR233;
 88  int nColours;
 89  rfbBool forceOwnCmap;
 90  rfbBool forceTrueColour;
 91  int requestedDepth;
 92
 93  int compressLevel;
 94  int qualityLevel;
 95  rfbBool enableJPEG;
 96  rfbBool useRemoteCursor;
 97  rfbBool palmVNC;  /* use palmvnc specific SetScale (vs ultravnc) */
 98  int scaleSetting; /* 0 means no scale set, else 1/scaleSetting */
 99} AppData;
100
101
102struct _rfbClient;
103
104typedef void (*HandleTextChatProc)(struct _rfbClient* client, int value, char *text);
105typedef void (*HandleKeyboardLedStateProc)(struct _rfbClient* client, int value, int pad);
106typedef rfbBool (*HandleCursorPosProc)(struct _rfbClient* client, int x, int y);
107typedef void (*SoftCursorLockAreaProc)(struct _rfbClient* client, int x, int y, int w, int h);
108typedef void (*SoftCursorUnlockScreenProc)(struct _rfbClient* client);
109typedef void (*GotFrameBufferUpdateProc)(struct _rfbClient* client, int x, int y, int w, int h);
110typedef char* (*GetPasswordProc)(struct _rfbClient* client);
111typedef rfbBool (*MallocFrameBufferProc)(struct _rfbClient* client);
112typedef void (*GotXCutTextProc)(struct _rfbClient* client, const char *text, int textlen);
113typedef void (*BellProc)(struct _rfbClient* client);
114
115typedef void (*GotCursorShapeProc)(struct _rfbClient* client, int xhot, int yhot, int width, int height, int bytesPerPixel);
116typedef void (*GotCopyRectProc)(struct _rfbClient* client, int src_x, int src_y, int w, int h, int dest_x, int dest_y);
117
118typedef struct _rfbClient {
119	uint8_t* frameBuffer;
120	int width, height;
121
122	int endianTest;
123
124	AppData appData;
125
126	const char* programName;
127	char* serverHost;
128	int serverPort; /* if -1, then use file recorded by vncrec */
129	rfbBool listenSpecified;
130	int listenPort, flashPort;
131
132	struct {
133		int x, y, w, h;
134	} updateRect;
135
136	/* Note that the CoRRE encoding uses this buffer and assumes it is big enough
137	   to hold 255 * 255 * 32 bits -> 260100 bytes.  640*480 = 307200 bytes.
138	   Hextile also assumes it is big enough to hold 16 * 16 * 32 bits.
139	   Tight encoding assumes BUFFER_SIZE is at least 16384 bytes. */
140
141#define RFB_BUFFER_SIZE (640*480)
142	char buffer[RFB_BUFFER_SIZE];
143
144	/* rfbproto.c */
145
146	int sock;
147	rfbBool canUseCoRRE;
148	rfbBool canUseHextile;
149	char *desktopName;
150	rfbPixelFormat format;
151	rfbServerInitMsg si;
152
153	/* sockets.c */
154#define RFB_BUF_SIZE 8192
155	char buf[RFB_BUF_SIZE];
156	char *bufoutptr;
157	int buffered;
158
159	/* The zlib encoding requires expansion/decompression/deflation of the
160	   compressed data in the "buffer" above into another, result buffer.
161	   However, the size of the result buffer can be determined precisely
162	   based on the bitsPerPixel, height and width of the rectangle.  We
163	   allocate this buffer one time to be the full size of the buffer. */
164
165	/* Ultra Encoding uses this buffer too */
166	
167	int ultra_buffer_size;
168	char *ultra_buffer;
169
170	int raw_buffer_size;
171	char *raw_buffer;
172
173#ifdef LIBVNCSERVER_HAVE_LIBZ
174	z_stream decompStream;
175	rfbBool decompStreamInited;
176#endif
177
178
179#ifdef LIBVNCSERVER_HAVE_LIBZ
180#ifdef LIBVNCSERVER_HAVE_LIBJPEG
181	/*
182	 * Variables for the ``tight'' encoding implementation.
183	 */
184
185	/* Separate buffer for compressed data. */
186#define ZLIB_BUFFER_SIZE 30000
187	char zlib_buffer[ZLIB_BUFFER_SIZE];
188
189	/* Four independent compression streams for zlib library. */
190	z_stream zlibStream[4];
191	rfbBool zlibStreamActive[4];
192
193	/* Filter stuff. Should be initialized by filter initialization code. */
194	rfbBool cutZeros;
195	int rectWidth, rectColors;
196	char tightPalette[256*4];
197	uint8_t tightPrevRow[2048*3*sizeof(uint16_t)];
198
199	/* JPEG decoder state. */
200	rfbBool jpegError;
201
202	struct jpeg_source_mgr* jpegSrcManager;
203	void* jpegBufferPtr;
204	size_t jpegBufferLen;
205
206#endif
207#endif
208
209
210	/* cursor.c */
211	uint8_t *rcSource, *rcMask;
212
213	/* private data pointer */
214	rfbClientData* clientData;
215
216	rfbVNCRec* vncRec;
217
218	/* Keyboard State support (is 'Caps Lock' set on the remote display???) */
219	int KeyboardLedStateEnabled;
220	int CurrentKeyboardLedState;
221
222	int canHandleNewFBSize;
223
224	/* hooks */
225	HandleTextChatProc         HandleTextChat;
226	HandleKeyboardLedStateProc HandleKeyboardLedState;
227	HandleCursorPosProc HandleCursorPos;
228	SoftCursorLockAreaProc SoftCursorLockArea;
229	SoftCursorUnlockScreenProc SoftCursorUnlockScreen;
230	GotFrameBufferUpdateProc GotFrameBufferUpdate;
231	/* the pointer returned by GetPassword will be freed after use! */
232	GetPasswordProc GetPassword;
233	MallocFrameBufferProc MallocFrameBuffer;
234	GotXCutTextProc GotXCutText;
235	BellProc Bell;
236
237	GotCursorShapeProc GotCursorShape;
238	GotCopyRectProc GotCopyRect;
239
240	/* Which messages are supported by the server
241	 * This is a *guess* for most servers.
242	 * (If we can even detect the type of server)
243	 *
244	 * If the server supports the "rfbEncodingSupportedMessages"
245	 * then this will be updated when the encoding is received to
246	 * accurately reflect the servers capabilities.
247	 */
248	rfbSupportedMessages supportedMessages;
249
250	/* negotiated protocol version */
251	int major, minor;
252} rfbClient;
253
254/* cursor.c */
255
256extern rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int height, uint32_t enc);
257
258/* listen.c */
259
260extern void listenForIncomingConnections(rfbClient* viewer);
261
262/* rfbproto.c */
263
264extern rfbBool rfbEnableClientLogging;
265typedef void (*rfbClientLogProc)(const char *format, ...);
266extern rfbClientLogProc rfbClientLog,rfbClientErr;
267extern rfbBool ConnectToRFBServer(rfbClient* client,const char *hostname, int port);
268extern rfbBool InitialiseRFBConnection(rfbClient* client);
269extern rfbBool SetFormatAndEncodings(rfbClient* client);
270extern rfbBool SendIncrementalFramebufferUpdateRequest(rfbClient* client);
271extern rfbBool SendFramebufferUpdateRequest(rfbClient* client,
272					 int x, int y, int w, int h,
273					 rfbBool incremental);
274extern rfbBool SendScaleSetting(rfbClient* client,int scaleSetting);
275extern rfbBool SendPointerEvent(rfbClient* client,int x, int y, int buttonMask);
276extern rfbBool SendKeyEvent(rfbClient* client,uint32_t key, rfbBool down);
277extern rfbBool SendClientCutText(rfbClient* client,char *str, int len);
278extern rfbBool HandleRFBServerMessage(rfbClient* client);
279
280extern rfbBool TextChatSend(rfbClient* client, char *text);
281extern rfbBool TextChatOpen(rfbClient* client);
282extern rfbBool TextChatClose(rfbClient* client);
283extern rfbBool TextChatFinish(rfbClient* client);
284extern rfbBool PermitServerInput(rfbClient* client, int enabled);
285
286extern void PrintPixelFormat(rfbPixelFormat *format);
287
288/* client data */
289
290void rfbClientSetClientData(rfbClient* client, void* tag, void* data);
291void* rfbClientGetClientData(rfbClient* client, void* tag);
292
293/* protocol extensions */
294
295typedef struct _rfbClientProtocolExtension {
296	int* encodings;
297	/* returns TRUE if the encoding was handled */
298	rfbBool (*handleEncoding)(rfbClient* cl,
299		rfbFramebufferUpdateRectHeader* rect);
300	/* returns TRUE if it handled the message */
301	rfbBool (*handleMessage)(rfbClient* cl,
302		 rfbServerToClientMsg* message);
303	struct _rfbClientProtocolExtension* next;
304} rfbClientProtocolExtension;
305
306void rfbClientRegisterExtension(rfbClientProtocolExtension* e);
307
308/* sockets.c */
309
310extern rfbBool errorMessageOnReadFailure;
311
312extern rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n);
313extern rfbBool WriteToRFBServer(rfbClient* client, char *buf, int n);
314extern int FindFreeTcpPort(void);
315extern int ListenAtTcpPort(int port);
316extern int ConnectClientToTcpAddr(unsigned int host, int port);
317extern int AcceptTcpConnection(int listenSock);
318extern rfbBool SetNonBlocking(int sock);
319
320extern rfbBool StringToIPAddr(const char *str, unsigned int *addr);
321extern rfbBool SameMachine(int sock);
322extern int WaitForMessage(rfbClient* client,unsigned int usecs);
323
324/* vncviewer.c */
325rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,int bytesPerPixel);
326rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv);
327/* rfbClientCleanup() does not touch client->frameBuffer */
328void rfbClientCleanup(rfbClient* client);
329
330#if(defined __cplusplus)
331}
332#endif
333
334#endif
335