OLD | NEW |
| (Empty) |
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 void SetMode(SSLMode mode); | |
29 virtual int StartSSL(const char* hostname, bool restartable); | |
30 virtual int Send(const void* pv, size_t cb); | |
31 virtual int Recv(void* pv, size_t cb); | |
32 virtual int Close(); | |
33 | |
34 // Note that the socket returns ST_CONNECTING while SSL is being negotiated. | |
35 virtual ConnState GetState() const; | |
36 | |
37 protected: | |
38 enum SSLState { | |
39 SSL_NONE, SSL_WAIT, SSL_CONNECTING, SSL_CONNECTED, SSL_ERROR | |
40 }; | |
41 struct SSLImpl; | |
42 | |
43 virtual void OnConnectEvent(AsyncSocket* socket); | |
44 virtual void OnReadEvent(AsyncSocket* socket); | |
45 virtual void OnWriteEvent(AsyncSocket* socket); | |
46 virtual void OnCloseEvent(AsyncSocket* socket, int err); | |
47 virtual void OnMessage(Message* pmsg); | |
48 | |
49 int BeginSSL(); | |
50 int ContinueSSL(); | |
51 int ProcessContext(long int status, _SecBufferDesc* sbd_in, | |
52 _SecBufferDesc* sbd_out); | |
53 int DecryptData(); | |
54 | |
55 int Read(); | |
56 int Flush(); | |
57 void Error(const char* context, int err, bool signal = true); | |
58 void Cleanup(); | |
59 | |
60 void PostEvent(); | |
61 | |
62 private: | |
63 SSLState state_; | |
64 SSLMode mode_; | |
65 std::string ssl_host_name_; | |
66 // If true, socket will retain SSL configuration after Close. | |
67 bool restartable_; | |
68 // If true, we are delaying signalling close until all data is read. | |
69 bool signal_close_; | |
70 // If true, we are waiting to be woken up to signal readability or closure. | |
71 bool message_pending_; | |
72 SSLImpl* impl_; | |
73 }; | |
74 | |
75 ///////////////////////////////////////////////////////////////////////////// | |
76 | |
77 } // namespace rtc | |
78 | |
79 #endif // WEBRTC_BASE_SCHANNELADAPTER_H__ | |
OLD | NEW |