1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/conn/scheme/SchemeSocketFactory.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* 1.5 + * ==================================================================== 1.6 + * Licensed to the Apache Software Foundation (ASF) under one 1.7 + * or more contributor license agreements. See the NOTICE file 1.8 + * distributed with this work for additional information 1.9 + * regarding copyright ownership. The ASF licenses this file 1.10 + * to you under the Apache License, Version 2.0 (the 1.11 + * "License"); you may not use this file except in compliance 1.12 + * with the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, 1.17 + * software distributed under the License is distributed on an 1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1.19 + * KIND, either express or implied. See the License for the 1.20 + * specific language governing permissions and limitations 1.21 + * under the License. 1.22 + * ==================================================================== 1.23 + * 1.24 + * This software consists of voluntary contributions made by many 1.25 + * individuals on behalf of the Apache Software Foundation. For more 1.26 + * information on the Apache Software Foundation, please see 1.27 + * <http://www.apache.org/>. 1.28 + * 1.29 + */ 1.30 + 1.31 +package ch.boye.httpclientandroidlib.conn.scheme; 1.32 + 1.33 +import java.io.IOException; 1.34 +import java.net.InetSocketAddress; 1.35 +import java.net.Socket; 1.36 +import java.net.UnknownHostException; 1.37 + 1.38 +import ch.boye.httpclientandroidlib.conn.ConnectTimeoutException; 1.39 +import ch.boye.httpclientandroidlib.params.HttpParams; 1.40 + 1.41 +/** 1.42 + * A factory for creating, initializing and connecting sockets. The factory encapsulates the logic 1.43 + * for establishing a socket connection. 1.44 + * 1.45 + * @since 4.1 1.46 + */ 1.47 +public interface SchemeSocketFactory { 1.48 + 1.49 + /** 1.50 + * Creates a new, unconnected socket. The socket should subsequently be passed to 1.51 + * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}. 1.52 + * 1.53 + * @param params Optional {@link HttpParams parameters}. In most cases these parameters 1.54 + * will not be required and will have no effect, as usually socket 1.55 + * initialization should take place in the 1.56 + * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)} 1.57 + * method. However, in rare cases one may want to pass additional parameters 1.58 + * to this method in order to create a customized {@link Socket} instance, 1.59 + * for instance bound to a SOCKS proxy server. 1.60 + * 1.61 + * @return a new socket 1.62 + * 1.63 + * @throws IOException if an I/O error occurs while creating the socket 1.64 + */ 1.65 + Socket createSocket(HttpParams params) throws IOException; 1.66 + 1.67 + /** 1.68 + * Connects a socket to the target host with the given remote address. 1.69 + * 1.70 + * @param sock the socket to connect, as obtained from 1.71 + * {@link #createSocket(HttpParams) createSocket}. 1.72 + * <code>null</code> indicates that a new socket 1.73 + * should be created and connected. 1.74 + * @param remoteAddress the remote address to connect to 1.75 + * @param localAddress the local address to bind the socket to, or 1.76 + * <code>null</code> for any 1.77 + * @param params additional {@link HttpParams parameters} for connecting 1.78 + * 1.79 + * @return the connected socket. The returned object may be different 1.80 + * from the <code>sock</code> argument if this factory supports 1.81 + * a layered protocol. 1.82 + * 1.83 + * @throws IOException if an I/O error occurs 1.84 + * @throws UnknownHostException if the IP address of the target host 1.85 + * can not be determined 1.86 + * @throws ConnectTimeoutException if the socket cannot be connected 1.87 + * within the time limit defined in the <code>params</code> 1.88 + */ 1.89 + Socket connectSocket( 1.90 + Socket sock, 1.91 + InetSocketAddress remoteAddress, 1.92 + InetSocketAddress localAddress, 1.93 + HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException; 1.94 + 1.95 + /** 1.96 + * Checks whether a socket provides a secure connection. The socket must be 1.97 + * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams) connected} 1.98 + * by this factory. The factory will <i>not</i> perform I/O operations in this method. 1.99 + * <p> 1.100 + * As a rule of thumb, plain sockets are not secure and TLS/SSL sockets are secure. However, 1.101 + * there may be application specific deviations. For example, a plain socket to a host in the 1.102 + * same intranet ("trusted zone") could be considered secure. On the other hand, a TLS/SSL 1.103 + * socket could be considered insecure based on the cipher suite chosen for the connection. 1.104 + * 1.105 + * @param sock the connected socket to check 1.106 + * 1.107 + * @return <code>true</code> if the connection of the socket 1.108 + * should be considered secure, or 1.109 + * <code>false</code> if it should not 1.110 + * 1.111 + * @throws IllegalArgumentException 1.112 + * if the argument is invalid, for example because it is 1.113 + * not a connected socket or was created by a different 1.114 + * socket factory. 1.115 + * Note that socket factories are <i>not</i> required to 1.116 + * check these conditions, they may simply return a default 1.117 + * value when called with an invalid socket argument. 1.118 + */ 1.119 + boolean isSecure(Socket sock) throws IllegalArgumentException; 1.120 + 1.121 +}