Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(915)

Unified Diff: net/websockets/websocket_frame.h

Issue 10384180: Add functions used for building WebSocket frame data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Matt's comment on Patch Set 6. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/net.gyp ('k') | net/websockets/websocket_frame.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/websockets/websocket_frame.h
diff --git a/net/websockets/websocket_frame.h b/net/websockets/websocket_frame.h
index 593d439481282b023397b241e08d9fa2975d9942..8903c9cdc3c8541613048d18035367b8da435842 100644
--- a/net/websockets/websocket_frame.h
+++ b/net/websockets/websocket_frame.h
@@ -60,6 +60,9 @@ struct NET_EXPORT_PRIVATE WebSocketFrameHeader {
// Users of this struct should treat WebSocket frames as a data stream; it's
// important to keep the frame data flowing, especially in the browser process.
// Users should not let the data stuck somewhere in the pipeline.
+//
+// This struct is used for reading WebSocket frame data (created by
+// WebSocketFrameParser). To construct WebSocket frames, use functions below.
struct NET_EXPORT_PRIVATE WebSocketFrameChunk {
WebSocketFrameChunk();
~WebSocketFrameChunk();
@@ -75,6 +78,54 @@ struct NET_EXPORT_PRIVATE WebSocketFrameChunk {
std::vector<char> data;
};
+// Contains four-byte data representing "masking key" of WebSocket frames.
+struct WebSocketMaskingKey {
+ char key[WebSocketFrameHeader::kMaskingKeyLength];
+};
+
+// Writes wire format of a WebSocket frame header into |output|, and returns
+// the number of bytes written.
+//
+// WebSocket frame format is defined at:
+// <http://tools.ietf.org/html/rfc6455#section-5.2>. This function writes
+// everything but payload data in a WebSocket frame to |buffer|.
+//
+// If |header->masked| is true, |masking_key| must point to a valid
+// WebSocketMaskingKey object containing the masking key for that frame
+// (possibly generated by GenerateWebSocketMaskingKey() function below).
+// Otherwise, |masking_key| must be NULL.
+//
+// |buffer| should have enough size to contain the frame header. Size of a
+// frame header varies from 2 bytes to 14 bytes depending on the payload length
+// and maskedness. If the size of |buffer| is insufficient, this function
+// returns ERR_INVALID_ARGUMENT and does not write any data to |buffer|.
+NET_EXPORT_PRIVATE int WriteWebSocketFrameHeader(
+ const WebSocketFrameHeader& header,
+ const WebSocketMaskingKey* masking_key,
+ char* buffer,
+ int buffer_size);
+
+// Generates a masking key suitable for use in a new WebSocket frame.
+NET_EXPORT_PRIVATE WebSocketMaskingKey GenerateWebSocketMaskingKey();
+
+// Masks WebSocket frame payload.
+//
+// A client must mask every WebSocket frame by XOR'ing the frame payload
+// with four-byte random data (masking key). This function applies the masking
+// to the given payload data.
+//
+// This function masks |data| with |masking_key|, assuming |data| is partial
+// data starting from |frame_offset| bytes from the beginning of the payload
+// data.
+//
+// Since frame masking is a reversible operation, this function can also be
+// used for unmasking a WebSocket frame.
+NET_EXPORT_PRIVATE void MaskWebSocketFramePayload(
+ const WebSocketMaskingKey& masking_key,
+ uint64 frame_offset,
+ char* data,
+ int data_size);
+
} // namespace net
#endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_
« no previous file with comments | « net/net.gyp ('k') | net/websockets/websocket_frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698