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