annotate src/RfbProto.java @ 1:cbe9c4ac0369

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