3
|
1 /**
|
|
2 * Title: tnvt.java
|
|
3 * Copyright: Copyright (c) 2001 Company:
|
|
4 *
|
|
5 * @author Kenneth J. Pouncey
|
|
6 * @version 0.5
|
|
7 *
|
|
8 * Description:
|
|
9 *
|
|
10 * This program is free software; you can redistribute it and/or modify it under
|
|
11 * the terms of the GNU General Public License as published by the Free Software
|
|
12 * Foundation; either version 2, or (at your option) any later version.
|
|
13 *
|
|
14 * This program is distributed in the hope that it will be useful, but WITHOUT
|
|
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
17 * details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU General Public License along with
|
|
20 * this software; see the file COPYING. If not, write to the Free Software
|
|
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
22 *
|
|
23 */
|
|
24 package org.tn5250j.framework.tn5250;
|
|
25
|
|
26 import static org.tn5250j.TN5250jConstants.AID_HELP;
|
|
27 import static org.tn5250j.TN5250jConstants.AID_PRINT;
|
|
28 import static org.tn5250j.TN5250jConstants.CMD_CLEAR_FORMAT_TABLE;
|
|
29 import static org.tn5250j.TN5250jConstants.CMD_CLEAR_UNIT;
|
|
30 import static org.tn5250j.TN5250jConstants.CMD_CLEAR_UNIT_ALTERNATE;
|
|
31 import static org.tn5250j.TN5250jConstants.CMD_READ_INPUT_FIELDS;
|
|
32 import static org.tn5250j.TN5250jConstants.CMD_READ_MDT_FIELDS;
|
|
33 import static org.tn5250j.TN5250jConstants.CMD_READ_MDT_IMMEDIATE_ALT;
|
|
34 import static org.tn5250j.TN5250jConstants.CMD_READ_SCREEN_IMMEDIATE;
|
|
35 import static org.tn5250j.TN5250jConstants.CMD_READ_SCREEN_TO_PRINT;
|
|
36 import static org.tn5250j.TN5250jConstants.CMD_RESTORE_SCREEN;
|
|
37 import static org.tn5250j.TN5250jConstants.CMD_ROLL;
|
|
38 import static org.tn5250j.TN5250jConstants.CMD_SAVE_SCREEN;
|
|
39 import static org.tn5250j.TN5250jConstants.CMD_WRITE_ERROR_CODE;
|
|
40 import static org.tn5250j.TN5250jConstants.CMD_WRITE_ERROR_CODE_TO_WINDOW;
|
|
41 import static org.tn5250j.TN5250jConstants.CMD_WRITE_STRUCTURED_FIELD;
|
|
42 import static org.tn5250j.TN5250jConstants.CMD_WRITE_TO_DISPLAY;
|
|
43 import static org.tn5250j.TN5250jConstants.NR_REQUEST_ERROR;
|
|
44 import static org.tn5250j.TN5250jConstants.PF1;
|
|
45 import static org.tn5250j.TN5250jConstants.PF10;
|
|
46 import static org.tn5250j.TN5250jConstants.PF11;
|
|
47 import static org.tn5250j.TN5250jConstants.PF12;
|
|
48 import static org.tn5250j.TN5250jConstants.PF13;
|
|
49 import static org.tn5250j.TN5250jConstants.PF14;
|
|
50 import static org.tn5250j.TN5250jConstants.PF15;
|
|
51 import static org.tn5250j.TN5250jConstants.PF16;
|
|
52 import static org.tn5250j.TN5250jConstants.PF17;
|
|
53 import static org.tn5250j.TN5250jConstants.PF18;
|
|
54 import static org.tn5250j.TN5250jConstants.PF19;
|
|
55 import static org.tn5250j.TN5250jConstants.PF2;
|
|
56 import static org.tn5250j.TN5250jConstants.PF20;
|
|
57 import static org.tn5250j.TN5250jConstants.PF21;
|
|
58 import static org.tn5250j.TN5250jConstants.PF22;
|
|
59 import static org.tn5250j.TN5250jConstants.PF23;
|
|
60 import static org.tn5250j.TN5250jConstants.PF24;
|
|
61 import static org.tn5250j.TN5250jConstants.PF3;
|
|
62 import static org.tn5250j.TN5250jConstants.PF4;
|
|
63 import static org.tn5250j.TN5250jConstants.PF5;
|
|
64 import static org.tn5250j.TN5250jConstants.PF6;
|
|
65 import static org.tn5250j.TN5250jConstants.PF7;
|
|
66 import static org.tn5250j.TN5250jConstants.PF8;
|
|
67 import static org.tn5250j.TN5250jConstants.PF9;
|
|
68
|
|
69 import java.io.BufferedInputStream;
|
|
70 import java.io.BufferedOutputStream;
|
|
71 import java.io.ByteArrayOutputStream;
|
|
72 import java.io.IOException;
|
|
73 import java.io.InputStream;
|
|
74 import java.io.OutputStream;
|
|
75 import java.net.Socket;
|
|
76 import java.util.Arrays;
|
|
77 import java.util.Properties;
|
|
78 import java.util.concurrent.ArrayBlockingQueue;
|
|
79 import java.util.concurrent.BlockingQueue;
|
|
80
|
|
81 import javax.net.ssl.SSLSocket;
|
|
82
|
8
|
83 import com.five_ten_sg.connectbot.service.TerminalBridge;
|
|
84 import com.five_ten_sg.connectbot.service.TerminalManager;
|
|
85
|
3
|
86 import org.tn5250j.TN5250jConstants;
|
|
87 import org.tn5250j.encoding.CharMappings;
|
|
88 import org.tn5250j.encoding.ICodePage;
|
|
89 import org.tn5250j.framework.transport.SocketConnector;
|
|
90 import org.tn5250j.tools.logging.TN5250jLogFactory;
|
|
91 import org.tn5250j.tools.logging.TN5250jLogger;
|
|
92
|
|
93 public final class tnvt implements Runnable {
|
|
94 // negotiating commands
|
|
95 private static final byte IAC = (byte) -1; // 255 FF
|
|
96 private static final byte DONT = (byte) -2; //254 FE
|
|
97 private static final byte DO = (byte) -3; //253 FD
|
|
98 private static final byte WONT = (byte) -4; //252 FC
|
|
99 private static final byte WILL = (byte) -5; //251 FB
|
|
100 private static final byte SB = (byte) -6; //250 Sub Begin FA
|
|
101 private static final byte SE = (byte) -16; //240 Sub End F0
|
|
102 private static final byte EOR = (byte) -17; //239 End of Record EF
|
|
103 private static final byte TERMINAL_TYPE = (byte) 24; // 18
|
|
104 private static final byte OPT_END_OF_RECORD = (byte) 25; // 19
|
|
105 private static final byte TRANSMIT_BINARY = (byte) 0; // 0
|
|
106 private static final byte QUAL_IS = (byte) 0; // 0
|
|
107 private static final byte TIMING_MARK = (byte) 6; // 6
|
|
108 private static final byte NEW_ENVIRONMENT = (byte) 39; // 27
|
|
109 private static final byte IS = (byte) 0; // 0
|
|
110 private static final byte SEND = (byte) 1; // 1
|
|
111 private static final byte INFO = (byte) 2; // 2
|
|
112 private static final byte VAR = (byte) 0; // 0
|
|
113 private static final byte VALUE = (byte) 1; // 1
|
|
114 private static final byte NEGOTIATE_ESC = (byte) 2; // 2
|
|
115 private static final byte USERVAR = (byte) 3; // 3
|
|
116
|
|
117 // miscellaneous
|
|
118 private static final byte ESC = 0x04; // 04
|
|
119
|
|
120 private Socket sock;
|
11
|
121 public BufferedInputStream bin;
|
|
122 public BufferedOutputStream bout;
|
3
|
123 private final BlockingQueue<Object> dsq = new ArrayBlockingQueue<Object>(25);
|
|
124 private Stream5250 bk;
|
|
125 private DataStreamProducer producer;
|
|
126 protected Screen5250 screen52;
|
|
127 private boolean waitingForInput;
|
|
128 private boolean invited;
|
|
129 private boolean negotiated = false;
|
|
130 private Thread me;
|
|
131 private Thread pthread;
|
|
132 private int readType;
|
|
133 private boolean enhanced = true;
|
|
134 private boolean cursorOn = false;
|
10
|
135 private String hostname = "";
|
3
|
136 private int port = 23;
|
|
137 private boolean connected = false;
|
|
138 private boolean support132 = true;
|
|
139 private ByteArrayOutputStream baosp = null;
|
|
140 private ByteArrayOutputStream baosrsp = null;
|
|
141 private int devSeq = -1;
|
|
142 private String devName;
|
|
143 private String devNameUsed;
|
|
144 private KbdTypesCodePages kbdTypesCodePage;
|
|
145 // WVL - LDC : TR.000300 : Callback scenario from 5250
|
|
146 private boolean scan; // = false;
|
|
147 private static int STRSCAN = 1;
|
|
148 // WVL - LDC : 05/08/2005 : TFX.006253 - support STRPCCMD
|
|
149 private boolean strpccmd; // = false;
|
|
150 private String user;
|
|
151 private String password;
|
|
152 private String library;
|
|
153 private String initialMenu;
|
|
154 private String program;
|
|
155 private boolean keepTrucking = true;
|
|
156 private boolean pendingUnlock = false;
|
|
157 private boolean[] dataIncluded;
|
|
158 protected ICodePage codePage;
|
|
159 private boolean firstScreen;
|
|
160 private String sslType;
|
|
161 private WTDSFParser sfParser;
|
8
|
162 private TerminalBridge bridge;
|
|
163 private TerminalManager manager;
|
3
|
164
|
|
165 private final TN5250jLogger log = TN5250jLogFactory.getLogger(this.getClass());
|
|
166
|
|
167 /**
|
|
168 * @param screen52
|
10
|
169 * @param enhanced
|
3
|
170 * @param support132
|
10
|
171 * @param bridge
|
|
172 * @param manager
|
3
|
173 */
|
8
|
174 public tnvt(Screen5250 screen52, boolean enhanced, boolean support132, TerminalBridge bridge, TerminalManager manager) {
|
|
175 this.screen52 = screen52;
|
3
|
176 this.support132 = support132;
|
8
|
177 this.enhanced = enhanced;
|
|
178 this.bridge = bridge;
|
|
179 this.manager = manager;
|
3
|
180 setCodePage("37");
|
|
181 dataIncluded = new boolean[24];
|
|
182
|
|
183 if (System.getProperties().containsKey("SESSION_CONNECT_USER")) {
|
|
184 user = System.getProperties().getProperty("SESSION_CONNECT_USER");
|
|
185 if (System.getProperties().containsKey("SESSION_CONNECT_PASSWORD"))
|
|
186 password = System.getProperties().getProperty(
|
|
187 "SESSION_CONNECT_PASSWORD");
|
|
188 if (System.getProperties().containsKey("SESSION_CONNECT_LIBRARY"))
|
|
189 library = System.getProperties().getProperty(
|
|
190 "SESSION_CONNECT_LIBRARY");
|
|
191 if (System.getProperties().containsKey("SESSION_CONNECT_MENU"))
|
|
192 initialMenu = System.getProperties().getProperty(
|
|
193 "SESSION_CONNECT_MENU");
|
|
194 if (System.getProperties().containsKey("SESSION_CONNECT_PROGRAM"))
|
|
195 program = System.getProperties().getProperty(
|
|
196 "SESSION_CONNECT_PROGRAM");
|
|
197 }
|
|
198
|
|
199 baosp = new ByteArrayOutputStream();
|
|
200 baosrsp = new ByteArrayOutputStream();
|
|
201 }
|
|
202
|
10
|
203 public void showURL(String url) {
|
|
204 if (url.indexOf("://") < 0) url = "http://" + url;
|
|
205 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
|
206 manager.startActivity(intent);
|
|
207 }
|
|
208
|
3
|
209 public String getHostName() {
|
|
210
|
10
|
211 return hostname;
|
3
|
212 }
|
|
213
|
|
214
|
|
215 public void setSSLType(String type) {
|
|
216 sslType = type;
|
|
217 }
|
|
218
|
|
219 public void setDeviceName(String name) {
|
|
220
|
|
221 devName = name;
|
|
222
|
|
223 }
|
|
224
|
|
225 public String getDeviceName() {
|
|
226 return devName;
|
|
227 }
|
|
228
|
|
229 public String getAllocatedDeviceName() {
|
|
230 return devNameUsed;
|
|
231 }
|
|
232
|
|
233 public boolean isConnected() {
|
|
234
|
|
235 return connected;
|
|
236 }
|
|
237
|
|
238 /**
|
|
239 * @return true when SSL is used and socket is connected.
|
|
240 * @see {@link #isConnected()}
|
|
241 */
|
|
242 public boolean isSslSocket() {
|
|
243 if (this.connected && this.sock != null && this.sock instanceof SSLSocket) {
|
|
244 return true;
|
|
245 } else {
|
|
246 return false;
|
|
247 }
|
|
248 }
|
|
249
|
|
250 public final void setProxy(String proxyHost, String proxyPort) {
|
|
251
|
|
252 Properties systemProperties = System.getProperties();
|
|
253 systemProperties.put("socksProxySet", "true");
|
|
254 systemProperties.put("socksProxyHost", proxyHost);
|
|
255 systemProperties.put("socksProxyPort", proxyPort);
|
|
256
|
|
257 System.setProperties(systemProperties);
|
|
258 log.info(" socks set ");
|
|
259 }
|
|
260
|
|
261 public final boolean connect() {
|
|
262
|
10
|
263 return connect(hostname, port);
|
3
|
264
|
|
265 }
|
|
266
|
|
267
|
10
|
268 public final boolean connect(String hostname, int port) {
|
3
|
269
|
|
270 // We will now see if there are any bypass signon parameters to be
|
|
271 // processed. The system properties override these parameters so
|
|
272 // have precidence if specified.
|
|
273 Properties props = controller.getConnectionProperties();
|
|
274 if (user == null && props.containsKey("SESSION_CONNECT_USER")) {
|
|
275 user = props.getProperty("SESSION_CONNECT_USER");
|
|
276 log.info(" user -> " + user + " " + controller.getSessionName());
|
|
277 if (props.containsKey("SESSION_CONNECT_PASSWORD"))
|
|
278 password = props.getProperty("SESSION_CONNECT_PASSWORD");
|
|
279 if (props.containsKey("SESSION_CONNECT_LIBRARY"))
|
|
280 library = props.getProperty("SESSION_CONNECT_LIBRARY");
|
|
281 if (props.containsKey("SESSION_CONNECT_MENU"))
|
|
282 initialMenu = props.getProperty("SESSION_CONNECT_MENU");
|
|
283 if (props.containsKey("SESSION_CONNECT_PROGRAM"))
|
|
284 program = props.getProperty("SESSION_CONNECT_PROGRAM");
|
|
285 }
|
|
286
|
|
287
|
|
288 try {
|
10
|
289 this.hostname = hostname;
|
|
290 this.port = port;
|
3
|
291
|
|
292 try {
|
6
|
293 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
3
|
294 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED,"X - Connecting");
|
|
295 } catch (Exception exc) {
|
|
296 log.warn("setStatus(ON) " + exc.getMessage());
|
|
297 }
|
|
298
|
|
299 // sock = new Socket(s, port);
|
|
300 //smk - For SSL compability
|
|
301 SocketConnector sc = new SocketConnector();
|
8
|
302 if (sslType != null) sc.setSSLType(sslType);
|
10
|
303 sock = sc.createSocket(hostname, port, bridge, manager);
|
3
|
304
|
|
305 if (sock == null) {
|
|
306 log.warn("I did not get a socket");
|
|
307 disconnect();
|
|
308 return false;
|
|
309 }
|
|
310
|
|
311 connected = true;
|
|
312 // used for JDK1.3
|
|
313 sock.setKeepAlive(true);
|
|
314 sock.setTcpNoDelay(true);
|
|
315 sock.setSoLinger(false, 0);
|
|
316 InputStream in = sock.getInputStream();
|
|
317 OutputStream out = sock.getOutputStream();
|
|
318
|
|
319 bin = new BufferedInputStream(in, 8192);
|
|
320 bout = new BufferedOutputStream(out);
|
|
321
|
|
322 byte abyte0[];
|
|
323 while (negotiate(abyte0 = readNegotiations()));
|
|
324 negotiated = true;
|
|
325 try {
|
|
326 screen52.setCursorActive(false);
|
|
327 } catch (Exception excc) {
|
|
328 log.warn("setCursorOff " + excc.getMessage());
|
|
329
|
|
330 }
|
|
331
|
|
332 producer = new DataStreamProducer(this, bin, dsq, abyte0);
|
|
333 pthread = new Thread(producer);
|
|
334 // pthread.setPriority(pthread.MIN_PRIORITY);
|
|
335 pthread.setPriority(Thread.NORM_PRIORITY);
|
|
336 // pthread.setPriority(Thread.NORM_PRIORITY / 2);
|
|
337 pthread.start();
|
|
338
|
|
339 try {
|
6
|
340 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_NOTINHIBITED,
|
3
|
341 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED);
|
|
342 } catch (Exception exc) {
|
|
343 log.warn("setStatus(OFF) " + exc.getMessage());
|
|
344 }
|
|
345
|
|
346 keepTrucking = true;
|
|
347 me = new Thread(this);
|
|
348 me.start();
|
|
349
|
|
350 } catch (Exception exception) {
|
|
351 if (exception.getMessage() == null)
|
|
352 exception.printStackTrace();
|
|
353 log.warn("connect() " + exception.getMessage());
|
|
354
|
|
355 if (sock == null)
|
|
356 log.warn("I did not get a socket");
|
|
357
|
|
358 disconnect();
|
|
359 return false;
|
|
360 }
|
|
361 return true;
|
|
362
|
|
363 }
|
|
364
|
|
365 public final boolean disconnect() {
|
|
366
|
|
367 // Added by LUC - LDC to fix a null pointer exception.
|
|
368 if (!connected) {
|
|
369 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
|
370 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED,"X - Disconnected");
|
|
371 return false;
|
|
372 }
|
|
373
|
|
374 if (me != null && me.isAlive()) {
|
|
375 me.interrupt();
|
|
376 keepTrucking = false;
|
|
377 pthread.interrupt();
|
|
378 }
|
|
379
|
|
380 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
|
381 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED,"X - Disconnected");
|
|
382 screen52.getOIA().setKeyBoardLocked(false);
|
|
383 pendingUnlock = false;
|
|
384
|
|
385 try {
|
|
386 if (sock != null) {
|
|
387 log.info("Closing socket");
|
|
388 sock.close();
|
|
389 }
|
8
|
390 if (bin != null) bin.close();
|
|
391 if (bout != null) bout.close();
|
|
392 connected = false;
|
3
|
393 firstScreen = false;
|
|
394
|
|
395 // WVL - LDC : TR.000345 : properly disconnect and clear screen
|
|
396 // Is this the right place to set screen realestate on disconnect?
|
|
397 //controller.getScreen().clearAll();
|
|
398 screen52.goto_XY(0);
|
|
399 screen52.setCursorActive(false);
|
|
400 screen52.clearAll();
|
|
401 screen52.restoreScreen();
|
|
402 } catch (Exception exception) {
|
|
403 log.warn(exception.getMessage());
|
|
404 connected = false;
|
|
405 devSeq = -1;
|
|
406 return false;
|
|
407
|
|
408 }
|
|
409 devSeq = -1;
|
|
410 return true;
|
|
411 }
|
|
412
|
|
413 private final ByteArrayOutputStream appendByteStream(byte abyte0[]) {
|
|
414 ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
415 for (int i = 0; i < abyte0.length; i++) {
|
|
416 bytearrayoutputstream.write(abyte0[i]);
|
|
417 if (abyte0[i] == -1)
|
|
418 bytearrayoutputstream.write(-1);
|
|
419 }
|
|
420
|
|
421 return bytearrayoutputstream;
|
|
422 }
|
|
423
|
|
424 private final byte[] readNegotiations() throws IOException {
|
|
425 int i = bin.read();
|
|
426 if (i < 0) {
|
|
427 throw new IOException("Connection closed.");
|
|
428 } else {
|
|
429 int j = bin.available();
|
|
430 byte abyte0[] = new byte[j + 1];
|
|
431 abyte0[0] = (byte) i;
|
|
432 bin.read(abyte0, 1, j);
|
|
433 return abyte0;
|
|
434 }
|
|
435 }
|
|
436
|
|
437 private final void writeByte(byte abyte0[]) throws IOException {
|
|
438
|
|
439 bout.write(abyte0);
|
|
440 bout.flush();
|
|
441 }
|
|
442
|
|
443 // private final void writeByte(byte byte0) throws IOException {
|
|
444 //
|
|
445 // bout.write(byte0);
|
|
446 // bout.flush();
|
|
447 // }
|
|
448
|
|
449 public final void sendHeartBeat() throws IOException {
|
|
450
|
|
451 byte[] b = { (byte) 0xff, (byte) 0xf1 };
|
|
452 bout.write(b);
|
|
453 bout.flush();
|
|
454 }
|
|
455
|
|
456 private final void readImmediate(int readType) {
|
|
457
|
|
458 if (screen52.isStatusErrorCode()) {
|
|
459 screen52.restoreErrorLine();
|
|
460 screen52.setStatus(Screen5250.STATUS_ERROR_CODE,
|
|
461 Screen5250.STATUS_VALUE_OFF, null);
|
|
462 }
|
|
463
|
|
464 if (!enhanced) {
|
|
465 screen52.setCursorActive(false);
|
|
466 }
|
|
467 // screen52.setStatus(Screen5250.STATUS_SYSTEM,
|
|
468 // Screen5250.STATUS_VALUE_ON, null);
|
|
469 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
|
470 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED);
|
|
471
|
|
472 screen52.getOIA().setKeyBoardLocked(true);
|
|
473 pendingUnlock = false;
|
|
474 invited = false;
|
|
475
|
|
476 screen52.getScreenFields().readFormatTable(baosp, readType, codePage);
|
|
477
|
|
478 try {
|
|
479
|
|
480 writeGDS(0, 3, baosp.toByteArray());
|
|
481 } catch (IOException ioe) {
|
|
482
|
|
483 log.warn(ioe.getMessage());
|
|
484 baosp.reset();
|
|
485 }
|
|
486 baosp.reset();
|
|
487
|
|
488 }
|
|
489
|
|
490 public final boolean sendAidKey(int aid) {
|
|
491
|
|
492 if (screen52.isStatusErrorCode()) {
|
|
493 screen52.restoreErrorLine();
|
|
494 screen52.setStatus(Screen5250.STATUS_ERROR_CODE,
|
|
495 Screen5250.STATUS_VALUE_OFF, null);
|
|
496 }
|
|
497
|
|
498 if (!enhanced) {
|
|
499 screen52.setCursorActive(false);
|
|
500 }
|
|
501 // screen52.setStatus(Screen5250.STATUS_SYSTEM,
|
|
502 // Screen5250.STATUS_VALUE_ON, null);
|
|
503 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
|
504 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED);
|
|
505
|
|
506 screen52.getOIA().setKeyBoardLocked(true);
|
|
507 pendingUnlock = false;
|
|
508 invited = false;
|
|
509 baosp.write(screen52.getCurrentRow());
|
|
510 baosp.write(screen52.getCurrentCol());
|
|
511 baosp.write(aid);
|
|
512
|
|
513 if (dataIncluded(aid))
|
|
514
|
|
515 screen52.getScreenFields().readFormatTable(baosp, readType,
|
|
516 codePage);
|
|
517
|
|
518 try {
|
|
519
|
|
520 writeGDS(0, 3, baosp.toByteArray());
|
|
521 } catch (IOException ioe) {
|
|
522
|
|
523 log.warn(ioe.getMessage());
|
|
524 baosp.reset();
|
|
525 return false;
|
|
526 }
|
|
527 baosp.reset();
|
|
528 return true;
|
|
529
|
|
530 }
|
|
531
|
|
532 private boolean dataIncluded(int aid) {
|
|
533
|
|
534 switch (aid) {
|
|
535
|
|
536 case PF1:
|
|
537 return !dataIncluded[0];
|
|
538 case PF2:
|
|
539 return !dataIncluded[1];
|
|
540 case PF3:
|
|
541 return !dataIncluded[2];
|
|
542 case PF4:
|
|
543 return !dataIncluded[3];
|
|
544 case PF5:
|
|
545 return !dataIncluded[4];
|
|
546 case PF6:
|
|
547 return !dataIncluded[5];
|
|
548 case PF7:
|
|
549 return !dataIncluded[6];
|
|
550 case PF8:
|
|
551 return !dataIncluded[7];
|
|
552 case PF9:
|
|
553 return !dataIncluded[8];
|
|
554 case PF10:
|
|
555 return !dataIncluded[9];
|
|
556 case PF11:
|
|
557 return !dataIncluded[10];
|
|
558 case PF12:
|
|
559 return !dataIncluded[11];
|
|
560 case PF13:
|
|
561 return !dataIncluded[12];
|
|
562 case PF14:
|
|
563 return !dataIncluded[13];
|
|
564 case PF15:
|
|
565 return !dataIncluded[14];
|
|
566 case PF16:
|
|
567 return !dataIncluded[15];
|
|
568 case PF17:
|
|
569 return !dataIncluded[16];
|
|
570 case PF18:
|
|
571 return !dataIncluded[17];
|
|
572 case PF19:
|
|
573 return !dataIncluded[18];
|
|
574 case PF20:
|
|
575 return !dataIncluded[19];
|
|
576 case PF21:
|
|
577 return !dataIncluded[20];
|
|
578 case PF22:
|
|
579 return !dataIncluded[21];
|
|
580 case PF23:
|
|
581 return !dataIncluded[22];
|
|
582 case PF24:
|
|
583 return !dataIncluded[23];
|
|
584
|
|
585 default:
|
|
586 return true;
|
|
587
|
|
588 }
|
|
589
|
|
590 }
|
|
591
|
|
592 /**
|
|
593 * Help request -
|
|
594 *
|
|
595 *
|
|
596 * See notes inside method
|
|
597 */
|
|
598 public final void sendHelpRequest() {
|
|
599
|
|
600 // Client sends header 000D12A0000004000003####F3FFEF
|
|
601 // operation code 3
|
|
602 // row - first ##
|
|
603 // column - second ##
|
|
604 // F3 - Help Aid Key
|
|
605 // System.out.println("Help request sent");
|
|
606 baosp.write(screen52.getCurrentRow());
|
|
607 baosp.write(screen52.getCurrentCol());
|
|
608 baosp.write(AID_HELP);
|
|
609
|
|
610 try {
|
|
611 writeGDS(0, 3, baosp.toByteArray());
|
|
612 } catch (IOException ioe) {
|
|
613
|
|
614 log.warn(ioe.getMessage());
|
|
615 }
|
|
616 baosp.reset();
|
|
617 }
|
|
618
|
|
619 /**
|
|
620 * Attention Key -
|
|
621 *
|
|
622 *
|
|
623 * See notes inside method
|
|
624 */
|
|
625 public final void sendAttentionKey() {
|
|
626
|
|
627 // Client sends header 000A12A000004400000FFEF
|
|
628 // 0x40 -> 01000000
|
|
629 //
|
|
630 // flags
|
|
631 // bit 0 - ERR
|
|
632 // bit 1 - ATN Attention
|
|
633 // bits 2-4 - reserved
|
|
634 // bit 5 - SRQ system request
|
|
635 // bit 6 - TRQ Test request key
|
|
636 // bit 7 - HLP
|
|
637
|
|
638 // System.out.println("Attention key sent");
|
|
639
|
|
640 try {
|
|
641 writeGDS(0x40, 0, null);
|
|
642 } catch (IOException ioe) {
|
|
643
|
|
644 log.warn(ioe.getMessage());
|
|
645 }
|
|
646 }
|
|
647
|
|
648 /**
|
|
649 * Opens a dialog and asks the user before sending a request
|
|
650 *
|
|
651 * @see {@link #systemRequest(String)}
|
|
652 */
|
|
653 public final void systemRequest() {
|
|
654 final String sysreq = this.controller.showSystemRequest();
|
|
655 systemRequest(sysreq);
|
|
656 }
|
|
657
|
|
658 /**
|
|
659 * @param sr - system request option
|
|
660 * @see {@link #systemRequest(String)}
|
|
661 */
|
|
662 public final void systemRequest(char sr) {
|
|
663 systemRequest(Character.toString(sr));
|
|
664 }
|
|
665
|
|
666 /**
|
|
667 * System request, taken from the rfc1205, 5250 Telnet interface section 4.3
|
|
668 *
|
|
669 * @param sr system request option (allowed to be null, but than nothing happens)
|
|
670 */
|
|
671 public final void systemRequest(String sr) {
|
|
672 byte[] bytes = null;
|
|
673
|
|
674 if ( (sr != null) && (sr.length() > 0)) {
|
|
675 // XXX: Not sure, if this is a sufficient check for 'clear dataq'
|
|
676 if (sr.charAt(0) == '2') {
|
|
677 dsq.clear();
|
|
678 }
|
|
679 for (int i = 0, l = sr.length(); i < l; i++) {
|
|
680 baosp.write(codePage.uni2ebcdic(sr.charAt(i)));
|
|
681 }
|
|
682 bytes = baosp.toByteArray();
|
|
683 }
|
|
684
|
|
685 try {
|
|
686 writeGDS(4, 0, bytes);
|
|
687 } catch (IOException ioe) {
|
|
688 log.info(ioe.getMessage());
|
|
689 }
|
|
690 baosp.reset();
|
|
691 }
|
|
692
|
|
693 /**
|
|
694 * Cancel Invite - taken from the rfc1205 - 5250 Telnet interface section
|
|
695 * 4.3
|
|
696 *
|
|
697 * See notes inside method
|
|
698 */
|
|
699 public final void cancelInvite() {
|
|
700
|
|
701 // screen52.setStatus(Screen5250.STATUS_SYSTEM,
|
|
702 // Screen5250.STATUS_VALUE_ON, null);
|
|
703 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
|
704 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED);
|
|
705
|
|
706 // from rfc1205 section 4.3
|
|
707 // Server: Sends header with the 000A12A0 00000400 000AFFEF
|
|
708 // Opcode = Cancel Invite.
|
|
709
|
|
710 // Client: sends header with the 000A12A0 00000400 000AFFEF
|
|
711 // Opcode = Cancel Invite to
|
|
712 // indicate that the work station is
|
|
713 // no longer invited.
|
|
714 try {
|
|
715 writeGDS(0, 10, null);
|
|
716 } catch (IOException ioe) {
|
|
717
|
|
718 log.warn(ioe.getMessage());
|
|
719 }
|
|
720
|
|
721 }
|
|
722
|
|
723 public final void hostPrint(int aid) {
|
|
724
|
|
725 if (screen52.isStatusErrorCode()) {
|
|
726 screen52.restoreErrorLine();
|
|
727 screen52.setStatus(Screen5250.STATUS_ERROR_CODE,
|
|
728 Screen5250.STATUS_VALUE_OFF, null);
|
|
729 }
|
|
730
|
|
731 screen52.setCursorActive(false);
|
|
732 // screen52.setStatus(Screen5250.STATUS_SYSTEM,
|
|
733 // Screen5250.STATUS_VALUE_ON, null);
|
|
734 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
|
735 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED);
|
|
736
|
|
737 // From client access ip capture
|
|
738 // it seems to use an operation code of 3 and 4
|
|
739 // also note that the flag field that says reserved is being sent as
|
|
740 // well
|
|
741 // with a value of 0x80
|
|
742 //
|
|
743 // I have tried with not setting these flags and sending with 3 or 1
|
|
744 // there is no effect and I still get a host print screen. Go figure
|
|
745 //0000: 000D 12A0 0000 0400 8003 1407 F6FFEF
|
|
746 //0000: 000D 12A0 0000 0400 8001 110E F6FFEF
|
|
747 //
|
|
748 // Client sends header 000D12A0000004000003####F6FFEF
|
|
749 // operation code 3
|
|
750 // row - first ##
|
|
751 // column - second ##
|
|
752 // F6 - Print Aid Key
|
|
753
|
|
754 baosp.write(screen52.getCurrentRow());
|
|
755 baosp.write(screen52.getCurrentCol());
|
|
756 baosp.write(AID_PRINT); // aid key
|
|
757
|
|
758 try {
|
|
759 writeGDS(0, 3, baosp.toByteArray());
|
|
760 } catch (IOException ioe) {
|
|
761
|
|
762 log.warn(ioe.getMessage());
|
|
763 }
|
|
764 baosp.reset();
|
|
765 }
|
|
766
|
|
767 public final void toggleDebug() {
|
|
768 producer.toggleDebug(codePage);
|
|
769 }
|
|
770
|
|
771 // write gerneral data stream
|
|
772 private final void writeGDS(int flags, int opcode, byte abyte0[])
|
|
773 throws IOException {
|
|
774
|
|
775 // Added to fix for JDK 1.4 this was null coming from another method.
|
|
776 // There was a weird keyRelease event coming from another panel when
|
|
777 // using a key instead of the mouse to select button.
|
|
778 // The other method was fixed as well but this check should be here
|
|
779 // anyway.
|
|
780 if (bout == null)
|
|
781 return;
|
|
782
|
|
783 int length;
|
|
784 if (abyte0 != null)
|
|
785 length = abyte0.length + 10;
|
|
786 else
|
|
787 length = 10;
|
|
788
|
|
789 // refer to rfc1205 - 5250 Telnet interface
|
|
790 // Section 3. Data Stream Format
|
|
791
|
|
792 // Logical Record Length - 16 bits
|
|
793 baosrsp.write(length >> 8); // Length LL
|
|
794 baosrsp.write(length & 0xff); // LL
|
|
795
|
|
796 // Record Type - 16 bits
|
|
797 // It should always be set to '12A0'X to indicate the
|
|
798 // General Data Stream (GDS) record type.
|
|
799 baosrsp.write(18); // 0x12
|
|
800 baosrsp.write(160); // 0xA0
|
|
801
|
|
802 // the next 16 bits are not used
|
|
803 baosrsp.write(0); // 0x00
|
|
804 baosrsp.write(0); // 0x00
|
|
805
|
|
806 // The second part is meant to be variable in length
|
|
807 // currently this portion is 4 octets long (1 byte or 8 bits for us ;-O)
|
|
808 baosrsp.write(4); // 0x04
|
|
809
|
|
810 baosrsp.write(flags); // flags
|
|
811 // bit 0 - ERR
|
|
812 // bit 1 - ATN Attention
|
|
813 // bits 2-4 - reserved
|
|
814 // bit 5 - SRQ system request
|
|
815 // bit 6 - TRQ Test request key
|
|
816 // bit 7 - HLP
|
|
817 baosrsp.write(0); // reserved - set to 0x00
|
|
818 baosrsp.write(opcode); // opcode
|
|
819
|
|
820 if (abyte0 != null)
|
|
821 baosrsp.write(abyte0, 0, abyte0.length);
|
|
822
|
|
823 baosrsp = appendByteStream(baosrsp.toByteArray());
|
|
824
|
|
825 // make sure we indicate no more to be sent
|
|
826 baosrsp.write(IAC);
|
|
827 baosrsp.write(EOR);
|
|
828
|
|
829 baosrsp.writeTo(bout);
|
|
830
|
|
831 // byte[] b = new byte[baosrsp.size()];
|
|
832 // b = baosrsp.toByteArray();
|
|
833 // dump(b);
|
|
834 bout.flush();
|
|
835 // baos = null;
|
|
836 baosrsp.reset();
|
|
837 }
|
|
838
|
|
839 protected final int getOpCode() {
|
|
840
|
|
841 return bk.getOpCode();
|
|
842 }
|
|
843
|
|
844 // private final void sendNotify() throws IOException {
|
|
845 //
|
|
846 // writeGDS(0, 0, null);
|
|
847 // }
|
|
848
|
|
849 protected boolean[] getActiveAidKeys() {
|
|
850 boolean aids[] = new boolean[dataIncluded.length];
|
|
851 System.arraycopy(dataIncluded,0,aids,0,dataIncluded.length);
|
|
852 return aids;
|
|
853 }
|
|
854
|
|
855 private final void setInvited() {
|
|
856
|
|
857 log.debug("invited");
|
|
858 if (!screen52.isStatusErrorCode())
|
|
859 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_NOTINHIBITED,
|
|
860 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED);
|
|
861
|
|
862 invited = true;
|
|
863 }
|
|
864
|
|
865 // WVL - LDC : 05/08/2005 : TFX.006253 - Support STRPCCMD
|
|
866 private void strpccmd()
|
|
867 {
|
|
868 try
|
|
869 {
|
|
870 int str = 11;
|
|
871 char c;
|
|
872 ScreenPlanes planes = screen52.getPlanes();
|
|
873 c = planes.getChar(str);
|
|
874 boolean waitFor = !(c == 'a');
|
|
875
|
|
876 StringBuffer command = new StringBuffer();
|
|
877 for (int i = str+1; i < 132; i++)
|
|
878 {
|
|
879 c = planes.getChar(i);
|
|
880 if (Character.isISOControl(c))
|
|
881 c = ' ';
|
|
882 command.append(c);
|
|
883 }
|
|
884
|
|
885 String cmd = command.toString().trim();
|
|
886
|
|
887 run(cmd, waitFor);
|
|
888 }
|
|
889 finally
|
|
890 {
|
|
891 strpccmd = false;
|
|
892 screen52.sendKeys(TN5250jConstants.MNEMONIC_ENTER);
|
|
893 }
|
|
894 }
|
|
895
|
|
896 // WVL - LDC : 05/08/2005 : TFX.006253 - Support STRPCCMD
|
|
897 private void run(String cmd, boolean waitFor)
|
|
898 {
|
|
899 try
|
|
900 {
|
|
901 log.debug("RUN cmd = " + cmd);
|
|
902 log.debug("RUN wait = " + waitFor);
|
|
903
|
|
904 Runtime r = Runtime.getRuntime();
|
|
905 Process p = r.exec(cmd);
|
|
906 if (waitFor)
|
|
907 {
|
|
908 int result = p.waitFor();
|
|
909 log.debug("RUN result = " + result);
|
|
910 }
|
|
911 }
|
|
912 catch (Throwable t)
|
|
913 {
|
|
914 log.error(t);
|
|
915 }
|
|
916 }
|
|
917
|
|
918
|
|
919 // WVL - LDC : TR.000300 : Callback scenario from 5250
|
|
920 /**
|
|
921 * Activate or deactivate the command scanning behaviour.
|
|
922 *
|
|
923 * @param scan
|
|
924 * if true, scanning is enabled; disabled otherwise.
|
|
925 *
|
|
926 * @see scan4Cmd()
|
|
927 */
|
|
928 public void setScanningEnabled(boolean scan) {
|
|
929 this.scan = scan;
|
|
930 }
|
|
931
|
|
932 // WVL - LDC : TR.000300 : Callback scenario from 5250
|
|
933 /**
|
|
934 * Checks whether command scanning is enabled.
|
|
935 *
|
|
936 * @return true is command scanning is enabled; false otherwise.
|
|
937 */
|
|
938 public boolean isScanningEnabled() {
|
|
939 return this.scan;
|
|
940 }
|
|
941
|
|
942 // WVL - LDC : TR.000300 : Callback scenario from 5250
|
|
943 /**
|
|
944 * When command scanning is activated, the terminal reads the first and
|
|
945 * second character in the datastream (the zero position allows to
|
|
946 * devisualize the scan stream). If the sequence <code>#!</code> is
|
|
947 * encountered and if this sequence is <strong>not </strong> followed by a
|
|
948 * blank character, the {@link parseCommand(ScreenChar[])}is called.
|
|
949 */
|
|
950 private void scan() {
|
|
951 // System.out.println("Checking command : " +
|
|
952 // screen52.screen[1].getChar() + screen52.screen[2].getChar());
|
|
953
|
|
954 // ScreenChar[] screen = screen52.screen;
|
|
955 ScreenPlanes planes = screen52.getPlanes();
|
|
956
|
|
957 if ((planes.getChar(STRSCAN) == '#')
|
|
958 && (planes.getChar(STRSCAN + 1) == '!')
|
|
959 && (planes.getChar(STRSCAN + 2) != ' ')) {
|
|
960 try {
|
|
961 parseCommand();
|
|
962 } catch (Throwable t) {
|
|
963 log.info("Exec cmd: " + t.getMessage());
|
|
964 t.printStackTrace();
|
|
965 }
|
|
966 }
|
|
967 }
|
|
968
|
|
969 // WVL - LDC : TR.000300 : Callback scenario from 5250
|
|
970 /**
|
|
971 * The screen is parsed starting from second position until a white space is
|
|
972 * encountered. When found the Session#execCommand(String, int) is
|
|
973 * called with the parsed string. The position immediately following the
|
|
974 * encountered white space, separating the command from the rest of the
|
|
975 * screen, is passed as starting index.
|
|
976 *
|
|
977 * Note that the character at the starting position can potentially be a
|
|
978 * white space itself. The starting position in <code>execCommand</code>
|
|
979 * provided to make the scanning sequence more flexible. We'd like for
|
|
980 * example to embed also a <code>+</code> or <code>-</code> sign to
|
|
981 * indicate whether the tnvt should trigger a repaint or not. This would
|
|
982 * allow the flashing of command sequences without them becoming visible.
|
|
983 *
|
|
984 * <ul>
|
|
985 * <li><strong>PRE </strong> The screen character at position
|
|
986 * <code>STRSCAN + 2</code> is not a white space.</li>
|
|
987 * </ul>
|
|
988 */
|
|
989 private void parseCommand() {
|
|
990 // Search for the command i.e. the first token in the stream
|
|
991 // after the #! sequence separated by a space from the rest
|
|
992 // of the screen.
|
|
993 char[] screen = screen52.getScreenAsAllChars();
|
|
994 for (int s = STRSCAN + 2, i = s; i < screen.length; i++) {
|
|
995 if (screen[i] == ' ') {
|
|
996 String command = new String(screen, s, i - s);
|
|
997
|
|
998 // Skip all white spaces between the command and the rest of
|
|
999 // the screen.
|
|
1000 //for (; (i < screen.length) && (screen[i] == ' '); i++);
|
|
1001
|
|
1002 String remainder = new String(screen, i + 1, screen.length
|
|
1003 - (i + 1));
|
|
1004 // System.out.println("Sensing action command in the input! = "
|
|
1005 // + command);
|
|
1006 controller.fireScanned(command, remainder);
|
|
1007 break;
|
|
1008 }
|
|
1009 }
|
|
1010 }
|
|
1011
|
|
1012 public void run() {
|
|
1013
|
|
1014 if (enhanced)
|
|
1015 sfParser = new WTDSFParser(this);
|
|
1016
|
|
1017 bk = new Stream5250();
|
|
1018
|
|
1019 while (keepTrucking) {
|
|
1020
|
|
1021 try {
|
|
1022 bk.initialize((byte[]) dsq.take());
|
|
1023 } catch (InterruptedException ie) {
|
|
1024 log.warn(" vt thread interrupted and stopping ");
|
|
1025 keepTrucking = false;
|
|
1026 continue;
|
|
1027 }
|
|
1028
|
|
1029 // lets play nicely with the others on the playground
|
|
1030 // me.yield();
|
|
1031
|
|
1032 Thread.yield();
|
|
1033
|
|
1034 invited = false;
|
|
1035
|
|
1036 screen52.setCursorActive(false);
|
|
1037
|
|
1038 // System.out.println("operation code: " + bk.getOpCode());
|
|
1039 if (bk == null)
|
|
1040 continue;
|
|
1041
|
|
1042 switch (bk.getOpCode()) {
|
|
1043 case 00:
|
|
1044 log.debug("No operation");
|
|
1045 break;
|
|
1046 case 1:
|
|
1047 log.debug("Invite Operation");
|
|
1048 parseIncoming();
|
|
1049 // screen52.setKeyboardLocked(false);
|
|
1050 pendingUnlock = true;
|
|
1051 cursorOn = true;
|
|
1052 setInvited();
|
|
1053 break;
|
|
1054 case 2:
|
|
1055 log.debug("Output Only");
|
|
1056 parseIncoming();
|
|
1057 // System.out.println(screen52.dirty);
|
|
1058 screen52.updateDirty();
|
|
1059
|
|
1060 // invited = true;
|
|
1061
|
|
1062 break;
|
|
1063 case 3:
|
|
1064 log.debug("Put/Get Operation");
|
|
1065 parseIncoming();
|
|
1066 // inviteIt =true;
|
|
1067 setInvited();
|
|
1068 if (!firstScreen) {
|
|
1069 firstScreen = true;
|
|
1070 controller.fireSessionChanged(TN5250jConstants.STATE_CONNECTED);
|
|
1071 }
|
|
1072 break;
|
|
1073 case 4:
|
|
1074 log.debug("Save Screen Operation");
|
|
1075 parseIncoming();
|
|
1076 break;
|
|
1077
|
|
1078 case 5:
|
|
1079 log.debug("Restore Screen Operation");
|
|
1080 parseIncoming();
|
|
1081 break;
|
|
1082 case 6:
|
|
1083 log.debug("Read Immediate");
|
|
1084 sendAidKey(0);
|
|
1085 break;
|
|
1086 case 7:
|
|
1087 log.debug("Reserved");
|
|
1088 break;
|
|
1089 case 8:
|
|
1090 log.debug("Read Screen Operation");
|
|
1091 try {
|
|
1092 readScreen();
|
|
1093 } catch (IOException ex) {
|
|
1094 log.warn(ex.getMessage());
|
|
1095 }
|
|
1096 break;
|
|
1097
|
|
1098 case 9:
|
|
1099 log.debug("Reserved");
|
|
1100 break;
|
|
1101
|
|
1102 case 10:
|
|
1103 log.debug("Cancel Invite Operation");
|
|
1104 cancelInvite();
|
|
1105 break;
|
|
1106
|
|
1107 case 11:
|
|
1108 log.debug("Turn on message light");
|
|
1109 screen52.getOIA().setMessageLightOn();
|
|
1110 screen52.setCursorActive(true);
|
|
1111
|
|
1112 break;
|
|
1113 case 12:
|
|
1114 log.debug("Turn off Message light");
|
|
1115 screen52.getOIA().setMessageLightOff();
|
|
1116 screen52.setCursorActive(true);
|
|
1117
|
|
1118 break;
|
|
1119 default:
|
|
1120 break;
|
|
1121 }
|
|
1122
|
|
1123 if (screen52.isUsingGuiInterface())
|
|
1124 screen52.drawFields();
|
|
1125
|
|
1126 try {
|
|
1127 if (!strpccmd) {
|
|
1128 screen52.updateDirty();
|
|
1129 } else {
|
|
1130 strpccmd();
|
|
1131 }
|
|
1132 } catch (Exception exd) {
|
|
1133 log.warn(" tnvt.run: " + exd.getMessage());
|
|
1134 exd.printStackTrace();
|
|
1135 }
|
|
1136
|
|
1137 if (pendingUnlock && !screen52.isStatusErrorCode()) {
|
|
1138 screen52.getOIA().setKeyBoardLocked(false);
|
|
1139 pendingUnlock = false;
|
|
1140 }
|
|
1141
|
|
1142 if (cursorOn && !screen52.getOIA().isKeyBoardLocked()) {
|
|
1143 screen52.setCursorActive(true);
|
|
1144 cursorOn = false;
|
|
1145 }
|
|
1146
|
|
1147 // lets play nicely with the others on the playground
|
|
1148 //me.yield();
|
|
1149 Thread.yield();
|
|
1150
|
|
1151 }
|
|
1152 }
|
|
1153
|
|
1154 public void dumpStuff() {
|
|
1155
|
|
1156 if (log.isDebugEnabled()) {
|
|
1157 log.debug(" Pending unlock " + pendingUnlock);
|
|
1158 log.debug(" Status Error " + screen52.isStatusErrorCode());
|
|
1159 log.debug(" Keyboard Locked " + screen52.getOIA().isKeyBoardLocked());
|
|
1160 log.debug(" Cursor On " + cursorOn);
|
|
1161 log.debug(" Cursor Active " + screen52.cursorActive);
|
|
1162 }
|
|
1163
|
|
1164 }
|
|
1165
|
|
1166
|
|
1167 private final void readScreen() throws IOException {
|
|
1168 int rows = screen52.getRows();
|
|
1169 int cols = screen52.getColumns();
|
|
1170 byte abyte0[] = new byte[rows * cols];
|
|
1171 fillScreenArray(abyte0, rows, cols);
|
|
1172 writeGDS(0, 0, abyte0);
|
|
1173 abyte0 = null;
|
|
1174 }
|
|
1175
|
|
1176 private final void fillScreenArray(byte[] sa, int rows, int cols) {
|
|
1177 int la = 32;
|
|
1178 int sac = 0;
|
|
1179 int len = rows * cols;
|
|
1180
|
|
1181 ScreenPlanes planes = screen52.planes;
|
|
1182
|
|
1183 for (int y = 0; y < len; y++) { // save the screen data
|
|
1184
|
|
1185 if (planes.isAttributePlace(y)) {
|
|
1186 la = planes.getCharAttr(y);
|
|
1187 sa[sac++] = (byte) la;
|
|
1188 } else {
|
|
1189 if (planes.getCharAttr(y) != la) {
|
|
1190 la = planes.getCharAttr(y);
|
|
1191 sac--;
|
|
1192 sa[sac++] = (byte) la;
|
|
1193 }
|
|
1194 //LDC: Check to see if it is an displayable character. If not,
|
|
1195 // do not convert the character.
|
|
1196 // The characters on screen are in unicode
|
|
1197 //sa[sac++] =
|
|
1198 // (byte)codePage.uni2ebcdic(screen52.screen[y].getChar());
|
|
1199 char ch = planes.getChar(y);
|
|
1200 byte byteCh = (byte) ch;
|
|
1201 if (isDataUnicode(ch))
|
|
1202 byteCh = codePage.uni2ebcdic(ch);
|
|
1203 sa[sac++] = byteCh;
|
|
1204 }
|
|
1205 }
|
|
1206 }
|
|
1207
|
|
1208 private final void fillRegenerationBuffer(ByteArrayOutputStream sc, int rows, int cols)
|
|
1209 throws IOException {
|
|
1210
|
|
1211 int la = 32;
|
|
1212 int sac = 0;
|
|
1213 int len = rows * cols;
|
|
1214
|
|
1215 ScreenPlanes planes = screen52.planes;
|
|
1216 byte[] sa = new byte[len];
|
|
1217
|
|
1218 try {
|
|
1219 boolean guiExists = sfParser != null && sfParser.isGuisExists();
|
|
1220
|
|
1221
|
|
1222 for (int y = 0; y < len; y++) { // save the screen data
|
|
1223
|
|
1224 if (guiExists) {
|
|
1225
|
|
1226 byte[] guiSeg = sfParser.getSegmentAtPos(y);
|
|
1227 if (guiSeg != null) {
|
|
1228 //log.info(" gui saved at " + y + " - " + screen52.getRow(y) + "," +
|
|
1229 // screen52.getCol(y));
|
|
1230
|
|
1231 byte[] gsa = new byte[sa.length + guiSeg.length + 2];
|
|
1232 System.arraycopy(sa,0,gsa,0,sa.length);
|
|
1233 System.arraycopy(guiSeg,0,gsa,sac+2,guiSeg.length);
|
|
1234 sa = new byte[gsa.length];
|
|
1235 System.arraycopy(gsa,0,sa,0,gsa.length);
|
|
1236 sa[sac++] = (byte)0x04;
|
|
1237 sa[sac++] = (byte)0x11;
|
|
1238 sac += guiSeg.length;
|
|
1239 //y--;
|
|
1240 // continue;
|
|
1241 }
|
|
1242 }
|
|
1243 if (planes.isAttributePlace(y)) {
|
|
1244 la = planes.getCharAttr(y);
|
|
1245 sa[sac++] = (byte) la;
|
|
1246 } else {
|
|
1247 if (planes.getCharAttr(y) != la) {
|
|
1248 la = planes.getCharAttr(y);
|
|
1249 sac--;
|
|
1250 sa[sac++] = (byte) la;
|
|
1251 }
|
|
1252 //LDC: Check to see if it is an displayable character. If not,
|
|
1253 // do not convert the character.
|
|
1254 // The characters on screen are in unicode
|
|
1255 //sa[sac++] =
|
|
1256 // (byte)codePage.uni2ebcdic(screen52.screen[y].getChar());
|
|
1257 char ch = planes.getChar(y);
|
|
1258 byte byteCh = (byte) ch;
|
|
1259 if (isDataUnicode(ch))
|
|
1260 byteCh = codePage.uni2ebcdic(ch);
|
|
1261 sa[sac++] = byteCh;
|
|
1262 }
|
|
1263 }
|
|
1264 }
|
|
1265 catch(Exception exc) {
|
|
1266
|
|
1267 log.info(exc.getMessage());
|
|
1268 exc.printStackTrace();
|
|
1269 }
|
|
1270 sc.write(sa);
|
|
1271 }
|
|
1272
|
|
1273 public final void saveScreen() throws IOException {
|
|
1274
|
|
1275 ByteArrayOutputStream sc = new ByteArrayOutputStream();
|
|
1276 sc.write(4);
|
|
1277 sc.write(0x12); // 18
|
|
1278 sc.write(0); // 18
|
|
1279 sc.write(0); // 18
|
|
1280
|
|
1281 sc.write((byte) screen52.getRows()); // store the current size
|
|
1282 sc.write((byte) screen52.getColumns()); // ""
|
|
1283
|
|
1284 int cp = screen52.getCurrentPos(); // save off current position
|
|
1285 // fix below submitted by Mitch Blevins
|
|
1286 //int cp = screen52.getScreenFields().getCurrentFieldPos();
|
|
1287 // save off current position
|
|
1288 sc.write((byte) (cp >> 8 & 0xff)); // ""
|
|
1289 sc.write((byte) (cp & 0xff)); // ""
|
|
1290
|
|
1291 sc.write((byte) (screen52.homePos >> 8 & 0xff)); // save home pos
|
|
1292 sc.write((byte) (screen52.homePos & 0xff)); // ""
|
|
1293
|
|
1294 int rows = screen52.getRows(); // store the current size
|
|
1295 int cols = screen52.getColumns(); // ""
|
|
1296
|
|
1297 // byte[] sa = new byte[rows * cols];
|
|
1298 fillRegenerationBuffer(sc,rows,cols);
|
|
1299 // fillScreenArray(sa, rows, cols);
|
|
1300 //
|
|
1301 // sc.write(sa);
|
|
1302 // sa = null;
|
|
1303 int sizeFields = screen52.getScreenFields().getSize();
|
|
1304 sc.write((byte) (sizeFields >> 8 & 0xff)); // ""
|
|
1305 sc.write((byte) (sizeFields & 0xff)); // ""
|
|
1306
|
|
1307 if (sizeFields > 0) {
|
|
1308 int x = 0;
|
|
1309 int s = screen52.getScreenFields().getSize();
|
|
1310 ScreenField sf = null;
|
|
1311 while (x < s) {
|
|
1312 sf = screen52.getScreenFields().getField(x);
|
|
1313 sc.write((byte) sf.getAttr()); // attribute
|
|
1314 int sp = sf.startPos();
|
|
1315 sc.write((byte) (sp >> 8 & 0xff)); // ""
|
|
1316 sc.write((byte) (sp & 0xff)); // ""
|
|
1317 if (sf.mdt)
|
|
1318 sc.write((byte) 1);
|
|
1319 else
|
|
1320 sc.write((byte) 0);
|
|
1321 sc.write((byte) (sf.getLength() >> 8 & 0xff)); // ""
|
|
1322 sc.write((byte) (sf.getLength() & 0xff)); // ""
|
|
1323 sc.write((byte) sf.getFFW1() & 0xff);
|
|
1324 sc.write((byte) sf.getFFW2() & 0xff);
|
|
1325 sc.write((byte) sf.getFCW1() & 0xff);
|
|
1326 sc.write((byte) sf.getFCW2() & 0xff);
|
|
1327 log.debug("Saved ");
|
|
1328 log.debug(sf.toString());
|
|
1329
|
|
1330 x++;
|
|
1331 }
|
|
1332 sf = null;
|
|
1333 }
|
|
1334
|
|
1335 // The following two lines of code looks to have caused all sorts of
|
|
1336 // problems so for now we have commented them out.
|
|
1337 // screen52.getScreenFields().setCurrentField(null); // set it to null
|
|
1338 // for GC ?
|
|
1339 // screen52.clearTable();
|
|
1340
|
|
1341 try {
|
|
1342 writeGDS(0, 3, sc.toByteArray());
|
|
1343 } catch (IOException ioe) {
|
|
1344
|
|
1345 log.warn(ioe.getMessage());
|
|
1346 }
|
|
1347
|
|
1348 sc = null;
|
|
1349 log.debug("Save Screen end ");
|
|
1350 }
|
|
1351
|
|
1352 /**
|
|
1353 *
|
|
1354 * @throws IOException
|
|
1355 */
|
|
1356 public final void restoreScreen() throws IOException {
|
|
1357 int which = 0;
|
|
1358
|
|
1359 ScreenPlanes planes = screen52.planes;
|
|
1360
|
|
1361 try {
|
|
1362 log.debug("Restore ");
|
|
1363
|
|
1364 bk.getNextByte();
|
|
1365 bk.getNextByte();
|
|
1366
|
|
1367 int rows = bk.getNextByte() & 0xff;
|
|
1368 int cols = bk.getNextByte() & 0xff;
|
|
1369 int pos = bk.getNextByte() << 8 & 0xff00; // current position
|
|
1370 pos |= bk.getNextByte() & 0xff;
|
|
1371 int hPos = bk.getNextByte() << 8 & 0xff00; // home position
|
|
1372 hPos |= bk.getNextByte() & 0xff;
|
|
1373 if (rows != screen52.getRows())
|
|
1374 screen52.setRowsCols(rows, cols);
|
|
1375 screen52.clearAll(); // initialize what we currenty have
|
|
1376 if (sfParser != null && sfParser.isGuisExists())
|
|
1377 sfParser.clearGuiStructs();
|
|
1378
|
|
1379 int b = 32;
|
|
1380 int la = 32;
|
|
1381 int len = rows * cols;
|
|
1382 for (int y = 0; y < len; y++) {
|
|
1383
|
|
1384 b = bk.getNextByte();
|
|
1385 if (b == 0x04) {
|
|
1386
|
|
1387 log.info(" gui restored at " + y + " - " + screen52.getRow(y) + "," +
|
|
1388 screen52.getCol(y));
|
|
1389 int command = bk.getNextByte();
|
|
1390 byte[] seg = bk.getSegment();
|
|
1391
|
|
1392 if (seg.length > 0) {
|
|
1393 screen52.goto_XY(y);
|
|
1394 sfParser.parseWriteToDisplayStructuredField(seg);
|
|
1395 }
|
|
1396 y--;
|
|
1397 // screen52.goto_XY(y);
|
|
1398 }
|
|
1399 else {
|
|
1400 // b = bk.getNextByte();
|
|
1401 if (planes.isUseGui(y))
|
|
1402 continue;
|
|
1403 if (isAttribute(b)) {
|
|
1404 planes.setScreenCharAndAttr(y, planes.getChar(y), b, true);
|
|
1405 la = b;
|
|
1406
|
|
1407 }
|
|
1408 else {
|
|
1409 //LDC - 12/02/2003 - Check to see if it is an displayable
|
|
1410 // character. If not,
|
|
1411 // do not convert the character.
|
|
1412 // The characters on screen are in unicode
|
|
1413 char ch = (char) b;
|
|
1414 if (isDataEBCDIC(b))
|
|
1415 ch = codePage.ebcdic2uni(b);
|
|
1416
|
|
1417 planes.setScreenCharAndAttr(y, ch, la, false);
|
|
1418 }
|
|
1419 }
|
|
1420 }
|
|
1421
|
|
1422 int numFields = bk.getNextByte() << 8 & 0xff00;
|
|
1423 numFields |= bk.getNextByte() & 0xff;
|
|
1424 log.debug("number of fields " + numFields);
|
|
1425
|
|
1426 if (numFields > 0) {
|
|
1427 int x = 0;
|
|
1428 int attr = 0;
|
|
1429 int fPos = 0;
|
|
1430 int fLen = 0;
|
|
1431 int ffw1 = 0;
|
|
1432 int ffw2 = 0;
|
|
1433 int fcw1 = 0;
|
|
1434 int fcw2 = 0;
|
|
1435 boolean mdt = false;
|
|
1436
|
|
1437 ScreenField sf = null;
|
|
1438 while (x < numFields) {
|
|
1439
|
|
1440 attr = bk.getNextByte();
|
|
1441 fPos = bk.getNextByte() << 8 & 0xff00;
|
|
1442 fPos |= bk.getNextByte() & 0xff;
|
|
1443 if (bk.getNextByte() == 1)
|
|
1444 mdt = true;
|
|
1445 else
|
|
1446 mdt = false;
|
|
1447 fLen = bk.getNextByte() << 8 & 0xff00;
|
|
1448 fLen |= bk.getNextByte() & 0xff;
|
|
1449 ffw1 = bk.getNextByte();
|
|
1450 ffw2 = bk.getNextByte();
|
|
1451 fcw1 = bk.getNextByte();
|
|
1452 fcw2 = bk.getNextByte();
|
|
1453
|
|
1454 sf = screen52.getScreenFields().setField(attr,
|
|
1455 screen52.getRow(fPos), screen52.getCol(fPos), fLen,
|
|
1456 ffw1, ffw2, fcw1, fcw2);
|
|
1457
|
|
1458 while (fLen-- > 0) {
|
|
1459
|
|
1460 // now we set the field plane attributes
|
|
1461 planes.setScreenFieldAttr(fPos++,ffw1);
|
|
1462
|
|
1463 }
|
|
1464
|
|
1465 if (mdt) {
|
|
1466 sf.setMDT();
|
|
1467 screen52.getScreenFields().setMasterMDT();
|
|
1468 }
|
|
1469 if (log.isDebugEnabled()) {
|
|
1470 log.debug("/nRestored ");
|
|
1471 log.debug(sf.toString());
|
|
1472 }
|
|
1473 x++;
|
|
1474 }
|
|
1475 }
|
|
1476
|
|
1477 // Redraw the gui fields if we are in gui mode
|
|
1478 if (screen52.isUsingGuiInterface())
|
|
1479 screen52.drawFields();
|
|
1480
|
|
1481 screen52.restoreScreen(); // display the screen
|
|
1482
|
|
1483 // The position was saved with currentPos which 1,1 offset of the
|
|
1484 // screen position.
|
|
1485 // The setPendingInsert is the where the cursor position will be
|
|
1486 // displayed after the restore.
|
|
1487 screen52.setPendingInsert(true, screen52.getRow(pos + cols), screen52
|
|
1488 .getCol(pos + cols));
|
|
1489 // We need to offset the pos by -1 since the position is 1,1 based
|
|
1490 // and the goto_XY is 0,0 based.
|
|
1491 screen52.goto_XY(pos - 1);
|
|
1492 screen52.isInField();
|
|
1493 // // Redraw the gui fields if we are in gui mode
|
|
1494 // if (screen52.isUsingGuiInterface())
|
|
1495 // screen52.drawFields();
|
|
1496 } catch (Exception e) {
|
|
1497 log.warn("error restoring screen " + which + " with "
|
|
1498 + e.getMessage());
|
|
1499 }
|
|
1500 }
|
|
1501
|
|
1502 public final boolean waitingForInput() {
|
|
1503
|
|
1504 return waitingForInput;
|
|
1505 }
|
|
1506
|
|
1507 private void parseIncoming() {
|
|
1508
|
|
1509 boolean done = false;
|
|
1510 boolean error = false;
|
|
1511
|
|
1512 try {
|
|
1513 while (bk.hasNext() && !done) {
|
|
1514 byte b = bk.getNextByte();
|
|
1515
|
|
1516 switch (b) {
|
|
1517 case 0:
|
|
1518 case 1:
|
|
1519 break;
|
|
1520 case CMD_SAVE_SCREEN: // 0x02 2 Save Screen
|
|
1521 case 3: // 0x03 3 Save Partial Screen
|
|
1522 log.debug("save screen partial");
|
|
1523 saveScreen();
|
|
1524 break;
|
|
1525
|
|
1526 case ESC: // ESCAPE
|
|
1527 break;
|
|
1528 case 7: // audible bell
|
|
1529 controller.signalBell();
|
|
1530 bk.getNextByte();
|
|
1531 bk.getNextByte();
|
|
1532 break;
|
|
1533 case CMD_WRITE_TO_DISPLAY: // 0x11 17 write to display
|
|
1534 error = writeToDisplay(true);
|
|
1535 // WVL - LDC : TR.000300 : Callback scenario from 5250
|
|
1536 // Only scan when WRITE_TO_DISPLAY operation (i.e. refill
|
|
1537 // screen buffer)
|
|
1538 // has been issued!
|
|
1539 if (scan)
|
|
1540 scan();
|
|
1541
|
|
1542 break;
|
|
1543 case CMD_RESTORE_SCREEN: // 0x12 18 Restore Screen
|
|
1544 case 13: // 0x13 19 Restore Partial Screen
|
|
1545 log.debug("restore screen partial");
|
|
1546 restoreScreen();
|
|
1547 break;
|
|
1548
|
|
1549 case CMD_CLEAR_UNIT_ALTERNATE: // 0x20 32 clear unit alternate
|
|
1550 int param = bk.getNextByte();
|
|
1551 if (param != 0) {
|
|
1552 log.debug(" clear unit alternate error "
|
|
1553 + Integer.toHexString(param));
|
|
1554 sendNegResponse(NR_REQUEST_ERROR, 03, 01, 05,
|
|
1555 " clear unit alternate not supported");
|
|
1556 done = true;
|
|
1557 } else {
|
|
1558 if (screen52.getRows() != 27)
|
|
1559 screen52.setRowsCols(27, 132);
|
|
1560
|
|
1561 screen52.clearAll();
|
|
1562 if (sfParser != null && sfParser.isGuisExists())
|
|
1563 sfParser.clearGuiStructs();
|
|
1564
|
|
1565
|
|
1566 }
|
|
1567 break;
|
|
1568
|
|
1569 case CMD_WRITE_ERROR_CODE: // 0x21 33 Write Error Code
|
|
1570 writeErrorCode();
|
|
1571 error = writeToDisplay(false);
|
|
1572 break;
|
|
1573 case CMD_WRITE_ERROR_CODE_TO_WINDOW: // 0x22 34
|
|
1574 // Write Error Code to window
|
|
1575 writeErrorCodeToWindow();
|
|
1576 error = writeToDisplay(false);
|
|
1577 break;
|
|
1578
|
|
1579 case CMD_READ_SCREEN_IMMEDIATE: // 0x62 98
|
|
1580 case CMD_READ_SCREEN_TO_PRINT: // 0x66 102 read screen to print
|
|
1581 readScreen();
|
|
1582 break;
|
|
1583
|
|
1584 case CMD_CLEAR_UNIT: // 64 0x40 clear unit
|
|
1585 if (screen52.getRows() != 24)
|
|
1586 screen52.setRowsCols(24, 80);
|
|
1587 screen52.clearAll();
|
|
1588 if (sfParser != null && sfParser.isGuisExists())
|
|
1589 sfParser.clearGuiStructs();
|
|
1590
|
|
1591 break;
|
|
1592
|
|
1593 case CMD_CLEAR_FORMAT_TABLE: // 80 0x50 Clear format table
|
|
1594 screen52.clearTable();
|
|
1595 break;
|
|
1596
|
|
1597 case CMD_READ_INPUT_FIELDS: //0x42 66 read input fields
|
|
1598 case CMD_READ_MDT_FIELDS: // 0x52 82 read MDT Fields
|
|
1599 bk.getNextByte();
|
|
1600 bk.getNextByte();
|
|
1601 readType = b;
|
|
1602 screen52.goHome();
|
|
1603 // do nothing with the cursor here it is taken care of
|
|
1604 // in the main loop.
|
|
1605 //////////////// screen52.setCursorOn();
|
|
1606 waitingForInput = true;
|
|
1607 pendingUnlock = true;
|
|
1608 // screen52.setKeyboardLocked(false);
|
|
1609 break;
|
|
1610 case CMD_READ_MDT_IMMEDIATE_ALT: // 0x53 83
|
|
1611 readType = b;
|
|
1612 // screen52.goHome();
|
|
1613 // waitingForInput = true;
|
|
1614 // screen52.setKeyboardLocked(false);
|
|
1615 readImmediate(readType);
|
|
1616 break;
|
|
1617 case CMD_WRITE_STRUCTURED_FIELD: // 243 0xF3 -13 Write
|
|
1618 // structured field
|
|
1619 writeStructuredField();
|
|
1620 break;
|
|
1621 case CMD_ROLL: // 0x23 35 Roll Not sure what it does right now
|
|
1622 int updown = bk.getNextByte();
|
|
1623 int topline = bk.getNextByte();
|
|
1624 int bottomline = bk.getNextByte();
|
|
1625 screen52.rollScreen(updown, topline, bottomline);
|
|
1626 break;
|
|
1627
|
|
1628 default:
|
|
1629 done = true;
|
|
1630 sendNegResponse(NR_REQUEST_ERROR, 03, 01, 01,
|
|
1631 "parseIncoming");
|
|
1632 break;
|
|
1633 }
|
|
1634
|
|
1635 if (error)
|
|
1636 done = true;
|
|
1637 }
|
|
1638 // BEGIN FRAMEWORK
|
|
1639 // I took this out for debugging a problem
|
|
1640 // ScreenField[] a = this.screen52.getScreenFields().getFields();
|
|
1641 // if (log.isDebugEnabled()) {
|
|
1642 // for (int x = 0; x < a.length; x++) {
|
|
1643 // log.debug(a[x].toString());
|
|
1644 // }
|
|
1645 // }
|
|
1646 //
|
|
1647 // String strokes = this.screen52.getKeys();
|
|
1648 // if (!strokes.equals("")) {
|
|
1649 // Tn5250jKeyEvents e = new Tn5250jKeyEvents(this.screen52,
|
|
1650 // strokes);
|
|
1651 // //from the previous screen.
|
|
1652 // Tn5250jController.getCurrent().handleEvent(e);
|
|
1653 // }
|
|
1654 //
|
|
1655 // Tn5250jEvent event = new Tn5250jEvent(screen52);
|
|
1656 // Tn5250jController.getCurrent().handleEvent(event);
|
|
1657 //
|
|
1658 // //END FRAMEWORK
|
|
1659 } catch (Exception exc) {
|
|
1660 log.warn("incoming " + exc.getMessage());
|
|
1661 }
|
|
1662 ;
|
|
1663 }
|
|
1664
|
|
1665 /**
|
|
1666 * This routine handles sending negative responses back to the host.
|
|
1667 *
|
|
1668 * You can find a description of the types of responses to be sent back by
|
|
1669 * looking at section 12.4 of the 5250 Functions Reference manual
|
|
1670 *
|
|
1671 *
|
|
1672 * @param cat
|
|
1673 * @param modifier
|
|
1674 * @param uByte1
|
|
1675 * @param uByte2
|
|
1676 * @param from
|
|
1677 *
|
|
1678 */
|
|
1679 protected void sendNegResponse(int cat, int modifier, int uByte1,
|
|
1680 int uByte2, String from) {
|
|
1681
|
|
1682 try {
|
|
1683
|
|
1684 int os = bk.getByteOffset(-1) & 0xf0;
|
|
1685 int cp = (bk.getCurrentPos() - 1);
|
|
1686 log.info("invalid " + from + " command " + os
|
|
1687 + " at pos " + cp);
|
|
1688 } catch (Exception e) {
|
|
1689
|
|
1690 log.warn("Send Negative Response error " + e.getMessage());
|
|
1691 }
|
|
1692
|
|
1693 baosp.write(cat);
|
|
1694 baosp.write(modifier);
|
|
1695 baosp.write(uByte1);
|
|
1696 baosp.write(uByte2);
|
|
1697
|
|
1698 try {
|
|
1699 writeGDS(128, 0, baosp.toByteArray());
|
|
1700 } catch (IOException ioe) {
|
|
1701
|
|
1702 log.warn(ioe.getMessage());
|
|
1703 }
|
|
1704 baosp.reset();
|
|
1705
|
|
1706 }
|
|
1707
|
|
1708 public void sendNegResponse2(int ec) {
|
|
1709
|
|
1710 screen52.setPrehelpState(true, true, false);
|
|
1711 baosp.write(0x00);
|
|
1712 baosp.write(ec);
|
|
1713
|
|
1714 try {
|
|
1715 writeGDS(1, 0, baosp.toByteArray());
|
|
1716 } catch (IOException ioe) {
|
|
1717
|
|
1718 log.warn(ioe.getMessage());
|
|
1719 }
|
|
1720
|
|
1721 baosp.reset();
|
|
1722 }
|
|
1723
|
|
1724 private boolean writeToDisplay(boolean controlsExist) {
|
|
1725
|
|
1726 boolean error = false;
|
|
1727 boolean done = false;
|
|
1728 int attr;
|
|
1729 byte control0 = 0;
|
|
1730 byte control1 = 0;
|
|
1731 int saRows = screen52.getRows();
|
|
1732 int saCols = screen52.getColumns();
|
|
1733
|
|
1734 try {
|
|
1735 if (controlsExist) {
|
|
1736 control0 = bk.getNextByte();
|
|
1737 control1 = bk.getNextByte();
|
|
1738 processCC0(control0);
|
|
1739 }
|
|
1740 while (bk.hasNext() && !done) {
|
|
1741 // pos = bk.getCurrentPos();
|
|
1742
|
|
1743 // int rowc = screen52.getCurrentRow();
|
|
1744 // int colc = screen52.getCurrentCol();
|
|
1745
|
|
1746 byte bytebk = bk.getNextByte();
|
|
1747
|
|
1748 switch (bytebk) {
|
|
1749
|
|
1750 case 1: // SOH - Start of Header Order
|
|
1751 log.debug("SOH - Start of Header Order");
|
|
1752 error = processSOH();
|
|
1753
|
|
1754 break;
|
|
1755 case 02: // RA - Repeat to address
|
|
1756 log.debug("RA - Repeat to address");
|
|
1757 int row = screen52.getCurrentRow();
|
|
1758 int col = screen52.getCurrentCol();
|
|
1759
|
|
1760 int toRow = bk.getNextByte();
|
|
1761 int toCol = bk.getNextByte() & 0xff;
|
|
1762 if (toRow >= row) {
|
|
1763 int repeat = bk.getNextByte();
|
|
1764
|
|
1765 // a little intelligence here I hope
|
|
1766 if (row == 1 && col == 2 && toRow == screen52.getRows()
|
|
1767 && toCol == screen52.getColumns())
|
|
1768
|
|
1769 screen52.clearScreen();
|
|
1770 else {
|
|
1771 if (repeat != 0) {
|
|
1772 //LDC - 13/02/2003 - convert it to unicode
|
|
1773 repeat = codePage.ebcdic2uni(repeat);
|
|
1774 //repeat = getASCIIChar(repeat);
|
|
1775 }
|
|
1776
|
|
1777 int times = ((toRow * screen52.getColumns()) + toCol)
|
|
1778 - ((row * screen52.getColumns()) + col);
|
|
1779 while (times-- >= 0) {
|
|
1780 screen52.setChar(repeat);
|
|
1781 }
|
|
1782
|
|
1783 }
|
|
1784 } else {
|
|
1785 sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x23,
|
|
1786 " RA invalid");
|
|
1787 error = true;
|
|
1788 }
|
|
1789 break;
|
|
1790
|
|
1791 case 03: // EA - Erase to address
|
|
1792 log.debug("EA - Erase to address");
|
|
1793 int EArow = screen52.getCurrentRow();
|
|
1794 int EAcol = screen52.getCurrentCol();
|
|
1795
|
|
1796 int toEARow = bk.getNextByte();
|
|
1797 int toEACol = bk.getNextByte() & 0xff;
|
|
1798 int EALength = bk.getNextByte() & 0xff;
|
|
1799 while (--EALength > 0) {
|
|
1800
|
|
1801 bk.getNextByte();
|
|
1802
|
|
1803 }
|
|
1804 char EAAttr = (char) 0;
|
|
1805
|
|
1806 // a little intelligence here I hope
|
|
1807 if (EArow == 1 && EAcol == 2
|
|
1808 && toEARow == screen52.getRows()
|
|
1809 && toEACol == screen52.getColumns())
|
|
1810
|
|
1811 screen52.clearScreen();
|
|
1812 else {
|
|
1813 int times = ((toEARow * screen52.getColumns()) + toEACol)
|
|
1814 - ((EArow * screen52.getColumns()) + EAcol);
|
|
1815 while (times-- >= 0) {
|
|
1816 screen52.setChar(EAAttr);
|
|
1817 }
|
|
1818 }
|
|
1819 break;
|
|
1820 case 04: // Command - Escape
|
|
1821 log.debug("Command - Escape");
|
|
1822 done = true;
|
|
1823 break;
|
|
1824
|
|
1825 case 16: // TD - Transparent Data
|
|
1826 log.debug("TD - Transparent Data");
|
|
1827 int j = (bk.getNextByte() & 0xff) << 8 | bk.getNextByte()
|
|
1828 & 0xff; // length
|
|
1829 break;
|
|
1830
|
|
1831 case 17: // SBA - set buffer address order (row column)
|
|
1832 log.debug("SBA - set buffer address order (row column)");
|
|
1833 int saRow = bk.getNextByte();
|
|
1834 int saCol = bk.getNextByte() & 0xff;
|
|
1835 // make sure it is in bounds
|
|
1836 if (saRow >= 0 && saRow <= screen52.getRows() && saCol >= 0
|
|
1837 && saCol <= screen52.getColumns()) {
|
|
1838 screen52.setCursor(saRow, saCol); // now set screen
|
|
1839 // position for output
|
|
1840
|
|
1841 } else {
|
|
1842
|
|
1843 sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x22,
|
|
1844 "invalid row/col order" + " saRow = " + saRow
|
|
1845 + " saRows = " + screen52.getRows()
|
|
1846 + " saCol = " + saCol);
|
|
1847
|
|
1848 error = true;
|
|
1849
|
|
1850 }
|
|
1851 break;
|
|
1852
|
|
1853 case 18: // WEA - Extended Attribute
|
|
1854 log.debug("WEA - Extended Attribute");
|
|
1855 bk.getNextByte();
|
|
1856 bk.getNextByte();
|
|
1857 break;
|
|
1858
|
|
1859 case 19: // IC - Insert Cursor
|
|
1860 log.debug("IC - Insert Cursor");
|
|
1861 int icX = bk.getNextByte();
|
|
1862 int icY = bk.getNextByte() & 0xff;
|
|
1863 if (icX >= 0 && icX <= saRows && icY >= 0 && icY <= saCols) {
|
|
1864
|
|
1865 log.debug(" IC " + icX + " " + icY);
|
|
1866 screen52.setPendingInsert(true, icX, icY);
|
|
1867 } else {
|
|
1868 sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x22,
|
|
1869 " IC/IM position invalid ");
|
|
1870 error = true;
|
|
1871 }
|
|
1872
|
|
1873 break;
|
|
1874
|
|
1875 case 20: // MC - Move Cursor
|
|
1876 log.debug("MC - Move Cursor");
|
|
1877 int imcX = bk.getNextByte();
|
|
1878 int imcY = bk.getNextByte() & 0xff;
|
|
1879 if (imcX >= 0 && imcX <= saRows && imcY >= 0
|
|
1880 && imcY <= saCols) {
|
|
1881
|
|
1882 log.debug(" MC " + imcX + " " + imcY);
|
|
1883 screen52.setPendingInsert(false, imcX, imcY);
|
|
1884 } else {
|
|
1885 sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x22,
|
|
1886 " IC/IM position invalid ");
|
|
1887 error = true;
|
|
1888 }
|
|
1889
|
|
1890 break;
|
|
1891
|
|
1892 case 21: // WTDSF - Write To Display Structured Field order
|
8
|
1893 log.debug("WTDSF - Write To Display Structured Field order");
|
3
|
1894 byte[] seg = bk.getSegment();
|
|
1895 error = sfParser.parseWriteToDisplayStructuredField(seg);
|
|
1896 break;
|
|
1897
|
|
1898 case 29: // SF - Start of Field
|
|
1899 log.debug("SF - Start of Field");
|
|
1900 int fcw1 = 0;
|
|
1901 int fcw2 = 0;
|
|
1902 int ffw1 = 0;
|
|
1903 int ffw0 = bk.getNextByte() & 0xff; // FFW
|
|
1904
|
|
1905 if ((ffw0 & 0x40) == 0x40) {
|
|
1906 ffw1 = bk.getNextByte() & 0xff; // FFW 1
|
|
1907
|
|
1908 fcw1 = bk.getNextByte() & 0xff; // check for field
|
|
1909 // control word
|
|
1910
|
|
1911 // check if the first fcw1 is an 0x81 if it is then get
|
8
|
1912 // the next pair for checking
|
3
|
1913 if (fcw1 == 0x81) {
|
|
1914 bk.getNextByte();
|
|
1915 fcw1 = bk.getNextByte() & 0xff; // check for field
|
|
1916 // control word
|
|
1917 }
|
|
1918
|
|
1919 if (!isAttribute(fcw1)) {
|
|
1920
|
|
1921 fcw2 = bk.getNextByte() & 0xff; // FCW 2
|
|
1922 attr = bk.getNextByte() & 0xff; // attribute field
|
|
1923
|
|
1924 while (!isAttribute(attr)) {
|
|
1925 log.info(Integer.toHexString(fcw1) + " "
|
|
1926 + Integer.toHexString(fcw2)
|
|
1927 + " ");
|
|
1928 log.info(Integer.toHexString(attr)
|
|
1929 + " "
|
|
1930 + Integer.toHexString(bk
|
|
1931 .getNextByte() & 0xff));
|
8
|
1932 attr = bk.getNextByte() & 0xff; // attribute field
|
3
|
1933 }
|
|
1934 } else {
|
|
1935 attr = fcw1; // attribute of field
|
|
1936 fcw1 = 0;
|
|
1937 }
|
|
1938 } else {
|
|
1939 attr = ffw0;
|
|
1940 }
|
|
1941
|
|
1942 int fLength = (bk.getNextByte() & 0xff) << 8
|
|
1943 | bk.getNextByte() & 0xff;
|
|
1944 screen52.addField(attr, fLength, ffw0, ffw1, fcw1, fcw2);
|
|
1945
|
|
1946 break;
|
|
1947 // WVL - LDC : 05/08/2005 : TFX.006253 - Support STRPCCMD
|
|
1948 case -128: //STRPCCMD
|
|
1949 // if (screen52.getCurrentPos() == 82) {
|
|
1950 log.debug("STRPCCMD got a -128 command at " + screen52.getCurrentPos());
|
|
1951 StringBuffer value = new StringBuffer();
|
|
1952 int b;
|
|
1953 char c;
|
|
1954 int[] pco = new int[9];
|
|
1955 int[] pcoOk = {0xfc, 0xd7, 0xc3, 0xd6, 0x40, 0x83, 0x80, 0xa1, 0x80};
|
|
1956
|
|
1957 for (int i = 0; i < 9; i++)
|
|
1958 {
|
|
1959 b = bk.getNextByte();
|
|
1960 pco[i] = ((b & 0xff));
|
|
1961 c = codePage.ebcdic2uni(b);
|
|
1962 value.append(c);
|
|
1963 }
|
|
1964
|
|
1965 // Check "PCO-String"
|
|
1966 if (Arrays.equals(pco, pcoOk)) {
|
|
1967 strpccmd = true;
|
|
1968 }
|
|
1969 // we return in the stream to have all chars
|
|
1970 // arrive at the screen for later processing
|
|
1971 for (int i = 0; i < 9; i++)
|
|
1972 bk.setPrevByte();
|
|
1973 //}
|
|
1974 // no break: so every chars arrives
|
|
1975 // on the screen for later parsing
|
|
1976 //break;
|
|
1977
|
|
1978 default: // all others must be output to screen
|
|
1979 log.debug("all others must be output to screen");
|
|
1980 byte byte0 = bk.getByteOffset(-1);
|
|
1981 if (isAttribute(byte0)) {
|
|
1982 screen52.setAttr(byte0);
|
|
1983 } else {
|
|
1984 if (!screen52.isStatusErrorCode()) {
|
|
1985 if (!isDataEBCDIC(byte0)) {
|
|
1986 // if (byte0 == 255) {
|
|
1987 // sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x42,
|
|
1988 // " Attempt to send FF to screen");
|
|
1989 // }
|
|
1990 // else
|
|
1991
|
|
1992 screen52.setChar(byte0);
|
|
1993 } else
|
|
1994 //LDC - 13/02/2003 - Convert it to unicode
|
|
1995 //screen52.setChar(getASCIIChar(byte0));
|
|
1996 screen52.setChar(codePage.ebcdic2uni(byte0));
|
|
1997 } else {
|
|
1998 if (byte0 == 0)
|
|
1999 screen52.setChar(byte0);
|
|
2000 else
|
|
2001 //LDC - 13/02/2003 - Convert it to unicode
|
|
2002 //screen52.setChar(getASCIIChar(byte0));
|
|
2003 screen52.setChar(codePage.ebcdic2uni(byte0));
|
|
2004 }
|
|
2005 }
|
|
2006
|
|
2007 break;
|
|
2008 }
|
|
2009
|
|
2010 if (error)
|
|
2011 done = true;
|
|
2012 }
|
|
2013 }
|
|
2014
|
|
2015 catch (Exception e) {
|
|
2016 log.warn("write to display " + e.getMessage());
|
|
2017 e.printStackTrace();
|
|
2018 }
|
|
2019 ;
|
|
2020
|
|
2021 processCC1(control1);
|
|
2022
|
|
2023 return error;
|
|
2024
|
|
2025 }
|
|
2026
|
|
2027 private boolean processSOH() throws Exception {
|
|
2028
|
|
2029 int l = bk.getNextByte(); // length
|
|
2030 log.debug(" byte 0 " + l);
|
|
2031
|
|
2032 if (l > 0 && l <= 7) {
|
|
2033 bk.getNextByte(); // flag byte 2
|
|
2034 bk.getNextByte(); // reserved
|
|
2035 bk.getNextByte(); // resequence fields
|
|
2036
|
|
2037 screen52.clearTable();
|
|
2038
|
|
2039 // well that is the first time I have seen this. This fixes a
|
8
|
2040 // problem with S/36 command line. Finally got it.
|
|
2041 if (l <= 3) return false;
|
3
|
2042
|
|
2043 screen52.setErrorLine(bk.getNextByte()); // error row
|
|
2044
|
|
2045 int byte1 = 0;
|
|
2046 if (l >= 5) {
|
|
2047 byte1 = bk.getNextByte();
|
|
2048 dataIncluded[23] = (byte1 & 0x80) == 0x80;
|
|
2049 dataIncluded[22] = (byte1 & 0x40) == 0x40;
|
|
2050 dataIncluded[21] = (byte1 & 0x20) == 0x20;
|
|
2051 dataIncluded[20] = (byte1 & 0x10) == 0x10;
|
|
2052 dataIncluded[19] = (byte1 & 0x8) == 0x8;
|
|
2053 dataIncluded[18] = (byte1 & 0x4) == 0x4;
|
|
2054 dataIncluded[17] = (byte1 & 0x2) == 0x2;
|
|
2055 dataIncluded[16] = (byte1 & 0x1) == 0x1;
|
|
2056 }
|
|
2057
|
|
2058 if (l >= 6) {
|
|
2059 byte1 = bk.getNextByte();
|
|
2060 dataIncluded[15] = (byte1 & 0x80) == 0x80;
|
|
2061 dataIncluded[14] = (byte1 & 0x40) == 0x40;
|
|
2062 dataIncluded[13] = (byte1 & 0x20) == 0x20;
|
|
2063 dataIncluded[12] = (byte1 & 0x10) == 0x10;
|
|
2064 dataIncluded[11] = (byte1 & 0x8) == 0x8;
|
|
2065 dataIncluded[10] = (byte1 & 0x4) == 0x4;
|
|
2066 dataIncluded[9] = (byte1 & 0x2) == 0x2;
|
|
2067 dataIncluded[8] = (byte1 & 0x1) == 0x1;
|
|
2068 }
|
|
2069
|
|
2070 if (l >= 7) {
|
|
2071 byte1 = bk.getNextByte();
|
|
2072 dataIncluded[7] = (byte1 & 0x80) == 0x80;
|
|
2073 dataIncluded[6] = (byte1 & 0x40) == 0x40;
|
|
2074 dataIncluded[5] = (byte1 & 0x20) == 0x20;
|
|
2075 dataIncluded[4] = (byte1 & 0x10) == 0x10;
|
|
2076 dataIncluded[3] = (byte1 & 0x8) == 0x8;
|
|
2077 dataIncluded[2] = (byte1 & 0x4) == 0x4;
|
|
2078 dataIncluded[1] = (byte1 & 0x2) == 0x2;
|
|
2079 dataIncluded[0] = (byte1 & 0x1) == 0x1;
|
|
2080 }
|
|
2081 return false;
|
|
2082 } else {
|
|
2083 sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x2B,
|
|
2084 "invalid SOH length");
|
|
2085 return true;
|
|
2086 }
|
|
2087
|
|
2088 }
|
|
2089
|
|
2090 private void processCC0(byte byte0) {
|
|
2091 log.debug(" Control byte0 " + Integer.toBinaryString(byte0 & 0xff));
|
|
2092 boolean lockKeyboard = true;
|
|
2093 boolean resetMDT = false;
|
|
2094 boolean resetMDTAll = false;
|
|
2095 boolean nullMDT = false;
|
|
2096 boolean nullAll = false;
|
|
2097
|
|
2098 // Bits 3 to 6 are reserved and should be set to '0000'
|
|
2099 // 0xE0 = '11100000' - only the first 3 bits are tested
|
|
2100 if ((byte0 & 0xE0) == 0x00) {
|
|
2101 lockKeyboard = false;
|
|
2102 }
|
|
2103
|
|
2104 // '00100000' = 0x20 /32 -- just lock keyboard
|
|
2105 // '01000000' = 0x40 /64
|
|
2106 // '01100000' = 0x60 /96
|
|
2107 // '10000000' = 0x80 /128
|
|
2108 // '10100000' = 0xA0 /160
|
|
2109 // '11000000' = 0xC0 /192
|
|
2110 // '11100000' = 0xE0 /224
|
|
2111
|
|
2112 switch (byte0 & 0xE0) {
|
|
2113
|
|
2114 case 0x40:
|
|
2115 resetMDT = true;
|
|
2116 break;
|
|
2117 case 0x60:
|
|
2118 resetMDTAll = true;
|
|
2119 break;
|
|
2120 case 0x80:
|
|
2121 nullMDT = true;
|
|
2122 break;
|
|
2123 case 0xA0:
|
|
2124 resetMDT = true;
|
|
2125 nullAll = true;
|
|
2126 break;
|
|
2127 case 0xC0:
|
|
2128 resetMDT = true;
|
|
2129 nullMDT = true;
|
|
2130 break;
|
|
2131
|
|
2132 case 0xE0:
|
|
2133 resetMDTAll = true;
|
|
2134 nullAll = true;
|
|
2135 break;
|
|
2136
|
|
2137 }
|
|
2138
|
|
2139 if (lockKeyboard) {
|
|
2140 screen52.getOIA().setKeyBoardLocked(true);
|
|
2141 pendingUnlock = false;
|
|
2142 } else
|
|
2143 pendingUnlock = false;
|
|
2144
|
|
2145 if (resetMDT || resetMDTAll || nullMDT || nullAll) {
|
|
2146 ScreenField sf;
|
|
2147
|
|
2148 int f = screen52.getScreenFields().getSize();
|
|
2149 for (int x = 0; x < f; x++) {
|
|
2150 sf = screen52.getScreenFields().getField(x);
|
|
2151
|
|
2152 if (!sf.isBypassField()) {
|
|
2153 if ((nullMDT && sf.mdt) || nullAll) {
|
|
2154 sf.setFieldChar((char) 0x0);
|
|
2155 screen52.drawField(sf);
|
|
2156 }
|
|
2157 }
|
|
2158 if (resetMDTAll || (resetMDT && !sf.isBypassField()))
|
|
2159 sf.resetMDT();
|
|
2160
|
|
2161 }
|
|
2162 sf = null;
|
|
2163 }
|
|
2164
|
|
2165 }
|
|
2166
|
|
2167 private void processCC1(byte byte1) {
|
|
2168 log.debug(" Control byte1 " + Integer.toBinaryString(byte1 & 0xff));
|
|
2169
|
|
2170 if ((byte1 & 0x04) == 0x04) {
|
|
2171 controller.signalBell();
|
|
2172 }
|
|
2173 if ((byte1 & 0x02) == 0x02) {
|
|
2174 screen52.getOIA().setMessageLightOff();
|
|
2175 }
|
|
2176 if ((byte1 & 0x01) == 0x01) {
|
|
2177 screen52.getOIA().setMessageLightOn();
|
|
2178 }
|
|
2179
|
|
2180 if ((byte1 & 0x01) == 0x01 && (byte1 & 0x02) == 0x02) {
|
|
2181 screen52.getOIA().setMessageLightOn();
|
|
2182 }
|
|
2183
|
|
2184 // reset blinking cursor seems to control whether to set or not set the
|
|
2185 // the cursor position. No documentation for this just testing and
|
|
2186 // looking at the bit settings of this field. This was a pain in the
|
|
2187 // ass!
|
|
2188 //
|
|
2189 // if it is off '0' then keep existing cursor positioning information
|
|
2190 // if it is on '1' then reset the cursor positioning information
|
|
2191 // *** Note *** unless we receive bit 4 on at the same time
|
|
2192 // this seems to work so far
|
|
2193 if ((byte1 & 0x20) == 0x20 && (byte1 & 0x08) == 0x00) {
|
|
2194 screen52.setPendingInsert(false);
|
|
2195 log.debug(" WTD position no move");
|
|
2196 } else {
|
|
2197
|
|
2198 screen52.setPendingInsert(true);
|
|
2199 log.debug(" WTD position move to home" + screen52.homePos + " row "
|
|
2200 + screen52.getRow(screen52.homePos) + " col "
|
|
2201 + screen52.getCol(screen52.homePos));
|
|
2202
|
|
2203 }
|
|
2204 // in enhanced mode we sometimes only receive bit 6 turned on which
|
|
2205 // is reset blinking cursor
|
|
2206 if ((byte1 & 0x20) == 0x20 && enhanced) {
|
|
2207 cursorOn = true;
|
|
2208 }
|
|
2209
|
|
2210 if (!screen52.isStatusErrorCode() && (byte1 & 0x08) == 0x08) {
|
|
2211
|
|
2212 // screen52.setStatus(screen52.STATUS_SYSTEM,screen52.STATUS_VALUE_OFF,null);
|
|
2213 cursorOn = true;
|
|
2214 }
|
|
2215
|
|
2216 if ((byte1 & 0x20) == 0x20 && (byte1 & 0x08) == 0x00) {
|
|
2217 screen52.setPendingInsert(false, 1, 1);
|
|
2218 }
|
|
2219
|
|
2220 }
|
|
2221
|
|
2222 private boolean isAttribute(int byte0) {
|
|
2223 int byte1 = byte0 & 0xff;
|
|
2224 return (byte1 & 0xe0) == 0x20;
|
|
2225 }
|
|
2226
|
|
2227 //LDC - 12/02/2003 - Function name changed from isData to isDataEBCDIC
|
|
2228 private boolean isDataEBCDIC(int byte0) {
|
|
2229 int byte1 = byte0 & 0xff;
|
|
2230 // here it should always be less than 255
|
|
2231 if (byte1 >= 64 && byte1 < 255)
|
|
2232
|
|
2233 return true;
|
|
2234 else
|
|
2235 return false;
|
|
2236
|
|
2237 }
|
|
2238
|
|
2239 //LDC - 12/02/2003 - Test if the unicode character is a displayable
|
|
2240 // character.
|
|
2241 // The first 32 characters are non displayable characters
|
|
2242 // This is normally the inverse of isDataEBCDIC (That's why there is a
|
|
2243 // check on 255 -> 0xFFFF
|
|
2244 private boolean isDataUnicode(int byte0) {
|
|
2245 return (((byte0 < 0) || (byte0 >= 32)) && (byte0 != 0xFFFF));
|
|
2246 }
|
|
2247
|
|
2248 private void writeStructuredField() {
|
|
2249
|
|
2250 boolean done = false;
|
|
2251 try {
|
|
2252 int length = ((bk.getNextByte() & 0xff) << 8 | (bk.getNextByte() & 0xff));
|
|
2253 while (bk.hasNext() && !done) {
|
|
2254 switch (bk.getNextByte()) {
|
|
2255
|
|
2256 case -39: // SOH - Start of Header Order
|
|
2257
|
|
2258 switch (bk.getNextByte()) {
|
|
2259 case 112: // 5250 Query
|
|
2260 bk.getNextByte(); // get null required field
|
|
2261 sendQueryResponse();
|
|
2262 break;
|
|
2263 default:
|
|
2264 log.debug("invalid structured field sub command "
|
|
2265 + bk.getByteOffset(-1));
|
|
2266 break;
|
|
2267 }
|
|
2268 break;
|
|
2269 default:
|
|
2270 log.debug("invalid structured field command "
|
|
2271 + bk.getByteOffset(-1));
|
|
2272 break;
|
|
2273 }
|
|
2274 }
|
|
2275 } catch (Exception e) {
|
|
2276 }
|
|
2277 ;
|
|
2278
|
|
2279 }
|
|
2280
|
|
2281 private final void writeErrorCode() throws Exception {
|
|
2282 screen52.setCursor(screen52.getErrorLine(), 1); // Skip the control byte
|
|
2283 screen52.setStatus(Screen5250.STATUS_ERROR_CODE,
|
|
2284 Screen5250.STATUS_VALUE_ON, null);
|
|
2285 screen52.saveErrorLine();
|
|
2286 cursorOn = true;
|
|
2287
|
|
2288 }
|
|
2289
|
|
2290 private final void writeErrorCodeToWindow() throws Exception {
|
|
2291 int fromCol = bk.getNextByte() & 0xff; // from column
|
|
2292 int toCol = bk.getNextByte() & 0xff; // to column
|
|
2293 screen52.setCursor(screen52.getErrorLine(), fromCol); // Skip the control
|
|
2294 // byte
|
|
2295 screen52.setStatus(Screen5250.STATUS_ERROR_CODE,
|
|
2296 Screen5250.STATUS_VALUE_ON, null);
|
|
2297 screen52.saveErrorLine();
|
|
2298 cursorOn = true;
|
|
2299
|
|
2300 }
|
|
2301
|
|
2302 /**
|
|
2303 * Method sendQueryResponse
|
|
2304 *
|
|
2305 * The query command is used to obtain information about the capabilities of
|
|
2306 * the 5250 display.
|
|
2307 *
|
|
2308 * The Query command must follow an Escape (0x04) and Write Structured Field
|
|
2309 * command (0xF3).
|
|
2310 *
|
|
2311 * This section is modeled after the rfc1205 - 5250 Telnet Interface section
|
|
2312 * 5.3
|
|
2313 *
|
|
2314 * @throws IOException
|
|
2315 */
|
|
2316 private final void sendQueryResponse() throws IOException {
|
|
2317
|
|
2318 log.info("sending query response");
|
|
2319 byte abyte0[] = new byte[64];
|
|
2320 abyte0[0] = 0; // Cursor Row/column (set to zero)
|
|
2321 abyte0[1] = 0; // ""
|
|
2322 abyte0[2] = -120; // X'88' inbound write structure Field aid
|
|
2323 if (enhanced == true) {
|
|
2324 abyte0[3] = 0; // 0x003D (61) length of query response
|
|
2325 abyte0[4] = 64; // "" see note below ?????????
|
|
2326 } else {
|
|
2327 abyte0[3] = 0; // 0x003A (58) length of query response
|
|
2328 abyte0[4] = 58; // ""
|
|
2329 // the length between 58 and 64 seems to cause
|
|
2330 // different formatting codes to be sent from
|
|
2331 // the host ???????????????? why ???????
|
|
2332 // Well the why can be found in the manual if
|
|
2333 // read a little more ;-)
|
|
2334 }
|
|
2335 abyte0[5] = -39; // command class 0xD9
|
|
2336 abyte0[6] = 112; // Command type query 0x70
|
|
2337 abyte0[7] = -128; // 0x80 Flag byte
|
|
2338 abyte0[8] = 6; // Controller Hardware Class
|
|
2339 abyte0[9] = 0; // 0x0600 - Other WSF or another 5250 Emulator
|
|
2340 abyte0[10] = 1; // Controller Code Level
|
|
2341 abyte0[11] = 1; // Version 1 Rel 1.0
|
|
2342 abyte0[12] = 0; // ""
|
|
2343
|
|
2344 abyte0[13] = 0; // 13 - 28 are reserved so set to 0x00
|
|
2345 abyte0[14] = 0; // ""
|
|
2346 abyte0[15] = 0; // ""
|
|
2347 abyte0[16] = 0; // ""
|
|
2348 abyte0[17] = 0; // ""
|
|
2349 abyte0[18] = 0; // ""
|
|
2350 abyte0[19] = 0; // ""
|
|
2351 abyte0[20] = 0; // ""
|
|
2352 abyte0[21] = 0; // ""
|
|
2353 abyte0[22] = 0; // ""
|
|
2354 abyte0[23] = 0; // ""
|
|
2355 abyte0[24] = 0; // ""
|
|
2356 abyte0[25] = 0; // ""
|
|
2357 abyte0[26] = 0; // ""
|
|
2358 abyte0[27] = 0; // ""
|
|
2359 abyte0[28] = 0; // ""
|
|
2360 abyte0[29] = 1; // Device type - 0x01 5250 Emulator
|
|
2361 abyte0[30] = codePage.uni2ebcdic('5'); // Device type character
|
|
2362 abyte0[31] = codePage.uni2ebcdic('2'); // ""
|
|
2363 abyte0[32] = codePage.uni2ebcdic('5'); // ""
|
|
2364 abyte0[33] = codePage.uni2ebcdic('1'); // ""
|
|
2365 abyte0[34] = codePage.uni2ebcdic('0'); // ""
|
|
2366 abyte0[35] = codePage.uni2ebcdic('1'); // ""
|
|
2367 abyte0[36] = codePage.uni2ebcdic('1'); // ""
|
|
2368
|
|
2369 abyte0[37] = 2; // Keyboard Id - 0x02 Standard Keyboard
|
|
2370 abyte0[38] = 0; // extended keyboard id
|
|
2371 abyte0[39] = 0; // reserved
|
|
2372
|
|
2373 abyte0[40] = 0; // 40 - 43 Display Serial Number
|
|
2374 abyte0[41] = 36; //
|
|
2375 abyte0[42] = 36; //
|
|
2376 abyte0[43] = 0; //
|
|
2377
|
|
2378 abyte0[44] = 1; // Maximum number of display fields - 256
|
|
2379 abyte0[45] = 0; // 0x0100
|
|
2380 abyte0[46] = 0; // 46 -48 Reserved set to 0x00
|
|
2381 abyte0[47] = 0;
|
|
2382 abyte0[48] = 0;
|
|
2383 abyte0[49] = 1; // 49 - 53 Controller Display Capability
|
|
2384 abyte0[50] = 17; // see rfc - tired of typing :-)
|
|
2385 abyte0[51] = 0; // ""
|
|
2386 abyte0[52] = 0; // ""
|
|
2387
|
|
2388 // 53
|
|
2389 // Bit 0-2: B'000' - no graphics capability
|
|
2390 // B'001' - 5292-2 style graphics
|
|
2391 // Bit 3-7: B '00000' = reserved (it seems for Client access)
|
|
2392
|
|
2393 if (enhanced == true) {
|
|
2394 // abyte0[53] = 0x5E; // 0x5E turns on ehnhanced mode
|
|
2395 // abyte0[53] = 0x27; // 0x5E turns on ehnhanced mode
|
|
2396 abyte0[53] = 0x7; // 0x5E turns on ehnhanced mode
|
|
2397 log.info("enhanced options");
|
|
2398 } else
|
|
2399 abyte0[53] = 0x0; // 0x0 is normal emulation
|
|
2400
|
|
2401 abyte0[54] = 24; // 54 - 60 Reserved set to 0x00
|
|
2402 // 54 - I found out is used for enhanced user
|
|
2403 // interface level 3. Bit 4 allows headers
|
|
2404 // and footers for windows
|
|
2405 abyte0[54] = 8; // 54 - 60 Reserved set to 0x00
|
|
2406 // 54 - I found out is used for enhanced user
|
|
2407 // interface level 3. Bit 4 allows headers
|
|
2408 // and footers for windows
|
|
2409 abyte0[55] = 0;
|
|
2410 abyte0[56] = 0;
|
|
2411 abyte0[57] = 0;
|
|
2412 abyte0[58] = 0;
|
|
2413 abyte0[59] = 0;
|
|
2414 abyte0[60] = 0;
|
|
2415 abyte0[61] = 0; // gridlines are not supported
|
|
2416 abyte0[62] = 0; // gridlines are not supported
|
|
2417 abyte0[63] = 0;
|
|
2418 writeGDS(0, 0, abyte0); // now tell them about us
|
|
2419 abyte0 = null;
|
|
2420
|
|
2421 }
|
|
2422
|
|
2423 protected final boolean negotiate(byte abyte0[]) throws IOException {
|
|
2424 int i = 0;
|
|
2425
|
|
2426
|
|
2427 // from server negotiations
|
|
2428 if(abyte0[i] == IAC) { // -1
|
|
2429
|
|
2430 while(i < abyte0.length && abyte0[i++] == -1)
|
|
2431 // while(i < abyte0.length && (abyte0[i] == -1 || abyte0[i++] == 0x20))
|
|
2432 switch(abyte0[i++]) {
|
|
2433
|
|
2434 // we will not worry about what it WONT do
|
|
2435 case WONT: // -4
|
|
2436 default:
|
|
2437 break;
|
|
2438
|
|
2439 case DO: //-3
|
|
2440
|
|
2441 // not sure why but since moving to V5R2 we are receiving a
|
|
2442 // DO with no option when connecting a second session with
|
|
2443 // device name. Can not find the cause at all. If anybody
|
|
2444 // is interested please debug this until then this works.
|
|
2445 if (i < abyte0.length) {
|
|
2446 switch(abyte0[i]) {
|
|
2447 case TERMINAL_TYPE: // 24
|
|
2448 baosp.write(IAC);
|
|
2449 baosp.write(WILL);
|
|
2450 baosp.write(TERMINAL_TYPE);
|
|
2451 writeByte(baosp.toByteArray());
|
|
2452 baosp.reset();
|
|
2453
|
|
2454 break;
|
|
2455
|
|
2456 case OPT_END_OF_RECORD: // 25
|
|
2457
|
|
2458 baosp.write(IAC);
|
|
2459 baosp.write(WILL);
|
|
2460 baosp.write(OPT_END_OF_RECORD);
|
|
2461 writeByte(baosp.toByteArray());
|
|
2462 baosp.reset();
|
|
2463 break;
|
|
2464
|
|
2465 case TRANSMIT_BINARY: // 0
|
|
2466
|
|
2467 baosp.write(IAC);
|
|
2468 baosp.write(WILL);
|
|
2469 baosp.write(TRANSMIT_BINARY);
|
|
2470 writeByte(baosp.toByteArray());
|
|
2471 baosp.reset();
|
|
2472
|
|
2473 break;
|
|
2474
|
|
2475 case TIMING_MARK: // 6 rfc860
|
|
2476 // System.out.println("Timing Mark Received and notifying " +
|
|
2477 // "the server that we will not do it");
|
|
2478 baosp.write(IAC);
|
|
2479 baosp.write(WONT);
|
|
2480 baosp.write(TIMING_MARK);
|
|
2481 writeByte(baosp.toByteArray());
|
|
2482 baosp.reset();
|
|
2483
|
|
2484 break;
|
|
2485
|
|
2486 case NEW_ENVIRONMENT: // 39 rfc1572, rfc4777
|
|
2487 // allways send new environment vars ...
|
|
2488 baosp.write(IAC);
|
|
2489 baosp.write(WILL);
|
|
2490 baosp.write(NEW_ENVIRONMENT);
|
|
2491 writeByte(baosp.toByteArray());
|
|
2492 baosp.reset();
|
|
2493 break;
|
|
2494
|
|
2495 default: // every thing else we will not do at this time
|
|
2496 baosp.write(IAC);
|
|
2497 baosp.write(WONT);
|
|
2498 baosp.write(abyte0[i]); // either
|
|
2499 writeByte(baosp.toByteArray());
|
|
2500 baosp.reset();
|
|
2501
|
|
2502 break;
|
|
2503 }
|
|
2504 }
|
|
2505
|
|
2506 i++;
|
|
2507 break;
|
|
2508
|
|
2509 case WILL:
|
|
2510
|
|
2511 switch(abyte0[i]) {
|
|
2512 case OPT_END_OF_RECORD: // 25
|
|
2513 baosp.write(IAC);
|
|
2514 baosp.write(DO);
|
|
2515 baosp.write(OPT_END_OF_RECORD);
|
|
2516 writeByte(baosp.toByteArray());
|
|
2517 baosp.reset();
|
|
2518
|
|
2519 break;
|
|
2520
|
|
2521 case TRANSMIT_BINARY: // '\0'
|
|
2522 baosp.write(IAC);
|
|
2523 baosp.write(DO);
|
|
2524 baosp.write(TRANSMIT_BINARY);
|
|
2525 writeByte(baosp.toByteArray());
|
|
2526 baosp.reset();
|
|
2527
|
|
2528 break;
|
|
2529 }
|
|
2530 i++;
|
|
2531 break;
|
|
2532
|
|
2533 case SB: // -6
|
|
2534
|
|
2535 if(abyte0[i] == NEW_ENVIRONMENT && abyte0[i + 1] == 1) {
|
|
2536 negNewEnvironment();
|
|
2537
|
|
2538 while (++i < abyte0.length && abyte0[i + 1] != IAC);
|
|
2539 }
|
|
2540
|
|
2541 if(abyte0[i] == TERMINAL_TYPE && abyte0[i + 1] == 1) {
|
|
2542 baosp.write(IAC);
|
|
2543 baosp.write(SB);
|
|
2544 baosp.write(TERMINAL_TYPE);
|
|
2545 baosp.write(QUAL_IS);
|
|
2546 if(!support132)
|
|
2547 baosp.write("IBM-3179-2".getBytes());
|
|
2548 else
|
|
2549 baosp.write("IBM-3477-FC".getBytes());
|
|
2550 baosp.write(IAC);
|
|
2551 baosp.write(SE);
|
|
2552 writeByte(baosp.toByteArray());
|
|
2553 baosp.reset();
|
|
2554
|
|
2555 i++;
|
|
2556 }
|
|
2557 i++;
|
|
2558 break;
|
|
2559 }
|
|
2560 return true;
|
|
2561 }
|
|
2562 else {
|
|
2563 return false;
|
|
2564 }
|
|
2565 }
|
|
2566
|
|
2567 /**
|
|
2568 * Negotiate new environment string for device name
|
|
2569 *
|
|
2570 * @throws IOException
|
|
2571 */
|
|
2572 private void negNewEnvironment() throws IOException {
|
|
2573
|
|
2574 baosp.write(IAC);
|
|
2575 baosp.write(SB);
|
|
2576 baosp.write(NEW_ENVIRONMENT);
|
|
2577 baosp.write(IS);
|
|
2578
|
|
2579 // http://tools.ietf.org/html/rfc4777
|
|
2580
|
|
2581 if (kbdTypesCodePage != null) {
|
|
2582 baosp.write(USERVAR);
|
|
2583 baosp.write("KBDTYPE".getBytes());
|
|
2584 baosp.write(VALUE);
|
|
2585 baosp.write(kbdTypesCodePage.kbdType.getBytes());
|
|
2586
|
|
2587 baosp.write(USERVAR);
|
|
2588 baosp.write("CODEPAGE".getBytes());
|
|
2589 baosp.write(VALUE);
|
|
2590 baosp.write(kbdTypesCodePage.codepage.getBytes());
|
|
2591
|
|
2592 baosp.write(USERVAR);
|
|
2593 baosp.write("CHARSET".getBytes());
|
|
2594 baosp.write(VALUE);
|
|
2595 baosp.write(kbdTypesCodePage.charset.getBytes());
|
|
2596 }
|
|
2597
|
|
2598 if (devName != null) {
|
|
2599 baosp.write(USERVAR);
|
|
2600
|
|
2601 baosp.write("DEVNAME".getBytes());
|
|
2602
|
|
2603 baosp.write(VALUE);
|
|
2604
|
|
2605 baosp.write(negDeviceName().getBytes());
|
|
2606 }
|
|
2607
|
|
2608 if (user != null) {
|
|
2609
|
|
2610 baosp.write(VAR);
|
|
2611 baosp.write("USER".getBytes());
|
|
2612 baosp.write(VALUE);
|
|
2613 baosp.write(user.getBytes());
|
|
2614
|
|
2615 if (password != null) {
|
|
2616 baosp.write(USERVAR);
|
|
2617 baosp.write("IBMRSEED".getBytes());
|
|
2618 baosp.write(VALUE);
|
|
2619 baosp.write(NEGOTIATE_ESC);
|
|
2620 baosp.write(0x0);
|
|
2621 baosp.write(0x0);
|
|
2622 baosp.write(0x0);
|
|
2623 baosp.write(0x0);
|
|
2624 baosp.write(0x0);
|
|
2625 baosp.write(0x0);
|
|
2626 baosp.write(0x0);
|
|
2627 baosp.write(0x0);
|
|
2628 baosp.write(USERVAR);
|
|
2629 baosp.write("IBMSUBSPW".getBytes());
|
|
2630 baosp.write(VALUE);
|
|
2631 baosp.write(password.getBytes());
|
|
2632 }
|
|
2633
|
|
2634 if (library != null) {
|
|
2635 baosp.write(USERVAR);
|
|
2636 baosp.write("IBMCURLIB".getBytes());
|
|
2637 baosp.write(VALUE);
|
|
2638 baosp.write(library.getBytes());
|
|
2639 }
|
|
2640
|
|
2641 if (initialMenu != null) {
|
|
2642 baosp.write(USERVAR);
|
|
2643 baosp.write("IBMIMENU".getBytes());
|
|
2644 baosp.write(VALUE);
|
|
2645 baosp.write(initialMenu.getBytes());
|
|
2646 }
|
|
2647
|
|
2648 if (program != null) {
|
|
2649 baosp.write(USERVAR);
|
|
2650 baosp.write("IBMPROGRAM".getBytes());
|
|
2651 baosp.write(VALUE);
|
|
2652 baosp.write(program.getBytes());
|
|
2653 }
|
|
2654 }
|
|
2655 baosp.write(IAC);
|
|
2656 baosp.write(SE);
|
|
2657
|
|
2658 writeByte(baosp.toByteArray());
|
|
2659 baosp.reset();
|
|
2660
|
|
2661 }
|
|
2662
|
|
2663 /**
|
|
2664 * This will negotiate a device name with controller. if the sequence is
|
|
2665 * less than zero then it will send the device name as specified. On each
|
|
2666 * unsuccessful attempt a sequential number is appended until we find one or
|
|
2667 * the controller says no way.
|
|
2668 *
|
|
2669 * @return String
|
|
2670 */
|
|
2671 private String negDeviceName() {
|
|
2672
|
|
2673 if (devSeq++ == -1) {
|
|
2674 devNameUsed = devName;
|
|
2675 return devName;
|
|
2676 } else {
|
|
2677 StringBuffer sb = new StringBuffer(devName + devSeq);
|
|
2678 int ei = 1;
|
|
2679 while (sb.length() > 10) {
|
|
2680
|
|
2681 sb.setLength(0);
|
|
2682 sb.append(devName.substring(0, devName.length() - ei++));
|
|
2683 sb.append(devSeq);
|
|
2684
|
|
2685 }
|
|
2686 devNameUsed = sb.toString();
|
|
2687 return devNameUsed;
|
|
2688 }
|
|
2689 }
|
|
2690
|
|
2691 public final void setCodePage(String cp) {
|
|
2692 codePage = CharMappings.getCodePage(cp);
|
|
2693 cp = cp.toLowerCase();
|
|
2694 for (KbdTypesCodePages kbdtyp : KbdTypesCodePages.values()) {
|
|
2695 if (("cp"+kbdtyp.codepage).equals(cp) || kbdtyp.ccsid.equals(cp)) {
|
|
2696 kbdTypesCodePage = kbdtyp;
|
|
2697 break;
|
|
2698 }
|
|
2699 }
|
|
2700 if (log.isInfoEnabled()) {
|
|
2701 log.info("Choosed keyboard mapping " + kbdTypesCodePage.toString() + " for code page " + cp);
|
|
2702 }
|
|
2703 }
|
|
2704
|
|
2705 public final ICodePage getCodePage() {
|
|
2706 return codePage;
|
|
2707 }
|
|
2708
|
|
2709 /**
|
|
2710 * @see org.tn5250j.Session5250#signalBell()
|
|
2711 */
|
|
2712 public void signalBell() {
|
|
2713 controller.signalBell();
|
|
2714 }
|
|
2715
|
|
2716 }
|