Mercurial > 510Connectbot
annotate src/org/tn5250j/framework/tn5250/DataStreamProducer.java @ 306:90e47d99ea54 ganymed
add ecdsa key support everywhere
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 30 Jul 2014 13:38:04 -0700 |
parents | c438c2ff0052 |
children | 7ac1a0b02f44 |
rev | line source |
---|---|
3 | 1 package org.tn5250j.framework.tn5250; |
2 | |
3 import java.io.BufferedInputStream; | |
4 import java.io.BufferedOutputStream; | |
5 import java.io.ByteArrayOutputStream; | |
6 import java.io.EOFException; | |
7 import java.io.FileNotFoundException; | |
8 import java.io.FileOutputStream; | |
9 import java.io.IOException; | |
10 import java.net.SocketException; | |
11 import java.util.concurrent.BlockingQueue; | |
12 | |
13 import org.tn5250j.encoding.ICodePage; | |
72
8181cb01c64d
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
69
diff
changeset
|
14 |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
15 import android.util.Log; |
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
16 |
3 | 17 |
18 public class DataStreamProducer implements Runnable { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
19 private static final String TAG = "DataStreamProducer"; |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
20 private tnvt vt; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
21 private BufferedInputStream bin; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
22 private ByteArrayOutputStream baosin; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
23 private Thread me; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
24 private byte[] saveStream; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
25 private final BlockingQueue<Object> dsq; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
26 private byte[] abyte2; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
27 private FileOutputStream fw; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
28 private BufferedOutputStream dw; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
29 private boolean dumpBytes = false; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
30 private ICodePage codePage; |
3 | 31 |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
32 |
3 | 33 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
34 public DataStreamProducer(tnvt vt, BufferedInputStream bin, BlockingQueue<Object> queue, byte[] init) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
35 this.bin = bin; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
36 this.vt = vt; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
37 baosin = new ByteArrayOutputStream(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
38 dsq = queue; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
39 abyte2 = init; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
40 } |
3 | 41 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
42 public void setInputStream(ByteArrayOutputStream is) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
43 baosin = is; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
44 } |
3 | 45 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
46 public final void run() { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
47 boolean done = false; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
48 me = Thread.currentThread(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
49 // load the first response screen |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
50 loadStream(abyte2, 0); |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
51 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
52 while (!done) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
53 try { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
54 byte[] abyte0 = readIncoming(); |
3 | 55 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
56 // WVL - LDC : 17/05/2004 : Device name negotiations send TIMING MARK |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
57 // Restructured to the readIncoming() method to return null |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
58 // on TIMING MARK. Don't process in that case (abyte0 == null)! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
59 if (abyte0 != null) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
60 // WVL - LDC : 16/07/2003 : TR.000345 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
61 // When the socket has been closed, the reading returns |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
62 // no bytes (an empty byte arrray). |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
63 // But the loadStream fails on this, so we check it here! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
64 if (abyte0.length > 0) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
65 loadStream(abyte0, 0); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
66 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
67 // WVL - LDC : 16/07/2003 : TR.000345 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
68 // Returning no bytes means the input buffer has |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
69 // reached end-of-stream, so we do a disconnect! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
70 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
71 done = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
72 vt.disconnect(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
73 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
74 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
75 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
76 catch (SocketException se) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
77 Log.w(TAG, " DataStreamProducer thread interrupted and stopping " + se.getMessage()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
78 done = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
79 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
80 catch (IOException ioe) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
81 Log.w(TAG, ioe.getMessage()); |
3 | 82 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
83 if (me.isInterrupted()) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
84 done = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
85 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
86 catch (Exception ex) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
87 Log.w(TAG, ex.getMessage()); |
3 | 88 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
89 if (me.isInterrupted()) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
90 done = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
91 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
92 } |
3 | 93 } |
94 | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
95 private final void loadStream(byte abyte0[], int i) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
96 int j = 0; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
97 int size = 0; |
3 | 98 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
99 if (saveStream == null) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
100 j = (abyte0[i] & 0xff) << 8 | abyte0[i + 1] & 0xff; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
101 size = abyte0.length; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
102 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
103 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
104 size = saveStream.length + abyte0.length; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
105 byte[] inter = new byte[size]; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
106 System.arraycopy(saveStream, 0, inter, 0, saveStream.length); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
107 System.arraycopy(abyte0, 0, inter, saveStream.length, abyte0.length); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
108 abyte0 = new byte[size]; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
109 System.arraycopy(inter, 0, abyte0, 0, size); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
110 saveStream = null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
111 inter = null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
112 j = (abyte0[i] & 0xff) << 8 | abyte0[i + 1] & 0xff; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
113 Log.d(TAG, "partial stream found"); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
114 } |
3 | 115 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
116 if (j > size) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
117 saveStream = new byte[abyte0.length]; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
118 System.arraycopy(abyte0, 0, saveStream, 0, abyte0.length); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
119 Log.d(TAG, "partial stream saved"); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
120 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
121 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
122 byte abyte1[]; |
3 | 123 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
124 try { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
125 abyte1 = new byte[j + 2]; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
126 System.arraycopy(abyte0, i, abyte1, 0, j + 2); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
127 dsq.put(abyte1); |
3 | 128 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
129 if (abyte0.length > abyte1.length + i) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
130 loadStream(abyte0, i + j + 2); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
131 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
132 catch (Exception ex) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
133 Log.w(TAG, "load stream error " + ex.getMessage()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
134 // ex.printStackTrace(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
135 // dump(abyte0); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
136 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
137 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
138 } |
3 | 139 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
140 public final byte[] readIncoming() |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
141 throws IOException { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
142 boolean done = false; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
143 boolean negotiate = false; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
144 baosin.reset(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
145 int j = -1; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
146 int i = 0; |
3 | 147 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
148 while (!done) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
149 i = bin.read(); |
3 | 150 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
151 // WVL - LDC : 16/07/2003 : TR.000345 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
152 // The inStream return -1 when end-of-stream is reached. This |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
153 // happens e.g. when the connection is closed from the AS/400. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
154 // So we stop in this case! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
155 // ==> an empty byte array is returned from this method. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
156 if (i == -1) { // nothing read! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
157 done = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
158 vt.disconnect(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
159 continue; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
160 } |
3 | 161 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
162 // We use the values instead of the static values IAC and EOR |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
163 // because they are defined as bytes. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
164 // |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
165 // The > if(i != 255 || j != 255) < is a hack for the double FF FF's |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
166 // that are being returned. I do not know why this is like this and |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
167 // can not find any documentation for it. It is also being returned |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
168 // on my Client Access tcp dump as well so they are handling it. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
169 // |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
170 // my5250 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
171 // 0000: 00 50 DA 44 C8 45 42 00 00 00 00 24 08 00 45 00 .P.D.EB....$..E. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
172 // 0010: 04 2A BC F9 00 00 40 06 D0 27 C1 A8 33 04 C1 A8 .*....@..'..3... |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
173 // 0020: 33 58 00 17 04 18 6F A2 83 CB 00 1E D1 BA 50 18 3X....o.......P. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
174 // 0030: 20 00 8A 9A 00 00 03 FF FF 12 A0 00 00 04 00 00 ............... |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
175 // --------------------------- || || ------------------------------------- |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
176 // 0040: 03 04 40 04 11 00 20 01 07 00 00 00 18 00 00 10 ..@... ......... |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
177 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
178 if (j == 255 && i == 255) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
179 j = -1; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
180 continue; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
181 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
182 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
183 baosin.write(i); |
3 | 184 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
185 // check for end of record EOR and IAC - FFEF |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
186 if (j == 255 && i == 239) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
187 done = true; |
3 | 188 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
189 // This is to check for the TELNET TIMING MARK OPTION |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
190 // rfc860 explains this in more detail. When we receive it |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
191 // we will negotiate with the server by sending a WONT'T TIMING-MARK |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
192 // This will let the server know that we processed the information |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
193 // and are just waiting for the user to enter some data so keep the |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
194 // socket alive. This is more or less a AYT (ARE YOU THERE) or not. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
195 if (i == 253 && j == 255) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
196 done = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
197 negotiate = true; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
198 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
199 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
200 j = i; |
3 | 201 } |
202 | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
203 // after the initial negotiation we might get other options such as |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
204 // timing marks ?????????????? do we ???????????? look at telnet spec |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
205 // yes we do. rfc860 explains about timing marks. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
206 // WVL - LDC : 17/05/2004 : Device name negotiations send TIMING MARK |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
207 // to existing device! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
208 // Handled incorrectly: we cannot continue processing the TIMING MARK DO |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
209 // after we have handled it in the vt.negotiate() |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
210 // We should not return the bytes; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
211 // ==> restructured to return null after negotiation! |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
212 // Impacts the run method! Added the null check. |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
213 byte[] rBytes = baosin.toByteArray(); |
3 | 214 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
215 if (dumpBytes) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
216 dump(rBytes); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
217 } |
3 | 218 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
219 if (negotiate) { |
3 | 220 // get the negotiation option |
221 baosin.write(bin.read()); | |
222 vt.negotiate(rBytes); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
223 return null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
224 } |
3 | 225 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
226 return rBytes; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
227 } |
3 | 228 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
229 protected final void toggleDebug(ICodePage cp) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
230 if (codePage == null) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
231 codePage = cp; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
232 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
233 dumpBytes = !dumpBytes; |
3 | 234 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
235 if (dumpBytes) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
236 try { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
237 if (fw == null) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
238 fw = new FileOutputStream("log.txt"); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
239 dw = new BufferedOutputStream(fw); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
240 } |
3 | 241 } |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
242 catch (FileNotFoundException fnfe) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
243 Log.w(TAG, fnfe.getMessage()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
244 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
245 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
246 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
247 try { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
248 if (dw != null) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
249 dw.close(); |
3 | 250 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
251 if (fw != null) |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
252 fw.close(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
253 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
254 dw = null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
255 fw = null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
256 codePage = null; |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
257 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
258 catch (IOException ioe) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
259 Log.w(TAG, ioe.getMessage()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
260 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
261 } |
3 | 262 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
263 Log.i(TAG, "Data Stream output is now " + dumpBytes); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
264 } |
3 | 265 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
266 public void dump(byte[] abyte0) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
267 try { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
268 Log.i(TAG, "\n Buffer Dump of data from AS400: "); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
269 dw.write("\r\n Buffer Dump of data from AS400: ".getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
270 StringBuffer h = new StringBuffer(); |
3 | 271 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
272 for (int x = 0; x < abyte0.length; x++) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
273 if (x % 16 == 0) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
274 System.out.println(" " + h.toString()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
275 dw.write((" " + h.toString() + "\r\n").getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
276 h.setLength(0); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
277 h.append("+0000"); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
278 h.setLength(5 - Integer.toHexString(x).length()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
279 h.append(Integer.toHexString(x).toUpperCase()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
280 System.out.print(h.toString()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
281 dw.write(h.toString().getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
282 h.setLength(0); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
283 } |
3 | 284 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
285 char ac = codePage.ebcdic2uni(abyte0[x]); |
3 | 286 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
287 if (ac < ' ') |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
288 h.append('.'); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
289 else |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
290 h.append(ac); |
3 | 291 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
292 if (x % 4 == 0) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
293 System.out.print(" "); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
294 dw.write((" ").getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
295 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
296 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
297 if (Integer.toHexString(abyte0[x] & 0xff).length() == 1) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
298 System.out.print("0" + Integer.toHexString(abyte0[x] & 0xff).toUpperCase()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
299 dw.write(("0" + Integer.toHexString(abyte0[x] & 0xff).toUpperCase()).getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
300 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
301 else { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
302 System.out.print(Integer.toHexString(abyte0[x] & 0xff).toUpperCase()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
303 dw.write((Integer.toHexString(abyte0[x] & 0xff).toUpperCase()).getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
304 } |
3 | 305 } |
306 | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
307 System.out.println(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
308 dw.write("\r\n".getBytes()); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
309 dw.flush(); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
310 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
311 catch (EOFException _ex) { } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
312 catch (Exception _ex) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
313 Log.w(TAG, "Cannot dump from host\n\r"); |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
314 } |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
315 } |
3 | 316 |
317 // public void dumpBytes() { | |
318 // byte shit[] = bk.buffer; | |
319 // for (int i = 0;i < shit.length;i++) | |
320 // System.out.println(i + ">" + shit[i] + "< - ascii - >" + getASCIIChar(shit[i]) + "<"); | |
321 // } | |
322 // | |
323 // public void dumpHexBytes(byte[] abyte) { | |
324 // byte shit[] = abyte; | |
325 // for (int i = 0;i < shit.length;i++) | |
326 // System.out.println(i + ">" + shit[i] + "< hex >" + Integer.toHexString((shit[i] & 0xff))); | |
327 // } | |
328 | |
98
16e023784917
protect both read calls with test for blocking
Carl Byington <carl@five-ten-sg.com>
parents:
72
diff
changeset
|
329 } |