comparison src/net/sourceforge/jsocks/Socks4Proxy.java @ 349:205ee2873330

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