Package org.jline.builtins.telnet
Class TelnetIO.IACHandler
- java.lang.Object
-
- org.jline.builtins.telnet.TelnetIO.IACHandler
-
- Enclosing class:
- TelnetIO
class TelnetIO.IACHandler extends java.lang.ObjectAn inner class for handling incoming option negotiations implementing the telnet protocol specification based upon following Standards and RFCs:- 854 Telnet Protocol Specification
- 855 Telnet Option Specifications
- 857 Telnet Echo Option
- 858 Telnet Supress Go Ahead Option
- 727 Telnet Logout Option
- 1073 Telnet Window Size Option
- 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:
- 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.
- 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.
- 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 Summary
Fields Modifier and Type Field Description private int[]bufferTelnet readin buffer Here its implemented guys.private booleanDO_ECHODO_ECHO or notprivate booleanDO_LINEMODEDO_LINEMODE or notprivate booleanDO_NAWSDO_NAWS or notprivate booleanDO_NEWENVDO_NEWENV or notprivate booleanDO_SUPGADO_SUPGA or notprivate booleanDO_TTYPEDO_TTYPE or notprivate booleanWAIT_DO_REPLY_ECHOprivate booleanWAIT_DO_REPLY_LINEMODEprivate booleanWAIT_DO_REPLY_NAWSprivate booleanWAIT_DO_REPLY_NEWENVprivate booleanWAIT_DO_REPLY_SUPGAAre we waiting for a DO reply?private booleanWAIT_DO_REPLY_TTYPEprivate booleanWAIT_LM_DO_REPLY_FORWARDMASKprivate booleanWAIT_LM_MODE_ACKprivate booleanWAIT_NE_SEND_REPLYprivate booleanWAIT_WILL_REPLY_ECHOprivate booleanWAIT_WILL_REPLY_NAWSprivate booleanWAIT_WILL_REPLY_SUPGAAre we waiting for a WILL reply?private booleanWAIT_WILL_REPLY_TTYPE
-
Constructor Summary
Constructors Constructor Description IACHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddoCharacterModeInit()voiddoLineModeInit()private voidenable(int i)Method enables or disables a supported OptionvoidgetTTYPE()Method that sends a TTYPE Subnegotiation Request.voidhandleC(int i)Method to handle a IAC that came in over the line.voidhandleLINEMODE()Method that handles LINEMODE subnegotiation.voidhandleLMForwardMask(int WHAT)voidhandleLMMode()voidhandleLMSLC()private voidhandleNAWS()Method that reads a NawsSubnegotiation that ends up with a IAC SE If the measurements are unbelieveable it switches to the defaults.voidhandleNEInfo()voidhandleNEIs()voidhandleNEWENV()private voidhandleTTYPE()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.private booleanisEnabled(int i)Method that informs internally about the status of the supported Negotiation Options.private voidnegotiateEnvironment()Method that sends a NEW-ENVIRON SEND subnegotiation request for default variables and user variables.voidnegotiateLineMode()Method that sends a LINEMODE MODE Subnegotiation request.private voidparse(int[] buf)Method that parses further on for options.private booleanparseTWO(int[] buf)Method that parses for options with two characters.private java.lang.StringreadIACSETerminatedString(int maxlength)Method that reads a subnegotiation String, one of those that end with a IAC SE combination.private intreadNEVariableName(java.lang.StringBuffer sbuf)voidreadNEVariables()private intreadNEVariableValue(java.lang.StringBuffer sbuf)private booleanreadTriple(int[] triple)private voidsendCommand(int i, int j, boolean westarted)Method that sends a Telnet IAC String with TelnetIO.write(byte b) method.private voidsetWait(int WHAT, int OPTION, boolean WAIT)Method that mutates the wait status of an option in negotiation.private voidskipToSE()Method that skips a subnegotiation response.private booleansupported(int i)Method that informs internally about the supported Negotiation Optionsprivate booleanwaitDOreply(int i)Method that informs internally about the DO wait status of an option.private booleanwaitWILLreply(int i)Method that informs internally about the WILL wait status of an option.
-
-
-
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
-
-
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.IOExceptionMethod 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.IOExceptionMethod 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.IOExceptionMethod 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.IOExceptionMethod 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.IOExceptionMethod 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.IOExceptionMethod that sends a TTYPE Subnegotiation Request. IAC SB TERMINAL-TYPE SEND- Throws:
java.io.IOException
-
negotiateLineMode
public void negotiateLineMode() throws java.io.IOExceptionMethod that sends a LINEMODE MODE Subnegotiation request. IAC LINEMODE MODE MASK SE- Throws:
java.io.IOException
-
negotiateEnvironment
private void negotiateEnvironment() throws java.io.IOExceptionMethod 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.IOExceptionMethod 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.IOExceptionMethod 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.IOExceptionMethod 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.IOExceptionMethod 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 WILLOPTION- Integer that represents the OptionWAIT- Boolean that represents the status of wait that should be set
-
-