diff options
author | Brian Hinz <bphinz@users.sourceforge.net> | 2012-03-18 21:39:04 +0000 |
---|---|---|
committer | Brian Hinz <bphinz@users.sourceforge.net> | 2012-03-18 21:39:04 +0000 |
commit | 35022e07a90807f5f0686c146e49f469d4b3f2fd (patch) | |
tree | 9734715a7e8f83eb7c6d31867e5cef7e7be0f5e8 /java/com/tigervnc/rfb/CConnection.java | |
parent | ef41e92001036029284c7bcfb6a9249cc2008a87 (diff) | |
download | tigervnc-35022e07a90807f5f0686c146e49f469d4b3f2fd.tar.gz tigervnc-35022e07a90807f5f0686c146e49f469d4b3f2fd.zip |
Changes aimed at making the behavior of the java client more consistent with the binary client.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4871 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'java/com/tigervnc/rfb/CConnection.java')
-rw-r--r-- | java/com/tigervnc/rfb/CConnection.java | 138 |
1 files changed, 89 insertions, 49 deletions
diff --git a/java/com/tigervnc/rfb/CConnection.java b/java/com/tigervnc/rfb/CConnection.java index 0ec44044..1e55f043 100644 --- a/java/com/tigervnc/rfb/CConnection.java +++ b/java/com/tigervnc/rfb/CConnection.java @@ -25,31 +25,37 @@ import com.tigervnc.rdr.*; abstract public class CConnection extends CMsgHandler { - public CConnection() { + public CConnection() + { + csecurity = null; is = null; os = null; reader_ = null; + writer_ = null; shared = false; + state_ = RFBSTATE_UNINITIALISED; useProtocol3_3 = false; security = new SecurityClient(); } - // setStreams() sets the streams to be used for the connection. These must - // be set before initialiseProtocol() and processMsg() are called. The - // CSecurity object may call setStreams() again to provide alternative - // streams over which the RFB protocol is sent (i.e. encrypting/decrypting - // streams). Ownership of the streams remains with the caller - // (i.e. SConnection will not delete them). - public void setStreams(InStream is_, OutStream os_) { - is = is_; - os = os_; + // deleteReaderAndWriter() deletes the reader and writer associated with + // this connection. This may be useful if you want to delete the streams + // before deleting the SConnection to make sure that no attempt by the + // SConnection is made to read or write. + // XXX Do we really need this at all??? + public void deleteReaderAndWriter() + { + reader_ = null; + writer_ = null; } // initialiseProtocol() should be called once the streams and security // types are set. Subsequently, processMsg() should be called whenever // there is data to read on the InStream. - public void initialiseProtocol() { + public final void initialiseProtocol() + { state_ = RFBSTATE_PROTOCOL_VERSION; } // processMsg() should be called whenever there is data to read on the // InStream. You must have called initialiseProtocol() first. - public void processMsg() { + public void processMsg() + { switch (state_) { case RFBSTATE_PROTOCOL_VERSION: processVersionMsg(); break; @@ -65,7 +71,8 @@ abstract public class CConnection extends CMsgHandler { } } - private void processVersionMsg() { + private void processVersionMsg() + { vlog.debug("reading protocol version"); Boolean done = new Boolean(true); if (!cp.readVersion(is, done)) { @@ -74,8 +81,8 @@ abstract public class CConnection extends CMsgHandler { } if (!done.booleanValue()) return; - vlog.info("Server supports RFB protocol version "+cp.majorVersion+"."+ - cp.minorVersion); + vlog.info("Server supports RFB protocol version " + +cp.majorVersion+"."+ cp.minorVersion); // The only official RFB protocol versions are currently 3.3, 3.7 and 3.8 if (cp.beforeVersion(3,3)) { @@ -97,15 +104,14 @@ abstract public class CConnection extends CMsgHandler { cp.majorVersion+"."+cp.minorVersion); } - private void processSecurityTypesMsg() { - vlog.info("processing security types message"); + private void processSecurityTypesMsg() + { + vlog.debug("processing security types message"); int secType = Security.secTypeInvalid; List<Integer> secTypes = new ArrayList<Integer>(); secTypes = Security.GetEnabledSecTypes(); - //for (Iterator i = secTypes.iterator(); i.hasNext(); ) - // vlog.info(((Integer)i.next()).toString()); if (cp.isVersion(3,3)) { @@ -123,10 +129,10 @@ abstract public class CConnection extends CMsgHandler { secType = refType; break; } - if (!i.hasNext()) - secType = Security.secTypeInvalid; } + if (!secTypes.contains(secType)) + secType = Security.secTypeInvalid; } else { vlog.error("Unknown 3.3 security type "+secType); throw new Exception("Unknown 3.3 security type"); @@ -140,9 +146,11 @@ abstract public class CConnection extends CMsgHandler { if (nServerSecTypes == 0) throwConnFailedException(); + Iterator j; + for (int i = 0; i < nServerSecTypes; i++) { int serverSecType = is.readU8(); - vlog.info("Server offers security type "+ + vlog.debug("Server offers security type "+ Security.secTypeName(serverSecType)+"("+serverSecType+")"); /* @@ -150,7 +158,7 @@ abstract public class CConnection extends CMsgHandler { * It means server's order specifies priority. */ if (secType == Security.secTypeInvalid) { - for (Iterator j = secTypes.iterator(); j.hasNext(); ) { + for (j = secTypes.iterator(); j.hasNext(); ) { int refType = (Integer)j.next(); if (refType == serverSecType) { secType = refType; @@ -164,7 +172,7 @@ abstract public class CConnection extends CMsgHandler { if (secType != Security.secTypeInvalid) { os.writeU8(secType); os.flush(); - vlog.info("Choosing security type "+Security.secTypeName(secType)+ + vlog.debug("Choosing security type "+Security.secTypeName(secType)+ "("+secType+")"); } } @@ -246,10 +254,30 @@ abstract public class CConnection extends CMsgHandler { // which we are connected. This might be the result of getPeerEndpoint on // a TcpSocket, for example, or a host specified by DNS name & port. // The serverName is used when verifying the Identity of a host (see RA2). - public void setServerName(String name) { + public final void setServerName(String name) { serverName = name; } + // setStreams() sets the streams to be used for the connection. These must + // be set before initialiseProtocol() and processMsg() are called. The + // CSecurity object may call setStreams() again to provide alternative + // streams over which the RFB protocol is sent (i.e. encrypting/decrypting + // streams). Ownership of the streams remains with the caller + // (i.e. SConnection will not delete them). + public final void setStreams(InStream is_, OutStream os_) + { + is = is_; + os = os_; + } + + // setShared sets the value of the shared flag which will be sent to the + // server upon initialisation. + public final void setShared(boolean s) { shared = s; } + + // setProtocol3_3 configures whether or not the CConnection should + // only ever support protocol version 3.3 + public final void setProtocol3_3(boolean s) { useProtocol3_3 = s; } + public void setServerPort(int port) { serverPort = port; } @@ -258,15 +286,22 @@ abstract public class CConnection extends CMsgHandler { nSecTypes = 0; } - // setShared sets the value of the shared flag which will be sent to the - // server upon initialisation. - public void setShared(boolean s) { shared = s; } + // Methods to be overridden in a derived class - // setProtocol3_3 configures whether or not the CConnection should - // only ever support protocol version 3.3 - public void setProtocol3_3(boolean s) { useProtocol3_3 = s; } + // getIdVerifier() returns the identity verifier associated with the connection. + // Ownership of the IdentityVerifier is retained by the CConnection instance. + //public IdentityVerifier getIdentityVerifier() { return 0; } - // Methods to be overridden in a derived class + // authSuccess() is called when authentication has succeeded. + public void authSuccess() {} + + // serverInit() is called when the ServerInit message is received. The + // derived class must call on to CConnection::serverInit(). + public void serverInit() + { + state_ = RFBSTATE_NORMAL; + vlog.debug("initialisation done"); + } // getCSecurity() gets the CSecurity object for the given type. The type // is guaranteed to be one of the secTypes passed in to addSecType(). The @@ -286,16 +321,6 @@ abstract public class CConnection extends CMsgHandler { clientSecTypeOrder = csto; } - // authSuccess() is called when authentication has succeeded. - public void authSuccess() {} - - // serverInit() is called when the ServerInit message is received. The - // derived class must call on to CConnection::serverInit(). - public void serverInit() { - state_ = RFBSTATE_NORMAL; - vlog.debug("initialisation done"); - } - // Other methods public CMsgReaderV3 reader() { return reader_; } @@ -318,7 +343,22 @@ abstract public class CConnection extends CMsgHandler { public int state() { return state_; } - protected void setState(int s) { state_ = s; } + protected final void setState(int s) { state_ = s; } + + public void fence(int flags, int len, byte[] data) + { + super.fence(flags, len, data); + + if ((flags & fenceTypes.fenceFlagRequest) != 0) + return; + + // We cannot guarantee any synchronisation at this level + flags = 0; + + synchronized(this) { + writer().writeFence(flags, len, data); + } + } private void throwAuthFailureException() { String reason; @@ -333,11 +373,11 @@ abstract public class CConnection extends CMsgHandler { throw new AuthFailureException(reason); } - InStream is = null; - OutStream os = null; - CMsgReaderV3 reader_ = null; - CMsgWriterV3 writer_ = null; - boolean shared = false; + InStream is; + OutStream os; + CMsgReaderV3 reader_; + CMsgWriterV3 writer_; + boolean shared; public CSecurity csecurity; public SecurityClient security; public static final int maxSecTypes = 8; @@ -346,7 +386,7 @@ abstract public class CConnection extends CMsgHandler { int state_ = RFBSTATE_UNINITIALISED; String serverName; int serverPort; - boolean useProtocol3_3 = false; + boolean useProtocol3_3; boolean clientSecTypeOrder; static LogWriter vlog = new LogWriter("CConnection"); |