Class TelnetIO.IACHandler

  • Enclosing class:
    TelnetIO

    class TelnetIO.IACHandler
    extends java.lang.Object
    An inner class for handling incoming option negotiations implementing the telnet protocol specification based upon following Standards and RFCs:
    1. 854 Telnet Protocol Specification
    2. 855 Telnet Option Specifications
    3. 857 Telnet Echo Option
    4. 858 Telnet Supress Go Ahead Option
    5. 727 Telnet Logout Option
    6. 1073 Telnet Window Size Option
    7. 1091 Telnet Terminal-Type Option

    Furthermore there are some more, which helped to solve problems, or might be important for future enhancements:
    1143 The Q Method of Implementing Option Negotiation
    1416 Telnet Authentication Option

    After an intense study of the available material (mainly cryptical written RFCs, a telnet client implementation for the macintosh based upon NCSA telnet, and a server side implementation called key, a mud-like system completely written in Java) I realized the problems we are facing regarding to the telnet protocol:

    1. a minimal spread of invented options, which means there are a lot of invented options, but rarely they made it through to become a standard.
    2. Dependency on a special type of implementation is dangerous in our case. We are no kind of host that offers the user to run several processes at once, a BBS is intended to be a single process the user is interacting with.
    3. The LAMER has to be expected to log in with the standard Microsoft telnet implementation. This means forget every nice feature and most of the almost-standards.
    Version:
    1.1 16/06/1998

    To-Do:

    • UNIX conform new style TTYPE negotiation. Setting a list and selecting from it...
    • Field Detail

      • buffer

        private int[] buffer
        Telnet readin buffer Here its implemented guys. Open your eyes upon this solution. The others take a one byte solution :)
      • DO_ECHO

        private boolean DO_ECHO
        DO_ECHO or not
      • DO_SUPGA

        private boolean DO_SUPGA
        DO_SUPGA or not
      • DO_NAWS

        private boolean DO_NAWS
        DO_NAWS or not
      • DO_TTYPE

        private boolean DO_TTYPE
        DO_TTYPE or not
      • DO_LINEMODE

        private boolean DO_LINEMODE
        DO_LINEMODE or not
      • DO_NEWENV

        private boolean DO_NEWENV
        DO_NEWENV or not
      • WAIT_DO_REPLY_SUPGA

        private boolean WAIT_DO_REPLY_SUPGA
        Are we waiting for a DO reply?
      • WAIT_DO_REPLY_ECHO

        private boolean WAIT_DO_REPLY_ECHO
      • WAIT_DO_REPLY_NAWS

        private boolean WAIT_DO_REPLY_NAWS
      • WAIT_DO_REPLY_TTYPE

        private boolean WAIT_DO_REPLY_TTYPE
      • WAIT_DO_REPLY_LINEMODE

        private boolean WAIT_DO_REPLY_LINEMODE
      • WAIT_LM_MODE_ACK

        private boolean WAIT_LM_MODE_ACK
      • WAIT_LM_DO_REPLY_FORWARDMASK

        private boolean WAIT_LM_DO_REPLY_FORWARDMASK
      • WAIT_DO_REPLY_NEWENV

        private boolean WAIT_DO_REPLY_NEWENV
      • WAIT_NE_SEND_REPLY

        private boolean WAIT_NE_SEND_REPLY
      • WAIT_WILL_REPLY_SUPGA

        private boolean WAIT_WILL_REPLY_SUPGA
        Are we waiting for a WILL reply?
      • WAIT_WILL_REPLY_ECHO

        private boolean WAIT_WILL_REPLY_ECHO
      • WAIT_WILL_REPLY_NAWS

        private boolean WAIT_WILL_REPLY_NAWS
      • WAIT_WILL_REPLY_TTYPE

        private boolean WAIT_WILL_REPLY_TTYPE
    • Constructor Detail

      • IACHandler

        IACHandler()
    • Method Detail

      • doCharacterModeInit

        public void doCharacterModeInit()
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • doLineModeInit

        public void doLineModeInit()
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • handleC

        public void handleC​(int i)
                     throws java.io.IOException
        Method to handle a IAC that came in over the line.
        Parameters:
        i - (int)ed byte that followed the IAC
        Throws:
        java.io.IOException
      • parseTWO

        private boolean parseTWO​(int[] buf)
        Method that parses for options with two characters.
        Parameters:
        buf - int [] that represents the first byte that followed the IAC first.
        Returns:
        true when it was a two byte command (IAC OPTIONBYTE)
      • parse

        private void parse​(int[] buf)
                    throws java.io.IOException
        Method that parses further on for options.
        Parameters:
        buf - that represents the first two bytes that followed the IAC.
        Throws:
        java.io.IOException
      • handleNAWS

        private void handleNAWS()
                         throws java.io.IOException
        Method that reads a NawsSubnegotiation that ends up with a IAC SE If the measurements are unbelieveable it switches to the defaults.
        Throws:
        java.io.IOException
      • handleTTYPE

        private void handleTTYPE()
                          throws java.io.IOException
        Method that reads a TTYPE Subnegotiation String that ends up with a IAC SE If no Terminal is valid, we switch to the dumb "none" terminal.
        Throws:
        java.io.IOException
      • handleLINEMODE

        public void handleLINEMODE()
                            throws java.io.IOException
        Method that handles LINEMODE subnegotiation.
        Throws:
        java.io.IOException
      • handleLMMode

        public void handleLMMode()
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • handleLMSLC

        public void handleLMSLC()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • handleLMForwardMask

        public void handleLMForwardMask​(int WHAT)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • handleNEWENV

        public void handleNEWENV()
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • readNEVariableName

        private int readNEVariableName​(java.lang.StringBuffer sbuf)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • readNEVariableValue

        private int readNEVariableValue​(java.lang.StringBuffer sbuf)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • readNEVariables

        public void readNEVariables()
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • handleNEIs

        public void handleNEIs()
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • handleNEInfo

        public void handleNEInfo()
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • getTTYPE

        public void getTTYPE()
                      throws java.io.IOException
        Method that sends a TTYPE Subnegotiation Request. IAC SB TERMINAL-TYPE SEND
        Throws:
        java.io.IOException
      • negotiateLineMode

        public void negotiateLineMode()
                               throws java.io.IOException
        Method that sends a LINEMODE MODE Subnegotiation request. IAC LINEMODE MODE MASK SE
        Throws:
        java.io.IOException
      • negotiateEnvironment

        private void negotiateEnvironment()
                                   throws java.io.IOException
        Method that sends a NEW-ENVIRON SEND subnegotiation request for default variables and user variables. IAC SB NEW-ENVIRON SEND VAR USERVAR IAC SE
        Throws:
        java.io.IOException
      • skipToSE

        private void skipToSE()
                       throws java.io.IOException
        Method that skips a subnegotiation response.
        Throws:
        java.io.IOException
      • readTriple

        private boolean readTriple​(int[] triple)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • readIACSETerminatedString

        private java.lang.String readIACSETerminatedString​(int maxlength)
                                                    throws java.io.IOException
        Method that reads a subnegotiation String, one of those that end with a IAC SE combination. A maximum length is observed to prevent overflow.
        Returns:
        IAC SE terminated String
        Throws:
        java.io.IOException
      • supported

        private boolean supported​(int i)
        Method that informs internally about the supported Negotiation Options
        Parameters:
        i - int that represents requested the Option
        Returns:
        Boolean that represents support status
      • sendCommand

        private void sendCommand​(int i,
                                 int j,
                                 boolean westarted)
                          throws java.io.IOException
        Method that sends a Telnet IAC String with TelnetIO.write(byte b) method.
        Parameters:
        i - int that represents requested Command Type (DO,DONT,WILL,WONT)
        j - int that represents the Option itself (e.g. ECHO, NAWS)
        Throws:
        java.io.IOException
      • enable

        private void enable​(int i)
                     throws java.io.IOException
        Method enables or disables a supported Option
        Parameters:
        i - int that represents the Option
        Throws:
        java.io.IOException
      • isEnabled

        private boolean isEnabled​(int i)
        Method that informs internally about the status of the supported Negotiation Options.
        Parameters:
        i - int that represents requested the Option
        Returns:
        Boolean that represents the enabled status
      • waitWILLreply

        private boolean waitWILLreply​(int i)
        Method that informs internally about the WILL wait status of an option.
        Parameters:
        i - that represents requested the Option
        Returns:
        Boolean that represents WILL wait status of the Option
      • waitDOreply

        private boolean waitDOreply​(int i)
        Method that informs internally about the DO wait status of an option.
        Parameters:
        i - Integer that represents requested the Option
        Returns:
        Boolean that represents DO wait status of the Option
      • setWait

        private void setWait​(int WHAT,
                             int OPTION,
                             boolean WAIT)
        Method that mutates the wait status of an option in negotiation. We need the wait status to keep track of negotiation in process. So we cant miss if we started out or the other and so on.
        Parameters:
        WHAT - Integer values of DO or WILL
        OPTION - Integer that represents the Option
        WAIT - Boolean that represents the status of wait that should be set