[email protected] | 0cfad2f3 | 2012-05-17 06:40:39 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_SERVER_WEB_SOCKET_H_ |
| 6 | #define NET_SERVER_WEB_SOCKET_H_ |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/basictypes.h" |
byungchul | 38c3ae7 | 2014-08-25 23:27:46 | [diff] [blame^] | 11 | #include "base/strings/string_piece.h" |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 12 | |
| 13 | namespace net { |
| 14 | |
| 15 | class HttpConnection; |
byungchul | 38c3ae7 | 2014-08-25 23:27:46 | [diff] [blame^] | 16 | class HttpServer; |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 17 | class HttpServerRequestInfo; |
| 18 | |
| 19 | class WebSocket { |
| 20 | public: |
| 21 | enum ParseResult { |
| 22 | FRAME_OK, |
| 23 | FRAME_INCOMPLETE, |
[email protected] | c51ab12 | 2011-09-26 16:14:49 | [diff] [blame] | 24 | FRAME_CLOSE, |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 25 | FRAME_ERROR |
| 26 | }; |
| 27 | |
byungchul | 38c3ae7 | 2014-08-25 23:27:46 | [diff] [blame^] | 28 | static WebSocket* CreateWebSocket(HttpServer* server, |
| 29 | HttpConnection* connection, |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 30 | const HttpServerRequestInfo& request, |
| 31 | size_t* pos); |
| 32 | |
byungchul | 38c3ae7 | 2014-08-25 23:27:46 | [diff] [blame^] | 33 | static ParseResult DecodeFrameHybi17(const base::StringPiece& frame, |
[email protected] | 7c41235 | 2013-03-22 09:25:42 | [diff] [blame] | 34 | bool client_frame, |
| 35 | int* bytes_consumed, |
| 36 | std::string* output); |
| 37 | |
| 38 | static std::string EncodeFrameHybi17(const std::string& data, |
| 39 | int masking_key); |
| 40 | |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 41 | virtual void Accept(const HttpServerRequestInfo& request) = 0; |
| 42 | virtual ParseResult Read(std::string* message) = 0; |
| 43 | virtual void Send(const std::string& message) = 0; |
| 44 | virtual ~WebSocket() {} |
| 45 | |
| 46 | protected: |
byungchul | 38c3ae7 | 2014-08-25 23:27:46 | [diff] [blame^] | 47 | WebSocket(HttpServer* server, HttpConnection* connection); |
| 48 | |
| 49 | HttpServer* const server_; |
| 50 | HttpConnection* const connection_; |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | DISALLOW_COPY_AND_ASSIGN(WebSocket); |
| 54 | }; |
| 55 | |
| 56 | } // namespace net |
| 57 | |
[email protected] | 0cfad2f3 | 2012-05-17 06:40:39 | [diff] [blame] | 58 | #endif // NET_SERVER_WEB_SOCKET_H_ |