Mercurial > hg > Applications > TightVNC_orginal
comparison src/main/java/com/glavsoft/rfb/protocol/state/HandshakeState.java @ 52:472a9bcacb21 draft default tip
TightVNC 2.7.1.0
author | you@cr.ie.u-ryukyu.ac.jp |
---|---|
date | Wed, 07 Aug 2013 19:01:17 +0900 |
parents | 4689cc86d6cb |
children |
comparison
equal
deleted
inserted
replaced
0:4689cc86d6cb | 52:472a9bcacb21 |
---|---|
1 // Copyright (C) 2010, 2011 GlavSoft LLC. | 1 // Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 //------------------------------------------------------------------------- | 4 //------------------------------------------------------------------------- |
5 // This file is part of the TightVNC software. Please visit our Web site: | 5 // This file is part of the TightVNC software. Please visit our Web site: |
6 // | 6 // |
26 | 26 |
27 import com.glavsoft.exceptions.TransportException; | 27 import com.glavsoft.exceptions.TransportException; |
28 import com.glavsoft.exceptions.UnsupportedProtocolVersionException; | 28 import com.glavsoft.exceptions.UnsupportedProtocolVersionException; |
29 import com.glavsoft.rfb.protocol.ProtocolContext; | 29 import com.glavsoft.rfb.protocol.ProtocolContext; |
30 | 30 |
31 import java.util.logging.Logger; | |
31 import java.util.regex.Matcher; | 32 import java.util.regex.Matcher; |
32 import java.util.regex.Pattern; | 33 import java.util.regex.Pattern; |
33 | 34 |
34 public class HandshakeState extends ProtocolState { | 35 public class HandshakeState extends ProtocolState { |
35 | 36 |
55 return true; | 56 return true; |
56 } | 57 } |
57 | 58 |
58 private void handshake() throws TransportException, UnsupportedProtocolVersionException { | 59 private void handshake() throws TransportException, UnsupportedProtocolVersionException { |
59 String protocolString = reader.readString(PROTOCOL_STRING_LENGTH); | 60 String protocolString = reader.readString(PROTOCOL_STRING_LENGTH); |
60 logger.info("Server sent protocol string: " + protocolString.substring(0, protocolString.length() - 1)); | 61 Logger.getLogger(getClass().getName()).info("Server sent protocol string: " + protocolString.substring(0, protocolString.length() - 1)); |
61 Pattern pattern = Pattern.compile(PROTOCOL_STRING_REGEXP); | 62 Pattern pattern = Pattern.compile(PROTOCOL_STRING_REGEXP); |
62 final Matcher matcher = pattern.matcher(protocolString); | 63 final Matcher matcher = pattern.matcher(protocolString); |
63 if ( ! matcher.matches()) | 64 if ( ! matcher.matches()) |
64 throw new UnsupportedProtocolVersionException( | 65 throw new UnsupportedProtocolVersionException( |
65 "Unsupported protocol version: " + protocolString); | 66 "Unsupported protocol version: " + protocolString); |
74 minor = MAX_SUPPORTED_VERSION_MINOR; | 75 minor = MAX_SUPPORTED_VERSION_MINOR; |
75 } | 76 } |
76 | 77 |
77 if (minor >= MIN_SUPPORTED_VERSION_MINOR && minor < 7) { | 78 if (minor >= MIN_SUPPORTED_VERSION_MINOR && minor < 7) { |
78 changeStateTo(new SecurityType33State(context)); | 79 changeStateTo(new SecurityType33State(context)); |
79 context.getSettings().setProtocolVersion(PROTOCOL_VERSION_3_3); | 80 context.setProtocolVersion(PROTOCOL_VERSION_3_3); |
80 minor = 3; | 81 minor = 3; |
81 } else if (7 == minor) { | 82 } else if (7 == minor) { |
82 changeStateTo(new SecurityType37State(context)); | 83 changeStateTo(new SecurityType37State(context)); |
83 context.getSettings().setProtocolVersion(PROTOCOL_VERSION_3_7); | 84 context.setProtocolVersion(PROTOCOL_VERSION_3_7); |
84 minor = 7; | 85 minor = 7; |
85 } else if (minor >= MAX_SUPPORTED_VERSION_MINOR) { | 86 } else if (minor >= MAX_SUPPORTED_VERSION_MINOR) { |
86 changeStateTo(new SecurityTypeState(context)); | 87 changeStateTo(new SecurityTypeState(context)); |
87 context.getSettings().setProtocolVersion(PROTOCOL_VERSION_3_8); | 88 context.setProtocolVersion(PROTOCOL_VERSION_3_8); |
88 minor = 8; | 89 minor = 8; |
89 } else | 90 } else |
90 throw new UnsupportedProtocolVersionException( | 91 throw new UnsupportedProtocolVersionException( |
91 "Unsupported protocol version: " + protocolString); | 92 "Unsupported protocol version: " + protocolString); |
92 writer.write(("RFB 00" + major + ".00" + minor + "\n").getBytes()); | 93 writer.write(("RFB 00" + major + ".00" + minor + "\n").getBytes()); |
93 logger.info("Set protocol version to: " + context.getSettings().getProtocolVersion()); | 94 Logger.getLogger(getClass().getName()).info("Set protocol version to: " + context.getProtocolVersion()); |
94 } | 95 } |
95 | 96 |
96 } | 97 } |