Mercurial > 510Connectbot
comparison src/com/five_ten_sg/connectbot/transport/TN5250.java @ 31:139394237973 tn5250
start tn5250 integration
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 10 Jun 2014 12:00:07 -0700 |
parents | d738f6b876fe |
children | b086dd794dba |
comparison
equal
deleted
inserted
replaced
30:d738f6b876fe | 31:139394237973 |
---|---|
50 */ | 50 */ |
51 public class TN5250 extends AbsTransport { | 51 public class TN5250 extends AbsTransport { |
52 private static final String PROTOCOL = "tn5250"; | 52 private static final String PROTOCOL = "tn5250"; |
53 private static final String TAG = "ConnectBot.tn5250"; | 53 private static final String TAG = "ConnectBot.tn5250"; |
54 private static final int DEFAULT_PORT = 23; | 54 private static final int DEFAULT_PORT = 23; |
55 | |
55 private Screen5250 screen52; | 56 private Screen5250 screen52; |
56 | 57 private tnvt handler = null; |
57 private tnvt handler = null; | 58 private Socket socket; |
58 private Socket socket; | 59 private int width; |
59 | 60 private int height; |
60 private int width; | 61 private boolean connected = false; |
61 private int height; | |
62 | |
63 private boolean connected = false; | |
64 | 62 |
65 static final Pattern hostmask; | 63 static final Pattern hostmask; |
66 static { | 64 static { |
67 hostmask = Pattern.compile("^([0-9a-z.-]+)(:(\\d+))?$", Pattern.CASE_INSENSITIVE); | 65 hostmask = Pattern.compile("^([0-9a-z.-]+)(:(\\d+))?$", Pattern.CASE_INSENSITIVE); |
68 } | 66 } |
70 | 68 |
71 public TN5250() { | 69 public TN5250() { |
72 super(); | 70 super(); |
73 } | 71 } |
74 | 72 |
75 public TN5250(HostBean host, TerminalBridge bridge, TerminalManager manager) { | 73 |
76 super(host, bridge, manager); | 74 /** |
77 } | 75 * @return protocol part of the URI |
78 | 76 */ |
79 | |
80 /** | |
81 * @return protocol part of the URI | |
82 */ | |
83 public static String getProtocolName() { | 77 public static String getProtocolName() { |
84 return PROTOCOL; | 78 return PROTOCOL; |
85 } | 79 } |
86 | 80 |
81 | |
82 /** | |
83 * Encode the current transport into a URI that can be passed via intent calls. | |
84 * @return URI to host | |
85 */ | |
87 public Uri getUri(String input) { | 86 public Uri getUri(String input) { |
88 Matcher matcher = hostmask.matcher(input); | 87 Matcher matcher = hostmask.matcher(input); |
89 | 88 |
90 if (!matcher.matches()) | 89 if (!matcher.matches()) |
91 return null; | 90 return null; |
118 sb.append("/#") | 117 sb.append("/#") |
119 .append(Uri.encode(input)); | 118 .append(Uri.encode(input)); |
120 Uri uri = Uri.parse(sb.toString()); | 119 Uri uri = Uri.parse(sb.toString()); |
121 return uri; | 120 return uri; |
122 } | 121 } |
122 | |
123 | 123 |
124 /** | 124 /** |
125 * Causes transport to connect to the target host. After connecting but before a | 125 * Causes transport to connect to the target host. After connecting but before a |
126 * session is started, must call back to {@link TerminalBridge#onConnected()}. | 126 * session is started, must call back to {@link TerminalBridge#onConnected()}. |
127 * After that call a session may be opened. | 127 * After that call a session may be opened. |
143 public boolean willBlock() { | 143 public boolean willBlock() { |
144 // we don't use a relay thread between the transport and the vt320 buffer | 144 // we don't use a relay thread between the transport and the vt320 buffer |
145 return true; | 145 return true; |
146 } | 146 } |
147 | 147 |
148 | |
148 /** | 149 /** |
149 * Reads from the transport. Transport must support reading into a byte array | 150 * Reads from the transport. Transport must support reading into a byte array |
150 * <code>buffer</code> at the start of <code>offset</code> and a maximum of | 151 * <code>buffer</code> at the start of <code>offset</code> and a maximum of |
151 * <code>length</code> bytes. If the remote host disconnects, throw an | 152 * <code>length</code> bytes. If the remote host disconnects, throw an |
152 * {@link IOException}. | 153 * {@link IOException}. |
170 * @throws IOException when there is a problem writing after connection | 171 * @throws IOException when there is a problem writing after connection |
171 */ | 172 */ |
172 public void write(byte[] buffer) throws IOException { | 173 public void write(byte[] buffer) throws IOException { |
173 } | 174 } |
174 | 175 |
176 | |
175 /** | 177 /** |
176 * Writes to the transport. See {@link #write(byte[])} for behavior details. | 178 * Writes to the transport. See {@link #write(byte[])} for behavior details. |
177 * @param c character to write to the transport | 179 * @param c character to write to the transport |
178 * @throws IOException when there is a problem writing after connection | 180 * @throws IOException when there is a problem writing after connection |
179 */ | 181 */ |
180 public void write(int c) throws IOException { | 182 public void write(int c) throws IOException { |
181 } | 183 } |
182 | 184 |
185 | |
183 /** | 186 /** |
184 * Flushes the write commands to the transport. | 187 * Flushes the write commands to the transport. |
185 * @throws IOException when there is a problem writing after connection | 188 * @throws IOException when there is a problem writing after connection |
186 */ | 189 */ |
187 public void flush() throws IOException { | 190 public void flush() throws IOException { |
188 } | 191 } |
192 | |
189 | 193 |
190 /** | 194 /** |
191 * Closes the connection to the terminal. Note that the resulting failure to read | 195 * Closes the connection to the terminal. Note that the resulting failure to read |
192 * should call {@link TerminalBridge#dispatchDisconnect(boolean)}. !!! | 196 * should call {@link TerminalBridge#dispatchDisconnect(boolean)}. !!! |
193 */ | 197 */ |
194 public void close() { | 198 public void close() { |
195 handler.disconnect(); | 199 handler.disconnect(); |
196 connected = false; | 200 connected = false; |
197 } | 201 } |
202 | |
198 | 203 |
199 /** | 204 /** |
200 * Tells the transport what dimensions the display is currently | 205 * Tells the transport what dimensions the display is currently |
201 * @param columns columns of text | 206 * @param columns columns of text |
202 * @param rows rows of text | 207 * @param rows rows of text |
206 @Override | 211 @Override |
207 public void setDimensions(int columns, int rows, int width, int height) { | 212 public void setDimensions(int columns, int rows, int width, int height) { |
208 // do nothing | 213 // do nothing |
209 } | 214 } |
210 | 215 |
211 public void setOptions(Map<String, String> options) { | |
212 // do nothing | |
213 } | |
214 | |
215 public Map<String, String> getOptions() { | |
216 return null; | |
217 } | |
218 | |
219 public void setCompression(boolean compression) { | |
220 // do nothing | |
221 } | |
222 | |
223 public void setHttpproxy(String httpproxy) { | |
224 // do nothing | |
225 } | |
226 | |
227 public void setUseAuthAgent(String useAuthAgent) { | |
228 // do nothing | |
229 } | |
230 | |
231 public void setEmulation(String emulation) { | |
232 this.emulation = emulation; | |
233 } | |
234 | |
235 public String getEmulation() { | |
236 return emulation; | |
237 } | |
238 | |
239 public void setHost(HostBean host) { | |
240 this.host = host; | |
241 } | |
242 | |
243 public void setBridge(TerminalBridge bridge) { | |
244 this.bridge = bridge; | |
245 } | |
246 | |
247 public void setManager(TerminalManager manager) { | |
248 this.manager = manager; | |
249 } | |
250 | |
251 /** | |
252 * Whether or not this transport type can forward ports. | |
253 * @return true on ability to forward ports | |
254 */ | |
255 public boolean canForwardPorts() { | |
256 return false; | |
257 } | |
258 | |
259 /** | |
260 * Adds the {@link PortForwardBean} to the list. | |
261 * @param portForward the port forward bean to add | |
262 * @return true on successful addition | |
263 */ | |
264 public boolean addPortForward(PortForwardBean portForward) { | |
265 return false; | |
266 } | |
267 | |
268 /** | |
269 * Enables a port forward member. After calling this method, the port forward should | |
270 * be operational iff it could be enabled by the transport. | |
271 * @param portForward member of our current port forwards list to enable | |
272 * @return true on successful port forward setup | |
273 */ | |
274 public boolean enablePortForward(PortForwardBean portForward) { | |
275 return false; | |
276 } | |
277 | |
278 /** | |
279 * Disables a port forward member. After calling this method, the port forward should | |
280 * be non-functioning iff it could be disabled by the transport. | |
281 * @param portForward member of our current port forwards list to enable | |
282 * @return true on successful port forward tear-down | |
283 */ | |
284 public boolean disablePortForward(PortForwardBean portForward) { | |
285 return false; | |
286 } | |
287 | |
288 /** | |
289 * Removes the {@link PortForwardBean} from the available port forwards. | |
290 * @param portForward the port forward bean to remove | |
291 * @return true on successful removal | |
292 */ | |
293 public boolean removePortForward(PortForwardBean portForward) { | |
294 return false; | |
295 } | |
296 | |
297 /** | |
298 * Gets a list of the {@link PortForwardBean} currently used by this transport. | |
299 * @return the list of port forwards | |
300 */ | |
301 public List<PortForwardBean> getPortForwards() { | |
302 return null; | |
303 } | |
304 | |
305 /** | |
306 * Whether or not this transport type can transfer files. | |
307 * @return true on ability to transfer files | |
308 */ | |
309 public boolean canTransferFiles() { | |
310 return false; | |
311 } | |
312 | |
313 /** | |
314 * Downloads the specified remote file to a local folder. | |
315 * @param remoteFile The path to the remote file to be downloaded. Must be non-null. | |
316 * @param localFolder The path to local folder. Null = default external storage folder. | |
317 * @return true on success, false on failure | |
318 */ | |
319 public boolean downloadFile(String remoteFile, String localFolder) { | |
320 return false; | |
321 } | |
322 | |
323 /** | |
324 * Uploads the specified local file to the remote host. | |
325 * @param localFile The path to the local file to be uploaded. Must be non-null. | |
326 * @param remoteFolder The path to the remote directory. Null == default remote directory. | |
327 * @return true on success, false on failure | |
328 */ | |
329 public boolean uploadFile(String localFile, String remoteFile, | |
330 String remoteFolder, String mode) { | |
331 return false; | |
332 } | |
333 | 216 |
334 @Override | 217 @Override |
335 public int getDefaultPort() { | 218 public int getDefaultPort() { |
336 return DEFAULT_PORT; | 219 return DEFAULT_PORT; |
337 } | 220 } |
338 | 221 |
222 | |
339 @Override | 223 @Override |
340 public boolean isConnected() { | 224 public boolean isConnected() { |
341 return connected; | 225 return connected; |
342 } | 226 } |
343 | 227 |
228 | |
344 @Override | 229 @Override |
345 public boolean isSessionOpen() { | 230 public boolean isSessionOpen() { |
346 return connected; | 231 return connected; |
347 } | 232 } |
233 | |
348 | 234 |
349 @Override | 235 @Override |
350 public boolean isAuthenticated() { | 236 public boolean isAuthenticated() { |
351 return connected; | 237 return connected; |
352 } | 238 } |
359 } | 245 } |
360 else { | 246 else { |
361 return String.format("%s:%d", hostname, port); | 247 return String.format("%s:%d", hostname, port); |
362 } | 248 } |
363 } | 249 } |
250 | |
364 | 251 |
365 @Override | 252 @Override |
366 public void getSelectionArgs(Uri uri, Map<String, String> selection) { | 253 public void getSelectionArgs(Uri uri, Map<String, String> selection) { |
367 selection.put(HostDatabase.FIELD_HOST_PROTOCOL, PROTOCOL); | 254 selection.put(HostDatabase.FIELD_HOST_PROTOCOL, PROTOCOL); |
368 selection.put(HostDatabase.FIELD_HOST_NICKNAME, uri.getFragment()); | 255 selection.put(HostDatabase.FIELD_HOST_NICKNAME, uri.getFragment()); |
418 public boolean needsRelay() { | 305 public boolean needsRelay() { |
419 // we don't use a relay thread between the transport and the vt320 buffer | 306 // we don't use a relay thread between the transport and the vt320 buffer |
420 return false; | 307 return false; |
421 } | 308 } |
422 | 309 |
423 | |
424 @Override | |
425 public TerminalKeyListener getTerminalKeyListener(TerminalManager manager, TerminalBridge bridge, vt320 buffer, String encoding) { | |
426 return new TerminalKeyListener(manager, bridge, buffer, encoding); | |
427 } | |
428 | |
429 } | 310 } |