• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   ~SslSocketFactory() override;
27 
SetAutoDetectProxy()28   void SetAutoDetectProxy() {
29     autodetect_proxy_ = true;
30   }
SetForceConnect(bool force)31   void SetForceConnect(bool force) {
32     force_connect_ = force;
33   }
SetProxy(const ProxyInfo & proxy)34   void SetProxy(const ProxyInfo& proxy) {
35     autodetect_proxy_ = false;
36     proxy_ = proxy;
37   }
autodetect_proxy()38   bool autodetect_proxy() const { return autodetect_proxy_; }
proxy()39   const ProxyInfo& proxy() const { return proxy_; }
40 
UseSSL(const char * hostname)41   void UseSSL(const char* hostname) { hostname_ = hostname; }
DisableSSL()42   void DisableSSL() { hostname_.clear(); }
SetIgnoreBadCert(bool ignore)43   void SetIgnoreBadCert(bool ignore) { ignore_bad_cert_ = ignore; }
ignore_bad_cert()44   bool ignore_bad_cert() const { return ignore_bad_cert_; }
45 
46   void SetLogging(LoggingSeverity level, const std::string& label,
47                   bool binary_mode = false) {
48     logging_level_ = level;
49     logging_label_ = label;
50     binary_mode_ = binary_mode;
51   }
52 
53   // SocketFactory Interface
54   Socket* CreateSocket(int type) override;
55   Socket* CreateSocket(int family, int type) override;
56 
57   AsyncSocket* CreateAsyncSocket(int type) override;
58   AsyncSocket* CreateAsyncSocket(int family, int type) override;
59 
60  private:
61   friend class ProxySocketAdapter;
62   AsyncSocket* CreateProxySocket(const ProxyInfo& proxy, int family, int type);
63 
64   SocketFactory* factory_;
65   std::string agent_;
66   bool autodetect_proxy_, force_connect_;
67   ProxyInfo proxy_;
68   std::string hostname_, logging_label_;
69   LoggingSeverity logging_level_;
70   bool binary_mode_;
71   bool ignore_bad_cert_;
72 };
73 
74 ///////////////////////////////////////////////////////////////////////////////
75 
76 }  // namespace rtc
77 
78 #endif  // WEBRTC_BASE_SSLSOCKETFACTORY_H__
79