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