From 9c24eddf62f97f354c9715388e18859492f13e40 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Wed, 24 Jun 2009 19:18:35 +0000 Subject: 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 --- src/de/mud/telnet/TelnetProtocolHandler.java | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/de/mud/telnet') 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 @@ -91,6 +91,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 @@ -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; } } -- cgit v1.2.3