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
|
|
23
|
|
24 /**
|
|
25 * @author Kenny Root
|
|
26 *
|
|
27 */
|
|
28 public class PortForwardBean extends AbstractBean {
|
|
29 public static final String BEAN_NAME = "portforward";
|
|
30
|
|
31 /* Database fields */
|
|
32 private long id = -1;
|
|
33 private long hostId = -1;
|
|
34 private String nickname = null;
|
|
35 private String type = null;
|
|
36 private int sourcePort = -1;
|
|
37 private String destAddr = null;
|
|
38 private int destPort = -1;
|
|
39
|
|
40 /* Transient values */
|
|
41 private boolean enabled = false;
|
|
42 private Object identifier = null;
|
|
43
|
|
44 /**
|
|
45 * @param id database ID of port forward
|
|
46 * @param nickname Nickname to use to identify port forward
|
|
47 * @param type One of the port forward types from {@link HostDatabase}
|
|
48 * @param sourcePort Source port number
|
|
49 * @param destAddr Destination hostname or IP address
|
|
50 * @param destPort Destination port number
|
|
51 */
|
|
52 public PortForwardBean(long id, long hostId, String nickname, String type, int sourcePort, String destAddr, int destPort) {
|
|
53 this.id = id;
|
|
54 this.hostId = hostId;
|
|
55 this.nickname = nickname;
|
|
56 this.type = type;
|
|
57 this.sourcePort = sourcePort;
|
|
58 this.destAddr = destAddr;
|
|
59 this.destPort = destPort;
|
|
60 }
|
|
61
|
|
62 /**
|
|
63 * @param type One of the port forward types from {@link HostDatabase}
|
|
64 * @param source Source port number
|
|
65 * @param dest Destination is "host:port" format
|
|
66 */
|
|
67 public PortForwardBean(long hostId, String nickname, String type, String source, String dest) {
|
|
68 this.hostId = hostId;
|
|
69 this.nickname = nickname;
|
|
70 this.type = type;
|
|
71 this.sourcePort = Integer.parseInt(source);
|
|
72 setDest(dest);
|
|
73 }
|
|
74
|
|
75 @Override
|
|
76 public String getBeanName() {
|
|
77 return BEAN_NAME;
|
|
78 }
|
|
79
|
|
80 /**
|
|
81 * @param id the id to set
|
|
82 */
|
|
83 public void setId(long id) {
|
|
84 this.id = id;
|
|
85 }
|
|
86
|
|
87 /**
|
|
88 * @return the id
|
|
89 */
|
|
90 public long getId() {
|
|
91 return id;
|
|
92 }
|
|
93
|
|
94 /**
|
|
95 * @param nickname the nickname to set
|
|
96 */
|
|
97 public void setNickname(String nickname) {
|
|
98 this.nickname = nickname;
|
|
99 }
|
|
100
|
|
101 /**
|
|
102 * @return the nickname
|
|
103 */
|
|
104 public String getNickname() {
|
|
105 return nickname;
|
|
106 }
|
|
107
|
|
108 /**
|
|
109 * @param type the type to set
|
|
110 */
|
|
111 public void setType(String type) {
|
|
112 this.type = type;
|
|
113 }
|
|
114
|
|
115 /**
|
|
116 * @return the type
|
|
117 */
|
|
118 public String getType() {
|
|
119 return type;
|
|
120 }
|
|
121
|
|
122 /**
|
|
123 * @param sourcePort the sourcePort to set
|
|
124 */
|
|
125 public void setSourcePort(int sourcePort) {
|
|
126 this.sourcePort = sourcePort;
|
|
127 }
|
|
128
|
|
129 /**
|
|
130 * @return the sourcePort
|
|
131 */
|
|
132 public int getSourcePort() {
|
|
133 return sourcePort;
|
|
134 }
|
|
135
|
|
136 /**
|
|
137 * @param dest The destination in "host:port" format
|
|
138 */
|
|
139 public final void setDest(String dest) {
|
|
140 String[] destSplit = dest.split(":");
|
|
141 this.destAddr = destSplit[0];
|
|
142
|
|
143 if (destSplit.length > 1)
|
|
144 this.destPort = Integer.parseInt(destSplit[1]);
|
|
145 }
|
|
146
|
|
147 /**
|
|
148 * @param destAddr the destAddr to set
|
|
149 */
|
|
150 public void setDestAddr(String destAddr) {
|
|
151 this.destAddr = destAddr;
|
|
152 }
|
|
153
|
|
154 /**
|
|
155 * @return the destAddr
|
|
156 */
|
|
157 public String getDestAddr() {
|
|
158 return destAddr;
|
|
159 }
|
|
160
|
|
161 /**
|
|
162 * @param destPort the destPort to set
|
|
163 */
|
|
164 public void setDestPort(int destPort) {
|
|
165 this.destPort = destPort;
|
|
166 }
|
|
167
|
|
168 /**
|
|
169 * @return the destPort
|
|
170 */
|
|
171 public int getDestPort() {
|
|
172 return destPort;
|
|
173 }
|
|
174
|
|
175 /**
|
|
176 * @param enabled the enabled to set
|
|
177 */
|
|
178 public void setEnabled(boolean enabled) {
|
|
179 this.enabled = enabled;
|
|
180 }
|
|
181
|
|
182 /**
|
|
183 * @return the enabled
|
|
184 */
|
|
185 public boolean isEnabled() {
|
|
186 return enabled;
|
|
187 }
|
|
188
|
|
189 /**
|
|
190 * @param identifier the identifier of this particular type to set
|
|
191 */
|
|
192 public void setIdentifier(Object identifier) {
|
|
193 this.identifier = identifier;
|
|
194 }
|
|
195
|
|
196 /**
|
|
197 * @return the identifier used by this particular type
|
|
198 */
|
|
199 public Object getIdentifier() {
|
|
200 return identifier;
|
|
201 }
|
|
202
|
|
203 /**
|
|
204 * @return human readable description of the port forward
|
|
205 */
|
|
206 public CharSequence getDescription() {
|
|
207 String description = "Unknown type";
|
|
208
|
|
209 if (HostDatabase.PORTFORWARD_LOCAL.equals(type)) {
|
|
210 description = String.format("Local port %d to %s:%d", sourcePort, destAddr, destPort);
|
|
211 }
|
|
212 else if (HostDatabase.PORTFORWARD_REMOTE.equals(type)) {
|
|
213 description = String.format("Remote port %d to %s:%d", sourcePort, destAddr, destPort);
|
|
214 /* I don't think we need the SOCKS4 type.
|
|
215 } else if (HostDatabase.PORTFORWARD_DYNAMIC4.equals(type)) {
|
|
216 description = String.format("Dynamic port %d (SOCKS4)", sourcePort);
|
|
217 */
|
|
218 }
|
|
219 else if (HostDatabase.PORTFORWARD_DYNAMIC5.equals(type)) {
|
|
220 description = String.format("Dynamic port %d (SOCKS)", sourcePort);
|
|
221 }
|
|
222
|
|
223 return description;
|
|
224 }
|
|
225
|
|
226 /**
|
|
227 * @return
|
|
228 */
|
|
229 @Override
|
|
230 public ContentValues getValues() {
|
|
231 ContentValues values = new ContentValues();
|
|
232 values.put(HostDatabase.FIELD_PORTFORWARD_HOSTID, hostId);
|
|
233 values.put(HostDatabase.FIELD_PORTFORWARD_NICKNAME, nickname);
|
|
234 values.put(HostDatabase.FIELD_PORTFORWARD_TYPE, type);
|
|
235 values.put(HostDatabase.FIELD_PORTFORWARD_SOURCEPORT, sourcePort);
|
|
236 values.put(HostDatabase.FIELD_PORTFORWARD_DESTADDR, destAddr);
|
|
237 values.put(HostDatabase.FIELD_PORTFORWARD_DESTPORT, destPort);
|
|
238 return values;
|
|
239 }
|
|
240 }
|