aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/mud/telnet
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2009-06-24 19:18:35 +0000
committerKenny Root <kenny@the-b.org>2009-06-24 19:18:35 +0000
commit9c24eddf62f97f354c9715388e18859492f13e40 (patch)
tree8ba6d7048226655bae8964e469f43683f3047fb5 /src/de/mud/telnet
parent77440a7c3f4b9b2aa4918d290e0b2f37370a131c (diff)
downloadconnectbot-9c24eddf62f97f354c9715388e18859492f13e40.tar.gz
connectbot-9c24eddf62f97f354c9715388e18859492f13e40.tar.bz2
connectbot-9c24eddf62f97f354c9715388e18859492f13e40.zip
Add in CHARSET (RFC 2066) support to Telnet transport
git-svn-id: https://connectbot.googlecode.com/svn/trunk/connectbot@329 df292f66-193f-0410-a5fc-6d59da041ff2
Diffstat (limited to 'src/de/mud/telnet')
-rw-r--r--src/de/mud/telnet/TelnetProtocolHandler.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/de/mud/telnet/TelnetProtocolHandler.java b/src/de/mud/telnet/TelnetProtocolHandler.java
index fd4d034..74f08bb 100644
--- a/src/de/mud/telnet/TelnetProtocolHandler.java
+++ b/src/de/mud/telnet/TelnetProtocolHandler.java
@@ -92,6 +92,11 @@ public abstract class TelnetProtocolHandler {
protected abstract void write(byte[] b) throws IOException;
/**
+ * Read the charset name from terminal.
+ */
+ protected abstract String getCharsetName();
+
+ /**
* Send one byte to the remote host.
* @param b the byte to be sent
* @see #write(byte[] b)
@@ -167,6 +172,8 @@ public abstract class TelnetProtocolHandler {
private final static byte TELOPT_NAWS = (byte)31; /* NA-WindowSize*/
/** Telnet option: Terminal Type */
private final static byte TELOPT_TTYPE = (byte)24; /* terminal type */
+ /** Telnet option: CHARSET */
+ private final static byte TELOPT_CHARSET= (byte)42; /* charset */
private final static byte[] IACWILL = { IAC, WILL };
private final static byte[] IACWONT = { IAC, WONT };
@@ -175,6 +182,9 @@ public abstract class TelnetProtocolHandler {
private final static byte[] IACSB = { IAC, SB };
private final static byte[] IACSE = { IAC, SE };
+ private final static byte CHARSET_ACCEPTED = (byte)2;
+ private final static byte CHARSET_REJECTED = (byte)3;
+
/** Telnet option qualifier 'IS' */
private final static byte TELQUAL_IS = (byte)0;
/** Telnet option qualifier 'SEND' */
@@ -242,7 +252,28 @@ public abstract class TelnetProtocolHandler {
write(ttype.getBytes());
write(IACSE);
}
+ break;
+ case TELOPT_CHARSET:
+ System.out.println("Got SB CHARSET");
+ String charsetStr = new String(sbdata, "US-ASCII");
+ if (charsetStr.startsWith("TTABLE ")) {
+ charsetStr = charsetStr.substring(7);
+ }
+ String[] charsets = charsetStr.split(charsetStr.substring(0,0));
+ String myCharset = getCharsetName();
+ for (String charset : charsets) {
+ if (charset.equals(myCharset)) {
+ write(IACSB);write(TELOPT_CHARSET);write(CHARSET_ACCEPTED);
+ write(charset.getBytes());
+ write(IACSE);
+ System.out.println("Sent our charset!");
+ return;
+ }
+ }
+ write(IACSB);write(TELOPT_CHARSET);write(CHARSET_REJECTED);
+ write(IACSE);
+ break;
}
}