1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.proxy.handlers.socks;
21
22 import java.net.InetSocketAddress;
23
24 import org.apache.mina.proxy.handlers.ProxyRequest;
25
26
27
28
29
30
31
32 public class SocksProxyRequest extends ProxyRequest {
33
34
35
36
37 private byte protocolVersion;
38
39
40
41
42 private byte commandCode;
43
44
45
46
47 private String userName;
48
49
50
51
52 private String password;
53
54
55
56
57 private String host;
58
59
60
61
62 private int port;
63
64
65
66
67 private String serviceKerberosName;
68
69
70
71
72
73
74
75
76
77 public SocksProxyRequest(byte protocolVersion, byte commandCode,
78 InetSocketAddress endpointAddress, String userName) {
79 super(endpointAddress);
80 this.protocolVersion = protocolVersion;
81 this.commandCode = commandCode;
82 this.userName = userName;
83 }
84
85
86
87
88
89
90
91
92
93 public SocksProxyRequest(byte commandCode, String host, int port,
94 String userName) {
95 this.protocolVersion = SocksProxyConstants.SOCKS_VERSION_4;
96 this.commandCode = commandCode;
97 this.userName = userName;
98 this.host = host;
99 this.port = port;
100 }
101
102
103
104
105
106
107
108
109 public byte[] getIpAddress() {
110 if (getEndpointAddress() == null) {
111 return SocksProxyConstants.FAKE_IP;
112 }
113
114 return getEndpointAddress().getAddress().getAddress();
115 }
116
117
118
119
120
121
122 public byte[] getPort() {
123 byte[] port = new byte[2];
124 int p = (getEndpointAddress() == null ? this.port
125 : getEndpointAddress().getPort());
126 port[1] = (byte) p;
127 port[0] = (byte) (p >> 8);
128 return port;
129 }
130
131
132
133
134
135
136 public byte getCommandCode() {
137 return commandCode;
138 }
139
140
141
142
143
144
145 public byte getProtocolVersion() {
146 return protocolVersion;
147 }
148
149
150
151
152
153
154 public String getUserName() {
155 return userName;
156 }
157
158
159
160
161
162
163 public synchronized final String getHost() {
164 if (host == null) {
165 InetSocketAddress adr = getEndpointAddress();
166
167 if ( adr != null && !adr.isUnresolved()) {
168 host = getEndpointAddress().getHostName();
169 }
170 }
171
172 return host;
173 }
174
175
176
177
178
179
180 public String getPassword() {
181 return password;
182 }
183
184
185
186
187
188
189 public void setPassword(String password) {
190 this.password = password;
191 }
192
193
194
195
196
197
198 public String getServiceKerberosName() {
199 return serviceKerberosName;
200 }
201
202
203
204
205
206
207 public void setServiceKerberosName(String serviceKerberosName) {
208 this.serviceKerberosName = serviceKerberosName;
209 }
210 }