001/** 002 * 003 * Copyright the original author or authors 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smack.proxy; 018 019/** 020 * Class which stores proxy information such as proxy type, host, port, 021 * authentication etc. 022 * 023 * @author Atul Aggarwal 024 */ 025 026public class ProxyInfo { 027 public enum ProxyType { 028 HTTP, 029 SOCKS4, 030 SOCKS5 031 } 032 033 private String proxyAddress; 034 private int proxyPort; 035 private String proxyUsername; 036 private String proxyPassword; 037 private ProxyType proxyType; 038 private final ProxySocketConnection proxySocketConnection; 039 040 public ProxyInfo(ProxyType pType, String pHost, int pPort, String pUser, 041 String pPass) { 042 this.proxyType = pType; 043 this.proxyAddress = pHost; 044 this.proxyPort = pPort; 045 this.proxyUsername = pUser; 046 this.proxyPassword = pPass; 047 switch (proxyType) { 048 case HTTP: 049 proxySocketConnection = new HTTPProxySocketConnection(this); 050 break; 051 case SOCKS4: 052 proxySocketConnection = new Socks4ProxySocketConnection(this); 053 break; 054 case SOCKS5: 055 proxySocketConnection = new Socks5ProxySocketConnection(this); 056 break; 057 default: 058 throw new IllegalStateException(); 059 } 060 } 061 062 public static ProxyInfo forHttpProxy(String pHost, int pPort, String pUser, 063 String pPass) { 064 return new ProxyInfo(ProxyType.HTTP, pHost, pPort, pUser, pPass); 065 } 066 067 public static ProxyInfo forSocks4Proxy(String pHost, int pPort, String pUser, 068 String pPass) { 069 return new ProxyInfo(ProxyType.SOCKS4, pHost, pPort, pUser, pPass); 070 } 071 072 public static ProxyInfo forSocks5Proxy(String pHost, int pPort, String pUser, 073 String pPass) { 074 return new ProxyInfo(ProxyType.SOCKS5, pHost, pPort, pUser, pPass); 075 } 076 077 public ProxyType getProxyType() { 078 return proxyType; 079 } 080 081 public String getProxyAddress() { 082 return proxyAddress; 083 } 084 085 public int getProxyPort() { 086 return proxyPort; 087 } 088 089 public String getProxyUsername() { 090 return proxyUsername; 091 } 092 093 public String getProxyPassword() { 094 return proxyPassword; 095 } 096 097 public ProxySocketConnection getProxySocketConnection() { 098 return proxySocketConnection; 099 } 100}