Mercurial > 510Connectbot
annotate src/com/five_ten_sg/connectbot/bean/HostBean.java @ 193:8f0cdfc63378
read deployment.connections on startup for global preferences also
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 02 Jul 2014 18:08:23 -0700 |
parents | cf677a6f586d |
children | bd803721f94a |
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; |
188
cf677a6f586d
use floating point font size, change size by scaling factor rather than linear addition
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
48 private float 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 library = null; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
60 private String initialMenu = null; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
61 private String program = null; |
0 | 62 |
63 public HostBean() { | |
64 } | |
65 | |
66 @Override | |
67 public String getBeanName() { | |
68 return BEAN_NAME; | |
69 } | |
70 | |
71 public HostBean(String nickname, String protocol, String username, String hostname, int port) { | |
72 this.nickname = nickname; | |
73 this.protocol = protocol; | |
74 this.username = username; | |
75 this.hostname = hostname; | |
76 this.port = port; | |
77 } | |
78 | |
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
|
79 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
|
80 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
|
81 } |
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 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
|
84 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
|
85 } |
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 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
|
88 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
|
89 } |
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 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
|
92 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
|
93 } |
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 |
0 | 95 public void setId(long id) { |
96 this.id = id; | |
97 } | |
98 public long getId() { | |
99 return id; | |
100 } | |
101 public void setNickname(String nickname) { | |
102 this.nickname = nickname; | |
103 } | |
104 public String getNickname() { | |
105 return nickname; | |
106 } | |
107 public void setUsername(String username) { | |
108 this.username = username; | |
109 } | |
110 public String getUsername() { | |
111 return username; | |
112 } | |
113 public void setHostname(String hostname) { | |
114 this.hostname = hostname; | |
115 } | |
116 public String getHostname() { | |
117 return hostname; | |
118 } | |
119 public void setPort(int port) { | |
120 this.port = port; | |
121 } | |
122 public int getPort() { | |
123 return port; | |
124 } | |
125 | |
126 public void setProtocol(String protocol) { | |
127 this.protocol = protocol; | |
128 } | |
129 | |
130 public String getProtocol() { | |
131 return protocol; | |
132 } | |
133 | |
134 public void setHostKeyAlgo(String hostKeyAlgo) { | |
135 this.hostKeyAlgo = hostKeyAlgo; | |
136 } | |
137 public String getHostKeyAlgo() { | |
138 return hostKeyAlgo; | |
139 } | |
140 public void setHostKey(byte[] hostKey) { | |
141 if (hostKey == null) | |
142 this.hostKey = null; | |
143 else | |
144 this.hostKey = hostKey.clone(); | |
145 } | |
146 public byte[] getHostKey() { | |
147 if (hostKey == null) | |
148 return null; | |
149 else | |
150 return hostKey.clone(); | |
151 } | |
152 public void setLastConnect(long lastConnect) { | |
153 this.lastConnect = lastConnect; | |
154 } | |
155 public long getLastConnect() { | |
156 return lastConnect; | |
157 } | |
158 public void setColor(String color) { | |
159 this.color = color; | |
160 } | |
161 public String getColor() { | |
162 return color; | |
163 } | |
164 public void setUseKeys(boolean useKeys) { | |
165 this.useKeys = useKeys; | |
166 } | |
167 public boolean getUseKeys() { | |
168 return useKeys; | |
169 } | |
170 public void setUseAuthAgent(String useAuthAgent) { | |
171 this.useAuthAgent = useAuthAgent; | |
172 } | |
173 public String getUseAuthAgent() { | |
174 return useAuthAgent; | |
175 } | |
176 public void setPostLogin(String postLogin) { | |
177 this.postLogin = postLogin; | |
178 } | |
179 public String getPostLogin() { | |
180 return postLogin; | |
181 } | |
182 public void setPubkeyId(long pubkeyId) { | |
183 this.pubkeyId = pubkeyId; | |
184 } | |
185 public long getPubkeyId() { | |
186 return pubkeyId; | |
187 } | |
188 public void setWantSession(boolean wantSession) { | |
189 this.wantSession = wantSession; | |
190 } | |
191 public boolean getWantSession() { | |
192 return wantSession; | |
193 } | |
194 public void setDelKey(String delKey) { | |
195 this.delKey = delKey; | |
196 } | |
197 public String getDelKey() { | |
198 return delKey; | |
199 } | |
188
cf677a6f586d
use floating point font size, change size by scaling factor rather than linear addition
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
200 public void setFontSize(float fontSize) { |
0 | 201 this.fontSize = fontSize; |
202 } | |
188
cf677a6f586d
use floating point font size, change size by scaling factor rather than linear addition
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
203 public float getFontSize() { |
0 | 204 return fontSize; |
205 } | |
206 public void setCompression(boolean compression) { | |
207 this.compression = compression; | |
208 } | |
209 public boolean getCompression() { | |
210 return compression; | |
211 } | |
212 public void setHttpproxy(String httpproxy) { | |
213 this.httpproxy = httpproxy; | |
214 } | |
215 public String getHttpproxy() { | |
216 return httpproxy; | |
217 } | |
218 | |
219 public void setEncoding(String encoding) { | |
220 this.encoding = encoding; | |
221 } | |
222 | |
223 public String getEncoding() { | |
224 return this.encoding; | |
225 } | |
226 | |
227 public void setStayConnected(boolean stayConnected) { | |
228 this.stayConnected = stayConnected; | |
229 } | |
230 | |
231 public boolean getStayConnected() { | |
232 return stayConnected; | |
233 } | |
234 | |
235 public String getDescription() { | |
236 String description = String.format("%s@%s", username, hostname); | |
237 | |
238 if (port != 22) | |
239 description += String.format(":%d", port); | |
240 | |
241 return description; | |
242 } | |
243 | |
244 public boolean getWantX11Forward() { | |
245 return this.wantX11Forward; | |
246 } | |
247 | |
248 public void setWantX11Forward(boolean wantX11Forward) { | |
249 this.wantX11Forward = wantX11Forward; | |
250 } | |
251 | |
252 public String getX11Host() { | |
253 return this.x11Host; | |
254 } | |
255 | |
256 public void setX11Host(String x11Host) { | |
257 this.x11Host = x11Host; | |
258 } | |
259 | |
260 public int getX11Port() { | |
261 return this.x11Port; | |
262 } | |
263 | |
264 public void setX11Port(int x11Port) { | |
265 this.x11Port = x11Port; | |
266 } | |
267 | |
268 public String getMonitor() { | |
269 return this.monitor; | |
270 } | |
271 | |
272 public void setMonitor(String monitor) { | |
273 this.monitor = monitor; | |
274 } | |
275 | |
61 | 276 public String getHostEmulation() { |
277 return this.hostemulation; | |
278 } | |
279 | |
280 public void setHostEmulation(String hostemulation) { | |
281 this.hostemulation = hostemulation; | |
282 } | |
283 | |
284 public String getEncryption5250() { | |
285 return this.encryption5250; | |
286 } | |
287 | |
288 public void setEncryption5250(String encryption5250) { | |
289 this.encryption5250 = encryption5250; | |
290 } | |
291 | |
119
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
292 public String getLibrary() { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
293 return this.library; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
294 } |
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 public void setLibrary(String library) { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
297 this.library = library; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
298 } |
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 public String getInitialMenu() { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
301 return this.initialMenu; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
302 } |
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 public void setInitialMenu(String initialMenu) { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
305 this.initialMenu = initialMenu; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
306 } |
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 public String getProgram() { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
309 return this.program; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
310 } |
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 public void setProgram(String program) { |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
313 this.program = program; |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
314 } |
6969d6cebcd7
add more 5250 config items
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
315 |
0 | 316 @Override |
317 public ContentValues getValues() { | |
318 ContentValues values = new ContentValues(); | |
319 values.put(HostDatabase.FIELD_HOST_NICKNAME, nickname); | |
320 values.put(HostDatabase.FIELD_HOST_PROTOCOL, protocol); | |
321 values.put(HostDatabase.FIELD_HOST_USERNAME, username); | |
322 values.put(HostDatabase.FIELD_HOST_HOSTNAME, hostname); | |
323 values.put(HostDatabase.FIELD_HOST_PORT, port); | |
324 values.put(HostDatabase.FIELD_HOST_HOSTKEYALGO, hostKeyAlgo); | |
325 values.put(HostDatabase.FIELD_HOST_HOSTKEY, hostKey); | |
326 values.put(HostDatabase.FIELD_HOST_LASTCONNECT, lastConnect); | |
327 values.put(HostDatabase.FIELD_HOST_COLOR, color); | |
328 values.put(HostDatabase.FIELD_HOST_USEKEYS, Boolean.toString(useKeys)); | |
329 values.put(HostDatabase.FIELD_HOST_USEAUTHAGENT, useAuthAgent); | |
330 values.put(HostDatabase.FIELD_HOST_POSTLOGIN, postLogin); | |
331 values.put(HostDatabase.FIELD_HOST_PUBKEYID, pubkeyId); | |
332 values.put(HostDatabase.FIELD_HOST_WANTSESSION, Boolean.toString(wantSession)); | |
333 values.put(HostDatabase.FIELD_HOST_DELKEY, delKey); | |
334 values.put(HostDatabase.FIELD_HOST_FONTSIZE, fontSize); | |
335 values.put(HostDatabase.FIELD_HOST_COMPRESSION, Boolean.toString(compression)); | |
336 values.put(HostDatabase.FIELD_HOST_HTTPPROXY, httpproxy); | |
337 values.put(HostDatabase.FIELD_HOST_ENCODING, encoding); | |
338 values.put(HostDatabase.FIELD_HOST_STAYCONNECTED, stayConnected); | |
339 values.put(HostDatabase.FIELD_HOST_WANTX11FORWARD, wantX11Forward); | |
340 values.put(HostDatabase.FIELD_HOST_X11HOST, x11Host); | |
341 values.put(HostDatabase.FIELD_HOST_X11PORT, x11Port); | |
342 values.put(HostDatabase.FIELD_HOST_MONITOR, monitor); | |
63
07c7055cc124
add 5250 config entries
Carl Byington <carl@five-ten-sg.com>
parents:
61
diff
changeset
|
343 values.put(HostDatabase.FIELD_HOST_EMULATION, hostemulation); |
61 | 344 values.put(HostDatabase.FIELD_HOST_ENCRYPTION5250, encryption5250); |
123
446dbcf606eb
add more 5250 config items; ignore drawing outside the screen
Carl Byington <carl@five-ten-sg.com>
parents:
122
diff
changeset
|
345 values.put(HostDatabase.FIELD_HOST_LIBRARY5250, library); |
446dbcf606eb
add more 5250 config items; ignore drawing outside the screen
Carl Byington <carl@five-ten-sg.com>
parents:
122
diff
changeset
|
346 values.put(HostDatabase.FIELD_HOST_MENU5250, initialMenu); |
446dbcf606eb
add more 5250 config items; ignore drawing outside the screen
Carl Byington <carl@five-ten-sg.com>
parents:
122
diff
changeset
|
347 values.put(HostDatabase.FIELD_HOST_PROGRAM5250, program); |
0 | 348 return values; |
349 } | |
350 | |
351 @Override | |
352 public boolean equals(Object o) { | |
353 if (o == null || !(o instanceof HostBean)) | |
354 return false; | |
355 | |
356 HostBean host = (HostBean)o; | |
357 | |
358 if (id != -1 && host.getId() != -1) | |
359 return host.getId() == id; | |
360 | |
361 if (nickname == null) { | |
362 if (host.getNickname() != null) | |
363 return false; | |
364 } | |
365 else if (!nickname.equals(host.getNickname())) | |
366 return false; | |
367 | |
368 if (protocol == null) { | |
369 if (host.getProtocol() != null) | |
370 return false; | |
371 } | |
372 else if (!protocol.equals(host.getProtocol())) | |
373 return false; | |
374 | |
375 if (username == null) { | |
376 if (host.getUsername() != null) | |
377 return false; | |
378 } | |
379 else if (!username.equals(host.getUsername())) | |
380 return false; | |
381 | |
382 if (hostname == null) { | |
383 if (host.getHostname() != null) | |
384 return false; | |
385 } | |
386 else if (!hostname.equals(host.getHostname())) | |
387 return false; | |
388 | |
389 if (port != host.getPort()) | |
390 return false; | |
391 | |
392 return true; | |
393 } | |
394 | |
395 @Override | |
396 public int hashCode() { | |
397 int hash = 7; | |
398 | |
399 if (id != -1) | |
400 return (int)id; | |
401 | |
402 hash = 31 * hash + (null == nickname ? 0 : nickname.hashCode()); | |
403 hash = 31 * hash + (null == protocol ? 0 : protocol.hashCode()); | |
404 hash = 31 * hash + (null == username ? 0 : username.hashCode()); | |
405 hash = 31 * hash + (null == hostname ? 0 : hostname.hashCode()); | |
406 hash = 31 * hash + port; | |
407 return hash; | |
408 } | |
409 | |
410 /** | |
411 * @return URI identifying this HostBean | |
412 */ | |
413 public Uri getUri() { | |
414 StringBuilder sb = new StringBuilder(); | |
415 sb.append(protocol) | |
416 .append("://"); | |
417 | |
418 if (username != null) | |
419 sb.append(Uri.encode(username)) | |
420 .append('@'); | |
421 | |
422 sb.append(Uri.encode(hostname)) | |
423 .append(':') | |
424 .append(port) | |
425 .append("/#") | |
426 .append(nickname); | |
427 return Uri.parse(sb.toString()); | |
428 } | |
429 | |
430 } |