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