Chromium Code Reviews| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 // series of chunk objects of a WebSocket frame. | 53 // series of chunk objects of a WebSocket frame. |
| 54 // | 54 // |
| 55 // Frame dissection is necessary to handle WebSocket frame stream containing | 55 // Frame dissection is necessary to handle WebSocket frame stream containing |
| 56 // abritrarily large frames in the browser process. Because the server may send | 56 // abritrarily large frames in the browser process. Because the server may send |
| 57 // a huge frame that doesn't fit in the memory, we cannot store the entire | 57 // a huge frame that doesn't fit in the memory, we cannot store the entire |
| 58 // payload data in the memory. | 58 // payload data in the memory. |
| 59 // | 59 // |
| 60 // Users of this struct should treat WebSocket frames as a data stream; it's | 60 // Users of this struct should treat WebSocket frames as a data stream; it's |
| 61 // important to keep the frame data flowing, especially in the browser process. | 61 // important to keep the frame data flowing, especially in the browser process. |
| 62 // Users should not let the data stuck somewhere in the pipeline. | 62 // Users should not let the data stuck somewhere in the pipeline. |
| 63 // | |
| 64 // This struct is used for reading WebSocket frame data (created by | |
| 65 // WebSocketFrameParser). To construct WebSocket frames, use functions below. | |
| 63 struct NET_EXPORT_PRIVATE WebSocketFrameChunk { | 66 struct NET_EXPORT_PRIVATE WebSocketFrameChunk { |
| 64 WebSocketFrameChunk(); | 67 WebSocketFrameChunk(); |
| 65 ~WebSocketFrameChunk(); | 68 ~WebSocketFrameChunk(); |
| 66 | 69 |
| 67 // Non-null |header| is provided only if this chunk is the first part of | 70 // Non-null |header| is provided only if this chunk is the first part of |
| 68 // a series of chunks. | 71 // a series of chunks. |
| 69 scoped_ptr<WebSocketFrameHeader> header; | 72 scoped_ptr<WebSocketFrameHeader> header; |
| 70 | 73 |
| 71 // Indicates this part is the last chunk of a frame. | 74 // Indicates this part is the last chunk of a frame. |
| 72 bool final_chunk; | 75 bool final_chunk; |
| 73 | 76 |
| 74 // |data| is always unmasked even if the frame is masked. | 77 // |data| is always unmasked even if the frame is masked. |
| 75 std::vector<char> data; | 78 std::vector<char> data; |
| 76 }; | 79 }; |
| 77 | 80 |
| 81 // Contains four-byte data representing "masking key" of WebSocket frames. | |
| 82 struct WebSocketMaskingKey { | |
| 83 char key[WebSocketFrameHeader::kMaskingKeyLength]; | |
| 84 }; | |
|
mmenke
2012/05/22 17:12:41
Think this should also be used in net/websockets/w
Yuta Kitamura
2012/06/06 18:06:48
Yeah I'm going to do that later.
| |
| 85 | |
| 86 // Writes wire format of a WebSocket frame header into |output|. | |
| 87 // | |
| 88 // WebSocket frame format is defined at: | |
| 89 // <http://tools.ietf.org/html/rfc6455#section-5.2>. This function writes | |
| 90 // everything but payload data in a WebSocket frame to |output|. | |
| 91 // | |
| 92 // If |header->masked| is true, |masking_key| must point to a valid | |
| 93 // WebSocketMaskingKey object containing the masking key for that frame | |
| 94 // (possibly generated by GenerateWebSocketMaskingKey() function below). | |
| 95 // Otherwise, |masking_key| must be NULL. | |
| 96 NET_EXPORT_PRIVATE void WriteWebSocketFrameHeader( | |
| 97 const WebSocketFrameHeader& header, | |
| 98 const WebSocketMaskingKey* masking_key, | |
| 99 std::vector<char>* output); | |
| 100 | |
| 101 // Generates a masking key suitable for use in a new WebSocket frame. | |
| 102 NET_EXPORT_PRIVATE WebSocketMaskingKey GenerateWebSocketMaskingKey(); | |
| 103 | |
| 104 // Masks WebSocket frame payload. | |
| 105 // | |
| 106 // A client must mask every WebSocket frame by XOR'ing the frame payload | |
| 107 // with four-byte random data (masking key). This function applies the masking | |
| 108 // to the given payload data. | |
| 109 // | |
| 110 // This function masks |frame_data| with |masking_key|, assuming |frame_data| | |
| 111 // is partial data starting from |frame_offset| bytes from the beginning of | |
| 112 // the payload data. | |
| 113 NET_EXPORT_PRIVATE void MaskWebSocketFramePayload( | |
| 114 const WebSocketMaskingKey& masking_key, | |
| 115 uint64 frame_offset, | |
| 116 std::vector<char>* frame_data); | |
| 117 | |
| 78 } // namespace net | 118 } // namespace net |
| 79 | 119 |
| 80 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ | 120 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ |
| OLD | NEW |