Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetInputScanner.java')
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetInputScanner.java404
1 files changed, 202 insertions, 202 deletions
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetInputScanner.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetInputScanner.java
index 8f875f3d0..b285d8159 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetInputScanner.java
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetInputScanner.java
@@ -37,134 +37,134 @@ import java.util.Set;
*/
public class TelnetInputScanner extends Scanner {
- private boolean isCommand = false;
- private boolean isReadingTtype = false;
- private boolean shouldFinish = false;
- private boolean tTypeNegotiationStarted = false;
- private int lastRead = -1;
- private ArrayList<Integer> currentTerminalType = new ArrayList<>();
- private ArrayList<Integer> lastTerminalType = null;
- private Set<String> supportedTerminalTypes = new HashSet<>();
- private Callback callback;
+ private boolean isCommand = false;
+ private boolean isReadingTtype = false;
+ private boolean shouldFinish = false;
+ private boolean tTypeNegotiationStarted = false;
+ private int lastRead = -1;
+ private ArrayList<Integer> currentTerminalType = new ArrayList<>();
+ private ArrayList<Integer> lastTerminalType = null;
+ private Set<String> supportedTerminalTypes = new HashSet<>();
+ private Callback callback;
- public TelnetInputScanner(ConsoleInputStream toShell, ConsoleOutputStream toTelnet, Callback callback) {
- super(toShell, toTelnet);
- initializeSupportedTerminalTypes();
- TerminalTypeMappings currentMapping = supportedEscapeSequences.get(DEFAULT_TTYPE);
- currentEscapesToKey = currentMapping.getEscapesToKey();
- escapes = currentMapping.getEscapes();
- setBackspace(currentMapping.getBackspace());
- setDel(currentMapping.getDel());
- this.callback = callback;
- }
-
- private void initializeSupportedTerminalTypes() {
- supportedTerminalTypes.add("ANSI");
- supportedTerminalTypes.add("VT100");
- supportedTerminalTypes.add("VT220");
- supportedTerminalTypes.add("VT320");
- supportedTerminalTypes.add("XTERM");
- supportedTerminalTypes.add("SCO");
- }
+ public TelnetInputScanner(ConsoleInputStream toShell, ConsoleOutputStream toTelnet, Callback callback) {
+ super(toShell, toTelnet);
+ initializeSupportedTerminalTypes();
+ TerminalTypeMappings currentMapping = supportedEscapeSequences.get(DEFAULT_TTYPE);
+ currentEscapesToKey = currentMapping.getEscapesToKey();
+ escapes = currentMapping.getEscapes();
+ setBackspace(currentMapping.getBackspace());
+ setDel(currentMapping.getDel());
+ this.callback = callback;
+ }
+
+ private void initializeSupportedTerminalTypes() {
+ supportedTerminalTypes.add("ANSI");
+ supportedTerminalTypes.add("VT100");
+ supportedTerminalTypes.add("VT220");
+ supportedTerminalTypes.add("VT320");
+ supportedTerminalTypes.add("XTERM");
+ supportedTerminalTypes.add("SCO");
+ }
- @Override
+ @Override
public void scan(int b) throws IOException {
- b &= 0xFF;
+ b &= 0xFF;
- if (isEsc) {
- scanEsc(b);
- } else if (isCommand) {
- scanCommand(b);
- } else if (b == IAC) {
- startCommand();
- } else {
- switch (b) {
- case ESC:
- startEsc();
- toShell.add(new byte[]{(byte) b});
- break;
- default:
- if (b >= SPACE && b < MAX_CHAR) {
- echo((byte) b);
- flush();
- }
- toShell.add(new byte[]{(byte) b});
- }
+ if (isEsc) {
+ scanEsc(b);
+ } else if (isCommand) {
+ scanCommand(b);
+ } else if (b == IAC) {
+ startCommand();
+ } else {
+ switch (b) {
+ case ESC:
+ startEsc();
+ toShell.add(new byte[]{(byte) b});
+ break;
+ default:
+ if (b >= SPACE && b < MAX_CHAR) {
+ echo((byte) b);
+ flush();
+ }
+ toShell.add(new byte[]{(byte) b});
+ }
- }
- lastRead = b;
- }
+ }
+ lastRead = b;
+ }
- /* Telnet command codes are described in RFC 854, TELNET PROTOCOL SPECIFICATION
- * available at http://www.ietf.org/rfc/rfc854.txt
- *
- * Telnet terminal type negotiation option is described in RFC 1091, Telnet Terminal-Type Option
- * available at http://www.ietf.org/rfc/rfc1091.txt
- */
- private static final int SE = 240;
- private static final int EC = 247;
- private static final int EL = 248;
- private static final int SB = 250;
- private static final int WILL = 251;
- private static final int WILL_NOT = 252;
- private static final int DO = 253;
- private static final int DO_NOT = 254;
- private static final int TTYPE = 24;
- private static final int SEND = 1;
- private static final int IAC = 255;
- private static final int IS = 0;
+ /* Telnet command codes are described in RFC 854, TELNET PROTOCOL SPECIFICATION
+ * available at http://www.ietf.org/rfc/rfc854.txt
+ *
+ * Telnet terminal type negotiation option is described in RFC 1091, Telnet Terminal-Type Option
+ * available at http://www.ietf.org/rfc/rfc1091.txt
+ */
+ private static final int SE = 240;
+ private static final int EC = 247;
+ private static final int EL = 248;
+ private static final int SB = 250;
+ private static final int WILL = 251;
+ private static final int WILL_NOT = 252;
+ private static final int DO = 253;
+ private static final int DO_NOT = 254;
+ private static final int TTYPE = 24;
+ private static final int SEND = 1;
+ private static final int IAC = 255;
+ private static final int IS = 0;
- private boolean isNegotiation;
- private boolean isWill;
-
- private byte[] tTypeRequest = {(byte)IAC, (byte)SB, (byte)TTYPE, (byte)SEND, (byte)IAC, (byte)SE};
+ private boolean isNegotiation;
+ private boolean isWill;
+
+ private byte[] tTypeRequest = {(byte)IAC, (byte)SB, (byte)TTYPE, (byte)SEND, (byte)IAC, (byte)SE};
- private void scanCommand(final int b) throws IOException {
- if (isNegotiation) {
- scanNegotiation(b);
- } else if (isWill) {
- isWill = false;
- isCommand = false;
- if(b == TTYPE && tTypeNegotiationStarted == false) {
- sendRequest();
- }
- } else {
- switch (b) {
- case WILL:
- isWill = true;
- break;
- case WILL_NOT:
- break;
- case DO:
- break;
- case DO_NOT:
- break;
- case SB:
- isNegotiation = true;
- break;
- case EC:
- eraseChar();
- isCommand = false;
- break;
- case EL:
- default:
- isCommand = false;
- break;
- }
- }
- }
+ private void scanCommand(final int b) throws IOException {
+ if (isNegotiation) {
+ scanNegotiation(b);
+ } else if (isWill) {
+ isWill = false;
+ isCommand = false;
+ if(b == TTYPE && tTypeNegotiationStarted == false) {
+ sendRequest();
+ }
+ } else {
+ switch (b) {
+ case WILL:
+ isWill = true;
+ break;
+ case WILL_NOT:
+ break;
+ case DO:
+ break;
+ case DO_NOT:
+ break;
+ case SB:
+ isNegotiation = true;
+ break;
+ case EC:
+ eraseChar();
+ isCommand = false;
+ break;
+ case EL:
+ default:
+ isCommand = false;
+ break;
+ }
+ }
+ }
- private void scanNegotiation(final int b) {
- if (lastRead == SB && b == TTYPE) {
- isReadingTtype = true;
- } else if (b == IS) {
-
- } else if (b == IAC) {
-
- } else if (b == SE) {
- isNegotiation = false;
- isCommand = false;
- if (isReadingTtype == true) {
+ private void scanNegotiation(final int b) {
+ if (lastRead == SB && b == TTYPE) {
+ isReadingTtype = true;
+ } else if (b == IS) {
+
+ } else if (b == IAC) {
+
+ } else if (b == SE) {
+ isNegotiation = false;
+ isCommand = false;
+ if (isReadingTtype == true) {
isReadingTtype = false;
if (shouldFinish == true) {
setCurrentTerminalType();
@@ -186,66 +186,66 @@ public class TelnetInputScanner extends Scanner {
sendRequest();
}
}
- } else if (isReadingTtype == true){
- currentTerminalType.add(b);
- }
- }
-
- private boolean isTerminalTypeSupported() {
- byte[] tmp = new byte[currentTerminalType.size()];
- int idx = 0;
- for(Integer i : currentTerminalType) {
- tmp[idx] = i.byteValue();
- idx++;
- }
- String tType = new String(tmp);
-
- for(String terminal : supportedTerminalTypes) {
- if(tType.toUpperCase().contains(terminal)) {
- return true;
- }
- }
-
- return false;
- }
-
- private boolean isLast() {
- if(currentTerminalType.equals(lastTerminalType)) {
- return true;
- } else {
- return false;
- }
- }
-
- private void setCurrentTerminalType() {
- byte[] tmp = new byte[currentTerminalType.size()];
- int idx = 0;
- for(Integer i : currentTerminalType) {
- tmp[idx] = i.byteValue();
- idx++;
- }
- String tType = new String(tmp);
- String term = null;
- for(String terminal : supportedTerminalTypes) {
- if(tType.toUpperCase().contains(terminal)) {
- term = terminal;
- }
- }
- TerminalTypeMappings currentMapping = supportedEscapeSequences.get(term);
- if(currentMapping == null) {
- currentMapping = supportedEscapeSequences.get(DEFAULT_TTYPE);
- }
- currentEscapesToKey = currentMapping.getEscapesToKey();
- escapes = currentMapping.getEscapes();
- setBackspace(currentMapping.getBackspace());
- setDel(currentMapping.getDel());
- if(callback != null) {
- callback.finished();
- }
- }
-
- private void sendRequest() {
- try {
+ } else if (isReadingTtype == true){
+ currentTerminalType.add(b);
+ }
+ }
+
+ private boolean isTerminalTypeSupported() {
+ byte[] tmp = new byte[currentTerminalType.size()];
+ int idx = 0;
+ for(Integer i : currentTerminalType) {
+ tmp[idx] = i.byteValue();
+ idx++;
+ }
+ String tType = new String(tmp);
+
+ for(String terminal : supportedTerminalTypes) {
+ if(tType.toUpperCase().contains(terminal)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private boolean isLast() {
+ if(currentTerminalType.equals(lastTerminalType)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private void setCurrentTerminalType() {
+ byte[] tmp = new byte[currentTerminalType.size()];
+ int idx = 0;
+ for(Integer i : currentTerminalType) {
+ tmp[idx] = i.byteValue();
+ idx++;
+ }
+ String tType = new String(tmp);
+ String term = null;
+ for(String terminal : supportedTerminalTypes) {
+ if(tType.toUpperCase().contains(terminal)) {
+ term = terminal;
+ }
+ }
+ TerminalTypeMappings currentMapping = supportedEscapeSequences.get(term);
+ if(currentMapping == null) {
+ currentMapping = supportedEscapeSequences.get(DEFAULT_TTYPE);
+ }
+ currentEscapesToKey = currentMapping.getEscapesToKey();
+ escapes = currentMapping.getEscapes();
+ setBackspace(currentMapping.getBackspace());
+ setDel(currentMapping.getDel());
+ if(callback != null) {
+ callback.finished();
+ }
+ }
+
+ private void sendRequest() {
+ try {
toTelnet.write(tTypeRequest);
toTelnet.flush();
if(tTypeNegotiationStarted == false) {
@@ -255,32 +255,32 @@ public class TelnetInputScanner extends Scanner {
e.printStackTrace();
}
- }
+ }
- private void startCommand() {
- isCommand = true;
- isNegotiation = false;
- isWill = false;
- }
+ private void startCommand() {
+ isCommand = true;
+ isNegotiation = false;
+ isWill = false;
+ }
- private void eraseChar() throws IOException {
- toShell.add(new byte[]{BS});
- }
+ private void eraseChar() throws IOException {
+ toShell.add(new byte[]{BS});
+ }
- @Override
+ @Override
protected void scanEsc(int b) throws IOException {
- esc += (char) b;
- toShell.add(new byte[]{(byte) b});
- KEYS key = checkEscape(esc);
- if (key == KEYS.UNFINISHED) {
- return;
- }
- if (key == KEYS.UNKNOWN) {
- isEsc = false;
- scan(b);
- return;
- }
- isEsc = false;
- }
+ esc += (char) b;
+ toShell.add(new byte[]{(byte) b});
+ KEYS key = checkEscape(esc);
+ if (key == KEYS.UNFINISHED) {
+ return;
+ }
+ if (key == KEYS.UNKNOWN) {
+ isEsc = false;
+ scan(b);
+ return;
+ }
+ isEsc = false;
+ }
}

Back to the top