Mercurial > 510Connectbot
annotate src/com/five_ten_sg/connectbot/bean/HostBean.java @ 119:6969d6cebcd7
add more 5250 config items
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 18 Jun 2014 18:55:56 -0700 |
parents | 1c22e6a7efff |
children | 52b1d0ee27b1 |
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.bean; | |
19 | |
20 import com.five_ten_sg.connectbot.util.HostDatabase; | |
21 import android.content.ContentValues; | |
22 import android.net.Uri; | |
23 | |
24 /** | |
25 * @author Kenny Root | |
26 * | |
27 */ | |
28 public class HostBean extends AbstractBean { | |
29 public static final String BEAN_NAME = "host"; | |
30 | |
31 /* Database fields */ | |
61 | 32 private long id = -1; |
33 private String nickname = null; | |
34 private String username = null; | |
35 private String hostname = null; | |
36 private int port = 22; | |
37 private String protocol = "ssh"; | |
38 private String hostKeyAlgo = null; | |
39 private byte[] hostKey = null; | |
40 private long lastConnect = -1; | |
41 private String color; | |
0 | 42 private boolean useKeys = true; |
61 | 43 private String useAuthAgent = HostDatabase.AUTHAGENT_NO; |
44 private String postLogin = null; | |
45 private long pubkeyId = -1; | |
0 | 46 private boolean wantSession = true; |
61 | 47 private String delKey = HostDatabase.DELKEY_DEL; |
48 private int fontSize = -1; | |
0 | 49 private boolean compression = false; |
61 | 50 private String httpproxy = null; |
51 private String encoding = HostDatabase.ENCODING_DEFAULT; | |
0 | 52 private boolean stayConnected = false; |
53 private boolean wantX11Forward = false; | |
61 | 54 private String x11Host = "localhost"; |
55 private int x11Port = 6000; | |
56 private String monitor = null; | |
57 private String hostemulation = null; | |
58 private String encryption5250 = null; | |
119
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
59 private String password = null; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
60 private String library = null; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
61 private String initialMenu = null; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
62 private String program = null; |
0 | 63 |
64 public HostBean() { | |
65 } | |
66 | |
67 @Override | |
68 public String getBeanName() { | |
69 return BEAN_NAME; | |
70 } | |
71 | |
72 public HostBean(String nickname, String protocol, String username, String hostname, int port) { | |
73 this.nickname = nickname; | |
74 this.protocol = protocol; | |
75 this.username = username; | |
76 this.hostname = hostname; | |
77 this.port = port; | |
78 } | |
79 | |
83
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
80 public boolean isSSH() { |
88
1c22e6a7efff
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
83
diff
changeset
|
81 return protocol.equals("ssh"); |
83
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
82 } |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
83 |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
84 public boolean is5250() { |
88
1c22e6a7efff
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
83
diff
changeset
|
85 return protocol.equals("tn5250"); |
83
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
86 } |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
87 |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
88 public boolean isTelnet() { |
88
1c22e6a7efff
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
83
diff
changeset
|
89 return protocol.equals("telnet"); |
83
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
90 } |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
91 |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
92 public boolean isAsync() { |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
93 return isSSH() || isTelnet(); |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
94 } |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
63
diff
changeset
|
95 |
0 | 96 public void setId(long id) { |
97 this.id = id; | |
98 } | |
99 public long getId() { | |
100 return id; | |
101 } | |
102 public void setNickname(String nickname) { | |
103 this.nickname = nickname; | |
104 } | |
105 public String getNickname() { | |
106 return nickname; | |
107 } | |
108 public void setUsername(String username) { | |
109 this.username = username; | |
110 } | |
111 public String getUsername() { | |
112 return username; | |
113 } | |
114 public void setHostname(String hostname) { | |
115 this.hostname = hostname; | |
116 } | |
117 public String getHostname() { | |
118 return hostname; | |
119 } | |
120 public void setPort(int port) { | |
121 this.port = port; | |
122 } | |
123 public int getPort() { | |
124 return port; | |
125 } | |
126 | |
127 public void setProtocol(String protocol) { | |
128 this.protocol = protocol; | |
129 } | |
130 | |
131 public String getProtocol() { | |
132 return protocol; | |
133 } | |
134 | |
135 public void setHostKeyAlgo(String hostKeyAlgo) { | |
136 this.hostKeyAlgo = hostKeyAlgo; | |
137 } | |
138 public String getHostKeyAlgo() { | |
139 return hostKeyAlgo; | |
140 } | |
141 public void setHostKey(byte[] hostKey) { | |
142 if (hostKey == null) | |
143 this.hostKey = null; | |
144 else | |
145 this.hostKey = hostKey.clone(); | |
146 } | |
147 public byte[] getHostKey() { | |
148 if (hostKey == null) | |
149 return null; | |
150 else | |
151 return hostKey.clone(); | |
152 } | |
153 public void setLastConnect(long lastConnect) { | |
154 this.lastConnect = lastConnect; | |
155 } | |
156 public long getLastConnect() { | |
157 return lastConnect; | |
158 } | |
159 public void setColor(String color) { | |
160 this.color = color; | |
161 } | |
162 public String getColor() { | |
163 return color; | |
164 } | |
165 public void setUseKeys(boolean useKeys) { | |
166 this.useKeys = useKeys; | |
167 } | |
168 public boolean getUseKeys() { | |
169 return useKeys; | |
170 } | |
171 public void setUseAuthAgent(String useAuthAgent) { | |
172 this.useAuthAgent = useAuthAgent; | |
173 } | |
174 public String getUseAuthAgent() { | |
175 return useAuthAgent; | |
176 } | |
177 public void setPostLogin(String postLogin) { | |
178 this.postLogin = postLogin; | |
179 } | |
180 public String getPostLogin() { | |
181 return postLogin; | |
182 } | |
183 public void setPubkeyId(long pubkeyId) { | |
184 this.pubkeyId = pubkeyId; | |
185 } | |
186 public long getPubkeyId() { | |
187 return pubkeyId; | |
188 } | |
189 public void setWantSession(boolean wantSession) { | |
190 this.wantSession = wantSession; | |
191 } | |
192 public boolean getWantSession() { | |
193 return wantSession; | |
194 } | |
195 public void setDelKey(String delKey) { | |
196 this.delKey = delKey; | |
197 } | |
198 public String getDelKey() { | |
199 return delKey; | |
200 } | |
201 public void setFontSize(int fontSize) { | |
202 this.fontSize = fontSize; | |
203 } | |
204 public int getFontSize() { | |
205 return fontSize; | |
206 } | |
207 public void setCompression(boolean compression) { | |
208 this.compression = compression; | |
209 } | |
210 public boolean getCompression() { | |
211 return compression; | |
212 } | |
213 public void setHttpproxy(String httpproxy) { | |
214 this.httpproxy = httpproxy; | |
215 } | |
216 public String getHttpproxy() { | |
217 return httpproxy; | |
218 } | |
219 | |
220 public void setEncoding(String encoding) { | |
221 this.encoding = encoding; | |
222 } | |
223 | |
224 public String getEncoding() { | |
225 return this.encoding; | |
226 } | |
227 | |
228 public void setStayConnected(boolean stayConnected) { | |
229 this.stayConnected = stayConnected; | |
230 } | |
231 | |
232 public boolean getStayConnected() { | |
233 return stayConnected; | |
234 } | |
235 | |
236 public String getDescription() { | |
237 String description = String.format("%s@%s", username, hostname); | |
238 | |
239 if (port != 22) | |
240 description += String.format(":%d", port); | |
241 | |
242 return description; | |
243 } | |
244 | |
245 public boolean getWantX11Forward() { | |
246 return this.wantX11Forward; | |
247 } | |
248 | |
249 public void setWantX11Forward(boolean wantX11Forward) { | |
250 this.wantX11Forward = wantX11Forward; | |
251 } | |
252 | |
253 public String getX11Host() { | |
254 return this.x11Host; | |
255 } | |
256 | |
257 public void setX11Host(String x11Host) { | |
258 this.x11Host = x11Host; | |
259 } | |
260 | |
261 public int getX11Port() { | |
262 return this.x11Port; | |
263 } | |
264 | |
265 public void setX11Port(int x11Port) { | |
266 this.x11Port = x11Port; | |
267 } | |
268 | |
269 public String getMonitor() { | |
270 return this.monitor; | |
271 } | |
272 | |
273 public void setMonitor(String monitor) { | |
274 this.monitor = monitor; | |
275 } | |
276 | |
61 | 277 public String getHostEmulation() { |
278 return this.hostemulation; | |
279 } | |
280 | |
281 public void setHostEmulation(String hostemulation) { | |
282 this.hostemulation = hostemulation; | |
283 } | |
284 | |
285 public String getEncryption5250() { | |
286 return this.encryption5250; | |
287 } | |
288 | |
289 public void setEncryption5250(String encryption5250) { | |
290 this.encryption5250 = encryption5250; | |
291 } | |
292 | |
119
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
293 public String getPassword() { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
294 return this.password; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
295 } |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
296 |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
297 public void setPassword(String password) { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
298 this.password = password; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
299 } |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
300 |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
301 public String getLibrary() { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
302 return this.library; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
303 } |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
304 |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
305 public void setLibrary(String library) { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
306 this.library = library; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
307 } |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
308 |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
309 public String getInitialMenu() { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
310 return this.initialMenu; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
311 } |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
312 |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
313 public void setInitialMenu(String initialMenu) { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
314 this.initialMenu = initialMenu; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
315 } |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
316 |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
317 public String getProgram() { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
318 return this.program; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
319 } |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
320 |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
321 public void setProgram(String program) { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
322 this.program = program; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
323 } |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
324 |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
325 public String getxxx() { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
326 return this.xxx; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
327 } |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
328 |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
329 public void setxxx(String xxx) { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
330 this.xxx = xxx; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
331 } |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
332 |
0 | 333 @Override |
334 public ContentValues getValues() { | |
335 ContentValues values = new ContentValues(); | |
336 values.put(HostDatabase.FIELD_HOST_NICKNAME, nickname); | |
337 values.put(HostDatabase.FIELD_HOST_PROTOCOL, protocol); | |
338 values.put(HostDatabase.FIELD_HOST_USERNAME, username); | |
339 values.put(HostDatabase.FIELD_HOST_HOSTNAME, hostname); | |
340 values.put(HostDatabase.FIELD_HOST_PORT, port); | |
341 values.put(HostDatabase.FIELD_HOST_HOSTKEYALGO, hostKeyAlgo); | |
342 values.put(HostDatabase.FIELD_HOST_HOSTKEY, hostKey); | |
343 values.put(HostDatabase.FIELD_HOST_LASTCONNECT, lastConnect); | |
344 values.put(HostDatabase.FIELD_HOST_COLOR, color); | |
345 values.put(HostDatabase.FIELD_HOST_USEKEYS, Boolean.toString(useKeys)); | |
346 values.put(HostDatabase.FIELD_HOST_USEAUTHAGENT, useAuthAgent); | |
347 values.put(HostDatabase.FIELD_HOST_POSTLOGIN, postLogin); | |
348 values.put(HostDatabase.FIELD_HOST_PUBKEYID, pubkeyId); | |
349 values.put(HostDatabase.FIELD_HOST_WANTSESSION, Boolean.toString(wantSession)); | |
350 values.put(HostDatabase.FIELD_HOST_DELKEY, delKey); | |
351 values.put(HostDatabase.FIELD_HOST_FONTSIZE, fontSize); | |
352 values.put(HostDatabase.FIELD_HOST_COMPRESSION, Boolean.toString(compression)); | |
353 values.put(HostDatabase.FIELD_HOST_HTTPPROXY, httpproxy); | |
354 values.put(HostDatabase.FIELD_HOST_ENCODING, encoding); | |
355 values.put(HostDatabase.FIELD_HOST_STAYCONNECTED, stayConnected); | |
356 values.put(HostDatabase.FIELD_HOST_WANTX11FORWARD, wantX11Forward); | |
357 values.put(HostDatabase.FIELD_HOST_X11HOST, x11Host); | |
358 values.put(HostDatabase.FIELD_HOST_X11PORT, x11Port); | |
359 values.put(HostDatabase.FIELD_HOST_MONITOR, monitor); | |
63
07c7055cc124
add 5250 config entries
Carl Byington <carl@five-ten-sg.com>
parents:
61
diff
changeset
|
360 values.put(HostDatabase.FIELD_HOST_EMULATION, hostemulation); |
61 | 361 values.put(HostDatabase.FIELD_HOST_ENCRYPTION5250, encryption5250); |
0 | 362 return values; |
363 } | |
364 | |
365 @Override | |
366 public boolean equals(Object o) { | |
367 if (o == null || !(o instanceof HostBean)) | |
368 return false; | |
369 | |
370 HostBean host = (HostBean)o; | |
371 | |
372 if (id != -1 && host.getId() != -1) | |
373 return host.getId() == id; | |
374 | |
375 if (nickname == null) { | |
376 if (host.getNickname() != null) | |
377 return false; | |
378 } | |
379 else if (!nickname.equals(host.getNickname())) | |
380 return false; | |
381 | |
382 if (protocol == null) { | |
383 if (host.getProtocol() != null) | |
384 return false; | |
385 } | |
386 else if (!protocol.equals(host.getProtocol())) | |
387 return false; | |
388 | |
389 if (username == null) { | |
390 if (host.getUsername() != null) | |
391 return false; | |
392 } | |
393 else if (!username.equals(host.getUsername())) | |
394 return false; | |
395 | |
396 if (hostname == null) { | |
397 if (host.getHostname() != null) | |
398 return false; | |
399 } | |
400 else if (!hostname.equals(host.getHostname())) | |
401 return false; | |
402 | |
403 if (port != host.getPort()) | |
404 return false; | |
405 | |
406 return true; | |
407 } | |
408 | |
409 @Override | |
410 public int hashCode() { | |
411 int hash = 7; | |
412 | |
413 if (id != -1) | |
414 return (int)id; | |
415 | |
416 hash = 31 * hash + (null == nickname ? 0 : nickname.hashCode()); | |
417 hash = 31 * hash + (null == protocol ? 0 : protocol.hashCode()); | |
418 hash = 31 * hash + (null == username ? 0 : username.hashCode()); | |
419 hash = 31 * hash + (null == hostname ? 0 : hostname.hashCode()); | |
420 hash = 31 * hash + port; | |
421 return hash; | |
422 } | |
423 | |
424 /** | |
425 * @return URI identifying this HostBean | |
426 */ | |
427 public Uri getUri() { | |
428 StringBuilder sb = new StringBuilder(); | |
429 sb.append(protocol) | |
430 .append("://"); | |
431 | |
432 if (username != null) | |
433 sb.append(Uri.encode(username)) | |
434 .append('@'); | |
435 | |
436 sb.append(Uri.encode(hostname)) | |
437 .append(':') | |
438 .append(port) | |
439 .append("/#") | |
440 .append(nickname); | |
441 return Uri.parse(sb.toString()); | |
442 } | |
443 | |
444 } |