1 /* 2 * Copyright 2004 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_SCHANNELADAPTER_H__ 12 #define WEBRTC_BASE_SCHANNELADAPTER_H__ 13 14 #include <string> 15 #include "webrtc/base/ssladapter.h" 16 #include "webrtc/base/messagequeue.h" 17 struct _SecBufferDesc; 18 19 namespace rtc { 20 21 /////////////////////////////////////////////////////////////////////////////// 22 23 class SChannelAdapter : public SSLAdapter, public MessageHandler { 24 public: 25 SChannelAdapter(AsyncSocket* socket); 26 virtual ~SChannelAdapter(); 27 28 virtual int StartSSL(const char* hostname, bool restartable); 29 virtual int Send(const void* pv, size_t cb); 30 virtual int Recv(void* pv, size_t cb); 31 virtual int Close(); 32 33 // Note that the socket returns ST_CONNECTING while SSL is being negotiated. 34 virtual ConnState GetState() const; 35 36 protected: 37 enum SSLState { 38 SSL_NONE, SSL_WAIT, SSL_CONNECTING, SSL_CONNECTED, SSL_ERROR 39 }; 40 struct SSLImpl; 41 42 virtual void OnConnectEvent(AsyncSocket* socket); 43 virtual void OnReadEvent(AsyncSocket* socket); 44 virtual void OnWriteEvent(AsyncSocket* socket); 45 virtual void OnCloseEvent(AsyncSocket* socket, int err); 46 virtual void OnMessage(Message* pmsg); 47 48 int BeginSSL(); 49 int ContinueSSL(); 50 int ProcessContext(long int status, _SecBufferDesc* sbd_in, 51 _SecBufferDesc* sbd_out); 52 int DecryptData(); 53 54 int Read(); 55 int Flush(); 56 void Error(const char* context, int err, bool signal = true); 57 void Cleanup(); 58 59 void PostEvent(); 60 61 private: 62 SSLState state_; 63 std::string ssl_host_name_; 64 // If true, socket will retain SSL configuration after Close. 65 bool restartable_; 66 // If true, we are delaying signalling close until all data is read. 67 bool signal_close_; 68 // If true, we are waiting to be woken up to signal readability or closure. 69 bool message_pending_; 70 SSLImpl* impl_; 71 }; 72 73 ///////////////////////////////////////////////////////////////////////////// 74 75 } // namespace rtc 76 77 #endif // WEBRTC_BASE_SCHANNELADAPTER_H__ 78