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
33 public class SocksProxyRequest extends ProxyRequest {
34
35 private byte protocolVersion;
36
37 private byte commandCode;
38
39 private String userName;
40
41 private String password;
42
43 private String host;
44
45 private int port;
46
47 private String serviceKerberosName;
48
49
50
51
52 public SocksProxyRequest(byte protocolVersion, byte commandCode,
53 InetSocketAddress endpointAddress, String userName) {
54 super(endpointAddress);
55 this.protocolVersion = protocolVersion;
56 this.commandCode = commandCode;
57 this.userName = userName;
58 }
59
60
61
62
63 public SocksProxyRequest(byte commandCode, String host, int port,
64 String userName) {
65 this.protocolVersion = SocksProxyConstants.SOCKS_VERSION_4;
66 this.commandCode = commandCode;
67 this.userName = userName;
68 this.host = host;
69 this.port = port;
70 }
71
72 public byte[] getIpAddress() {
73 if (getEndpointAddress() == null)
74 return SocksProxyConstants.FAKE_IP;
75 else
76 return getEndpointAddress().getAddress().getAddress();
77 }
78
79 public byte[] getPort() {
80 byte[] port = new byte[2];
81 int p = (int) (getEndpointAddress() == null ? this.port
82 : getEndpointAddress().getPort());
83 port[1] = (byte) p;
84 port[0] = (byte) (p >> 8);
85 return port;
86 }
87
88 public byte getCommandCode() {
89 return commandCode;
90 }
91
92 public byte getProtocolVersion() {
93 return protocolVersion;
94 }
95
96 public String getUserName() {
97 return userName;
98 }
99
100 public synchronized final String getHost() {
101 if (host == null) {
102 if (getEndpointAddress() != null) {
103 host = getEndpointAddress().getHostName();
104 }
105 }
106
107 return host;
108 }
109
110 public String getPassword() {
111 return password;
112 }
113
114 public void setPassword(String password) {
115 this.password = password;
116 }
117
118 public String getServiceKerberosName() {
119 return serviceKerberosName;
120 }
121
122 public void setServiceKerberosName(String serviceKerberosName) {
123 this.serviceKerberosName = serviceKerberosName;
124 }
125 }