annotate src/com/five_ten_sg/connectbot/transport/TN5250.java @ 37:0395ca628303 tn5250

start tn5250 integration
author Carl Byington <carl@five-ten-sg.com>
date Tue, 10 Jun 2014 16:14:36 -0700
parents b086dd794dba
children 6b0f1ece1d91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
1 /*
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
2 * 510ConnectBot
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
3 * Copyright 2014 Carl Byington
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
4 *
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
5 * Licensed under the Apache License, Version 2.0 (the "License");
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
6 * you may not use this file except in compliance with the License.
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
7 * You may obtain a copy of the License at
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8 *
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
9 * http://www.apache.org/licenses/LICENSE-2.0
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
10 *
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 * Unless required by applicable law or agreed to in writing, software
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
12 * distributed under the License is distributed on an "AS IS" BASIS,
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
14 * See the License for the specific language governing permissions and
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
15 * limitations under the License.
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16 */
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18 package com.five_ten_sg.connectbot.transport;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20 import java.io.IOException;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21 import java.io.InputStream;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 import java.io.OutputStream;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 import java.net.Socket;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 import java.net.SocketException;
13
b39bcf616a6f adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
25 import java.net.UnknownHostException;
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
26 import java.util.List;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27 import java.util.Map;
13
b39bcf616a6f adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
28 import java.util.regex.Matcher;
b39bcf616a6f adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
29 import java.util.regex.Pattern;
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30
12
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
31 import org.tn5250j.framework.tn5250.Screen5250;
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
32 import org.tn5250j.framework.tn5250.tnvt;
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
33
13
b39bcf616a6f adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
34 import com.five_ten_sg.connectbot.R;
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
35 import com.five_ten_sg.connectbot.bean.HostBean;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
36 import com.five_ten_sg.connectbot.bean.PortForwardBean;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
37 import com.five_ten_sg.connectbot.service.TerminalBridge;
29
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
38 import com.five_ten_sg.connectbot.service.TerminalKeyListener;
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
39 import com.five_ten_sg.connectbot.service.TerminalManager;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
40 import com.five_ten_sg.connectbot.util.HostDatabase;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
41 import android.content.Context;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 import android.net.Uri;
13
b39bcf616a6f adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
43 import android.util.Log;
29
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
44 import de.mud.terminal.vt320;
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
46
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
47 /**
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
48 * @author Carl Byington
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 *
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
50 */
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
51 public class TN5250 extends AbsTransport {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 private static final String PROTOCOL = "tn5250";
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 private static final String TAG = "ConnectBot.tn5250";
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54 private static final int DEFAULT_PORT = 23;
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
55
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
56 private Screen5250 screen52;
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
57 private tnvt handler = null;
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
58 private Socket socket;
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
59 private boolean connected = false;
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60
12
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
61 static final Pattern hostmask;
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
62 static {
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
63 hostmask = Pattern.compile("^([0-9a-z.-]+)(:(\\d+))?$", Pattern.CASE_INSENSITIVE);
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
64 }
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
65
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
66
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 public TN5250() {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
68 super();
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
69 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
70
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
71
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
72 /**
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
73 * @return protocol part of the URI
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
74 */
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
75 public static String getProtocolName() {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
76 return PROTOCOL;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
77 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
78
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
79
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
80 /**
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
81 * Encode the current transport into a URI that can be passed via intent calls.
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
82 * @return URI to host
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
83 */
12
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
84 public Uri getUri(String input) {
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
85 Matcher matcher = hostmask.matcher(input);
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
86
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
87 if (!matcher.matches())
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
88 return null;
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
89
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
90 StringBuilder sb = new StringBuilder();
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
91 sb.append(PROTOCOL)
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
92 .append("://")
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
93 .append(matcher.group(1));
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
94 String portString = matcher.group(3);
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
95 int port = DEFAULT_PORT;
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
96
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
97 if (portString != null) {
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
98 try {
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
99 port = Integer.parseInt(portString);
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
100
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
101 if (port < 1 || port > 65535) {
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
102 port = DEFAULT_PORT;
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
103 }
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
104 }
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
105 catch (NumberFormatException nfe) {
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
106 // Keep the default port
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
107 }
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
108 }
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
109
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
110 if (port != DEFAULT_PORT) {
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
111 sb.append(':');
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
112 sb.append(port);
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
113 }
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
114
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
115 sb.append("/#")
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
116 .append(Uri.encode(input));
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
117 Uri uri = Uri.parse(sb.toString());
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
118 return uri;
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
119 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
120
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
121
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
122 /**
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
123 * Causes transport to connect to the target host. After connecting but before a
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
124 * session is started, must call back to {@link TerminalBridge#onConnected()}.
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
125 * After that call a session may be opened.
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
126 */
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
127 @Override
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
128 public void connect() {
30
d738f6b876fe start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 29
diff changeset
129 screen52 = new Screen5250();
29
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
130 handler = new tnvt(screen52, true, false, bridge, manager);
37
0395ca628303 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 32
diff changeset
131 handler.setSSLType("TLS");
32
b086dd794dba start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 31
diff changeset
132 screen52.setVT(handler);
b086dd794dba start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 31
diff changeset
133 screen52.setBuffer(buffer);
23
cfcb8d9859a8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 13
diff changeset
134 connected = handler.connect(host.getHostname(), host.getPort());
29
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
135 if (connected) bridge.onConnected();
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
136 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
137
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
138
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
139 /**
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
140 * Checks if read() will block. If there are no bytes remaining in
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
141 * the underlying transport, return true.
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
142 */
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
143 @Override
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
144 public boolean willBlock() {
29
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
145 // we don't use a relay thread between the transport and the vt320 buffer
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
146 return true;
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
147 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
148
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
149
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
150 /**
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
151 * Reads from the transport. Transport must support reading into a byte array
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
152 * <code>buffer</code> at the start of <code>offset</code> and a maximum of
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
153 * <code>length</code> bytes. If the remote host disconnects, throw an
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
154 * {@link IOException}.
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
155 * @param buffer byte buffer to store read bytes into
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
156 * @param offset where to start writing in the buffer
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
157 * @param length maximum number of bytes to read
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
158 * @return number of bytes read
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
159 * @throws IOException when remote host disconnects
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
160 */
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
161 public int read(byte[] buffer, int offset, int length) throws IOException {
29
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
162 // we don't use a relay thread between the transport and the vt320 buffer
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
163 return 0;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
164 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
165
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
166
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
167 /**
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
168 * Writes to the transport. If the host is not yet connected, simply return without
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
169 * doing anything. An {@link IOException} should be thrown if there is an error after
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
170 * connection.
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
171 * @param buffer bytes to write to transport
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
172 * @throws IOException when there is a problem writing after connection
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
173 */
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
174 public void write(byte[] buffer) throws IOException {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
175 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
176
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
177
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
178 /**
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
179 * Writes to the transport. See {@link #write(byte[])} for behavior details.
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
180 * @param c character to write to the transport
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
181 * @throws IOException when there is a problem writing after connection
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
182 */
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
183 public void write(int c) throws IOException {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
184 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
185
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
186
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
187 /**
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
188 * Flushes the write commands to the transport.
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
189 * @throws IOException when there is a problem writing after connection
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
190 */
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
191 public void flush() throws IOException {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
192 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
193
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
194
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
195 /**
32
b086dd794dba start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 31
diff changeset
196 * Closes the connection to the terminal.
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
197 */
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
198 public void close() {
13
b39bcf616a6f adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
199 handler.disconnect();
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
200 connected = false;
32
b086dd794dba start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 31
diff changeset
201 bridge.dispatchDisconnect(false);
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
202 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
203
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
204
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
205 /**
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
206 * Tells the transport what dimensions the display is currently
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
207 * @param columns columns of text
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
208 * @param rows rows of text
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
209 * @param width width in pixels
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
210 * @param height height in pixels
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
211 */
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
212 @Override
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
213 public void setDimensions(int columns, int rows, int width, int height) {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
214 // do nothing
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
215 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
216
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
217
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
218 @Override
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
219 public int getDefaultPort() {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
220 return DEFAULT_PORT;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
221 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
222
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
223
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
224 @Override
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
225 public boolean isConnected() {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
226 return connected;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
227 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
228
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
229
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
230 @Override
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
231 public boolean isSessionOpen() {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
232 return connected;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
233 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
234
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
235
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
236 @Override
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
237 public boolean isAuthenticated() {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
238 return connected;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
239 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
240
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
241
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
242 @Override
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
243 public String getDefaultNickname(String username, String hostname, int port) {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
244 if (port == DEFAULT_PORT) {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
245 return String.format("%s", hostname);
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
246 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
247 else {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
248 return String.format("%s:%d", hostname, port);
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
249 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
250 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
251
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 30
diff changeset
252
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
253 @Override
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
254 public void getSelectionArgs(Uri uri, Map<String, String> selection) {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
255 selection.put(HostDatabase.FIELD_HOST_PROTOCOL, PROTOCOL);
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
256 selection.put(HostDatabase.FIELD_HOST_NICKNAME, uri.getFragment());
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
257 selection.put(HostDatabase.FIELD_HOST_HOSTNAME, uri.getHost());
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
258 int port = uri.getPort();
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
259
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
260 if (port < 0)
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
261 port = DEFAULT_PORT;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
262
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
263 selection.put(HostDatabase.FIELD_HOST_PORT, Integer.toString(port));
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
264 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
265
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
266
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
267 @Override
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
268 public HostBean createHost(Uri uri) {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
269 HostBean host = new HostBean();
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
270 host.setProtocol(PROTOCOL);
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
271 host.setHostname(uri.getHost());
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
272 int port = uri.getPort();
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
273
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
274 if (port < 0)
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
275 port = DEFAULT_PORT;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
276
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
277 host.setPort(port);
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
278 String nickname = uri.getFragment();
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
279
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
280 if (nickname == null || nickname.length() == 0) {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
281 host.setNickname(getDefaultNickname(host.getUsername(),
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
282 host.getHostname(), host.getPort()));
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
283 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
284 else {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
285 host.setNickname(uri.getFragment());
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
286 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
287
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
288 return host;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
289 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
290
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
291
12
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 11
diff changeset
292 public String getFormatHint(Context context) {
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
293 return String.format("%s:%s",
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
294 context.getString(R.string.format_hostname),
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
295 context.getString(R.string.format_port));
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
296 }
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
297
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
298
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
299 @Override
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
300 public boolean usesNetwork() {
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
301 return true;
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
302 }
29
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
303
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
304
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
305 @Override
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
306 public boolean needsRelay() {
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
307 // we don't use a relay thread between the transport and the vt320 buffer
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
308 return false;
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
309 }
017eeed8332c start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 23
diff changeset
310
11
f3b3bbd227b8 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
311 }