/* * Copyright (c) 2019-2020. Developed by Hedgecode. * * Licensed under the Apache License, Version 2.0 (the "License"); * 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. */ package org.hedgecode.chess.scanner.proxy; import org.hedgecode.chess.scanner.ChessHogScannerConstants; import org.hedgecode.chess.scanner.proxy.type.HTTPSetter; import org.hedgecode.chess.scanner.proxy.type.SOCKSSetter; /** * Setter for proxy settings. * * @author Dmitry Samoshin aka gotty */ public enum Proxy { UNDEFINED ( ChessHogScannerConstants.PROXY_UNDEFINED, null ), HTTP ( ChessHogScannerConstants.PROXY_HTTP, new HTTPSetter() ), SOCKS ( ChessHogScannerConstants.PROXY_SOCKS, new SOCKSSetter() ); private String name; private ProxySetter setter; Proxy(String name, ProxySetter setter) { this.name = name; this.setter = setter; } private ProxySetter getSetter() { return setter; } public static Proxy byName(String name) { for (Proxy proxy : Proxy.values()) { if (proxy.name.equals(name)) return proxy; } return UNDEFINED; } public static void setProxy(ProxyParams proxyParams) { setProxy( proxyParams.getType(), proxyParams.getHost(), proxyParams.getPort(), proxyParams.getUser(), proxyParams.getPassword() ); } public static void setProxy(Proxy type, String host, String port) { setProxy(type, host, port, null, null); } public static void setProxy(Proxy type, String host, String port, String user, String password) { ProxySetter proxySetter = type.getSetter(); if (proxySetter != null) { proxySetter.setProxyHost(host); proxySetter.setProxyPort(port); if (user != null) { proxySetter.setProxyAuth(user, password); } } } }