Class TelnetIO.IACHandler

java.lang.Object
org.jline.builtins.telnet.TelnetIO.IACHandler
Enclosing class:
TelnetIO

class TelnetIO.IACHandler extends 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 Details

    • 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 Details

    • IACHandler

      IACHandler()
  • Method Details

    • doCharacterModeInit

      public void doCharacterModeInit() throws IOException
      Throws:
      IOException
    • doLineModeInit

      public void doLineModeInit() throws IOException
      Throws:
      IOException
    • handleC

      public void handleC(int i) throws IOException
      Method to handle a IAC that came in over the line.
      Parameters:
      i - (int)ed byte that followed the IAC
      Throws:
      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 IOException
      Method that parses further on for options.
      Parameters:
      buf - that represents the first two bytes that followed the IAC.
      Throws:
      IOException
    • handleNAWS

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

      private void handleTTYPE() throws 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:
      IOException
    • handleLINEMODE

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

      public void handleLMMode() throws IOException
      Throws:
      IOException
    • handleLMSLC

      public void handleLMSLC() throws IOException
      Throws:
      IOException
    • handleLMForwardMask

      public void handleLMForwardMask(int WHAT) throws IOException
      Throws:
      IOException
    • handleNEWENV

      public void handleNEWENV() throws IOException
      Throws:
      IOException
    • readNEVariableName

      private int readNEVariableName(StringBuffer sbuf) throws IOException
      Throws:
      IOException
    • readNEVariableValue

      private int readNEVariableValue(StringBuffer sbuf) throws IOException
      Throws:
      IOException
    • readNEVariables

      public void readNEVariables() throws IOException
      Throws:
      IOException
    • handleNEIs

      public void handleNEIs() throws IOException
      Throws:
      IOException
    • handleNEInfo

      public void handleNEInfo() throws IOException
      Throws:
      IOException
    • getTTYPE

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

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

      private void negotiateEnvironment() throws 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:
      IOException
    • skipToSE

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

      private boolean readTriple(int[] triple) throws IOException
      Throws:
      IOException
    • readIACSETerminatedString

      private String readIACSETerminatedString(int maxlength) throws 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:
      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 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:
      IOException
    • enable

      private void enable(int i) throws IOException
      Method enables or disables a supported Option
      Parameters:
      i - int that represents the Option
      Throws:
      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