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

Side by Side Diff: net/websockets/websocket_frame_parser.h

Issue 10824081: Add WebSocketError to indicate decoding failure reason (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_PARSER_H_ 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_FRAME_PARSER_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_FRAME_PARSER_H_ 6 #define NET_WEBSOCKETS_WEBSOCKET_FRAME_PARSER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 23 matching lines...) Expand all
34 // any more data and future invocations of Decode() will simply return false. 34 // any more data and future invocations of Decode() will simply return false.
35 // 35 //
36 // Payload data of parsed WebSocket frames may be incomplete; see comments in 36 // Payload data of parsed WebSocket frames may be incomplete; see comments in
37 // websocket_frame.h for more details. 37 // websocket_frame.h for more details.
38 bool Decode(const char* data, 38 bool Decode(const char* data,
39 size_t length, 39 size_t length,
40 ScopedVector<WebSocketFrameChunk>* frame_chunks); 40 ScopedVector<WebSocketFrameChunk>* frame_chunks);
41 41
42 // Returns true if the parser has ever failed to decode a WebSocket frame. 42 // Returns true if the parser has ever failed to decode a WebSocket frame.
43 // TODO(yutak): Provide human-readable description of failure. 43 // TODO(yutak): Provide human-readable description of failure.
44 bool failed() const { return failed_; } 44 bool failed() const { return failed_; }
mmenke 2012/08/01 14:44:59 Do we still need this? If so, think we should be
Takashi Toyoshima 2012/08/02 08:11:35 Ah, that is right. I'll remove this function and m
45 WebSocketError error_code() const { return error_code_; }
mmenke 2012/08/01 14:44:59 Suggest calling this websocket_error instead, to m
Takashi Toyoshima 2012/08/02 08:11:35 Done.
45 46
46 private: 47 private:
47 // Tries to decode a frame header from |current_read_pos_|. 48 // Tries to decode a frame header from |current_read_pos_|.
48 // If successful, this function updates |current_read_pos_|, 49 // If successful, this function updates |current_read_pos_|,
49 // |current_frame_header_|, and |masking_key_| (if available). 50 // |current_frame_header_|, and |masking_key_| (if available).
50 // This function may set |failed_| to true if it observes a corrupt frame. 51 // This function may set |failed_| to true if it observes a corrupt frame.
51 // If there is not enough data in the remaining buffer to parse a frame 52 // If there is not enough data in the remaining buffer to parse a frame
52 // header, this function returns without doing anything. 53 // header, this function returns without doing anything.
53 void DecodeFrameHeader(); 54 void DecodeFrameHeader();
54 55
(...skipping 13 matching lines...) Expand all
68 69
69 // Frame header and masking key of the current frame. 70 // Frame header and masking key of the current frame.
70 // |masking_key_| is filled with zeros if the current frame is not masked. 71 // |masking_key_| is filled with zeros if the current frame is not masked.
71 scoped_ptr<WebSocketFrameHeader> current_frame_header_; 72 scoped_ptr<WebSocketFrameHeader> current_frame_header_;
72 char masking_key_[WebSocketFrameHeader::kMaskingKeyLength]; 73 char masking_key_[WebSocketFrameHeader::kMaskingKeyLength];
73 74
74 // Amount of payload data read so far for the current frame. 75 // Amount of payload data read so far for the current frame.
75 uint64 frame_offset_; 76 uint64 frame_offset_;
76 77
77 bool failed_; 78 bool failed_;
79 WebSocketError error_code_;
78 80
79 DISALLOW_COPY_AND_ASSIGN(WebSocketFrameParser); 81 DISALLOW_COPY_AND_ASSIGN(WebSocketFrameParser);
80 }; 82 };
81 83
82 } // namespace net 84 } // namespace net
83 85
84 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_PARSER_H_ 86 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698