• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * $RCSfile$
3  * $Revision$
4  * $Date$
5  *
6  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package org.jivesoftware.smack.proxy;
19 
20 import javax.net.SocketFactory;
21 
22 /**
23  * Class which stores proxy information such as proxy type, host, port,
24  * authentication etc.
25  *
26  * @author Atul Aggarwal
27  */
28 
29 public class ProxyInfo
30 {
31     public static enum ProxyType
32     {
33         NONE,
34         HTTP,
35         SOCKS4,
36         SOCKS5
37     }
38 
39     private String proxyAddress;
40     private int proxyPort;
41     private String proxyUsername;
42     private String proxyPassword;
43     private ProxyType proxyType;
44 
ProxyInfo( ProxyType pType, String pHost, int pPort, String pUser, String pPass)45     public ProxyInfo(   ProxyType pType, String pHost, int pPort, String pUser,
46                         String pPass)
47     {
48         this.proxyType = pType;
49         this.proxyAddress = pHost;
50         this.proxyPort = pPort;
51         this.proxyUsername = pUser;
52         this.proxyPassword = pPass;
53     }
54 
forHttpProxy(String pHost, int pPort, String pUser, String pPass)55     public static ProxyInfo forHttpProxy(String pHost, int pPort, String pUser,
56                                     String pPass)
57     {
58         return new ProxyInfo(ProxyType.HTTP, pHost, pPort, pUser, pPass);
59     }
60 
forSocks4Proxy(String pHost, int pPort, String pUser, String pPass)61     public static ProxyInfo forSocks4Proxy(String pHost, int pPort, String pUser,
62                                     String pPass)
63     {
64         return new ProxyInfo(ProxyType.SOCKS4, pHost, pPort, pUser, pPass);
65     }
66 
forSocks5Proxy(String pHost, int pPort, String pUser, String pPass)67     public static ProxyInfo forSocks5Proxy(String pHost, int pPort, String pUser,
68                                     String pPass)
69     {
70         return new ProxyInfo(ProxyType.SOCKS5, pHost, pPort, pUser, pPass);
71     }
72 
forNoProxy()73     public static ProxyInfo forNoProxy()
74     {
75         return new ProxyInfo(ProxyType.NONE, null, 0, null, null);
76     }
77 
forDefaultProxy()78     public static ProxyInfo forDefaultProxy()
79     {
80         return new ProxyInfo(ProxyType.NONE, null, 0, null, null);
81     }
82 
getProxyType()83     public ProxyType getProxyType()
84     {
85         return proxyType;
86     }
87 
getProxyAddress()88     public String getProxyAddress()
89     {
90         return proxyAddress;
91     }
92 
getProxyPort()93     public int getProxyPort()
94     {
95         return proxyPort;
96     }
97 
getProxyUsername()98     public String getProxyUsername()
99     {
100         return proxyUsername;
101     }
102 
getProxyPassword()103     public String getProxyPassword()
104     {
105         return proxyPassword;
106     }
107 
getSocketFactory()108     public SocketFactory getSocketFactory()
109     {
110         if(proxyType == ProxyType.NONE)
111         {
112             return new DirectSocketFactory();
113         }
114         else if(proxyType == ProxyType.HTTP)
115         {
116             return new HTTPProxySocketFactory(this);
117         }
118         else if(proxyType == ProxyType.SOCKS4)
119         {
120             return new Socks4ProxySocketFactory(this);
121         }
122         else if(proxyType == ProxyType.SOCKS5)
123         {
124             return new Socks5ProxySocketFactory(this);
125         }
126         else
127         {
128             return null;
129         }
130     }
131 }
132