<yoshiki@xemacs.org>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xmd.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xmu/StdSel.h>
#include "rfbproto.h"
#include "caps.h"
extern int endianTest;
#define Swap16IfLE(s) \
(*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
#define Swap32IfLE(l) \
(*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \
(((l) & 0x00ff0000) >> 8) | \
(((l) & 0x0000ff00) << 8) | \
(((l) & 0x000000ff) << 24)) : (l))
#define MAX_ENCODINGS 20
#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")
typedef struct {
Bool shareDesktop;
Bool viewOnly;
Bool fullScreen;
Bool grabKeyboard;
Bool raiseOnBeep;
String encodingsString;
Bool useBGR233;
int nColours;
Bool useSharedColours;
Bool forceOwnCmap;
Bool forceTrueColour;
int requestedDepth;
Bool useShm;
int wmDecorationWidth;
int wmDecorationHeight;
char *userLogin;
char *passwordFile;
Bool passwordDialog;
int rawDelay;
int copyRectDelay;
Bool debug;
String play;
String record;
String movie;
Bool hideWindow;
Bool writeYUV;
Bool ffInfo;
int popupButtonCount;
int bumpScrollTime;
int bumpScrollPixels;
int compressLevel;
int qualityLevel;
Bool enableJPEG;
Bool useRemoteCursor;
Bool useX11Cursor;
Bool autoPass;
Bool debugFrames;
} AppData;
extern AppData appData;
extern char *fallback_resources[];
extern char vncServerHost[];
extern int vncServerPort;
extern Bool listenSpecified;
extern int listenPort;
extern XrmOptionDescRec cmdLineOptions[];
extern int numCmdLineOptions;
extern void removeArgs(int *argc, char** argv, int idx, int nargs);
extern void usage(void);
extern void GetArgsAndResources(int argc, char **argv);
extern unsigned long BGR233ToPixel[];
extern Colormap cmap;
extern Visual *vis;
extern unsigned int visdepth, visbpp;
extern void SetVisualAndCmap();
extern Bool HandleCursorShape(int xhot, int yhot, int width, int height,
CARD32 enc);
extern void SoftCursorLockArea(int x, int y, int w, int h);
extern void SoftCursorUnlockScreen(void);
extern void SoftCursorMove(int x, int y);
extern Atom wmDeleteWindow;
extern Widget form, viewport, desktop;
extern Window desktopWin;
extern Cursor dotCursor;
extern GC gc;
extern GC srcGC, dstGC;
extern Dimension dpyWidth, dpyHeight;
extern void DesktopInitBeforeRealization();
extern void DesktopInitAfterRealization();
extern void SendRFBEvent(Widget w, XEvent *event, String *params,
Cardinal *num_params);
extern void CopyDataToScreen(char *buf, int x, int y, int width, int height);
extern void SynchroniseScreen();
extern void ServerDialogDone(Widget w, XEvent *event, String *params,
Cardinal *num_params);
extern char *DoServerDialog();
extern void PasswordDialogDone(Widget w, XEvent *event, String *params,
Cardinal *num_params);
extern char *DoPasswordDialog();
extern void ToggleFullScreen(Widget w, XEvent *event, String *params,
Cardinal *num_params);
extern void SetFullScreenState(Widget w, XEvent *event, String *params,
Cardinal *num_params);
extern Bool BumpScroll(XEvent *ev);
extern void FullScreenOn();
extern void FullScreenOff();
extern void SetGrabKeyboardState(Widget w, XEvent *ev, String *params,
Cardinal *num_params);
extern void ToggleGrabKeyboard(Widget w, XEvent *ev, String *params,
Cardinal *num_params);
extern void listenForIncomingConnections();
extern void ToplevelInitBeforeRealization();
extern void ToplevelInitAfterRealization();
extern Time TimeFromEvent(XEvent *ev);
extern void Pause(Widget w, XEvent *event, String *params,
Cardinal *num_params);
extern void RunCommand(Widget w, XEvent *event, String *params,
Cardinal *num_params);
extern void Quit(Widget w, XEvent *event, String *params,
Cardinal *num_params);
extern void Cleanup();
extern Widget popup;
extern void ShowPopup(Widget w, XEvent *event, String *params,
Cardinal *num_params);
extern void HidePopup(Widget w, XEvent *event, String *params,
Cardinal *num_params);
extern void CreatePopup();
extern int rfbsock;
extern Bool canUseCoRRE;
extern Bool canUseHextile;
extern char *desktopName;
extern rfbPixelFormat myFormat;
extern rfbServerInitMsg si;
extern char *serverCutText;
extern Bool newServerCutText;
extern Bool ConnectToRFBServer(const char *hostname, int port);
extern Bool InitialiseRFBConnection();
extern Bool SetFormatAndEncodings();
extern Bool SendIncrementalFramebufferUpdateRequest();
extern Bool SendFramebufferUpdateRequest(int x, int y, int w, int h,
Bool incremental);
extern Bool SendPointerEvent(int x, int y, int buttonMask);
extern Bool SendKeyEvent(CARD32 key, Bool down);
extern Bool SendClientCutText(char *str, int len);
extern Bool HandleRFBServerMessage();
extern void PrintPixelFormat(rfbPixelFormat *format);
extern void InitialiseSelection();
extern void SelectionToVNC(Widget w, XEvent *event, String *params,
Cardinal *num_params);
extern void SelectionFromVNC(Widget w, XEvent *event, String *params,
Cardinal *num_params);
extern XImage *CreateShmImage();
extern void ShmCleanup();
extern Bool errorMessageOnReadFailure;
extern Bool vncLogTimeStamp;
extern Bool ReadFromRFBServer(char *out, unsigned int n);
extern Bool WriteExact(int sock, char *buf, int n);
extern int FindFreeTcpPort(void);
extern int ListenAtTcpPort(int port);
extern int ConnectToTcpAddr(unsigned int host, int port);
extern int AcceptTcpConnection(int listenSock);
extern Bool SetNonBlocking(int sock);
extern int StringToIPAddr(const char *str, unsigned int *addr);
extern Bool SameMachine(int sock);
extern Bool tunnelSpecified;
extern Bool createTunnel(int *argc, char **argv, int tunnelArgIndex);
extern char *programName;
extern XtAppContext appContext;
extern Display* dpy;
extern Widget toplevel;
extern FILE *vncLog;