Mercurial > 510Connectbot
annotate src/com/five_ten_sg/connectbot/bean/HostBean.java @ 63:07c7055cc124 tn5250
add 5250 config entries
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 13 Jun 2014 15:35:46 -0700 |
parents | ce8f13242339 |
children | 4ccfde0bc506 |
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; | |
0 | 59 |
60 public HostBean() { | |
61 } | |
62 | |
63 @Override | |
64 public String getBeanName() { | |
65 return BEAN_NAME; | |
66 } | |
67 | |
68 public HostBean(String nickname, String protocol, String username, String hostname, int port) { | |
69 this.nickname = nickname; | |
70 this.protocol = protocol; | |
71 this.username = username; | |
72 this.hostname = hostname; | |
73 this.port = port; | |
74 } | |
75 | |
76 public void setId(long id) { | |
77 this.id = id; | |
78 } | |
79 public long getId() { | |
80 return id; | |
81 } | |
82 public void setNickname(String nickname) { | |
83 this.nickname = nickname; | |
84 } | |
85 public String getNickname() { | |
86 return nickname; | |
87 } | |
88 public void setUsername(String username) { | |
89 this.username = username; | |
90 } | |
91 public String getUsername() { | |
92 return username; | |
93 } | |
94 public void setHostname(String hostname) { | |
95 this.hostname = hostname; | |
96 } | |
97 public String getHostname() { | |
98 return hostname; | |
99 } | |
100 public void setPort(int port) { | |
101 this.port = port; | |
102 } | |
103 public int getPort() { | |
104 return port; | |
105 } | |
106 | |
107 public void setProtocol(String protocol) { | |
108 this.protocol = protocol; | |
109 } | |
110 | |
111 public String getProtocol() { | |
112 return protocol; | |
113 } | |
114 | |
115 public void setHostKeyAlgo(String hostKeyAlgo) { | |
116 this.hostKeyAlgo = hostKeyAlgo; | |
117 } | |
118 public String getHostKeyAlgo() { | |
119 return hostKeyAlgo; | |
120 } | |
121 public void setHostKey(byte[] hostKey) { | |
122 if (hostKey == null) | |
123 this.hostKey = null; | |
124 else | |
125 this.hostKey = hostKey.clone(); | |
126 } | |
127 public byte[] getHostKey() { | |
128 if (hostKey == null) | |
129 return null; | |
130 else | |
131 return hostKey.clone(); | |
132 } | |
133 public void setLastConnect(long lastConnect) { | |
134 this.lastConnect = lastConnect; | |
135 } | |
136 public long getLastConnect() { | |
137 return lastConnect; | |
138 } | |
139 public void setColor(String color) { | |
140 this.color = color; | |
141 } | |
142 public String getColor() { | |
143 return color; | |
144 } | |
145 public void setUseKeys(boolean useKeys) { | |
146 this.useKeys = useKeys; | |
147 } | |
148 public boolean getUseKeys() { | |
149 return useKeys; | |
150 } | |
151 public void setUseAuthAgent(String useAuthAgent) { | |
152 this.useAuthAgent = useAuthAgent; | |
153 } | |
154 public String getUseAuthAgent() { | |
155 return useAuthAgent; | |
156 } | |
157 public void setPostLogin(String postLogin) { | |
158 this.postLogin = postLogin; | |
159 } | |
160 public String getPostLogin() { | |
161 return postLogin; | |
162 } | |
163 public void setPubkeyId(long pubkeyId) { | |
164 this.pubkeyId = pubkeyId; | |
165 } | |
166 public long getPubkeyId() { | |
167 return pubkeyId; | |
168 } | |
169 public void setWantSession(boolean wantSession) { | |
170 this.wantSession = wantSession; | |
171 } | |
172 public boolean getWantSession() { | |
173 return wantSession; | |
174 } | |
175 public void setDelKey(String delKey) { | |
176 this.delKey = delKey; | |
177 } | |
178 public String getDelKey() { | |
179 return delKey; | |
180 } | |
181 public void setFontSize(int fontSize) { | |
182 this.fontSize = fontSize; | |
183 } | |
184 public int getFontSize() { | |
185 return fontSize; | |
186 } | |
187 public void setCompression(boolean compression) { | |
188 this.compression = compression; | |
189 } | |
190 public boolean getCompression() { | |
191 return compression; | |
192 } | |
193 public void setHttpproxy(String httpproxy) { | |
194 this.httpproxy = httpproxy; | |
195 } | |
196 public String getHttpproxy() { | |
197 return httpproxy; | |
198 } | |
199 | |
200 public void setEncoding(String encoding) { | |
201 this.encoding = encoding; | |
202 } | |
203 | |
204 public String getEncoding() { | |
205 return this.encoding; | |
206 } | |
207 | |
208 public void setStayConnected(boolean stayConnected) { | |
209 this.stayConnected = stayConnected; | |
210 } | |
211 | |
212 public boolean getStayConnected() { | |
213 return stayConnected; | |
214 } | |
215 | |
216 public String getDescription() { | |
217 String description = String.format("%s@%s", username, hostname); | |
218 | |
219 if (port != 22) | |
220 description += String.format(":%d", port); | |
221 | |
222 return description; | |
223 } | |
224 | |
225 public boolean getWantX11Forward() { | |
226 return this.wantX11Forward; | |
227 } | |
228 | |
229 public void setWantX11Forward(boolean wantX11Forward) { | |
230 this.wantX11Forward = wantX11Forward; | |
231 } | |
232 | |
233 public String getX11Host() { | |
234 return this.x11Host; | |
235 } | |
236 | |
237 public void setX11Host(String x11Host) { | |
238 this.x11Host = x11Host; | |
239 } | |
240 | |
241 public int getX11Port() { | |
242 return this.x11Port; | |
243 } | |
244 | |
245 public void setX11Port(int x11Port) { | |
246 this.x11Port = x11Port; | |
247 } | |
248 | |
249 public String getMonitor() { | |
250 return this.monitor; | |
251 } | |
252 | |
253 public void setMonitor(String monitor) { | |
254 this.monitor = monitor; | |
255 } | |
256 | |
61 | 257 public String getHostEmulation() { |
258 return this.hostemulation; | |
259 } | |
260 | |
261 public void setHostEmulation(String hostemulation) { | |
262 this.hostemulation = hostemulation; | |
263 } | |
264 | |
265 public String getEncryption5250() { | |
266 return this.encryption5250; | |
267 } | |
268 | |
269 public void setEncryption5250(String encryption5250) { | |
270 this.encryption5250 = encryption5250; | |
271 } | |
272 | |
0 | 273 @Override |
274 public ContentValues getValues() { | |
275 ContentValues values = new ContentValues(); | |
276 values.put(HostDatabase.FIELD_HOST_NICKNAME, nickname); | |
277 values.put(HostDatabase.FIELD_HOST_PROTOCOL, protocol); | |
278 values.put(HostDatabase.FIELD_HOST_USERNAME, username); | |
279 values.put(HostDatabase.FIELD_HOST_HOSTNAME, hostname); | |
280 values.put(HostDatabase.FIELD_HOST_PORT, port); | |
281 values.put(HostDatabase.FIELD_HOST_HOSTKEYALGO, hostKeyAlgo); | |
282 values.put(HostDatabase.FIELD_HOST_HOSTKEY, hostKey); | |
283 values.put(HostDatabase.FIELD_HOST_LASTCONNECT, lastConnect); | |
284 values.put(HostDatabase.FIELD_HOST_COLOR, color); | |
285 values.put(HostDatabase.FIELD_HOST_USEKEYS, Boolean.toString(useKeys)); | |
286 values.put(HostDatabase.FIELD_HOST_USEAUTHAGENT, useAuthAgent); | |
287 values.put(HostDatabase.FIELD_HOST_POSTLOGIN, postLogin); | |
288 values.put(HostDatabase.FIELD_HOST_PUBKEYID, pubkeyId); | |
289 values.put(HostDatabase.FIELD_HOST_WANTSESSION, Boolean.toString(wantSession)); | |
290 values.put(HostDatabase.FIELD_HOST_DELKEY, delKey); | |
291 values.put(HostDatabase.FIELD_HOST_FONTSIZE, fontSize); | |
292 values.put(HostDatabase.FIELD_HOST_COMPRESSION, Boolean.toString(compression)); | |
293 values.put(HostDatabase.FIELD_HOST_HTTPPROXY, httpproxy); | |
294 values.put(HostDatabase.FIELD_HOST_ENCODING, encoding); | |
295 values.put(HostDatabase.FIELD_HOST_STAYCONNECTED, stayConnected); | |
296 values.put(HostDatabase.FIELD_HOST_WANTX11FORWARD, wantX11Forward); | |
297 values.put(HostDatabase.FIELD_HOST_X11HOST, x11Host); | |
298 values.put(HostDatabase.FIELD_HOST_X11PORT, x11Port); | |
299 values.put(HostDatabase.FIELD_HOST_MONITOR, monitor); | |
63
07c7055cc124
add 5250 config entries
Carl Byington <carl@five-ten-sg.com>
parents:
61
diff
changeset
|
300 values.put(HostDatabase.FIELD_HOST_EMULATION, hostemulation); |
61 | 301 values.put(HostDatabase.FIELD_HOST_ENCRYPTION5250, encryption5250); |
0 | 302 return values; |
303 } | |
304 | |
305 @Override | |
306 public boolean equals(Object o) { | |
307 if (o == null || !(o instanceof HostBean)) | |
308 return false; | |
309 | |
310 HostBean host = (HostBean)o; | |
311 | |
312 if (id != -1 && host.getId() != -1) | |
313 return host.getId() == id; | |
314 | |
315 if (nickname == null) { | |
316 if (host.getNickname() != null) | |
317 return false; | |
318 } | |
319 else if (!nickname.equals(host.getNickname())) | |
320 return false; | |
321 | |
322 if (protocol == null) { | |
323 if (host.getProtocol() != null) | |
324 return false; | |
325 } | |
326 else if (!protocol.equals(host.getProtocol())) | |
327 return false; | |
328 | |
329 if (username == null) { | |
330 if (host.getUsername() != null) | |
331 return false; | |
332 } | |
333 else if (!username.equals(host.getUsername())) | |
334 return false; | |
335 | |
336 if (hostname == null) { | |
337 if (host.getHostname() != null) | |
338 return false; | |
339 } | |
340 else if (!hostname.equals(host.getHostname())) | |
341 return false; | |
342 | |
343 if (port != host.getPort()) | |
344 return false; | |
345 | |
346 return true; | |
347 } | |
348 | |
349 @Override | |
350 public int hashCode() { | |
351 int hash = 7; | |
352 | |
353 if (id != -1) | |
354 return (int)id; | |
355 | |
356 hash = 31 * hash + (null == nickname ? 0 : nickname.hashCode()); | |
357 hash = 31 * hash + (null == protocol ? 0 : protocol.hashCode()); | |
358 hash = 31 * hash + (null == username ? 0 : username.hashCode()); | |
359 hash = 31 * hash + (null == hostname ? 0 : hostname.hashCode()); | |
360 hash = 31 * hash + port; | |
361 return hash; | |
362 } | |
363 | |
364 /** | |
365 * @return URI identifying this HostBean | |
366 */ | |
367 public Uri getUri() { | |
368 StringBuilder sb = new StringBuilder(); | |
369 sb.append(protocol) | |
370 .append("://"); | |
371 | |
372 if (username != null) | |
373 sb.append(Uri.encode(username)) | |
374 .append('@'); | |
375 | |
376 sb.append(Uri.encode(hostname)) | |
377 .append(':') | |
378 .append(port) | |
379 .append("/#") | |
380 .append(nickname); | |
381 return Uri.parse(sb.toString()); | |
382 } | |
383 | |
384 } |