1 | /***************************************************************************************** |
---|
2 | * VNCViewer for SAGE |
---|
3 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
4 | * University of Illinois at Chicago |
---|
5 | * |
---|
6 | * All rights reserved. |
---|
7 | * |
---|
8 | * Redistribution and use in source and binary forms, with or without |
---|
9 | * modification, are permitted provided that the following conditions are met: |
---|
10 | * |
---|
11 | * * Redistributions of source code must retain the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer. |
---|
13 | * * Redistributions in binary form must reproduce the above |
---|
14 | * copyright notice, this list of conditions and the following disclaimer |
---|
15 | * in the documentation and/or other materials provided with the distribution. |
---|
16 | * * Neither the name of the University of Illinois at Chicago nor |
---|
17 | * the names of its contributors may be used to endorse or promote |
---|
18 | * products derived from this software without specific prior written permission. |
---|
19 | * |
---|
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
31 | * |
---|
32 | * Direct questions, comments etc about VNCViewer for SAGE to www.evl.uic.edu/cavern/forum |
---|
33 | *****************************************************************************************/ |
---|
34 | |
---|
35 | #ifndef AURA_VNCVIEW_H |
---|
36 | #define AURA_VNCVIEW_H |
---|
37 | |
---|
38 | #define False 0 |
---|
39 | #define True 1 |
---|
40 | typedef char *String; |
---|
41 | |
---|
42 | typedef unsigned char uchar; |
---|
43 | typedef int Bool; |
---|
44 | |
---|
45 | #if defined(WIN32) |
---|
46 | //#include <Winsock2.h> |
---|
47 | #else |
---|
48 | |
---|
49 | #include <unistd.h> |
---|
50 | #include <string.h> |
---|
51 | #include <stdlib.h> |
---|
52 | #endif |
---|
53 | |
---|
54 | #include <stdio.h> |
---|
55 | #include <stdarg.h> |
---|
56 | |
---|
57 | |
---|
58 | // Util functions |
---|
59 | void aLog(const char* format,...); |
---|
60 | void aError(const char* format,...); |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | #include "rfb.h" |
---|
65 | |
---|
66 | #define MAX_ENCODINGS 10 |
---|
67 | |
---|
68 | #define FLASH_PORT_OFFSET 5400 |
---|
69 | #define SERVER_PORT_OFFSET 5900 |
---|
70 | |
---|
71 | // note that the CoRRE encoding uses this buffer and assumes it is big enough |
---|
72 | // to hold 255 * 255 * 32 bits -> 260100 bytes. 640*480 = 307200 bytes |
---|
73 | // also hextile assumes it is big enough to hold 16 * 16 * 32 bits |
---|
74 | #define BUFFER_SIZE (640*480) |
---|
75 | |
---|
76 | // socket buffer |
---|
77 | #define BUF_SIZE 8192 |
---|
78 | |
---|
79 | class sgVNCViewer; |
---|
80 | |
---|
81 | class VNCViewer |
---|
82 | { |
---|
83 | public: |
---|
84 | Bool shareDesktop; |
---|
85 | Bool viewOnly; |
---|
86 | Bool fullScreen; |
---|
87 | |
---|
88 | String encodingsString; |
---|
89 | |
---|
90 | Bool useBGR233; |
---|
91 | int nColours; |
---|
92 | Bool useSharedColours; |
---|
93 | Bool forceOwnCmap; |
---|
94 | Bool forceTrueColour; |
---|
95 | int requestedDepth; |
---|
96 | |
---|
97 | Bool useShm; |
---|
98 | |
---|
99 | int wmDecorationWidth; |
---|
100 | int wmDecorationHeight; |
---|
101 | |
---|
102 | char *passwordFile; |
---|
103 | Bool passwordDialog; |
---|
104 | |
---|
105 | int rawDelay; |
---|
106 | int copyRectDelay; |
---|
107 | |
---|
108 | Bool debug; |
---|
109 | |
---|
110 | int popupButtonCount; |
---|
111 | |
---|
112 | int bumpScrollTime; |
---|
113 | int bumpScrollPixels; |
---|
114 | |
---|
115 | int compressLevel; |
---|
116 | int qualityLevel; |
---|
117 | Bool useRemoteCursor; |
---|
118 | |
---|
119 | char vncServerHost[256]; |
---|
120 | int vncServerPort; |
---|
121 | |
---|
122 | int rfbsock; |
---|
123 | Bool canUseCoRRE; |
---|
124 | Bool canUseHextile; |
---|
125 | char *desktopName; |
---|
126 | rfbPixelFormat myFormat; |
---|
127 | rfbServerInitMsg si; |
---|
128 | char *serverCutText; |
---|
129 | Bool newServerCutText; |
---|
130 | |
---|
131 | // socket buffering |
---|
132 | char buffer[BUFFER_SIZE]; |
---|
133 | int buffered; |
---|
134 | char buf[BUF_SIZE]; |
---|
135 | char *bufoutptr; |
---|
136 | |
---|
137 | public: |
---|
138 | VNCViewer() |
---|
139 | { |
---|
140 | encodingsString = strdup("hextile corre rre raw copyrect"); |
---|
141 | shareDesktop = True; |
---|
142 | viewOnly = False; |
---|
143 | fullScreen = False; |
---|
144 | passwordFile = strdup("passwd"); |
---|
145 | passwordDialog = False; |
---|
146 | useBGR233 = False; |
---|
147 | nColours = 256; |
---|
148 | useSharedColours = True; |
---|
149 | forceOwnCmap = False; |
---|
150 | forceTrueColour = False; |
---|
151 | requestedDepth = 0; |
---|
152 | wmDecorationWidth = 4; |
---|
153 | wmDecorationHeight = 24; |
---|
154 | popupButtonCount = 0; |
---|
155 | debug = False; |
---|
156 | rawDelay = 0; |
---|
157 | copyRectDelay = 0; |
---|
158 | bumpScrollTime = 25; |
---|
159 | bumpScrollPixels = 20; |
---|
160 | compressLevel = 4; |
---|
161 | qualityLevel = 2; |
---|
162 | useRemoteCursor = False; |
---|
163 | |
---|
164 | vncServerPort = 0; |
---|
165 | serverCutText = NULL; |
---|
166 | newServerCutText = False; |
---|
167 | buffered = 0; |
---|
168 | bufoutptr = buf; |
---|
169 | }; |
---|
170 | ~VNCViewer() |
---|
171 | {}; |
---|
172 | |
---|
173 | void GetArgsAndResources(int argc, char **argv); |
---|
174 | Bool ConnectToRFBServer(); |
---|
175 | Bool InitialiseRFBConnection(char *pass); |
---|
176 | Bool SetFormatAndEncodings(); |
---|
177 | Bool SendIncrementalFramebufferUpdateRequest(); |
---|
178 | Bool SendFramebufferUpdateRequest(int x, int y, int w, int h, |
---|
179 | Bool incremental); |
---|
180 | Bool SendPointerEvent(int x, int y, int buttonMask); |
---|
181 | Bool SendKeyEvent(CARD32 key, Bool down); |
---|
182 | Bool SendClientCutText(char *str, int len); |
---|
183 | |
---|
184 | void PrintPixelFormat(rfbPixelFormat *format); |
---|
185 | void SetVisualAndCmap(); |
---|
186 | |
---|
187 | Bool HandleCoRRE8 (sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
188 | Bool HandleCoRRE16 (sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
189 | Bool HandleCoRRE32 (sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
190 | |
---|
191 | Bool HandleHextile8 (sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
192 | Bool HandleHextile16 (sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
193 | Bool HandleHextile32 (sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
194 | |
---|
195 | Bool HandleRRE8 (sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
196 | Bool HandleRRE16 (sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
197 | Bool HandleRRE32 (sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
198 | |
---|
199 | Bool HandleZlib8(sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
200 | Bool HandleZlib16(sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
201 | Bool HandleZlib32(sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
202 | |
---|
203 | Bool HandleTight8(sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
204 | Bool HandleTight16(sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
205 | Bool HandleTight32(sgVNCViewer *ct, int rx, int ry, int rw, int rh); |
---|
206 | |
---|
207 | |
---|
208 | void FilterGradient24 (int numRows, CARD32 *dst); |
---|
209 | |
---|
210 | int InitFilterCopy8 (int rw, int rh); |
---|
211 | void FilterCopy8 (int numRows, CARD8 *dst); |
---|
212 | int InitFilterGradient8 (int rw, int rh); |
---|
213 | void FilterGradient8 (int numRows, CARD8 *dst); |
---|
214 | int InitFilterPalette8 (int rw, int rh); |
---|
215 | void FilterPalette8 (int numRows, CARD8 *dst); |
---|
216 | |
---|
217 | int InitFilterCopy16 (int rw, int rh); |
---|
218 | void FilterCopy16 (int numRows, CARD16 *dst); |
---|
219 | int InitFilterGradient16 (int rw, int rh); |
---|
220 | void FilterGradient16 (int numRows, CARD16 *dst); |
---|
221 | int InitFilterPalette16 (int rw, int rh); |
---|
222 | void FilterPalette16 (int numRows, CARD16 *dst); |
---|
223 | |
---|
224 | int InitFilterCopy32 (int rw, int rh); |
---|
225 | void FilterCopy32 (int numRows, CARD32 *dst); |
---|
226 | int InitFilterGradient32 (int rw, int rh); |
---|
227 | void FilterGradient32 (int numRows, CARD32 *dst); |
---|
228 | int InitFilterPalette32 (int rw, int rh); |
---|
229 | void FilterPalette32 (int numRows, CARD32 *dst); |
---|
230 | |
---|
231 | long ReadCompactLen (void); |
---|
232 | Bool DecompressJpegRect8(sgVNCViewer *ct, int x, int y, int w, int h); |
---|
233 | Bool DecompressJpegRect16(sgVNCViewer *ct, int x, int y, int w, int h); |
---|
234 | Bool DecompressJpegRect32(sgVNCViewer *ct, int x, int y, int w, int h); |
---|
235 | |
---|
236 | Bool ReadFromRFBServer(char *out, unsigned int n); |
---|
237 | Bool HandleRFBServerMessage(sgVNCViewer *ct); |
---|
238 | }; |
---|
239 | |
---|
240 | |
---|
241 | |
---|
242 | /* sockets.c */ |
---|
243 | |
---|
244 | extern Bool WriteExact(int sock, char *buf, int n); |
---|
245 | extern int ConnectToTcpAddr(unsigned int host, int port); |
---|
246 | extern Bool SetNonBlocking(int sock); |
---|
247 | |
---|
248 | extern int StringToIPAddr(const char *str, unsigned long *addr); |
---|
249 | extern Bool SameMachine(int sock); |
---|
250 | |
---|
251 | #endif |
---|