Mercurial > 510Connectbot
comparison src/org/tn5250j/framework/tn5250/tnvt.java @ 8:3b760b39962a tn5250
adding tn5250 files
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 22 May 2014 15:41:35 -0700 |
parents | 1b9e27659ef7 |
children | e773d0952613 |
comparison
equal
deleted
inserted
replaced
7:3248b46f3973 | 8:3b760b39962a |
---|---|
78 import java.util.concurrent.ArrayBlockingQueue; | 78 import java.util.concurrent.ArrayBlockingQueue; |
79 import java.util.concurrent.BlockingQueue; | 79 import java.util.concurrent.BlockingQueue; |
80 | 80 |
81 import javax.net.ssl.SSLSocket; | 81 import javax.net.ssl.SSLSocket; |
82 | 82 |
83 import com.five_ten_sg.connectbot.service.TerminalBridge; | |
84 import com.five_ten_sg.connectbot.service.TerminalManager; | |
85 | |
83 import org.tn5250j.Session5250; | 86 import org.tn5250j.Session5250; |
84 import org.tn5250j.TN5250jConstants; | 87 import org.tn5250j.TN5250jConstants; |
85 import org.tn5250j.encoding.CharMappings; | 88 import org.tn5250j.encoding.CharMappings; |
86 import org.tn5250j.encoding.ICodePage; | 89 import org.tn5250j.encoding.ICodePage; |
87 import org.tn5250j.framework.transport.SocketConnector; | 90 import org.tn5250j.framework.transport.SocketConnector; |
88 import org.tn5250j.tools.logging.TN5250jLogFactory; | 91 import org.tn5250j.tools.logging.TN5250jLogFactory; |
89 import org.tn5250j.tools.logging.TN5250jLogger; | 92 import org.tn5250j.tools.logging.TN5250jLogger; |
90 | 93 |
91 public final class tnvt implements Runnable { | 94 public final class tnvt implements Runnable { |
92 | |
93 | |
94 // negotiating commands | 95 // negotiating commands |
95 private static final byte IAC = (byte) -1; // 255 FF | 96 private static final byte IAC = (byte) -1; // 255 FF |
96 private static final byte DONT = (byte) -2; //254 FE | 97 private static final byte DONT = (byte) -2; //254 FE |
97 private static final byte DO = (byte) -3; //253 FD | 98 private static final byte DO = (byte) -3; //253 FD |
98 private static final byte WONT = (byte) -4; //252 FC | 99 private static final byte WONT = (byte) -4; //252 FC |
129 private boolean negotiated = false; | 130 private boolean negotiated = false; |
130 private Thread me; | 131 private Thread me; |
131 private Thread pthread; | 132 private Thread pthread; |
132 private int readType; | 133 private int readType; |
133 private boolean enhanced = true; | 134 private boolean enhanced = true; |
134 private Session5250 controller; | |
135 private boolean cursorOn = false; | 135 private boolean cursorOn = false; |
136 private String session = ""; | 136 private String session = ""; |
137 private int port = 23; | 137 private int port = 23; |
138 private boolean connected = false; | 138 private boolean connected = false; |
139 private boolean support132 = true; | 139 private boolean support132 = true; |
158 private boolean[] dataIncluded; | 158 private boolean[] dataIncluded; |
159 protected ICodePage codePage; | 159 protected ICodePage codePage; |
160 private boolean firstScreen; | 160 private boolean firstScreen; |
161 private String sslType; | 161 private String sslType; |
162 private WTDSFParser sfParser; | 162 private WTDSFParser sfParser; |
163 private TerminalBridge bridge; | |
164 private TerminalManager manager; | |
163 | 165 |
164 private final TN5250jLogger log = TN5250jLogFactory.getLogger(this.getClass()); | 166 private final TN5250jLogger log = TN5250jLogFactory.getLogger(this.getClass()); |
165 | 167 |
166 /** | 168 /** |
167 * @param session | 169 * @param session |
168 * @param screen52 | 170 * @param screen52 |
169 * @param type | 171 * @param type |
170 * @param support132 | 172 * @param support132 |
171 */ | 173 */ |
172 public tnvt(Session5250 session, Screen5250 screen52, boolean type, boolean support132) { | 174 public tnvt(Screen5250 screen52, boolean enhanced, boolean support132, TerminalBridge bridge, TerminalManager manager) { |
173 | |
174 controller = session; | |
175 if (log.isInfoEnabled()) { | 175 if (log.isInfoEnabled()) { |
176 log.info(" new session -> " + controller.getSessionName()); | 176 log.info(" new session -> " + controller.getSessionName()); |
177 } | 177 } |
178 | 178 this.screen52 = screen52; |
179 enhanced = type; | |
180 this.support132 = support132; | 179 this.support132 = support132; |
180 this.enhanced = enhanced; | |
181 this.bridge = bridge; | |
182 this.manager = manager; | |
181 setCodePage("37"); | 183 setCodePage("37"); |
182 this.screen52 = screen52; | |
183 dataIncluded = new boolean[24]; | 184 dataIncluded = new boolean[24]; |
184 | 185 |
185 if (System.getProperties().containsKey("SESSION_CONNECT_USER")) { | 186 if (System.getProperties().containsKey("SESSION_CONNECT_USER")) { |
186 user = System.getProperties().getProperty("SESSION_CONNECT_USER"); | 187 user = System.getProperties().getProperty("SESSION_CONNECT_USER"); |
187 if (System.getProperties().containsKey("SESSION_CONNECT_PASSWORD")) | 188 if (System.getProperties().containsKey("SESSION_CONNECT_PASSWORD")) |
293 } | 294 } |
294 | 295 |
295 // sock = new Socket(s, port); | 296 // sock = new Socket(s, port); |
296 //smk - For SSL compability | 297 //smk - For SSL compability |
297 SocketConnector sc = new SocketConnector(); | 298 SocketConnector sc = new SocketConnector(); |
298 if (sslType != null) | 299 if (sslType != null) sc.setSSLType(sslType); |
299 sc.setSSLType(sslType); | 300 sock = sc.createSocket(s, port, bridge, manager); |
300 sock = sc.createSocket(s, port); | |
301 | 301 |
302 if (sock == null) { | 302 if (sock == null) { |
303 log.warn("I did not get a socket"); | 303 log.warn("I did not get a socket"); |
304 disconnect(); | 304 disconnect(); |
305 return false; | 305 return false; |
382 try { | 382 try { |
383 if (sock != null) { | 383 if (sock != null) { |
384 log.info("Closing socket"); | 384 log.info("Closing socket"); |
385 sock.close(); | 385 sock.close(); |
386 } | 386 } |
387 if (bin != null) | 387 if (bin != null) bin.close(); |
388 bin.close(); | 388 if (bout != null) bout.close(); |
389 if (bout != null) | 389 connected = false; |
390 bout.close(); | |
391 connected = false; | |
392 firstScreen = false; | 390 firstScreen = false; |
393 | 391 |
394 // WVL - LDC : TR.000345 : properly disconnect and clear screen | 392 // WVL - LDC : TR.000345 : properly disconnect and clear screen |
395 // Is this the right place to set screen realestate on disconnect? | 393 // Is this the right place to set screen realestate on disconnect? |
396 //controller.getScreen().clearAll(); | 394 //controller.getScreen().clearAll(); |
397 screen52.goto_XY(0); | 395 screen52.goto_XY(0); |
398 screen52.setCursorActive(false); | 396 screen52.setCursorActive(false); |
399 screen52.clearAll(); | 397 screen52.clearAll(); |
400 screen52.restoreScreen(); | 398 screen52.restoreScreen(); |
401 | |
402 controller.fireSessionChanged(TN5250jConstants.STATE_DISCONNECTED); | |
403 | |
404 } catch (Exception exception) { | 399 } catch (Exception exception) { |
405 log.warn(exception.getMessage()); | 400 log.warn(exception.getMessage()); |
406 connected = false; | 401 connected = false; |
407 devSeq = -1; | 402 devSeq = -1; |
408 return false; | 403 return false; |
1163 log.debug(" Cursor Active " + screen52.cursorActive); | 1158 log.debug(" Cursor Active " + screen52.cursorActive); |
1164 } | 1159 } |
1165 | 1160 |
1166 } | 1161 } |
1167 | 1162 |
1168 // private final void execCmd() { | |
1169 // String name = ""; | |
1170 // String argString = ""; | |
1171 // | |
1172 // StringBuffer sb = new StringBuffer(); | |
1173 // sb.append(screen52.screen[0][3].getChar()); | |
1174 // sb.append(screen52.screen[0][4].getChar()); | |
1175 // sb.append(screen52.screen[0][5].getChar()); | |
1176 // sb.append(screen52.screen[0][6].getChar()); | |
1177 // | |
1178 // System.out.println("command = " + sb); | |
1179 // int x = 8; | |
1180 // sb.setLength(0); | |
1181 // while (screen52.screen[0][x].getChar() > ' ') { | |
1182 // sb.append(screen52.screen[0][x].getChar()); | |
1183 // x++; | |
1184 // } | |
1185 // name = sb.toString(); | |
1186 // System.out.println("name = " + name); | |
1187 // | |
1188 // sb.setLength(0); | |
1189 // x++; | |
1190 // while (screen52.screen[0][x].getChar() >= ' ') { | |
1191 // sb.append(screen52.screen[0][x].getChar()); | |
1192 // x++; | |
1193 // } | |
1194 // argString = sb.toString(); | |
1195 // System.out.println("args = " + argString); | |
1196 // | |
1197 // sendAidKey(AID_ENTER); | |
1198 // | |
1199 // try { | |
1200 // | |
1201 // Class c = Class.forName(name); | |
1202 // String args1[] = {argString}; | |
1203 // String args2[] = {}; | |
1204 // | |
1205 // Method m = c.getMethod("main", | |
1206 // new Class[] { args1.getClass() }); | |
1207 // m.setAccessible(true); | |
1208 // int mods = m.getModifiers(); | |
1209 // if (m.getReturnType() != | |
1210 // void.class || !Modifier.isStatic(mods) || | |
1211 // !Modifier.isPublic(mods)) { | |
1212 // | |
1213 // throw new NoSuchMethodException("main"); | |
1214 // } | |
1215 // try { | |
1216 // if (argString.length() > 0) | |
1217 // m.invoke(null, new Object[] { args1 }); | |
1218 // else | |
1219 // m.invoke(null, new Object[] { args2 }); | |
1220 // } | |
1221 // catch (IllegalAccessException e) { | |
1222 // // This should not happen, as we have | |
1223 // // disabled access checks | |
1224 // System.out.println("iae " + e.getMessage()); | |
1225 // | |
1226 // } | |
1227 // } | |
1228 // catch (ClassNotFoundException cnfe) { | |
1229 // System.out.println("cnfe " + cnfe.getMessage()); | |
1230 // } | |
1231 // catch (NoSuchMethodException nsmf) { | |
1232 // System.out.println("nsmf " + nsmf.getMessage()); | |
1233 // } | |
1234 // catch (InvocationTargetException ite) { | |
1235 // System.out.println("ite " + ite.getMessage()); | |
1236 // } | |
1237 // // catch (IllegalAccessException iae) { | |
1238 // // System.out.println("iae " + iae.getMessage()); | |
1239 // // } | |
1240 // // catch (InstantiationException ie) { | |
1241 // // System.out.println("ie " + ie.getMessage()); | |
1242 // // } | |
1243 // // try { | |
1244 // // | |
1245 // // Runtime rt = Runtime.getRuntime(); | |
1246 // // Process proc = rt.exec("notepad"); | |
1247 // // int exitVal = proc.exitValue(); | |
1248 // // } | |
1249 // // catch (Throwable t) { | |
1250 // // | |
1251 // // t.printStackTrace(); | |
1252 // // } | |
1253 // } | |
1254 | 1163 |
1255 private final void readScreen() throws IOException { | 1164 private final void readScreen() throws IOException { |
1256 | |
1257 int rows = screen52.getRows(); | 1165 int rows = screen52.getRows(); |
1258 int cols = screen52.getColumns(); | 1166 int cols = screen52.getColumns(); |
1259 byte abyte0[] = new byte[rows * cols]; | 1167 byte abyte0[] = new byte[rows * cols]; |
1260 fillScreenArray(abyte0, rows, cols); | 1168 fillScreenArray(abyte0, rows, cols); |
1261 writeGDS(0, 0, abyte0); | 1169 writeGDS(0, 0, abyte0); |
1262 abyte0 = null; | 1170 abyte0 = null; |
1263 } | 1171 } |
1264 | 1172 |
1265 private final void fillScreenArray(byte[] sa, int rows, int cols) { | 1173 private final void fillScreenArray(byte[] sa, int rows, int cols) { |
1266 | |
1267 int la = 32; | 1174 int la = 32; |
1268 int sac = 0; | 1175 int sac = 0; |
1269 int len = rows * cols; | 1176 int len = rows * cols; |
1270 | 1177 |
1271 ScreenPlanes planes = screen52.planes; | 1178 ScreenPlanes planes = screen52.planes; |
1978 } | 1885 } |
1979 | 1886 |
1980 break; | 1887 break; |
1981 | 1888 |
1982 case 21: // WTDSF - Write To Display Structured Field order | 1889 case 21: // WTDSF - Write To Display Structured Field order |
1983 log | 1890 log.debug("WTDSF - Write To Display Structured Field order"); |
1984 .debug("WTDSF - Write To Display Structured Field order"); | |
1985 byte[] seg = bk.getSegment(); | 1891 byte[] seg = bk.getSegment(); |
1986 error = sfParser.parseWriteToDisplayStructuredField(seg); | 1892 error = sfParser.parseWriteToDisplayStructuredField(seg); |
1987 | |
1988 // error = writeToDisplayStructuredField(); | |
1989 break; | 1893 break; |
1990 | 1894 |
1991 case 29: // SF - Start of Field | 1895 case 29: // SF - Start of Field |
1992 log.debug("SF - Start of Field"); | 1896 log.debug("SF - Start of Field"); |
1993 int fcw1 = 0; | 1897 int fcw1 = 0; |
2000 | 1904 |
2001 fcw1 = bk.getNextByte() & 0xff; // check for field | 1905 fcw1 = bk.getNextByte() & 0xff; // check for field |
2002 // control word | 1906 // control word |
2003 | 1907 |
2004 // check if the first fcw1 is an 0x81 if it is then get | 1908 // check if the first fcw1 is an 0x81 if it is then get |
2005 // the | 1909 // the next pair for checking |
2006 // next pair for checking | |
2007 if (fcw1 == 0x81) { | 1910 if (fcw1 == 0x81) { |
2008 bk.getNextByte(); | 1911 bk.getNextByte(); |
2009 fcw1 = bk.getNextByte() & 0xff; // check for field | 1912 fcw1 = bk.getNextByte() & 0xff; // check for field |
2010 // control word | 1913 // control word |
2011 } | 1914 } |
2021 + " "); | 1924 + " "); |
2022 log.info(Integer.toHexString(attr) | 1925 log.info(Integer.toHexString(attr) |
2023 + " " | 1926 + " " |
2024 + Integer.toHexString(bk | 1927 + Integer.toHexString(bk |
2025 .getNextByte() & 0xff)); | 1928 .getNextByte() & 0xff)); |
2026 // bk.getNextByte(); | 1929 attr = bk.getNextByte() & 0xff; // attribute field |
2027 attr = bk.getNextByte() & 0xff; // attribute | |
2028 // field | |
2029 } | 1930 } |
2030 } else { | 1931 } else { |
2031 attr = fcw1; // attribute of field | 1932 attr = fcw1; // attribute of field |
2032 fcw1 = 0; | 1933 fcw1 = 0; |
2033 } | 1934 } |
2131 bk.getNextByte(); // resequence fields | 2032 bk.getNextByte(); // resequence fields |
2132 | 2033 |
2133 screen52.clearTable(); | 2034 screen52.clearTable(); |
2134 | 2035 |
2135 // well that is the first time I have seen this. This fixes a | 2036 // well that is the first time I have seen this. This fixes a |
2136 // problem | 2037 // problem with S/36 command line. Finally got it. |
2137 // with S/36 command line. Finally got it. | 2038 if (l <= 3) return false; |
2138 if (l <= 3) | |
2139 return false; | |
2140 | 2039 |
2141 screen52.setErrorLine(bk.getNextByte()); // error row | 2040 screen52.setErrorLine(bk.getNextByte()); // error row |
2142 | 2041 |
2143 int byte1 = 0; | 2042 int byte1 = 0; |
2144 if (l >= 5) { | 2043 if (l >= 5) { |