2013-02-07 15:19:47 +01:00
|
|
|
/**
|
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Copyright the original author or authors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2013-02-07 15:19:47 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2008-07-15 04:59:21 +02:00
|
|
|
package org.jivesoftware.smack.proxy;
|
|
|
|
|
2021-03-29 15:31:42 +02:00
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.net.Proxy;
|
|
|
|
import java.net.SocketAddress;
|
|
|
|
|
2008-07-15 04:59:21 +02:00
|
|
|
/**
|
2018-05-09 23:06:12 +02:00
|
|
|
* Class which stores proxy information such as proxy type, host, port,
|
2008-07-15 04:59:21 +02:00
|
|
|
* authentication etc.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2008-07-15 04:59:21 +02:00
|
|
|
* @author Atul Aggarwal
|
|
|
|
*/
|
|
|
|
|
2018-04-06 10:21:46 +02:00
|
|
|
public class ProxyInfo {
|
|
|
|
public enum ProxyType {
|
2008-07-15 04:59:21 +02:00
|
|
|
HTTP,
|
|
|
|
SOCKS4,
|
|
|
|
SOCKS5
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2008-07-15 04:59:21 +02:00
|
|
|
private String proxyAddress;
|
|
|
|
private int proxyPort;
|
|
|
|
private String proxyUsername;
|
|
|
|
private String proxyPassword;
|
|
|
|
private ProxyType proxyType;
|
2015-07-17 08:50:19 +02:00
|
|
|
private final ProxySocketConnection proxySocketConnection;
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2018-05-09 23:06:12 +02:00
|
|
|
public ProxyInfo(ProxyType pType, String pHost, int pPort, String pUser,
|
2018-04-06 10:21:46 +02:00
|
|
|
String pPass) {
|
2008-07-15 04:59:21 +02:00
|
|
|
this.proxyType = pType;
|
|
|
|
this.proxyAddress = pHost;
|
|
|
|
this.proxyPort = pPort;
|
|
|
|
this.proxyUsername = pUser;
|
|
|
|
this.proxyPassword = pPass;
|
2021-03-29 15:31:42 +02:00
|
|
|
this.proxySocketConnection =
|
|
|
|
ProxySocketConnection
|
|
|
|
.forProxyType(proxyType)
|
|
|
|
.apply(this);
|
2008-07-15 04:59:21 +02:00
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2018-05-09 23:06:12 +02:00
|
|
|
public static ProxyInfo forHttpProxy(String pHost, int pPort, String pUser,
|
2018-04-06 10:21:46 +02:00
|
|
|
String pPass) {
|
2008-07-15 04:59:21 +02:00
|
|
|
return new ProxyInfo(ProxyType.HTTP, pHost, pPort, pUser, pPass);
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2018-05-09 23:06:12 +02:00
|
|
|
public static ProxyInfo forSocks4Proxy(String pHost, int pPort, String pUser,
|
2018-04-06 10:21:46 +02:00
|
|
|
String pPass) {
|
2008-07-15 04:59:21 +02:00
|
|
|
return new ProxyInfo(ProxyType.SOCKS4, pHost, pPort, pUser, pPass);
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2018-05-09 23:06:12 +02:00
|
|
|
public static ProxyInfo forSocks5Proxy(String pHost, int pPort, String pUser,
|
2018-04-06 10:21:46 +02:00
|
|
|
String pPass) {
|
2008-07-15 04:59:21 +02:00
|
|
|
return new ProxyInfo(ProxyType.SOCKS5, pHost, pPort, pUser, pPass);
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2021-03-29 15:31:42 +02:00
|
|
|
public Proxy.Type getJavaProxyType() {
|
|
|
|
switch (proxyType) {
|
|
|
|
case HTTP:
|
|
|
|
return Proxy.Type.HTTP;
|
|
|
|
case SOCKS4:
|
|
|
|
case SOCKS5:
|
|
|
|
return Proxy.Type.SOCKS;
|
|
|
|
default:
|
|
|
|
throw new AssertionError("Invalid proxy type: " + proxyType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 10:21:46 +02:00
|
|
|
public ProxyType getProxyType() {
|
2008-07-15 04:59:21 +02:00
|
|
|
return proxyType;
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2018-04-06 10:21:46 +02:00
|
|
|
public String getProxyAddress() {
|
2008-07-15 04:59:21 +02:00
|
|
|
return proxyAddress;
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2018-04-06 10:21:46 +02:00
|
|
|
public int getProxyPort() {
|
2008-07-15 04:59:21 +02:00
|
|
|
return proxyPort;
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2018-04-06 10:21:46 +02:00
|
|
|
public String getProxyUsername() {
|
2008-07-15 04:59:21 +02:00
|
|
|
return proxyUsername;
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2018-04-06 10:21:46 +02:00
|
|
|
public String getProxyPassword() {
|
2008-07-15 04:59:21 +02:00
|
|
|
return proxyPassword;
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2015-07-17 08:50:19 +02:00
|
|
|
public ProxySocketConnection getProxySocketConnection() {
|
|
|
|
return proxySocketConnection;
|
2008-07-15 04:59:21 +02:00
|
|
|
}
|
2021-03-29 15:31:42 +02:00
|
|
|
|
|
|
|
public Proxy toJavaProxy() {
|
|
|
|
final SocketAddress proxySocketAddress = new InetSocketAddress(proxyAddress, proxyPort);
|
|
|
|
final Proxy.Type type = getJavaProxyType();
|
|
|
|
return new Proxy(type, proxySocketAddress);
|
|
|
|
}
|
|
|
|
|
2008-07-15 04:59:21 +02:00
|
|
|
}
|