Package org.jline.builtins.telnet
Class TelnetIO.IACHandler
java.lang.Object
org.jline.builtins.telnet.TelnetIO.IACHandler
- Enclosing class:
TelnetIO
An 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
FieldsModifier and TypeFieldDescriptionprivate int[]
Telnet readin buffer Here its implemented guys.private boolean
DO_ECHO or notprivate boolean
DO_LINEMODE or notprivate boolean
DO_NAWS or notprivate boolean
DO_NEWENV or notprivate boolean
DO_SUPGA or notprivate boolean
DO_TTYPE or notprivate boolean
private boolean
private boolean
private boolean
private boolean
Are we waiting for a DO reply?private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
Are we waiting for a WILL reply?private boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
private void
enable
(int i) Method enables or disables a supported Optionvoid
getTTYPE()
Method that sends a TTYPE Subnegotiation Request.void
handleC
(int i) Method to handle a IAC that came in over the line.void
Method that handles LINEMODE subnegotiation.void
handleLMForwardMask
(int WHAT) void
void
private void
Method that reads a NawsSubnegotiation that ends up with a IAC SE If the measurements are unbelieveable it switches to the defaults.void
void
void
private void
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 boolean
isEnabled
(int i) Method that informs internally about the status of the supported Negotiation Options.private void
Method that sends a NEW-ENVIRON SEND subnegotiation request for default variables and user variables.void
Method that sends a LINEMODE MODE Subnegotiation request.private void
parse
(int[] buf) Method that parses further on for options.private boolean
parseTWO
(int[] buf) Method that parses for options with two characters.private String
readIACSETerminatedString
(int maxlength) Method that reads a subnegotiation String, one of those that end with a IAC SE combination.private int
void
private int
private boolean
readTriple
(int[] triple) private void
sendCommand
(int i, int j, boolean westarted) Method that sends a Telnet IAC String with TelnetIO.write(byte b) method.private void
setWait
(int WHAT, int OPTION, boolean WAIT) Method that mutates the wait status of an option in negotiation.private void
skipToSE()
Method that skips a subnegotiation response.private boolean
supported
(int i) Method that informs internally about the supported Negotiation Optionsprivate boolean
waitDOreply
(int i) Method that informs internally about the DO wait status of an option.private boolean
waitWILLreply
(int i) Method that informs internally about the WILL wait status of an option.
-
Field Details
-
buffer
private int[] bufferTelnet readin buffer Here its implemented guys. Open your eyes upon this solution. The others take a one byte solution :) -
DO_ECHO
private boolean DO_ECHODO_ECHO or not -
DO_SUPGA
private boolean DO_SUPGADO_SUPGA or not -
DO_NAWS
private boolean DO_NAWSDO_NAWS or not -
DO_TTYPE
private boolean DO_TTYPEDO_TTYPE or not -
DO_LINEMODE
private boolean DO_LINEMODEDO_LINEMODE or not -
DO_NEWENV
private boolean DO_NEWENVDO_NEWENV or not -
WAIT_DO_REPLY_SUPGA
private boolean WAIT_DO_REPLY_SUPGAAre 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_SUPGAAre 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
- Throws:
IOException
-
doLineModeInit
- Throws:
IOException
-
handleC
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
Method that parses further on for options.- Parameters:
buf
- that represents the first two bytes that followed the IAC.- Throws:
IOException
-
handleNAWS
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
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
Method that handles LINEMODE subnegotiation.- Throws:
IOException
-
handleLMMode
- Throws:
IOException
-
handleLMSLC
- Throws:
IOException
-
handleLMForwardMask
- Throws:
IOException
-
handleNEWENV
- Throws:
IOException
-
readNEVariableName
- Throws:
IOException
-
readNEVariableValue
- Throws:
IOException
-
readNEVariables
- Throws:
IOException
-
handleNEIs
- Throws:
IOException
-
handleNEInfo
- Throws:
IOException
-
getTTYPE
Method that sends a TTYPE Subnegotiation Request. IAC SB TERMINAL-TYPE SEND- Throws:
IOException
-
negotiateLineMode
Method that sends a LINEMODE MODE Subnegotiation request. IAC LINEMODE MODE MASK SE- Throws:
IOException
-
negotiateEnvironment
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
Method that skips a subnegotiation response.- Throws:
IOException
-
readTriple
- Throws:
IOException
-
readIACSETerminatedString
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
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
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 WILLOPTION
- Integer that represents the OptionWAIT
- Boolean that represents the status of wait that should be set
-