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, InetSocketAddress endpointAddress, String userName) {
78 super(endpointAddress);
79 this.protocolVersion = protocolVersion;
80 this.commandCode = commandCode;
81 this.userName = userName;
82 }
83
84
85
86
87
88
89
90
91
92 public SocksProxyRequest(byte commandCode, String host, int port, String userName) {
93 this.protocolVersion = SocksProxyConstants.SOCKS_VERSION_4;
94 this.commandCode = commandCode;
95 this.userName = userName;
96 this.host = host;
97 this.port = port;
98 }
99
100
101
102
103
104
105 public byte[] getIpAddress() {
106 if (getEndpointAddress() == null) {
107 return SocksProxyConstants.FAKE_IP;
108 }
109
110 return getEndpointAddress().getAddress().getAddress();
111 }
112
113
114
115
116
117
118 public byte[] getPort() {
119 byte[] port = new byte[2];
120 int p = (getEndpointAddress() == null ? this.port : getEndpointAddress().getPort());
121 port[1] = (byte) p;
122 port[0] = (byte) (p >> 8);
123 return port;
124 }
125
126
127
128
129
130
131 public byte getCommandCode() {
132 return commandCode;
133 }
134
135
136
137
138
139
140 public byte getProtocolVersion() {
141 return protocolVersion;
142 }
143
144
145
146
147
148
149 public String getUserName() {
150 return userName;
151 }
152
153
154
155
156
157
158 public synchronized final String getHost() {
159 if (host == null) {
160 InetSocketAddress adr = getEndpointAddress();
161
162 if (adr != null && adr.isUnresolved()) {
163 host = getEndpointAddress().getHostName();
164 }
165 }
166
167 return host;
168 }
169
170
171
172
173
174
175 public String getPassword() {
176 return password;
177 }
178
179
180
181
182
183
184 public void setPassword(String password) {
185 this.password = password;
186 }
187
188
189
190
191
192
193 public String getServiceKerberosName() {
194 return serviceKerberosName;
195 }
196
197
198
199
200
201
202 public void setServiceKerberosName(String serviceKerberosName) {
203 this.serviceKerberosName = serviceKerberosName;
204 }
205 }