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{ 028 public enum ProxyType 029 { 030 HTTP, 031 SOCKS4, 032 SOCKS5 033 } 034 035 private String proxyAddress; 036 private int proxyPort; 037 private String proxyUsername; 038 private String proxyPassword; 039 private ProxyType proxyType; 040 private final ProxySocketConnection proxySocketConnection; 041 042 public ProxyInfo(ProxyType pType, String pHost, int pPort, String pUser, 043 String pPass) 044 { 045 this.proxyType = pType; 046 this.proxyAddress = pHost; 047 this.proxyPort = pPort; 048 this.proxyUsername = pUser; 049 this.proxyPassword = pPass; 050 switch (proxyType) { 051 case HTTP: 052 proxySocketConnection = new HTTPProxySocketConnection(this); 053 break; 054 case SOCKS4: 055 proxySocketConnection = new Socks4ProxySocketConnection(this); 056 break; 057 case SOCKS5: 058 proxySocketConnection = new Socks5ProxySocketConnection(this); 059 break; 060 default: 061 throw new IllegalStateException(); 062 } 063 } 064 065 public static ProxyInfo forHttpProxy(String pHost, int pPort, String pUser, 066 String pPass) 067 { 068 return new ProxyInfo(ProxyType.HTTP, pHost, pPort, pUser, pPass); 069 } 070 071 public static ProxyInfo forSocks4Proxy(String pHost, int pPort, String pUser, 072 String pPass) 073 { 074 return new ProxyInfo(ProxyType.SOCKS4, pHost, pPort, pUser, pPass); 075 } 076 077 public static ProxyInfo forSocks5Proxy(String pHost, int pPort, String pUser, 078 String pPass) 079 { 080 return new ProxyInfo(ProxyType.SOCKS5, pHost, pPort, pUser, pPass); 081 } 082 083 public ProxyType getProxyType() 084 { 085 return proxyType; 086 } 087 088 public String getProxyAddress() 089 { 090 return proxyAddress; 091 } 092 093 public int getProxyPort() 094 { 095 return proxyPort; 096 } 097 098 public String getProxyUsername() 099 { 100 return proxyUsername; 101 } 102 103 public String getProxyPassword() 104 { 105 return proxyPassword; 106 } 107 108 public ProxySocketConnection getProxySocketConnection() { 109 return proxySocketConnection; 110 } 111}