1 |
27 |
unneback |
/*
|
2 |
|
|
* Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory
|
3 |
|
|
*
|
4 |
|
|
* This is free software; you can redistribute it and/or modify
|
5 |
|
|
* it under the terms of the GNU General Public License as published by
|
6 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
7 |
|
|
* (at your option) any later version.
|
8 |
|
|
*
|
9 |
|
|
* This software is distributed in the hope that it will be useful,
|
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
* GNU General Public License for more details.
|
13 |
|
|
*
|
14 |
|
|
* You should have received a copy of the GNU General Public License
|
15 |
|
|
* along with this software; if not, write to the Free Software
|
16 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
17 |
|
|
* USA.
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
/*
|
21 |
|
|
* vncviewer.h
|
22 |
|
|
*/
|
23 |
|
|
|
24 |
|
|
#include <stdio.h>
|
25 |
|
|
#include <stdlib.h>
|
26 |
|
|
#include <string.h>
|
27 |
|
|
#include <sys/time.h>
|
28 |
|
|
#ifdef NANOX
|
29 |
|
|
#define MWINCLUDECOLORS
|
30 |
|
|
#include "nano-X.h"
|
31 |
|
|
/* required for rfbproto.h */
|
32 |
|
|
typedef unsigned long CARD32;
|
33 |
|
|
typedef unsigned short CARD16;
|
34 |
|
|
typedef unsigned char CARD8;
|
35 |
|
|
#else
|
36 |
|
|
#include <X11/Xlib.h>
|
37 |
|
|
#include <X11/Xmd.h>
|
38 |
|
|
#endif
|
39 |
|
|
#include <rfbproto.h>
|
40 |
|
|
|
41 |
|
|
#ifdef NANOX
|
42 |
|
|
/* try and map some X stuff to nano-X */
|
43 |
|
|
#define Bool GR_BOOL
|
44 |
|
|
#define True GR_TRUE
|
45 |
|
|
#define False GR_FALSE
|
46 |
|
|
#define XGCValues GR_GC_INFO
|
47 |
|
|
|
48 |
|
|
typedef GR_ID Window; /* from X.h */
|
49 |
|
|
typedef GR_ID Colormap; /* from X.h */
|
50 |
|
|
typedef CARD32 Atom; /* from X.h */
|
51 |
|
|
typedef CARD32 Time; /* from X.h */
|
52 |
|
|
|
53 |
|
|
#define None 0L /* from X.h */
|
54 |
|
|
#define CurrentTime 0L /* from X.h */
|
55 |
|
|
#define PropertyChangeMask (1L<<22) /* from X.h */
|
56 |
|
|
#define XA_PRIMARY ((Atom) 1) /* from Xatom.h */
|
57 |
|
|
|
58 |
|
|
/* Flags used in StoreNamedColor, StoreColors */
|
59 |
|
|
#define DoRed (1<<0)
|
60 |
|
|
#define DoGreen (1<<1)
|
61 |
|
|
#define DoBlue (1<<2)
|
62 |
|
|
|
63 |
|
|
#define ConnectionNumber(dpy) ((dpy)->fd)
|
64 |
|
|
#define ScreenOfDisplay(dpy, scr) (&(dpy)->screens[scr])
|
65 |
|
|
#define DefaultScreen(dpy) ((dpy)->default_screen)
|
66 |
|
|
#define DefaultRootWindow(dpy) (ScreenOfDisplay(dpy,DefaultScreen(dpy))->root)
|
67 |
|
|
#define DefaultGC(dpy, scr) (ScreenOfDisplay(dpy,scr)->default_gc)
|
68 |
|
|
|
69 |
|
|
/* data structure used by color operations */
|
70 |
|
|
typedef struct {
|
71 |
|
|
unsigned long pixel;
|
72 |
|
|
unsigned short red, green, blue;
|
73 |
|
|
char flags; /* do_red, do_green, do_blue */
|
74 |
|
|
char pad;
|
75 |
|
|
} XColor;
|
76 |
|
|
|
77 |
|
|
#define GCForeground (1L<<2)
|
78 |
|
|
#define GCBackground (1L<<3)
|
79 |
|
|
|
80 |
|
|
/*
|
81 |
|
|
* the Screen structure is defined in Xlib.h
|
82 |
|
|
*/
|
83 |
|
|
typedef struct {
|
84 |
|
|
Window root; /* Root window id. */
|
85 |
|
|
} Screen;
|
86 |
|
|
/*
|
87 |
|
|
* the Display structure is defined as _XDisplay in Xlib.h
|
88 |
|
|
*/
|
89 |
|
|
typedef struct {
|
90 |
|
|
int fd; /* Network socket */
|
91 |
|
|
int default_screen; /* default screen for operations */
|
92 |
|
|
Screen *screens; /* pointer to list of screens */
|
93 |
|
|
} Display;
|
94 |
|
|
|
95 |
|
|
/*
|
96 |
|
|
* the XEvent union is defined in Xlib.h
|
97 |
|
|
*/
|
98 |
|
|
typedef struct {
|
99 |
|
|
int dummy;
|
100 |
|
|
} XEvent;
|
101 |
|
|
|
102 |
|
|
#endif /* NANOX */
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
extern int endianTest;
|
106 |
|
|
|
107 |
|
|
#define Swap16IfLE(s) \
|
108 |
|
|
(*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
|
109 |
|
|
|
110 |
|
|
#define Swap32IfLE(l) \
|
111 |
|
|
(*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \
|
112 |
|
|
(((l) & 0x00ff0000) >> 8) | \
|
113 |
|
|
(((l) & 0x0000ff00) << 8) | \
|
114 |
|
|
(((l) & 0x000000ff) << 24)) : (l))
|
115 |
|
|
|
116 |
|
|
#define MAX_ENCODINGS 10
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
/* args.c */
|
120 |
|
|
|
121 |
|
|
extern char *programName;
|
122 |
|
|
extern char hostname[];
|
123 |
|
|
extern int port;
|
124 |
|
|
extern Bool listenSpecified;
|
125 |
|
|
extern int listenPort, flashPort;
|
126 |
|
|
extern char *displayname;
|
127 |
|
|
extern Bool shareDesktop;
|
128 |
|
|
extern Bool viewOnly;
|
129 |
|
|
extern CARD32 explicitEncodings[];
|
130 |
|
|
extern int nExplicitEncodings;
|
131 |
|
|
extern Bool addCopyRect;
|
132 |
|
|
extern Bool addRRE;
|
133 |
|
|
extern Bool addCoRRE;
|
134 |
|
|
extern Bool addHextile;
|
135 |
|
|
extern Bool useBGR233;
|
136 |
|
|
extern Bool forceOwnCmap;
|
137 |
|
|
extern Bool forceTruecolour;
|
138 |
|
|
extern int requestedDepth;
|
139 |
|
|
extern char *geometry;
|
140 |
|
|
extern int wmDecorationWidth;
|
141 |
|
|
extern int wmDecorationHeight;
|
142 |
|
|
extern char *passwdFile;
|
143 |
|
|
extern int updateRequestPeriodms;
|
144 |
|
|
extern int updateRequestX;
|
145 |
|
|
extern int updateRequestY;
|
146 |
|
|
extern int updateRequestW;
|
147 |
|
|
extern int updateRequestH;
|
148 |
|
|
extern int rawDelay;
|
149 |
|
|
extern int copyRectDelay;
|
150 |
|
|
extern Bool debug;
|
151 |
|
|
|
152 |
|
|
extern void processArgs(int argc, char **argv);
|
153 |
|
|
extern void usage();
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
/* rfbproto.c */
|
157 |
|
|
|
158 |
|
|
extern int rfbsock;
|
159 |
|
|
extern Bool canUseCoRRE;
|
160 |
|
|
extern Bool canUseHextile;
|
161 |
|
|
extern char *desktopName;
|
162 |
|
|
extern rfbPixelFormat myFormat;
|
163 |
|
|
extern rfbServerInitMsg si;
|
164 |
|
|
extern struct timeval updateRequestTime;
|
165 |
|
|
extern Bool sendUpdateRequest;
|
166 |
|
|
|
167 |
|
|
extern Bool ConnectToRFBServer(const char *hostname, int port);
|
168 |
|
|
extern Bool InitialiseRFBConnection();
|
169 |
|
|
extern Bool SetFormatAndEncodings();
|
170 |
|
|
extern Bool SendIncrementalFramebufferUpdateRequest();
|
171 |
|
|
extern Bool SendFramebufferUpdateRequest(int x, int y, int w, int h,
|
172 |
|
|
Bool incremental);
|
173 |
|
|
extern Bool SendPointerEvent(int x, int y, int buttonMask);
|
174 |
|
|
extern Bool SendKeyEvent(CARD32 key, Bool down);
|
175 |
|
|
extern Bool SendClientCutText(char *str, int len);
|
176 |
|
|
extern Bool HandleRFBServerMessage();
|
177 |
|
|
|
178 |
|
|
#ifdef NANOX
|
179 |
|
|
|
180 |
|
|
/* nanox.c */
|
181 |
|
|
|
182 |
|
|
extern Display *dpy;
|
183 |
|
|
extern Window canvas;
|
184 |
|
|
extern Colormap cmap;
|
185 |
|
|
extern GR_GC_ID gc;
|
186 |
|
|
extern GR_GC_ID srcGC, dstGC;
|
187 |
|
|
extern unsigned long BGR233ToPixel[];
|
188 |
|
|
|
189 |
|
|
extern Bool CreateXWindow();
|
190 |
|
|
extern void ShutdownX();
|
191 |
|
|
extern Bool HandleXEvents(GR_EVENT *ev);
|
192 |
|
|
extern Bool AllXEventsPredicate(Display *dpy, XEvent *ev, char *arg);
|
193 |
|
|
extern void CopyDataToScreen(CARD8 *buf, int x, int y, int width, int height);
|
194 |
|
|
|
195 |
|
|
/* Xlib functions */
|
196 |
|
|
extern char *XDisplayName(char *display);
|
197 |
|
|
extern int XChangeGC(Display *dpy, GR_GC_ID gc, unsigned long vmask,
|
198 |
|
|
GR_GC_INFO *gcv);
|
199 |
|
|
extern int XStoreColor(Display *dpy, Colormap cmap, XColor *xc);
|
200 |
|
|
extern int XFillRectangle(Display *dpy, Window canvas, GR_GC_ID gc,
|
201 |
|
|
int x, int y, int w, int h);
|
202 |
|
|
extern int XSync(Display *dpy, Bool discard);
|
203 |
|
|
extern int XCopyArea(Display *dpy, Window src, Window dst, GR_GC_ID gc, \
|
204 |
|
|
int x1, int y1, int w, int h, int x2, int y2);
|
205 |
|
|
extern int XBell(Display *dpy, int percent);
|
206 |
|
|
extern int XSelectInput(Display *dpy, Window win, long evmask);
|
207 |
|
|
extern int XStoreBytes(Display *dpy, char *bytes, int nbytes);
|
208 |
|
|
extern int XSetSelectionOwner(Display *dpy, Atom sel, Window own, Time t);
|
209 |
|
|
|
210 |
|
|
#else /* NANOX */
|
211 |
|
|
|
212 |
|
|
/* x.c */
|
213 |
|
|
|
214 |
|
|
extern Display *dpy;
|
215 |
|
|
extern Window canvas;
|
216 |
|
|
extern Colormap cmap;
|
217 |
|
|
extern GC gc;
|
218 |
|
|
extern GC srcGC, dstGC;
|
219 |
|
|
extern unsigned long BGR233ToPixel[];
|
220 |
|
|
|
221 |
|
|
extern Bool CreateXWindow();
|
222 |
|
|
extern void ShutdownX();
|
223 |
|
|
extern Bool HandleXEvents();
|
224 |
|
|
extern Bool AllXEventsPredicate(Display *dpy, XEvent *ev, char *arg);
|
225 |
|
|
extern void CopyDataToScreen(CARD8 *buf, int x, int y, int width, int height);
|
226 |
|
|
|
227 |
|
|
#endif /* NANOX */
|
228 |
|
|
|
229 |
|
|
/* sockets.c */
|
230 |
|
|
|
231 |
|
|
extern Bool errorMessageFromReadExact;
|
232 |
|
|
|
233 |
|
|
extern Bool ReadExact(int sock, char *buf, int n);
|
234 |
|
|
extern Bool WriteExact(int sock, char *buf, int n);
|
235 |
|
|
extern int ListenAtTcpPort(int port);
|
236 |
|
|
extern int ConnectToTcpAddr(unsigned int host, int port);
|
237 |
|
|
extern int AcceptTcpConnection(int listenSock);
|
238 |
|
|
extern int StringToIPAddr(const char *str, unsigned int *addr);
|
239 |
|
|
extern Bool SameMachine(int sock);
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
/* listen.c */
|
243 |
|
|
|
244 |
|
|
extern void listenForIncomingConnections();
|