annotate src/RfbProto.java @ 2:498393e502bf

change Socket -> ServerSocket
author e085711
date Wed, 13 Apr 2011 07:37:37 +0900
parents cbe9c4ac0369
children 10dbc0e61adf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
2 // Copyright (C) 2001-2004 HorizonLive.com, Inc. All Rights Reserved.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
3 // Copyright (C) 2001-2006 Constantin Kaplinsky. All Rights Reserved.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
4 // Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
5 // Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
6 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
7 // This is free software; you can redistribute it and/or modify
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
8 // it under the terms of the GNU General Public License as published by
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
9 // the Free Software Foundation; either version 2 of the License, or
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
10 // (at your option) any later version.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
11 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
12 // This software is distributed in the hope that it will be useful,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
15 // GNU General Public License for more details.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
16 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
17 // You should have received a copy of the GNU General Public License
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
18 // along with this software; if not, write to the Free Software
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
20 // USA.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
21 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
22
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
23 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
24 // RfbProto.java
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
25 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
26
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
27 import java.io.*;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
28 import java.awt.*;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
29 import java.awt.event.*;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
30 import java.net.Socket;
2
498393e502bf change Socket -> ServerSocket
e085711
parents: 1
diff changeset
31 import java.net.ServerSocket;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
32 import java.util.zip.*;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
33 import java.nio.*;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
34
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
35 class RfbProto {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
36
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
37 final static String
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
38 versionMsg_3_3 = "RFB 003.003\n",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
39 versionMsg_3_7 = "RFB 003.007\n",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
40 versionMsg_3_8 = "RFB 003.008\n";
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
41
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
42 // Vendor signatures: standard VNC/RealVNC, TridiaVNC, and TightVNC
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
43 final static String
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
44 StandardVendor = "STDV",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
45 TridiaVncVendor = "TRDV",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
46 TightVncVendor = "TGHT";
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
47
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
48 // Security types
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
49 final static int
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
50 SecTypeInvalid = 0,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
51 SecTypeNone = 1,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
52 SecTypeVncAuth = 2,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
53 SecTypeTight = 16;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
54
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
55 // Supported tunneling types
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
56 final static int
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
57 NoTunneling = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
58 final static String
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
59 SigNoTunneling = "NOTUNNEL";
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
60
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
61 // Supported authentication types
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
62 final static int
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
63 AuthNone = 1,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
64 AuthVNC = 2,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
65 AuthUnixLogin = 129;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
66 final static String
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
67 SigAuthNone = "NOAUTH__",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
68 SigAuthVNC = "VNCAUTH_",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
69 SigAuthUnixLogin = "ULGNAUTH";
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
70
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
71 // VNC authentication results
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
72 final static int
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
73 VncAuthOK = 0,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
74 VncAuthFailed = 1,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
75 VncAuthTooMany = 2;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
76
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
77 // Standard server-to-client messages
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
78 final static int
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
79 FramebufferUpdate = 0,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
80 SetColourMapEntries = 1,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
81 Bell = 2,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
82 ServerCutText = 3;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
83
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
84 // Non-standard server-to-client messages
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
85 final static int
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
86 EndOfContinuousUpdates = 150;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
87 final static String
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
88 SigEndOfContinuousUpdates = "CUS_EOCU";
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
89
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
90 // Standard client-to-server messages
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
91 final static int
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
92 SetPixelFormat = 0,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
93 FixColourMapEntries = 1,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
94 SetEncodings = 2,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
95 FramebufferUpdateRequest = 3,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
96 KeyboardEvent = 4,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
97 PointerEvent = 5,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
98 ClientCutText = 6;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
99
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
100 // Non-standard client-to-server messages
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
101 final static int
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
102 EnableContinuousUpdates = 150;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
103 final static String
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
104 SigEnableContinuousUpdates = "CUC_ENCU";
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
105
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
106 // Supported encodings and pseudo-encodings
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
107 final static int
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
108 EncodingRaw = 0,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
109 EncodingCopyRect = 1,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
110 EncodingRRE = 2,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
111 EncodingCoRRE = 4,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
112 EncodingHextile = 5,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
113 EncodingZlib = 6,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
114 EncodingTight = 7,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
115 EncodingZRLE = 16,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
116 EncodingCompressLevel0 = 0xFFFFFF00,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
117 EncodingQualityLevel0 = 0xFFFFFFE0,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
118 EncodingXCursor = 0xFFFFFF10,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
119 EncodingRichCursor = 0xFFFFFF11,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
120 EncodingPointerPos = 0xFFFFFF18,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
121 EncodingLastRect = 0xFFFFFF20,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
122 EncodingNewFBSize = 0xFFFFFF21;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
123 final static String
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
124 SigEncodingRaw = "RAW_____",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
125 SigEncodingCopyRect = "COPYRECT",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
126 SigEncodingRRE = "RRE_____",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
127 SigEncodingCoRRE = "CORRE___",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
128 SigEncodingHextile = "HEXTILE_",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
129 SigEncodingZlib = "ZLIB____",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
130 SigEncodingTight = "TIGHT___",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
131 SigEncodingZRLE = "ZRLE____",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
132 SigEncodingCompressLevel0 = "COMPRLVL",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
133 SigEncodingQualityLevel0 = "JPEGQLVL",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
134 SigEncodingXCursor = "X11CURSR",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
135 SigEncodingRichCursor = "RCHCURSR",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
136 SigEncodingPointerPos = "POINTPOS",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
137 SigEncodingLastRect = "LASTRECT",
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
138 SigEncodingNewFBSize = "NEWFBSIZ";
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
139
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
140 final static int MaxNormalEncoding = 255;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
141
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
142 // Contstants used in the Hextile decoder
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
143 final static int
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
144 HextileRaw = 1,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
145 HextileBackgroundSpecified = 2,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
146 HextileForegroundSpecified = 4,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
147 HextileAnySubrects = 8,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
148 HextileSubrectsColoured = 16;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
149
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
150 // Contstants used in the Tight decoder
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
151 final static int TightMinToCompress = 12;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
152 final static int
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
153 TightExplicitFilter = 0x04,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
154 TightFill = 0x08,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
155 TightJpeg = 0x09,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
156 TightMaxSubencoding = 0x09,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
157 TightFilterCopy = 0x00,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
158 TightFilterPalette = 0x01,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
159 TightFilterGradient = 0x02;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
160
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
161
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
162 String host;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
163 int port;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
164 Socket sock;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
165 OutputStream os;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
166 SessionRecorder rec;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
167 boolean inNormalProtocol = false;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
168 VncViewer viewer;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
169
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
170 // Input stream is declared private to make sure it can be accessed
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
171 // only via RfbProto methods. We have to do this because we want to
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
172 // count how many bytes were read.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
173 private DataInputStream is;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
174 private long numBytesRead = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
175 public long getNumBytesRead() { return numBytesRead; }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
176
2
498393e502bf change Socket -> ServerSocket
e085711
parents: 1
diff changeset
177 boolean MYVNC=true;
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
178 Socket cliSock;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
179 ByteBuffer buffer;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
180 int rnBytes;
2
498393e502bf change Socket -> ServerSocket
e085711
parents: 1
diff changeset
181
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
182
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
183 // Java on UNIX does not call keyPressed() on some keys, for example
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
184 // swedish keys To prevent our workaround to produce duplicate
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
185 // keypresses on JVMs that actually works, keep track of if
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
186 // keyPressed() for a "broken" key was called or not.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
187 boolean brokenKeyPressed = false;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
188
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
189 // This will be set to true on the first framebuffer update
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
190 // containing Zlib-, ZRLE- or Tight-encoded data.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
191 boolean wereZlibUpdates = false;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
192
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
193 // This will be set to false if the startSession() was called after
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
194 // we have received at least one Zlib-, ZRLE- or Tight-encoded
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
195 // framebuffer update.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
196 boolean recordFromBeginning = true;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
197
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
198 // This fields are needed to show warnings about inefficiently saved
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
199 // sessions only once per each saved session file.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
200 boolean zlibWarningShown;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
201 boolean tightWarningShown;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
202
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
203 // Before starting to record each saved session, we set this field
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
204 // to 0, and increment on each framebuffer update. We don't flush
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
205 // the SessionRecorder data into the file before the second update.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
206 // This allows us to write initial framebuffer update with zero
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
207 // timestamp, to let the player show initial desktop before
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
208 // playback.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
209 int numUpdatesInSession;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
210
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
211 // Measuring network throughput.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
212 boolean timing;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
213 long timeWaitedIn100us;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
214 long timedKbits;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
215
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
216 // Protocol version and TightVNC-specific protocol options.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
217 int serverMajor, serverMinor;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
218 int clientMajor, clientMinor;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
219 boolean protocolTightVNC;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
220 CapsContainer tunnelCaps, authCaps;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
221 CapsContainer serverMsgCaps, clientMsgCaps;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
222 CapsContainer encodingCaps;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
223
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
224 // If true, informs that the RFB socket was closed.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
225 private boolean closed;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
226
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
227 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
228 // Constructor. Make TCP connection to RFB server.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
229 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
230
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
231 RfbProto(String h, int p, VncViewer v) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
232 viewer = v;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
233 host = h;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
234 port = p;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
235
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
236 if (viewer.socketFactory == null) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
237 sock = new Socket(host, port);
2
498393e502bf change Socket -> ServerSocket
e085711
parents: 1
diff changeset
238 if(MYVNC){
498393e502bf change Socket -> ServerSocket
e085711
parents: 1
diff changeset
239 ServerSocket serverSock = new ServerSocket(5550);
498393e502bf change Socket -> ServerSocket
e085711
parents: 1
diff changeset
240 cliSock = serverSock.accept();
0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
241 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
242
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
243 } else {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
244 try {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
245 Class factoryClass = Class.forName(viewer.socketFactory);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
246 SocketFactory factory = (SocketFactory)factoryClass.newInstance();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
247 if (viewer.inAnApplet)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
248 sock = factory.createSocket(host, port, viewer);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
249 else
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
250 sock = factory.createSocket(host, port, viewer.mainArgs);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
251 } catch(Exception e) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
252 e.printStackTrace();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
253 throw new IOException(e.getMessage());
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
254 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
255 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
256 is = new DataInputStream(new BufferedInputStream(sock.getInputStream(),
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
257 16384));
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
258 os = sock.getOutputStream();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
259
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
260 timing = false;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
261 timeWaitedIn100us = 5;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
262 timedKbits = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
263 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
264
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
265
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
266 synchronized void close() {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
267 try {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
268 sock.close();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
269 closed = true;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
270 System.out.println("RFB socket closed");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
271 if (rec != null) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
272 rec.close();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
273 rec = null;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
274 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
275 } catch (Exception e) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
276 e.printStackTrace();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
277 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
278 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
279
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
280 synchronized boolean closed() {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
281 return closed;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
282 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
283
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
284 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
285 // Read server's protocol version message
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
286 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
287
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
288 void readVersionMsg() throws Exception {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
289
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
290 byte[] b = new byte[12];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
291
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
292 readFully(b);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
293
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
294 if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ')
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
295 || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9')
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
296 || (b[6] < '0') || (b[6] > '9') || (b[7] != '.')
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
297 || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9')
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
298 || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n'))
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
299 {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
300 throw new Exception("Host " + host + " port " + port +
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
301 " is not an RFB server");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
302 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
303
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
304 serverMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0');
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
305 serverMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0');
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
306
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
307 if (serverMajor < 3) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
308 throw new Exception("RFB server does not support protocol version 3");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
309 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
310 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
311
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
312
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
313 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
314 // Write our protocol version message
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
315 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
316
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
317 void writeVersionMsg() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
318 clientMajor = 3;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
319 if (serverMajor > 3 || serverMinor >= 8) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
320 clientMinor = 8;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
321 os.write(versionMsg_3_8.getBytes());
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
322 } else if (serverMinor >= 7) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
323 clientMinor = 7;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
324 os.write(versionMsg_3_7.getBytes());
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
325 } else {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
326 clientMinor = 3;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
327 os.write(versionMsg_3_3.getBytes());
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
328 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
329 protocolTightVNC = false;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
330 initCapabilities();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
331 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
332
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
333
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
334 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
335 // Negotiate the authentication scheme.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
336 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
337
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
338 int negotiateSecurity() throws Exception {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
339 return (clientMinor >= 7) ?
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
340 selectSecurityType() : readSecurityType();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
341 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
342
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
343 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
344 // Read security type from the server (protocol version 3.3).
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
345 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
346
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
347 int readSecurityType() throws Exception {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
348 int secType = readU32();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
349
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
350 switch (secType) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
351 case SecTypeInvalid:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
352 readConnFailedReason();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
353 return SecTypeInvalid; // should never be executed
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
354 case SecTypeNone:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
355 case SecTypeVncAuth:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
356 return secType;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
357 default:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
358 throw new Exception("Unknown security type from RFB server: " + secType);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
359 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
360 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
361
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
362 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
363 // Select security type from the server's list (protocol versions 3.7/3.8).
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
364 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
365
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
366 int selectSecurityType() throws Exception {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
367 int secType = SecTypeInvalid;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
368
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
369 // Read the list of secutiry types.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
370 int nSecTypes = readU8();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
371 if (nSecTypes == 0) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
372 readConnFailedReason();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
373 return SecTypeInvalid; // should never be executed
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
374 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
375 byte[] secTypes = new byte[nSecTypes];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
376 readFully(secTypes);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
377
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
378 // Find out if the server supports TightVNC protocol extensions
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
379 for (int i = 0; i < nSecTypes; i++) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
380 if (secTypes[i] == SecTypeTight) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
381 protocolTightVNC = true;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
382 os.write(SecTypeTight);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
383 return SecTypeTight;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
384 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
385 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
386
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
387 // Find first supported security type.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
388 for (int i = 0; i < nSecTypes; i++) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
389 if (secTypes[i] == SecTypeNone || secTypes[i] == SecTypeVncAuth) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
390 secType = secTypes[i];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
391 break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
392 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
393 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
394
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
395 if (secType == SecTypeInvalid) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
396 throw new Exception("Server did not offer supported security type");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
397 } else {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
398 os.write(secType);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
399 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
400
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
401 return secType;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
402 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
403
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
404 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
405 // Perform "no authentication".
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
406 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
407
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
408 void authenticateNone() throws Exception {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
409 if (clientMinor >= 8)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
410 readSecurityResult("No authentication");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
411 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
412
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
413 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
414 // Perform standard VNC Authentication.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
415 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
416
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
417 void authenticateVNC(String pw) throws Exception {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
418 byte[] challenge = new byte[16];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
419 readFully(challenge);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
420
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
421 if (pw.length() > 8)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
422 pw = pw.substring(0, 8); // Truncate to 8 chars
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
423
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
424 // Truncate password on the first zero byte.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
425 int firstZero = pw.indexOf(0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
426 if (firstZero != -1)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
427 pw = pw.substring(0, firstZero);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
428
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
429 byte[] key = {0, 0, 0, 0, 0, 0, 0, 0};
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
430 System.arraycopy(pw.getBytes(), 0, key, 0, pw.length());
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
431
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
432 DesCipher des = new DesCipher(key);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
433
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
434 des.encrypt(challenge, 0, challenge, 0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
435 des.encrypt(challenge, 8, challenge, 8);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
436
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
437 os.write(challenge);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
438
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
439 readSecurityResult("VNC authentication");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
440 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
441
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
442 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
443 // Read security result.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
444 // Throws an exception on authentication failure.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
445 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
446
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
447 void readSecurityResult(String authType) throws Exception {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
448 int securityResult = readU32();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
449
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
450 switch (securityResult) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
451 case VncAuthOK:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
452 System.out.println(authType + ": success");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
453 break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
454 case VncAuthFailed:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
455 if (clientMinor >= 8)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
456 readConnFailedReason();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
457 throw new Exception(authType + ": failed");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
458 case VncAuthTooMany:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
459 throw new Exception(authType + ": failed, too many tries");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
460 default:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
461 throw new Exception(authType + ": unknown result " + securityResult);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
462 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
463 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
464
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
465 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
466 // Read the string describing the reason for a connection failure,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
467 // and throw an exception.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
468 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
469
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
470 void readConnFailedReason() throws Exception {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
471 int reasonLen = readU32();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
472 byte[] reason = new byte[reasonLen];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
473 readFully(reason);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
474 throw new Exception(new String(reason));
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
475 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
476
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
477 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
478 // Initialize capability lists (TightVNC protocol extensions).
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
479 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
480
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
481 void initCapabilities() {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
482 tunnelCaps = new CapsContainer();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
483 authCaps = new CapsContainer();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
484 serverMsgCaps = new CapsContainer();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
485 clientMsgCaps = new CapsContainer();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
486 encodingCaps = new CapsContainer();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
487
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
488 // Supported authentication methods
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
489 authCaps.add(AuthNone, StandardVendor, SigAuthNone,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
490 "No authentication");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
491 authCaps.add(AuthVNC, StandardVendor, SigAuthVNC,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
492 "Standard VNC password authentication");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
493
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
494 // Supported non-standard server-to-client messages
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
495 // [NONE]
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
496
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
497 // Supported non-standard client-to-server messages
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
498 // [NONE]
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
499
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
500 // Supported encoding types
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
501 encodingCaps.add(EncodingCopyRect, StandardVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
502 SigEncodingCopyRect, "Standard CopyRect encoding");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
503 encodingCaps.add(EncodingRRE, StandardVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
504 SigEncodingRRE, "Standard RRE encoding");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
505 encodingCaps.add(EncodingCoRRE, StandardVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
506 SigEncodingCoRRE, "Standard CoRRE encoding");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
507 encodingCaps.add(EncodingHextile, StandardVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
508 SigEncodingHextile, "Standard Hextile encoding");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
509 encodingCaps.add(EncodingZRLE, StandardVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
510 SigEncodingZRLE, "Standard ZRLE encoding");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
511 encodingCaps.add(EncodingZlib, TridiaVncVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
512 SigEncodingZlib, "Zlib encoding");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
513 encodingCaps.add(EncodingTight, TightVncVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
514 SigEncodingTight, "Tight encoding");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
515
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
516 // Supported pseudo-encoding types
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
517 encodingCaps.add(EncodingCompressLevel0, TightVncVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
518 SigEncodingCompressLevel0, "Compression level");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
519 encodingCaps.add(EncodingQualityLevel0, TightVncVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
520 SigEncodingQualityLevel0, "JPEG quality level");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
521 encodingCaps.add(EncodingXCursor, TightVncVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
522 SigEncodingXCursor, "X-style cursor shape update");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
523 encodingCaps.add(EncodingRichCursor, TightVncVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
524 SigEncodingRichCursor, "Rich-color cursor shape update");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
525 encodingCaps.add(EncodingPointerPos, TightVncVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
526 SigEncodingPointerPos, "Pointer position update");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
527 encodingCaps.add(EncodingLastRect, TightVncVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
528 SigEncodingLastRect, "LastRect protocol extension");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
529 encodingCaps.add(EncodingNewFBSize, TightVncVendor,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
530 SigEncodingNewFBSize, "Framebuffer size change");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
531 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
532
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
533 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
534 // Setup tunneling (TightVNC protocol extensions)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
535 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
536
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
537 void setupTunneling() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
538 int nTunnelTypes = readU32();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
539 if (nTunnelTypes != 0) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
540 readCapabilityList(tunnelCaps, nTunnelTypes);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
541
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
542 // We don't support tunneling yet.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
543 writeInt(NoTunneling);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
544 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
545 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
546
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
547 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
548 // Negotiate authentication scheme (TightVNC protocol extensions)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
549 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
550
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
551 int negotiateAuthenticationTight() throws Exception {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
552 int nAuthTypes = readU32();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
553 if (nAuthTypes == 0)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
554 return AuthNone;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
555
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
556 readCapabilityList(authCaps, nAuthTypes);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
557 for (int i = 0; i < authCaps.numEnabled(); i++) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
558 int authType = authCaps.getByOrder(i);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
559 if (authType == AuthNone || authType == AuthVNC) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
560 writeInt(authType);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
561 return authType;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
562 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
563 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
564 throw new Exception("No suitable authentication scheme found");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
565 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
566
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
567 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
568 // Read a capability list (TightVNC protocol extensions)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
569 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
570
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
571 void readCapabilityList(CapsContainer caps, int count) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
572 int code;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
573 byte[] vendor = new byte[4];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
574 byte[] name = new byte[8];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
575 for (int i = 0; i < count; i++) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
576 code = readU32();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
577 readFully(vendor);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
578 readFully(name);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
579 caps.enable(new CapabilityInfo(code, vendor, name));
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
580 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
581 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
582
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
583 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
584 // Write a 32-bit integer into the output stream.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
585 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
586
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
587 void writeInt(int value) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
588 byte[] b = new byte[4];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
589 b[0] = (byte) ((value >> 24) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
590 b[1] = (byte) ((value >> 16) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
591 b[2] = (byte) ((value >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
592 b[3] = (byte) (value & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
593 os.write(b);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
594 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
595
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
596 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
597 // Write the client initialisation message
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
598 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
599
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
600 void writeClientInit() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
601 if (viewer.options.shareDesktop) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
602 os.write(1);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
603 } else {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
604 os.write(0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
605 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
606 viewer.options.disableShareDesktop();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
607 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
608
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
609
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
610 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
611 // Read the server initialisation message
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
612 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
613
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
614 String desktopName;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
615 int framebufferWidth, framebufferHeight;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
616 int bitsPerPixel, depth;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
617 boolean bigEndian, trueColour;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
618 int redMax, greenMax, blueMax, redShift, greenShift, blueShift;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
619
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
620 void readServerInit() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
621 framebufferWidth = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
622 framebufferHeight = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
623 bitsPerPixel = readU8();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
624 depth = readU8();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
625 bigEndian = (readU8() != 0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
626 trueColour = (readU8() != 0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
627 redMax = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
628 greenMax = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
629 blueMax = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
630 redShift = readU8();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
631 greenShift = readU8();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
632 blueShift = readU8();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
633 byte[] pad = new byte[3];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
634 readFully(pad);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
635 int nameLength = readU32();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
636 byte[] name = new byte[nameLength];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
637 readFully(name);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
638 desktopName = new String(name);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
639
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
640 // Read interaction capabilities (TightVNC protocol extensions)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
641 if (protocolTightVNC) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
642 int nServerMessageTypes = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
643 int nClientMessageTypes = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
644 int nEncodingTypes = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
645 readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
646 readCapabilityList(serverMsgCaps, nServerMessageTypes);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
647 readCapabilityList(clientMsgCaps, nClientMessageTypes);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
648 readCapabilityList(encodingCaps, nEncodingTypes);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
649 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
650
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
651 inNormalProtocol = true;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
652 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
653
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
654
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
655 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
656 // Create session file and write initial protocol messages into it.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
657 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
658
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
659 void startSession(String fname) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
660 rec = new SessionRecorder(fname);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
661 rec.writeHeader();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
662 rec.write(versionMsg_3_3.getBytes());
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
663 rec.writeIntBE(SecTypeNone);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
664 rec.writeShortBE(framebufferWidth);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
665 rec.writeShortBE(framebufferHeight);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
666 byte[] fbsServerInitMsg = {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
667 32, 24, 0, 1, 0,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
668 (byte)0xFF, 0, (byte)0xFF, 0, (byte)0xFF,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
669 16, 8, 0, 0, 0, 0
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
670 };
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
671 rec.write(fbsServerInitMsg);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
672 rec.writeIntBE(desktopName.length());
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
673 rec.write(desktopName.getBytes());
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
674 numUpdatesInSession = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
675
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
676 // FIXME: If there were e.g. ZRLE updates only, that should not
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
677 // affect recording of Zlib and Tight updates. So, actually
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
678 // we should maintain separate flags for Zlib, ZRLE and
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
679 // Tight, instead of one ``wereZlibUpdates'' variable.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
680 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
681 if (wereZlibUpdates)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
682 recordFromBeginning = false;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
683
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
684 zlibWarningShown = false;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
685 tightWarningShown = false;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
686 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
687
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
688 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
689 // Close session file.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
690 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
691
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
692 void closeSession() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
693 if (rec != null) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
694 rec.close();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
695 rec = null;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
696 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
697 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
698
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
699
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
700 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
701 // Set new framebuffer size
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
702 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
703
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
704 void setFramebufferSize(int width, int height) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
705 framebufferWidth = width;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
706 framebufferHeight = height;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
707 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
708
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
709
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
710 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
711 // Read the server message type
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
712 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
713
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
714 int readServerMessageType() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
715 int msgType = readU8();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
716
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
717 // If the session is being recorded:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
718 if (rec != null) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
719 if (msgType == Bell) { // Save Bell messages in session files.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
720 rec.writeByte(msgType);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
721 if (numUpdatesInSession > 0)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
722 rec.flush();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
723 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
724 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
725
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
726 return msgType;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
727 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
728
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
729
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
730 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
731 // Read a FramebufferUpdate message
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
732 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
733
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
734 int updateNRects;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
735
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
736 void readFramebufferUpdate() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
737 skipBytes(1);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
738 updateNRects = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
739 // System.out.println(updateNRects);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
740
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
741 // If the session is being recorded:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
742 if (rec != null) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
743 rec.writeByte(FramebufferUpdate);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
744 rec.writeByte(0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
745 rec.writeShortBE(updateNRects);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
746 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
747
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
748 numUpdatesInSession++;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
749 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
750
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
751 // Read a FramebufferUpdate rectangle header
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
752
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
753 int updateRectX, updateRectY, updateRectW, updateRectH, updateRectEncoding;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
754
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
755 void readFramebufferUpdateRectHdr() throws Exception {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
756 updateRectX = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
757 updateRectY = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
758 updateRectW = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
759 updateRectH = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
760 updateRectEncoding = readU32();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
761 // System.out.println("readU16&32");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
762
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
763 if (updateRectEncoding == EncodingZlib ||
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
764 updateRectEncoding == EncodingZRLE ||
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
765 updateRectEncoding == EncodingTight)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
766 wereZlibUpdates = true;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
767
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
768 // If the session is being recorded:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
769 if (rec != null) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
770 if (numUpdatesInSession > 1)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
771 rec.flush(); // Flush the output on each rectangle.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
772 rec.writeShortBE(updateRectX);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
773 rec.writeShortBE(updateRectY);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
774 rec.writeShortBE(updateRectW);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
775 rec.writeShortBE(updateRectH);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
776 if (updateRectEncoding == EncodingZlib && !recordFromBeginning) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
777 // Here we cannot write Zlib-encoded rectangles because the
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
778 // decoder won't be able to reproduce zlib stream state.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
779 if (!zlibWarningShown) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
780 System.out.println("Warning: Raw encoding will be used " +
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
781 "instead of Zlib in recorded session.");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
782 zlibWarningShown = true;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
783 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
784 rec.writeIntBE(EncodingRaw);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
785 } else {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
786 rec.writeIntBE(updateRectEncoding);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
787 if (updateRectEncoding == EncodingTight && !recordFromBeginning &&
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
788 !tightWarningShown) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
789 System.out.println("Warning: Re-compressing Tight-encoded " +
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
790 "updates for session recording.");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
791 tightWarningShown = true;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
792 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
793 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
794 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
795
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
796 if (updateRectEncoding < 0 || updateRectEncoding > MaxNormalEncoding)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
797 return;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
798
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
799 if (updateRectX + updateRectW > framebufferWidth ||
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
800 updateRectY + updateRectH > framebufferHeight) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
801 throw new Exception("Framebuffer update rectangle too large: " +
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
802 updateRectW + "x" + updateRectH + " at (" +
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
803 updateRectX + "," + updateRectY + ")");
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
804 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
805 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
806
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
807 // Read CopyRect source X and Y.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
808
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
809 int copyRectSrcX, copyRectSrcY;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
810
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
811 void readCopyRect() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
812 copyRectSrcX = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
813 copyRectSrcY = readU16();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
814
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
815 // If the session is being recorded:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
816 if (rec != null) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
817 rec.writeShortBE(copyRectSrcX);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
818 rec.writeShortBE(copyRectSrcY);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
819 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
820 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
821
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
822
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
823 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
824 // Read a ServerCutText message
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
825 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
826
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
827 String readServerCutText() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
828 skipBytes(3);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
829 int len = readU32();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
830 byte[] text = new byte[len];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
831 readFully(text);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
832 return new String(text);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
833 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
834
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
835
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
836 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
837 // Read an integer in compact representation (1..3 bytes).
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
838 // Such format is used as a part of the Tight encoding.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
839 // Also, this method records data if session recording is active and
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
840 // the viewer's recordFromBeginning variable is set to true.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
841 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
842
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
843 int readCompactLen() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
844 int[] portion = new int[3];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
845 portion[0] = readU8();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
846 int byteCount = 1;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
847 int len = portion[0] & 0x7F;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
848 if ((portion[0] & 0x80) != 0) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
849 portion[1] = readU8();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
850 byteCount++;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
851 len |= (portion[1] & 0x7F) << 7;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
852 if ((portion[1] & 0x80) != 0) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
853 portion[2] = readU8();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
854 byteCount++;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
855 len |= (portion[2] & 0xFF) << 14;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
856 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
857 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
858
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
859 if (rec != null && recordFromBeginning)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
860 for (int i = 0; i < byteCount; i++)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
861 rec.writeByte(portion[i]);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
862
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
863 return len;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
864 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
865
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
866
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
867 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
868 // Write a FramebufferUpdateRequest message
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
869 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
870
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
871 void writeFramebufferUpdateRequest(int x, int y, int w, int h,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
872 boolean incremental)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
873 throws IOException
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
874 {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
875 byte[] b = new byte[10];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
876
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
877 b[0] = (byte) FramebufferUpdateRequest;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
878 b[1] = (byte) (incremental ? 1 : 0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
879 b[2] = (byte) ((x >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
880 b[3] = (byte) (x & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
881 b[4] = (byte) ((y >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
882 b[5] = (byte) (y & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
883 b[6] = (byte) ((w >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
884 b[7] = (byte) (w & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
885 b[8] = (byte) ((h >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
886 b[9] = (byte) (h & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
887
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
888 os.write(b);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
889 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
890
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
891
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
892 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
893 // Write a SetPixelFormat message
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
894 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
895
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
896 void writeSetPixelFormat(int bitsPerPixel, int depth, boolean bigEndian,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
897 boolean trueColour,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
898 int redMax, int greenMax, int blueMax,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
899 int redShift, int greenShift, int blueShift)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
900 throws IOException
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
901 {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
902 byte[] b = new byte[20];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
903
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
904 b[0] = (byte) SetPixelFormat;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
905 b[4] = (byte) bitsPerPixel;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
906 b[5] = (byte) depth;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
907 b[6] = (byte) (bigEndian ? 1 : 0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
908 b[7] = (byte) (trueColour ? 1 : 0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
909 b[8] = (byte) ((redMax >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
910 b[9] = (byte) (redMax & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
911 b[10] = (byte) ((greenMax >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
912 b[11] = (byte) (greenMax & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
913 b[12] = (byte) ((blueMax >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
914 b[13] = (byte) (blueMax & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
915 b[14] = (byte) redShift;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
916 b[15] = (byte) greenShift;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
917 b[16] = (byte) blueShift;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
918
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
919 os.write(b);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
920 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
921
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
922
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
923 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
924 // Write a FixColourMapEntries message. The values in the red, green and
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
925 // blue arrays are from 0 to 65535.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
926 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
927
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
928 void writeFixColourMapEntries(int firstColour, int nColours,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
929 int[] red, int[] green, int[] blue)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
930 throws IOException
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
931 {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
932 byte[] b = new byte[6 + nColours * 6];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
933
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
934 b[0] = (byte) FixColourMapEntries;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
935 b[2] = (byte) ((firstColour >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
936 b[3] = (byte) (firstColour & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
937 b[4] = (byte) ((nColours >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
938 b[5] = (byte) (nColours & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
939
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
940 for (int i = 0; i < nColours; i++) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
941 b[6 + i * 6] = (byte) ((red[i] >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
942 b[6 + i * 6 + 1] = (byte) (red[i] & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
943 b[6 + i * 6 + 2] = (byte) ((green[i] >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
944 b[6 + i * 6 + 3] = (byte) (green[i] & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
945 b[6 + i * 6 + 4] = (byte) ((blue[i] >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
946 b[6 + i * 6 + 5] = (byte) (blue[i] & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
947 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
948
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
949 os.write(b);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
950 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
951
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
952
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
953 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
954 // Write a SetEncodings message
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
955 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
956
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
957 void writeSetEncodings(int[] encs, int len) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
958 byte[] b = new byte[4 + 4 * len];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
959
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
960 b[0] = (byte) SetEncodings;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
961 b[2] = (byte) ((len >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
962 b[3] = (byte) (len & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
963
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
964 for (int i = 0; i < len; i++) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
965 b[4 + 4 * i] = (byte) ((encs[i] >> 24) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
966 b[5 + 4 * i] = (byte) ((encs[i] >> 16) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
967 b[6 + 4 * i] = (byte) ((encs[i] >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
968 b[7 + 4 * i] = (byte) (encs[i] & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
969 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
970
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
971 os.write(b);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
972 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
973
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
974
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
975 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
976 // Write a ClientCutText message
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
977 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
978
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
979 void writeClientCutText(String text) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
980 byte[] b = new byte[8 + text.length()];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
981
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
982 b[0] = (byte) ClientCutText;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
983 b[4] = (byte) ((text.length() >> 24) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
984 b[5] = (byte) ((text.length() >> 16) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
985 b[6] = (byte) ((text.length() >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
986 b[7] = (byte) (text.length() & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
987
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
988 System.arraycopy(text.getBytes(), 0, b, 8, text.length());
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
989
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
990 os.write(b);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
991 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
992
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
993
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
994 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
995 // A buffer for putting pointer and keyboard events before being sent. This
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
996 // is to ensure that multiple RFB events generated from a single Java Event
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
997 // will all be sent in a single network packet. The maximum possible
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
998 // length is 4 modifier down events, a single key event followed by 4
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
999 // modifier up events i.e. 9 key events or 72 bytes.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1000 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1001
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1002 byte[] eventBuf = new byte[72];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1003 int eventBufLen;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1004
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1005
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1006 // Useful shortcuts for modifier masks.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1007
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1008 final static int CTRL_MASK = InputEvent.CTRL_MASK;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1009 final static int SHIFT_MASK = InputEvent.SHIFT_MASK;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1010 final static int META_MASK = InputEvent.META_MASK;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1011 final static int ALT_MASK = InputEvent.ALT_MASK;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1012
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1013
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1014 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1015 // Write a pointer event message. We may need to send modifier key events
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1016 // around it to set the correct modifier state.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1017 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1018
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1019 int pointerMask = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1020
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1021 void writePointerEvent(MouseEvent evt) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1022 int modifiers = evt.getModifiers();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1023
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1024 int mask2 = 2;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1025 int mask3 = 4;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1026 if (viewer.options.reverseMouseButtons2And3) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1027 mask2 = 4;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1028 mask3 = 2;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1029 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1030
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1031 // Note: For some reason, AWT does not set BUTTON1_MASK on left
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1032 // button presses. Here we think that it was the left button if
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1033 // modifiers do not include BUTTON2_MASK or BUTTON3_MASK.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1034
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1035 if (evt.getID() == MouseEvent.MOUSE_PRESSED) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1036 if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1037 pointerMask = mask2;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1038 modifiers &= ~ALT_MASK;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1039 } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1040 pointerMask = mask3;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1041 modifiers &= ~META_MASK;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1042 } else {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1043 pointerMask = 1;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1044 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1045 } else if (evt.getID() == MouseEvent.MOUSE_RELEASED) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1046 pointerMask = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1047 if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1048 modifiers &= ~ALT_MASK;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1049 } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1050 modifiers &= ~META_MASK;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1051 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1052 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1053
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1054 eventBufLen = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1055 writeModifierKeyEvents(modifiers);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1056
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1057 int x = evt.getX();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1058 int y = evt.getY();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1059
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1060 if (x < 0) x = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1061 if (y < 0) y = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1062
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1063 eventBuf[eventBufLen++] = (byte) PointerEvent;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1064 eventBuf[eventBufLen++] = (byte) pointerMask;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1065 eventBuf[eventBufLen++] = (byte) ((x >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1066 eventBuf[eventBufLen++] = (byte) (x & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1067 eventBuf[eventBufLen++] = (byte) ((y >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1068 eventBuf[eventBufLen++] = (byte) (y & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1069
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1070 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1071 // Always release all modifiers after an "up" event
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1072 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1073
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1074 if (pointerMask == 0) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1075 writeModifierKeyEvents(0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1076 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1077
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1078 os.write(eventBuf, 0, eventBufLen);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1079 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1080
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1081
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1082 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1083 // Write a key event message. We may need to send modifier key events
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1084 // around it to set the correct modifier state. Also we need to translate
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1085 // from the Java key values to the X keysym values used by the RFB protocol.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1086 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1087
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1088 void writeKeyEvent(KeyEvent evt) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1089
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1090 int keyChar = evt.getKeyChar();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1091
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1092 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1093 // Ignore event if only modifiers were pressed.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1094 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1095
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1096 // Some JVMs return 0 instead of CHAR_UNDEFINED in getKeyChar().
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1097 if (keyChar == 0)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1098 keyChar = KeyEvent.CHAR_UNDEFINED;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1099
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1100 if (keyChar == KeyEvent.CHAR_UNDEFINED) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1101 int code = evt.getKeyCode();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1102 if (code == KeyEvent.VK_CONTROL || code == KeyEvent.VK_SHIFT ||
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1103 code == KeyEvent.VK_META || code == KeyEvent.VK_ALT)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1104 return;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1105 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1106
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1107 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1108 // Key press or key release?
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1109 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1110
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1111 boolean down = (evt.getID() == KeyEvent.KEY_PRESSED);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1112
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1113 int key;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1114 if (evt.isActionKey()) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1115
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1116 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1117 // An action key should be one of the following.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1118 // If not then just ignore the event.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1119 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1120
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1121 switch(evt.getKeyCode()) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1122 case KeyEvent.VK_HOME: key = 0xff50; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1123 case KeyEvent.VK_LEFT: key = 0xff51; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1124 case KeyEvent.VK_UP: key = 0xff52; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1125 case KeyEvent.VK_RIGHT: key = 0xff53; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1126 case KeyEvent.VK_DOWN: key = 0xff54; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1127 case KeyEvent.VK_PAGE_UP: key = 0xff55; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1128 case KeyEvent.VK_PAGE_DOWN: key = 0xff56; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1129 case KeyEvent.VK_END: key = 0xff57; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1130 case KeyEvent.VK_INSERT: key = 0xff63; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1131 case KeyEvent.VK_F1: key = 0xffbe; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1132 case KeyEvent.VK_F2: key = 0xffbf; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1133 case KeyEvent.VK_F3: key = 0xffc0; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1134 case KeyEvent.VK_F4: key = 0xffc1; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1135 case KeyEvent.VK_F5: key = 0xffc2; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1136 case KeyEvent.VK_F6: key = 0xffc3; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1137 case KeyEvent.VK_F7: key = 0xffc4; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1138 case KeyEvent.VK_F8: key = 0xffc5; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1139 case KeyEvent.VK_F9: key = 0xffc6; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1140 case KeyEvent.VK_F10: key = 0xffc7; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1141 case KeyEvent.VK_F11: key = 0xffc8; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1142 case KeyEvent.VK_F12: key = 0xffc9; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1143 default:
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1144 return;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1145 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1146
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1147 } else {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1148
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1149 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1150 // A "normal" key press. Ordinary ASCII characters go straight through.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1151 // For CTRL-<letter>, CTRL is sent separately so just send <letter>.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1152 // Backspace, tab, return, escape and delete have special keysyms.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1153 // Anything else we ignore.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1154 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1155
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1156 key = keyChar;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1157
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1158 if (key < 0x20) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1159 if (evt.isControlDown()) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1160 key += 0x60;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1161 } else {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1162 switch(key) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1163 case KeyEvent.VK_BACK_SPACE: key = 0xff08; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1164 case KeyEvent.VK_TAB: key = 0xff09; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1165 case KeyEvent.VK_ENTER: key = 0xff0d; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1166 case KeyEvent.VK_ESCAPE: key = 0xff1b; break;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1167 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1168 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1169 } else if (key == 0x7f) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1170 // Delete
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1171 key = 0xffff;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1172 } else if (key > 0xff) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1173 // JDK1.1 on X incorrectly passes some keysyms straight through,
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1174 // so we do too. JDK1.1.4 seems to have fixed this.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1175 // The keysyms passed are 0xff00 .. XK_BackSpace .. XK_Delete
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1176 // Also, we pass through foreign currency keysyms (0x20a0..0x20af).
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1177 if ((key < 0xff00 || key > 0xffff) &&
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1178 !(key >= 0x20a0 && key <= 0x20af))
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1179 return;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1180 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1181 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1182
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1183 // Fake keyPresses for keys that only generates keyRelease events
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1184 if ((key == 0xe5) || (key == 0xc5) || // XK_aring / XK_Aring
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1185 (key == 0xe4) || (key == 0xc4) || // XK_adiaeresis / XK_Adiaeresis
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1186 (key == 0xf6) || (key == 0xd6) || // XK_odiaeresis / XK_Odiaeresis
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1187 (key == 0xa7) || (key == 0xbd) || // XK_section / XK_onehalf
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1188 (key == 0xa3)) { // XK_sterling
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1189 // Make sure we do not send keypress events twice on platforms
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1190 // with correct JVMs (those that actually report KeyPress for all
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1191 // keys)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1192 if (down)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1193 brokenKeyPressed = true;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1194
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1195 if (!down && !brokenKeyPressed) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1196 // We've got a release event for this key, but haven't received
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1197 // a press. Fake it.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1198 eventBufLen = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1199 writeModifierKeyEvents(evt.getModifiers());
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1200 writeKeyEvent(key, true);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1201 os.write(eventBuf, 0, eventBufLen);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1202 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1203
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1204 if (!down)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1205 brokenKeyPressed = false;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1206 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1207
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1208 eventBufLen = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1209 writeModifierKeyEvents(evt.getModifiers());
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1210 writeKeyEvent(key, down);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1211
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1212 // Always release all modifiers after an "up" event
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1213 if (!down)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1214 writeModifierKeyEvents(0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1215
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1216 os.write(eventBuf, 0, eventBufLen);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1217 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1218
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1219
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1220 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1221 // Add a raw key event with the given X keysym to eventBuf.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1222 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1223
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1224 void writeKeyEvent(int keysym, boolean down) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1225 eventBuf[eventBufLen++] = (byte) KeyboardEvent;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1226 eventBuf[eventBufLen++] = (byte) (down ? 1 : 0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1227 eventBuf[eventBufLen++] = (byte) 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1228 eventBuf[eventBufLen++] = (byte) 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1229 eventBuf[eventBufLen++] = (byte) ((keysym >> 24) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1230 eventBuf[eventBufLen++] = (byte) ((keysym >> 16) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1231 eventBuf[eventBufLen++] = (byte) ((keysym >> 8) & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1232 eventBuf[eventBufLen++] = (byte) (keysym & 0xff);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1233 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1234
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1235
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1236 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1237 // Write key events to set the correct modifier state.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1238 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1239
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1240 int oldModifiers = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1241
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1242 void writeModifierKeyEvents(int newModifiers) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1243 if ((newModifiers & CTRL_MASK) != (oldModifiers & CTRL_MASK))
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1244 writeKeyEvent(0xffe3, (newModifiers & CTRL_MASK) != 0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1245
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1246 if ((newModifiers & SHIFT_MASK) != (oldModifiers & SHIFT_MASK))
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1247 writeKeyEvent(0xffe1, (newModifiers & SHIFT_MASK) != 0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1248
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1249 if ((newModifiers & META_MASK) != (oldModifiers & META_MASK))
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1250 writeKeyEvent(0xffe7, (newModifiers & META_MASK) != 0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1251
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1252 if ((newModifiers & ALT_MASK) != (oldModifiers & ALT_MASK))
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1253 writeKeyEvent(0xffe9, (newModifiers & ALT_MASK) != 0);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1254
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1255 oldModifiers = newModifiers;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1256 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1257
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1258 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1259 // Compress and write the data into the recorded session file. This
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1260 // method assumes the recording is on (rec != null).
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1261 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1262
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1263 void recordCompressedData(byte[] data, int off, int len) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1264 Deflater deflater = new Deflater();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1265 deflater.setInput(data, off, len);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1266 int bufSize = len + len / 100 + 12;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1267 byte[] buf = new byte[bufSize];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1268 deflater.finish();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1269 int compressedSize = deflater.deflate(buf);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1270 recordCompactLen(compressedSize);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1271 rec.write(buf, 0, compressedSize);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1272 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1273
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1274 void recordCompressedData(byte[] data) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1275 recordCompressedData(data, 0, data.length);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1276 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1277
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1278 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1279 // Write an integer in compact representation (1..3 bytes) into the
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1280 // recorded session file. This method assumes the recording is on
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1281 // (rec != null).
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1282 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1283
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1284 void recordCompactLen(int len) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1285 byte[] buf = new byte[3];
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1286 int bytes = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1287 buf[bytes++] = (byte)(len & 0x7F);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1288 if (len > 0x7F) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1289 buf[bytes-1] |= 0x80;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1290 buf[bytes++] = (byte)(len >> 7 & 0x7F);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1291 if (len > 0x3FFF) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1292 buf[bytes-1] |= 0x80;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1293 buf[bytes++] = (byte)(len >> 14 & 0xFF);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1294 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1295 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1296 rec.write(buf, 0, bytes);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1297 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1298
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1299 public void startTiming() {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1300 timing = true;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1301
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1302 // Carry over up to 1s worth of previous rate for smoothing.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1303
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1304 if (timeWaitedIn100us > 10000) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1305 timedKbits = timedKbits * 10000 / timeWaitedIn100us;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1306 timeWaitedIn100us = 10000;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1307 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1308 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1309
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1310 public void stopTiming() {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1311 timing = false;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1312 if (timeWaitedIn100us < timedKbits/2)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1313 timeWaitedIn100us = timedKbits/2; // upper limit 20Mbit/s
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1314 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1315
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1316 public long kbitsPerSecond() {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1317 return timedKbits * 10000 / timeWaitedIn100us;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1318 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1319
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1320 public long timeWaited() {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1321 return timeWaitedIn100us;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1322 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1323
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1324 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1325 // Methods for reading data via our DataInputStream member variable (is).
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1326 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1327 // In addition to reading data, the readFully() methods updates variables
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1328 // used to estimate data throughput.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1329 //
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1330
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1331 public void readFully(byte b[]) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1332 readFully(b, 0, b.length);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1333 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1334
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1335 public void readFully(byte b[], int off, int len) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1336 long before = 0;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1337 if (timing)
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1338 before = System.currentTimeMillis();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1339
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1340 is.readFully(b, off, len);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1341
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1342 if (timing) {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1343 long after = System.currentTimeMillis();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1344 long newTimeWaited = (after - before) * 10;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1345 int newKbits = len * 8 / 1000;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1346
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1347 // limit rate to between 10kbit/s and 40Mbit/s
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1348
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1349 if (newTimeWaited > newKbits*1000) newTimeWaited = newKbits*1000;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1350 if (newTimeWaited < newKbits/4) newTimeWaited = newKbits/4;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1351
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1352 timeWaitedIn100us += newTimeWaited;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1353 timedKbits += newKbits;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1354 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1355
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1356 numBytesRead += len;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1357 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1358
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1359 final int available() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1360 return is.available();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1361 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1362
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1363 // FIXME: DataInputStream::skipBytes() is not guaranteed to skip
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1364 // exactly n bytes. Probably we don't want to use this method.
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1365 final int skipBytes(int n) throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1366 int r = is.skipBytes(n);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1367 numBytesRead += r;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1368 return r;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1369 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1370
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1371 final int readU8() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1372 int r = is.readUnsignedByte();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1373 numBytesRead++;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1374
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1375 return r;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1376 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1377
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1378 final int readU16() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1379 int r = is.readUnsignedShort();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1380 numBytesRead += 2;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1381 return r;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1382 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1383
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1384 final int readU32() throws IOException {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1385 int r = is.readInt();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1386 numBytesRead += 4;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1387 return r;
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1388 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1389 void mark(int len) throws IOException{
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1390 is.mark(len);
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1391 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1392 void reset() throws IOException{
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1393 is.reset();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1394 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1395 final boolean markSupported() {
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1396 return is.markSupported();
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1397 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1398 }
30bb7074acb1 upload all file of tighVNCProxy
e085711
parents:
diff changeset
1399