comparison src/com/five_ten_sg/connectbot/bean/HostBean.java @ 0:0ce5cc452d02

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