0
|
1 package net.sourceforge.jsocks;
|
|
2 import java.io.IOException;
|
|
3 import java.io.InputStream;
|
|
4 import java.net.InetAddress;
|
|
5 import java.net.UnknownHostException;
|
|
6
|
|
7 /**
|
|
8 Proxy which describes SOCKS4 proxy.
|
|
9 */
|
|
10
|
|
11 public class Socks4Proxy extends Proxy implements Cloneable {
|
|
12
|
|
13 //Data members
|
|
14 String user;
|
|
15
|
|
16 //Public Constructors
|
|
17 //====================
|
|
18
|
|
19 /**
|
|
20 Creates the SOCKS4 proxy
|
|
21 @param p Proxy to use to connect to this proxy, allows proxy chaining.
|
|
22 @param proxyHost Address of the proxy server.
|
|
23 @param proxyPort Port of the proxy server
|
|
24 @param user User name to use for identification purposes.
|
|
25 @throws UnknownHostException If proxyHost can't be resolved.
|
|
26 */
|
|
27 public Socks4Proxy(String proxyHost, int proxyPort, String user)
|
|
28 throws UnknownHostException {
|
|
29 super(proxyHost, proxyPort);
|
|
30 this.user = new String(user);
|
|
31 version = 4;
|
|
32 }
|
|
33
|
|
34 /**
|
|
35 Creates the SOCKS4 proxy
|
|
36 @param p Proxy to use to connect to this proxy, allows proxy chaining.
|
|
37 @param proxyIP Address of the proxy server.
|
|
38 @param proxyPort Port of the proxy server
|
|
39 @param user User name to use for identification purposes.
|
|
40 */
|
|
41 public Socks4Proxy(Proxy p, InetAddress proxyIP, int proxyPort, String user) {
|
|
42 super(p, proxyIP, proxyPort);
|
|
43 this.user = new String(user);
|
|
44 version = 4;
|
|
45 }
|
|
46
|
|
47 /**
|
|
48 Creates the SOCKS4 proxy
|
|
49 @param proxyIP Address of the proxy server.
|
|
50 @param proxyPort Port of the proxy server
|
|
51 @param user User name to use for identification purposes.
|
|
52 */
|
|
53 public Socks4Proxy(InetAddress proxyIP, int proxyPort, String user) {
|
|
54 this(null, proxyIP, proxyPort, user);
|
|
55 }
|
|
56
|
|
57 //Public instance methods
|
|
58 //========================
|
|
59
|
|
60 /**
|
|
61 * Creates a clone of this proxy. Changes made to the clone should not
|
|
62 * affect this object.
|
|
63 */
|
|
64 public Object clone() {
|
|
65 Socks4Proxy newProxy = new Socks4Proxy(proxyIP, proxyPort, user);
|
|
66 newProxy.chainProxy = chainProxy;
|
|
67 return newProxy;
|
|
68 }
|
|
69
|
|
70
|
|
71 //Public Static(Class) Methods
|
|
72 //==============================
|
|
73
|
|
74
|
|
75 //Protected Methods
|
|
76 //=================
|
|
77
|
|
78 protected Proxy copy() {
|
|
79 Socks4Proxy copy = new Socks4Proxy(proxyIP, proxyPort, user);
|
|
80 copy.chainProxy = chainProxy;
|
|
81 return copy;
|
|
82 }
|
|
83
|
|
84 protected ProxyMessage formMessage(int cmd, InetAddress ip, int port) {
|
|
85 switch (cmd) {
|
|
86 case SOCKS_CMD_CONNECT:
|
|
87 cmd = Socks4Message.REQUEST_CONNECT;
|
|
88 break;
|
|
89
|
|
90 case SOCKS_CMD_BIND:
|
|
91 cmd = Socks4Message.REQUEST_BIND;
|
|
92 break;
|
|
93
|
|
94 default:
|
|
95 return null;
|
|
96 }
|
|
97
|
|
98 return new Socks4Message(cmd, ip, port, user);
|
|
99 }
|
|
100 protected ProxyMessage formMessage(int cmd, String host, int port)
|
|
101 throws UnknownHostException {
|
|
102 return formMessage(cmd, InetAddress.getByName(host), port);
|
|
103 }
|
|
104 protected ProxyMessage formMessage(InputStream in)
|
|
105 throws SocksException,
|
|
106 IOException {
|
|
107 return new Socks4Message(in, true);
|
|
108 }
|
|
109
|
|
110 }
|