Home | History | Annotate | Download | only in base
      1 /*
      2  *  Copyright 2007 The WebRTC Project Authors. All rights reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #ifndef WEBRTC_BASE_SSLSOCKETFACTORY_H__
     12 #define WEBRTC_BASE_SSLSOCKETFACTORY_H__
     13 
     14 #include "webrtc/base/proxyinfo.h"
     15 #include "webrtc/base/socketserver.h"
     16 
     17 namespace rtc {
     18 
     19 ///////////////////////////////////////////////////////////////////////////////
     20 // SslSocketFactory
     21 ///////////////////////////////////////////////////////////////////////////////
     22 
     23 class SslSocketFactory : public SocketFactory {
     24  public:
     25   SslSocketFactory(SocketFactory* factory, const std::string& user_agent)
     26      : factory_(factory), agent_(user_agent), autodetect_proxy_(true),
     27        force_connect_(false), logging_level_(LS_VERBOSE), binary_mode_(false),
     28        ignore_bad_cert_(false) {
     29   }
     30 
     31   void SetAutoDetectProxy() {
     32     autodetect_proxy_ = true;
     33   }
     34   void SetForceConnect(bool force) {
     35     force_connect_ = force;
     36   }
     37   void SetProxy(const ProxyInfo& proxy) {
     38     autodetect_proxy_ = false;
     39     proxy_ = proxy;
     40   }
     41   bool autodetect_proxy() const { return autodetect_proxy_; }
     42   const ProxyInfo& proxy() const { return proxy_; }
     43 
     44   void UseSSL(const char* hostname) { hostname_ = hostname; }
     45   void DisableSSL() { hostname_.clear(); }
     46   void SetIgnoreBadCert(bool ignore) { ignore_bad_cert_ = ignore; }
     47   bool ignore_bad_cert() const { return ignore_bad_cert_; }
     48 
     49   void SetLogging(LoggingSeverity level, const std::string& label,
     50                   bool binary_mode = false) {
     51     logging_level_ = level;
     52     logging_label_ = label;
     53     binary_mode_ = binary_mode;
     54   }
     55 
     56   // SocketFactory Interface
     57   virtual Socket* CreateSocket(int type);
     58   virtual Socket* CreateSocket(int family, int type);
     59 
     60   virtual AsyncSocket* CreateAsyncSocket(int type);
     61   virtual AsyncSocket* CreateAsyncSocket(int family, int type);
     62 
     63  private:
     64   friend class ProxySocketAdapter;
     65   AsyncSocket* CreateProxySocket(const ProxyInfo& proxy, int family, int type);
     66 
     67   SocketFactory* factory_;
     68   std::string agent_;
     69   bool autodetect_proxy_, force_connect_;
     70   ProxyInfo proxy_;
     71   std::string hostname_, logging_label_;
     72   LoggingSeverity logging_level_;
     73   bool binary_mode_;
     74   bool ignore_bad_cert_;
     75 };
     76 
     77 ///////////////////////////////////////////////////////////////////////////////
     78 
     79 }  // namespace rtc
     80 
     81 #endif  // WEBRTC_BASE_SSLSOCKETFACTORY_H__
     82