Mercurial > 510Connectbot
annotate src/com/five_ten_sg/connectbot/transport/Telnet.java @ 52:0e3fc85d0586 tn5250
start tn5250 integration
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 11 Jun 2014 12:18:18 -0700 |
parents | 139394237973 |
children | 77ac18bc1b2f |
rev | line source |
---|---|
0 | 1 /* |
2 * ConnectBot: simple, powerful, open-source SSH client for Android | |
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey | |
4 * | |
5 * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 * you may not use this file except in compliance with the License. | |
7 * You may obtain a copy of the License at | |
8 * | |
9 * http://www.apache.org/licenses/LICENSE-2.0 | |
10 * | |
11 * Unless required by applicable law or agreed to in writing, software | |
12 * distributed under the License is distributed on an "AS IS" BASIS, | |
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 * See the License for the specific language governing permissions and | |
15 * limitations under the License. | |
16 */ | |
17 | |
18 package com.five_ten_sg.connectbot.transport; | |
19 | |
20 import java.io.IOException; | |
21 import java.io.InputStream; | |
22 import java.io.OutputStream; | |
23 import java.net.Socket; | |
24 import java.net.SocketException; | |
25 import java.net.UnknownHostException; | |
26 import java.nio.charset.Charset; | |
27 import java.util.Map; | |
28 import java.util.regex.Matcher; | |
29 import java.util.regex.Pattern; | |
30 | |
31 import com.five_ten_sg.connectbot.R; | |
32 import com.five_ten_sg.connectbot.bean.HostBean; | |
33 import com.five_ten_sg.connectbot.service.TerminalBridge; | |
34 import com.five_ten_sg.connectbot.service.TerminalManager; | |
35 import com.five_ten_sg.connectbot.util.HostDatabase; | |
11 | 36 |
0 | 37 import android.content.Context; |
38 import android.net.Uri; | |
39 import android.util.Log; | |
13 | 40 |
0 | 41 import de.mud.telnet.TelnetProtocolHandler; |
42 | |
13 | 43 |
0 | 44 /** |
45 * Telnet transport implementation.<br/> | |
46 * Original idea from the JTA telnet package (de.mud.telnet) | |
47 * | |
48 * @author Kenny Root | |
49 * | |
50 */ | |
51 public class Telnet extends AbsTransport { | |
52 private static final String TAG = "ConnectBot.Telnet"; | |
53 private static final String PROTOCOL = "telnet"; | |
54 private static final int DEFAULT_PORT = 23; | |
55 | |
56 private TelnetProtocolHandler handler; | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
57 private Socket socket; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
58 private InputStream is; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
59 private OutputStream os; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
60 private int width; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
61 private int height; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
62 private boolean connected = false; |
0 | 63 |
64 static final Pattern hostmask; | |
65 static { | |
66 hostmask = Pattern.compile("^([0-9a-z.-]+)(:(\\d+))?$", Pattern.CASE_INSENSITIVE); | |
67 } | |
68 | |
69 public Telnet() { | |
70 handler = new TelnetProtocolHandler() { | |
71 /** get the current terminal type */ | |
72 @Override | |
73 public String getTerminalType() { | |
74 return getEmulation(); | |
75 } | |
76 /** get the current window size */ | |
77 @Override | |
78 public int[] getWindowSize() { | |
79 return new int[] { width, height }; | |
80 } | |
81 /** notify about local echo */ | |
82 @Override | |
83 public void setLocalEcho(boolean echo) { | |
84 /* EMPTY */ | |
85 } | |
86 /** write data to our back end */ | |
87 @Override | |
88 public void write(byte[] b) throws IOException { | |
89 if (os != null) | |
90 os.write(b); | |
91 } | |
92 /** sent on IAC EOR (prompt terminator for remote access systems). */ | |
93 @Override | |
94 public void notifyEndOfRecord() { | |
95 } | |
96 @Override | |
97 protected String getCharsetName() { | |
98 Charset charset = bridge.getCharset(); | |
99 | |
100 if (charset != null) | |
101 return charset.name(); | |
102 else | |
103 return ""; | |
104 } | |
105 }; | |
106 } | |
107 | |
108 | |
109 public static String getProtocolName() { | |
110 return PROTOCOL; | |
111 } | |
112 | |
113 | |
12 | 114 public Uri getUri(String input) { |
0 | 115 Matcher matcher = hostmask.matcher(input); |
116 | |
117 if (!matcher.matches()) | |
118 return null; | |
119 | |
120 StringBuilder sb = new StringBuilder(); | |
121 sb.append(PROTOCOL) | |
122 .append("://") | |
123 .append(matcher.group(1)); | |
124 String portString = matcher.group(3); | |
125 int port = DEFAULT_PORT; | |
126 | |
127 if (portString != null) { | |
128 try { | |
129 port = Integer.parseInt(portString); | |
130 | |
131 if (port < 1 || port > 65535) { | |
132 port = DEFAULT_PORT; | |
133 } | |
134 } | |
135 catch (NumberFormatException nfe) { | |
136 // Keep the default port | |
137 } | |
138 } | |
139 | |
140 if (port != DEFAULT_PORT) { | |
141 sb.append(':'); | |
142 sb.append(port); | |
143 } | |
144 | |
145 sb.append("/#") | |
146 .append(Uri.encode(input)); | |
147 Uri uri = Uri.parse(sb.toString()); | |
148 return uri; | |
149 } | |
150 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
151 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
152 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
153 public void connect() { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
154 try { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
155 socket = new Socket(host.getHostname(), host.getPort()); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
156 connected = true; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
157 is = socket.getInputStream(); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
158 os = socket.getOutputStream(); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
159 bridge.onConnected(); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
160 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
161 catch (UnknownHostException e) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
162 Log.d(TAG, "IO Exception connecting to host", e); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
163 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
164 catch (IOException e) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
165 Log.d(TAG, "IO Exception connecting to host", e); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
166 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
167 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
168 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
169 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
170 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
171 public boolean willBlock() { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
172 if (is == null) return true; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
173 try { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
174 return is.available() == 0; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
175 } catch (Exception e) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
176 return true; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
177 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
178 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
179 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
180 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
181 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
182 public int read(byte[] buffer, int start, int len) throws IOException { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
183 /* process all already read bytes */ |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
184 int n = 0; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
185 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
186 do { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
187 n = handler.negotiate(buffer, start); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
188 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
189 if (n > 0) |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
190 return n; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
191 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
192 while (n == 0); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
193 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
194 while (n <= 0) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
195 do { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
196 n = handler.negotiate(buffer, start); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
197 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
198 if (n > 0) |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
199 return n; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
200 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
201 while (n == 0); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
202 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
203 n = is.read(buffer, start, len); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
204 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
205 if (n < 0) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
206 bridge.dispatchDisconnect(false); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
207 throw new IOException("Remote end closed connection."); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
208 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
209 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
210 handler.inputfeed(buffer, start, n); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
211 n = handler.negotiate(buffer, start); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
212 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
213 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
214 return n; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
215 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
216 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
217 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
218 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
219 public void write(byte[] buffer) throws IOException { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
220 try { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
221 if (os != null) |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
222 os.write(buffer); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
223 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
224 catch (SocketException e) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
225 bridge.dispatchDisconnect(false); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
226 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
227 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
228 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
229 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
230 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
231 public void write(int c) throws IOException { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
232 try { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
233 if (os != null) |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
234 os.write(c); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
235 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
236 catch (SocketException e) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
237 bridge.dispatchDisconnect(false); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
238 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
239 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
240 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
241 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
242 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
243 public void flush() throws IOException { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
244 os.flush(); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
245 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
246 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
247 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
248 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
249 public void close() { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
250 connected = false; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
251 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
252 if (socket != null) |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
253 try { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
254 socket.close(); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
255 socket = null; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
256 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
257 catch (IOException e) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
258 Log.d(TAG, "Error closing telnet socket.", e); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
259 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
260 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
261 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
262 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
263 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
264 public void setDimensions(int columns, int rows, int width, int height) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
265 try { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
266 handler.setWindowSize(columns, rows); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
267 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
268 catch (IOException e) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
269 Log.e(TAG, "Couldn't resize remote terminal", e); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
270 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
271 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
272 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
273 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
274 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
275 public int getDefaultPort() { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
276 return DEFAULT_PORT; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
277 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
278 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
279 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
280 public boolean isConnected() { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
281 return connected; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
282 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
283 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
284 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
285 public boolean isSessionOpen() { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
286 return isConnected(); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
287 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
288 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
289 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
290 public boolean isAuthenticated() { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
291 return isConnected(); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
292 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
293 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
294 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
295 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
296 public String getDefaultNickname(String username, String hostname, int port) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
297 if (port == DEFAULT_PORT) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
298 return String.format("%s", hostname); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
299 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
300 else { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
301 return String.format("%s:%d", hostname, port); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
302 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
303 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
304 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
305 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
306 @Override |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
307 public void getSelectionArgs(Uri uri, Map<String, String> selection) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
308 selection.put(HostDatabase.FIELD_HOST_PROTOCOL, PROTOCOL); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
309 selection.put(HostDatabase.FIELD_HOST_NICKNAME, uri.getFragment()); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
310 selection.put(HostDatabase.FIELD_HOST_HOSTNAME, uri.getHost()); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
311 int port = uri.getPort(); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
312 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
313 if (port < 0) |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
314 port = DEFAULT_PORT; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
315 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
316 selection.put(HostDatabase.FIELD_HOST_PORT, Integer.toString(port)); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
317 } |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
318 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
319 |
0 | 320 @Override |
321 public HostBean createHost(Uri uri) { | |
322 HostBean host = new HostBean(); | |
323 host.setProtocol(PROTOCOL); | |
324 host.setHostname(uri.getHost()); | |
325 int port = uri.getPort(); | |
326 | |
327 if (port < 0) | |
328 port = DEFAULT_PORT; | |
329 | |
330 host.setPort(port); | |
331 String nickname = uri.getFragment(); | |
332 | |
333 if (nickname == null || nickname.length() == 0) { | |
334 host.setNickname(getDefaultNickname(host.getUsername(), | |
335 host.getHostname(), host.getPort())); | |
336 } | |
337 else { | |
338 host.setNickname(uri.getFragment()); | |
339 } | |
340 | |
341 return host; | |
342 } | |
343 | |
344 | |
12 | 345 public String getFormatHint(Context context) { |
0 | 346 return String.format("%s:%s", |
347 context.getString(R.string.format_hostname), | |
348 context.getString(R.string.format_port)); | |
349 } | |
350 | |
351 @Override | |
352 public boolean usesNetwork() { | |
353 return true; | |
354 } | |
355 } |