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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 // You need to look at |final_chunk| member variable to detect the end of a | 52 // You need to look at |final_chunk| member variable to detect the end of a |
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. |
mmenke
2012/05/21 15:08:37
nit: Think that we should have a note that this i
Yuta Kitamura
2012/05/22 10:29:35
Done.
| |
63 struct NET_EXPORT_PRIVATE WebSocketFrameChunk { | 63 struct NET_EXPORT_PRIVATE WebSocketFrameChunk { |
64 WebSocketFrameChunk(); | 64 WebSocketFrameChunk(); |
65 ~WebSocketFrameChunk(); | 65 ~WebSocketFrameChunk(); |
66 | 66 |
67 // Non-null |header| is provided only if this chunk is the first part of | 67 // Non-null |header| is provided only if this chunk is the first part of |
68 // a series of chunks. | 68 // a series of chunks. |
69 scoped_ptr<WebSocketFrameHeader> header; | 69 scoped_ptr<WebSocketFrameHeader> header; |
70 | 70 |
71 // Indicates this part is the last chunk of a frame. | 71 // Indicates this part is the last chunk of a frame. |
72 bool final_chunk; | 72 bool final_chunk; |
73 | 73 |
74 // |data| is always unmasked even if the frame is masked. | 74 // |data| is always unmasked even if the frame is masked. |
75 std::vector<char> data; | 75 std::vector<char> data; |
76 }; | 76 }; |
77 | 77 |
78 // Writes wire format of a WebSocket frame header into |output|. | |
79 // | |
80 // WebSocket frame format is defined at: | |
81 // <http://tools.ietf.org/html/rfc6455#section-5.2>. This function writes | |
82 // everything but payload data in a WebSocket frame to |output|. | |
83 // | |
84 // If |header->masked| is true, |masking_key| must point to four-byte data | |
85 // representing a masking key for that frame (possibly generated by | |
86 // GenerateWebSocketMaskingKey() function below). Otherwise, |masking_key| | |
87 // must be NULL. | |
88 NET_EXPORT_PRIVATE void WriteWebSocketFrameHeader( | |
89 const WebSocketFrameHeader* header, | |
mmenke
2012/05/21 15:08:37
Suggest you make this const WebSocketFrameHeader&
Yuta Kitamura
2012/05/22 10:29:35
Done.
| |
90 const char* masking_key, | |
91 std::vector<char>* output); | |
92 | |
93 // Generates a masking key suitable for use in a new WebSocket frame. | |
94 // | |
95 // |masking_key| should be non-NULL value pointing four-byte | |
96 // (== kMaskingKeyLength bytes) data. The generated masking key will be written | |
97 // to that buffer. | |
98 NET_EXPORT_PRIVATE void GenearteWebSocketMaskingKey(char* masking_key); | |
mmenke
2012/05/21 15:08:37
nit: GenearteWebSocketMaskingKey -> GenerateWebSoc
mmenke
2012/05/21 15:08:37
I suggest you make a struct for masking keys, so t
Yuta Kitamura
2012/05/22 10:29:35
Introduced a new struct WebSocketMaskingKey. Chang
Yuta Kitamura
2012/05/22 10:29:35
Doh! Fixed.
| |
99 | |
100 // Masks WebSocket frame payload. | |
101 // | |
102 // A browser must mask every WebSocket frame by XOR'ing the frame payload | |
mmenke
2012/05/21 15:08:37
nit: Suggest "client" instead of "browser", as pe
Yuta Kitamura
2012/05/22 10:29:35
Done.
| |
103 // with four-byte random data (masking key). This function applies the masking | |
104 // to the given payload data. | |
105 // | |
106 // This function masks |frame_data| with |masking_key|, assuming |frame_data| | |
107 // is partial data starting from |frame_offset| bytes from the beginning of | |
108 // the payload data. | |
mmenke
2012/05/21 15:08:37
Should make clear that this must not be called whe
Yuta Kitamura
2012/05/22 10:29:35
Resolved by changing the type of |masking_key| to
| |
109 NET_EXPORT_PRIVATE void MaskWebSocketFramePayload( | |
110 const char* masking_key, | |
111 uint64 frame_offset, | |
112 std::vector<char>* frame_data); | |
113 | |
78 } // namespace net | 114 } // namespace net |
79 | 115 |
80 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ | 116 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ |
OLD | NEW |