OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ | 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ |
6 #define NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ | 6 #define NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // |data| is always unmasked even if the frame is masked. |data| might be | 79 // |data| is always unmasked even if the frame is masked. |data| might be |
80 // null in the first chunk. | 80 // null in the first chunk. |
81 scoped_refptr<IOBufferWithSize> data; | 81 scoped_refptr<IOBufferWithSize> data; |
82 }; | 82 }; |
83 | 83 |
84 // Contains four-byte data representing "masking key" of WebSocket frames. | 84 // Contains four-byte data representing "masking key" of WebSocket frames. |
85 struct WebSocketMaskingKey { | 85 struct WebSocketMaskingKey { |
86 char key[WebSocketFrameHeader::kMaskingKeyLength]; | 86 char key[WebSocketFrameHeader::kMaskingKeyLength]; |
87 }; | 87 }; |
88 | 88 |
| 89 // Returns the size of WebSocket frame header. The size of WebSocket frame |
| 90 // header varies from 2 bytes to 14 bytes depending on the payload length |
| 91 // and maskedness. |
| 92 NET_EXPORT_PRIVATE int GetWebSocketFrameHeaderSize( |
| 93 const WebSocketFrameHeader& header); |
| 94 |
89 // Writes wire format of a WebSocket frame header into |output|, and returns | 95 // Writes wire format of a WebSocket frame header into |output|, and returns |
90 // the number of bytes written. | 96 // the number of bytes written. |
91 // | 97 // |
92 // WebSocket frame format is defined at: | 98 // WebSocket frame format is defined at: |
93 // <http://tools.ietf.org/html/rfc6455#section-5.2>. This function writes | 99 // <http://tools.ietf.org/html/rfc6455#section-5.2>. This function writes |
94 // everything but payload data in a WebSocket frame to |buffer|. | 100 // everything but payload data in a WebSocket frame to |buffer|. |
95 // | 101 // |
96 // If |header->masked| is true, |masking_key| must point to a valid | 102 // If |header->masked| is true, |masking_key| must point to a valid |
97 // WebSocketMaskingKey object containing the masking key for that frame | 103 // WebSocketMaskingKey object containing the masking key for that frame |
98 // (possibly generated by GenerateWebSocketMaskingKey() function below). | 104 // (possibly generated by GenerateWebSocketMaskingKey() function below). |
99 // Otherwise, |masking_key| must be NULL. | 105 // Otherwise, |masking_key| must be NULL. |
100 // | 106 // |
101 // |buffer| should have enough size to contain the frame header. Size of a | 107 // |buffer| should have enough size to contain the frame header. |
102 // frame header varies from 2 bytes to 14 bytes depending on the payload length | 108 // GetWebSocketFrameHeaderSize() can be used to know the size of header |
103 // and maskedness. If the size of |buffer| is insufficient, this function | 109 // beforehand. If the size of |buffer| is insufficient, this function returns |
104 // returns ERR_INVALID_ARGUMENT and does not write any data to |buffer|. | 110 // ERR_INVALID_ARGUMENT and does not write any data to |buffer|. |
105 NET_EXPORT_PRIVATE int WriteWebSocketFrameHeader( | 111 NET_EXPORT_PRIVATE int WriteWebSocketFrameHeader( |
106 const WebSocketFrameHeader& header, | 112 const WebSocketFrameHeader& header, |
107 const WebSocketMaskingKey* masking_key, | 113 const WebSocketMaskingKey* masking_key, |
108 char* buffer, | 114 char* buffer, |
109 int buffer_size); | 115 int buffer_size); |
110 | 116 |
111 // Generates a masking key suitable for use in a new WebSocket frame. | 117 // Generates a masking key suitable for use in a new WebSocket frame. |
112 NET_EXPORT_PRIVATE WebSocketMaskingKey GenerateWebSocketMaskingKey(); | 118 NET_EXPORT_PRIVATE WebSocketMaskingKey GenerateWebSocketMaskingKey(); |
113 | 119 |
114 // Masks WebSocket frame payload. | 120 // Masks WebSocket frame payload. |
(...skipping 10 matching lines...) Expand all Loading... |
125 // used for unmasking a WebSocket frame. | 131 // used for unmasking a WebSocket frame. |
126 NET_EXPORT_PRIVATE void MaskWebSocketFramePayload( | 132 NET_EXPORT_PRIVATE void MaskWebSocketFramePayload( |
127 const WebSocketMaskingKey& masking_key, | 133 const WebSocketMaskingKey& masking_key, |
128 uint64 frame_offset, | 134 uint64 frame_offset, |
129 char* data, | 135 char* data, |
130 int data_size); | 136 int data_size); |
131 | 137 |
132 } // namespace net | 138 } // namespace net |
133 | 139 |
134 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ | 140 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ |
OLD | NEW |