OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 void BufferInput(bool on = true); | 44 void BufferInput(bool on = true); |
45 virtual void ProcessInput(char* data, size_t* len) = 0; | 45 virtual void ProcessInput(char* data, size_t* len) = 0; |
46 | 46 |
47 void OnReadEvent(AsyncSocket* socket) override; | 47 void OnReadEvent(AsyncSocket* socket) override; |
48 | 48 |
49 private: | 49 private: |
50 char * buffer_; | 50 char * buffer_; |
51 size_t buffer_size_, data_len_; | 51 size_t buffer_size_, data_len_; |
52 bool buffering_; | 52 bool buffering_; |
53 DISALLOW_COPY_AND_ASSIGN(BufferedReadAdapter); | 53 RTC_DISALLOW_COPY_AND_ASSIGN(BufferedReadAdapter); |
54 }; | 54 }; |
55 | 55 |
56 /////////////////////////////////////////////////////////////////////////////// | 56 /////////////////////////////////////////////////////////////////////////////// |
57 | 57 |
58 // Interface for implementing proxy server sockets. | 58 // Interface for implementing proxy server sockets. |
59 class AsyncProxyServerSocket : public BufferedReadAdapter { | 59 class AsyncProxyServerSocket : public BufferedReadAdapter { |
60 public: | 60 public: |
61 AsyncProxyServerSocket(AsyncSocket* socket, size_t buffer_size); | 61 AsyncProxyServerSocket(AsyncSocket* socket, size_t buffer_size); |
62 ~AsyncProxyServerSocket() override; | 62 ~AsyncProxyServerSocket() override; |
63 sigslot::signal2<AsyncProxyServerSocket*, | 63 sigslot::signal2<AsyncProxyServerSocket*, |
64 const SocketAddress&> SignalConnectRequest; | 64 const SocketAddress&> SignalConnectRequest; |
65 virtual void SendConnectResult(int err, const SocketAddress& addr) = 0; | 65 virtual void SendConnectResult(int err, const SocketAddress& addr) = 0; |
66 }; | 66 }; |
67 | 67 |
68 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
69 | 69 |
70 // Implements a socket adapter that performs the client side of a | 70 // Implements a socket adapter that performs the client side of a |
71 // fake SSL handshake. Used for "ssltcp" P2P functionality. | 71 // fake SSL handshake. Used for "ssltcp" P2P functionality. |
72 class AsyncSSLSocket : public BufferedReadAdapter { | 72 class AsyncSSLSocket : public BufferedReadAdapter { |
73 public: | 73 public: |
74 explicit AsyncSSLSocket(AsyncSocket* socket); | 74 explicit AsyncSSLSocket(AsyncSocket* socket); |
75 | 75 |
76 int Connect(const SocketAddress& addr) override; | 76 int Connect(const SocketAddress& addr) override; |
77 | 77 |
78 protected: | 78 protected: |
79 void OnConnectEvent(AsyncSocket* socket) override; | 79 void OnConnectEvent(AsyncSocket* socket) override; |
80 void ProcessInput(char* data, size_t* len) override; | 80 void ProcessInput(char* data, size_t* len) override; |
81 DISALLOW_COPY_AND_ASSIGN(AsyncSSLSocket); | 81 RTC_DISALLOW_COPY_AND_ASSIGN(AsyncSSLSocket); |
82 }; | 82 }; |
83 | 83 |
84 // Implements a socket adapter that performs the server side of a | 84 // Implements a socket adapter that performs the server side of a |
85 // fake SSL handshake. Used when implementing a relay server that does "ssltcp". | 85 // fake SSL handshake. Used when implementing a relay server that does "ssltcp". |
86 class AsyncSSLServerSocket : public BufferedReadAdapter { | 86 class AsyncSSLServerSocket : public BufferedReadAdapter { |
87 public: | 87 public: |
88 explicit AsyncSSLServerSocket(AsyncSocket* socket); | 88 explicit AsyncSSLServerSocket(AsyncSocket* socket); |
89 | 89 |
90 protected: | 90 protected: |
91 void ProcessInput(char* data, size_t* len) override; | 91 void ProcessInput(char* data, size_t* len) override; |
92 DISALLOW_COPY_AND_ASSIGN(AsyncSSLServerSocket); | 92 RTC_DISALLOW_COPY_AND_ASSIGN(AsyncSSLServerSocket); |
93 }; | 93 }; |
94 | 94 |
95 /////////////////////////////////////////////////////////////////////////////// | 95 /////////////////////////////////////////////////////////////////////////////// |
96 | 96 |
97 // Implements a socket adapter that speaks the HTTP/S proxy protocol. | 97 // Implements a socket adapter that speaks the HTTP/S proxy protocol. |
98 class AsyncHttpsProxySocket : public BufferedReadAdapter { | 98 class AsyncHttpsProxySocket : public BufferedReadAdapter { |
99 public: | 99 public: |
100 AsyncHttpsProxySocket(AsyncSocket* socket, const std::string& user_agent, | 100 AsyncHttpsProxySocket(AsyncSocket* socket, const std::string& user_agent, |
101 const SocketAddress& proxy, | 101 const SocketAddress& proxy, |
102 const std::string& username, const CryptString& password); | 102 const std::string& username, const CryptString& password); |
(...skipping 27 matching lines...) Expand all Loading... |
130 bool force_connect_; | 130 bool force_connect_; |
131 size_t content_length_; | 131 size_t content_length_; |
132 int defer_error_; | 132 int defer_error_; |
133 bool expect_close_; | 133 bool expect_close_; |
134 enum ProxyState { | 134 enum ProxyState { |
135 PS_INIT, PS_LEADER, PS_AUTHENTICATE, PS_SKIP_HEADERS, PS_ERROR_HEADERS, | 135 PS_INIT, PS_LEADER, PS_AUTHENTICATE, PS_SKIP_HEADERS, PS_ERROR_HEADERS, |
136 PS_TUNNEL_HEADERS, PS_SKIP_BODY, PS_TUNNEL, PS_WAIT_CLOSE, PS_ERROR | 136 PS_TUNNEL_HEADERS, PS_SKIP_BODY, PS_TUNNEL, PS_WAIT_CLOSE, PS_ERROR |
137 } state_; | 137 } state_; |
138 HttpAuthContext * context_; | 138 HttpAuthContext * context_; |
139 std::string unknown_mechanisms_; | 139 std::string unknown_mechanisms_; |
140 DISALLOW_COPY_AND_ASSIGN(AsyncHttpsProxySocket); | 140 RTC_DISALLOW_COPY_AND_ASSIGN(AsyncHttpsProxySocket); |
141 }; | 141 }; |
142 | 142 |
143 /* TODO: Implement this. | 143 /* TODO: Implement this. |
144 class AsyncHttpsProxyServerSocket : public AsyncProxyServerSocket { | 144 class AsyncHttpsProxyServerSocket : public AsyncProxyServerSocket { |
145 public: | 145 public: |
146 explicit AsyncHttpsProxyServerSocket(AsyncSocket* socket); | 146 explicit AsyncHttpsProxyServerSocket(AsyncSocket* socket); |
147 | 147 |
148 private: | 148 private: |
149 virtual void ProcessInput(char * data, size_t& len); | 149 virtual void ProcessInput(char * data, size_t& len); |
150 void Error(int error); | 150 void Error(int error); |
151 DISALLOW_COPY_AND_ASSIGN(AsyncHttpsProxyServerSocket); | 151 RTC_DISALLOW_COPY_AND_ASSIGN(AsyncHttpsProxyServerSocket); |
152 }; | 152 }; |
153 */ | 153 */ |
154 | 154 |
155 /////////////////////////////////////////////////////////////////////////////// | 155 /////////////////////////////////////////////////////////////////////////////// |
156 | 156 |
157 // Implements a socket adapter that speaks the SOCKS proxy protocol. | 157 // Implements a socket adapter that speaks the SOCKS proxy protocol. |
158 class AsyncSocksProxySocket : public BufferedReadAdapter { | 158 class AsyncSocksProxySocket : public BufferedReadAdapter { |
159 public: | 159 public: |
160 AsyncSocksProxySocket(AsyncSocket* socket, const SocketAddress& proxy, | 160 AsyncSocksProxySocket(AsyncSocket* socket, const SocketAddress& proxy, |
161 const std::string& username, const CryptString& password); | 161 const std::string& username, const CryptString& password); |
(...skipping 14 matching lines...) Expand all Loading... |
176 void Error(int error); | 176 void Error(int error); |
177 | 177 |
178 private: | 178 private: |
179 enum State { | 179 enum State { |
180 SS_INIT, SS_HELLO, SS_AUTH, SS_CONNECT, SS_TUNNEL, SS_ERROR | 180 SS_INIT, SS_HELLO, SS_AUTH, SS_CONNECT, SS_TUNNEL, SS_ERROR |
181 }; | 181 }; |
182 State state_; | 182 State state_; |
183 SocketAddress proxy_, dest_; | 183 SocketAddress proxy_, dest_; |
184 std::string user_; | 184 std::string user_; |
185 CryptString pass_; | 185 CryptString pass_; |
186 DISALLOW_COPY_AND_ASSIGN(AsyncSocksProxySocket); | 186 RTC_DISALLOW_COPY_AND_ASSIGN(AsyncSocksProxySocket); |
187 }; | 187 }; |
188 | 188 |
189 // Implements a proxy server socket for the SOCKS protocol. | 189 // Implements a proxy server socket for the SOCKS protocol. |
190 class AsyncSocksProxyServerSocket : public AsyncProxyServerSocket { | 190 class AsyncSocksProxyServerSocket : public AsyncProxyServerSocket { |
191 public: | 191 public: |
192 explicit AsyncSocksProxyServerSocket(AsyncSocket* socket); | 192 explicit AsyncSocksProxyServerSocket(AsyncSocket* socket); |
193 | 193 |
194 private: | 194 private: |
195 void ProcessInput(char* data, size_t* len) override; | 195 void ProcessInput(char* data, size_t* len) override; |
196 void DirectSend(const ByteBuffer& buf); | 196 void DirectSend(const ByteBuffer& buf); |
197 | 197 |
198 void HandleHello(ByteBuffer* request); | 198 void HandleHello(ByteBuffer* request); |
199 void SendHelloReply(uint8 method); | 199 void SendHelloReply(uint8 method); |
200 void HandleAuth(ByteBuffer* request); | 200 void HandleAuth(ByteBuffer* request); |
201 void SendAuthReply(uint8 result); | 201 void SendAuthReply(uint8 result); |
202 void HandleConnect(ByteBuffer* request); | 202 void HandleConnect(ByteBuffer* request); |
203 void SendConnectResult(int result, const SocketAddress& addr) override; | 203 void SendConnectResult(int result, const SocketAddress& addr) override; |
204 | 204 |
205 void Error(int error); | 205 void Error(int error); |
206 | 206 |
207 static const int kBufferSize = 1024; | 207 static const int kBufferSize = 1024; |
208 enum State { | 208 enum State { |
209 SS_HELLO, SS_AUTH, SS_CONNECT, SS_CONNECT_PENDING, SS_TUNNEL, SS_ERROR | 209 SS_HELLO, SS_AUTH, SS_CONNECT, SS_CONNECT_PENDING, SS_TUNNEL, SS_ERROR |
210 }; | 210 }; |
211 State state_; | 211 State state_; |
212 DISALLOW_COPY_AND_ASSIGN(AsyncSocksProxyServerSocket); | 212 RTC_DISALLOW_COPY_AND_ASSIGN(AsyncSocksProxyServerSocket); |
213 }; | 213 }; |
214 | 214 |
215 /////////////////////////////////////////////////////////////////////////////// | 215 /////////////////////////////////////////////////////////////////////////////// |
216 | 216 |
217 // Implements a socket adapter that logs everything that it sends and receives. | 217 // Implements a socket adapter that logs everything that it sends and receives. |
218 class LoggingSocketAdapter : public AsyncSocketAdapter { | 218 class LoggingSocketAdapter : public AsyncSocketAdapter { |
219 public: | 219 public: |
220 LoggingSocketAdapter(AsyncSocket* socket, LoggingSeverity level, | 220 LoggingSocketAdapter(AsyncSocket* socket, LoggingSeverity level, |
221 const char * label, bool hex_mode = false); | 221 const char * label, bool hex_mode = false); |
222 | 222 |
223 int Send(const void* pv, size_t cb) override; | 223 int Send(const void* pv, size_t cb) override; |
224 int SendTo(const void* pv, size_t cb, const SocketAddress& addr) override; | 224 int SendTo(const void* pv, size_t cb, const SocketAddress& addr) override; |
225 int Recv(void* pv, size_t cb) override; | 225 int Recv(void* pv, size_t cb) override; |
226 int RecvFrom(void* pv, size_t cb, SocketAddress* paddr) override; | 226 int RecvFrom(void* pv, size_t cb, SocketAddress* paddr) override; |
227 int Close() override; | 227 int Close() override; |
228 | 228 |
229 protected: | 229 protected: |
230 void OnConnectEvent(AsyncSocket* socket) override; | 230 void OnConnectEvent(AsyncSocket* socket) override; |
231 void OnCloseEvent(AsyncSocket* socket, int err) override; | 231 void OnCloseEvent(AsyncSocket* socket, int err) override; |
232 | 232 |
233 private: | 233 private: |
234 LoggingSeverity level_; | 234 LoggingSeverity level_; |
235 std::string label_; | 235 std::string label_; |
236 bool hex_mode_; | 236 bool hex_mode_; |
237 LogMultilineState lms_; | 237 LogMultilineState lms_; |
238 DISALLOW_COPY_AND_ASSIGN(LoggingSocketAdapter); | 238 RTC_DISALLOW_COPY_AND_ASSIGN(LoggingSocketAdapter); |
239 }; | 239 }; |
240 | 240 |
241 /////////////////////////////////////////////////////////////////////////////// | 241 /////////////////////////////////////////////////////////////////////////////// |
242 | 242 |
243 } // namespace rtc | 243 } // namespace rtc |
244 | 244 |
245 #endif // WEBRTC_BASE_SOCKETADAPTERS_H_ | 245 #endif // WEBRTC_BASE_SOCKETADAPTERS_H_ |
OLD | NEW |