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

Unified Diff: net/websockets/websocket_frame_parser.cc

Issue 10824081: Add WebSocketError to indicate decoding failure reason (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ready for the next review Created 8 years, 5 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
Index: net/websockets/websocket_frame_parser.cc
diff --git a/net/websockets/websocket_frame_parser.cc b/net/websockets/websocket_frame_parser.cc
index edbd0e6fc82bf3baaa88662372474e1929cb107c..af6ca3e53475081582257446df00ec3c40e14942 100644
--- a/net/websockets/websocket_frame_parser.cc
+++ b/net/websockets/websocket_frame_parser.cc
@@ -36,7 +36,7 @@ namespace net {
WebSocketFrameParser::WebSocketFrameParser()
: current_read_pos_(0),
frame_offset_(0),
- failed_(false) {
+ websocket_error_(WEB_SOCKET_OK) {
std::fill(masking_key_,
masking_key_ + WebSocketFrameHeader::kMaskingKeyLength,
'\0');
@@ -49,7 +49,7 @@ bool WebSocketFrameParser::Decode(
const char* data,
size_t length,
ScopedVector<WebSocketFrameChunk>* frame_chunks) {
- if (failed_)
+ if (websocket_error_ != WEB_SOCKET_OK)
return false;
if (!length)
return true;
@@ -61,7 +61,7 @@ bool WebSocketFrameParser::Decode(
bool first_chunk = false;
if (!current_frame_header_.get()) {
DecodeFrameHeader();
- if (failed_)
+ if (websocket_error_ != WEB_SOCKET_OK)
return false;
// If frame header is incomplete, then carry over the remaining
// data to the next round of Decode().
@@ -121,8 +121,6 @@ void WebSocketFrameParser::DecodeFrameHeader() {
bool masked = (second_byte & kMaskBit) != 0;
uint64 payload_length = second_byte & kPayloadLengthMask;
- bool valid_length_format = true;
- bool message_too_big = false;
if (payload_length == kPayloadLengthWithTwoByteExtendedLengthField) {
if (end - current < 2)
return;
@@ -131,21 +129,19 @@ void WebSocketFrameParser::DecodeFrameHeader() {
current += 2;
payload_length = payload_length_16;
if (payload_length <= kMaxPayloadLengthWithoutExtendedLengthField)
- valid_length_format = false;
+ websocket_error_ = WEB_SOCKET_ERR_PROTOCOL_ERROR;
} else if (payload_length == kPayloadLengthWithEightByteExtendedLengthField) {
if (end - current < 8)
return;
ReadBigEndian(current, &payload_length);
current += 8;
if (payload_length <= kuint16max ||
- payload_length > static_cast<uint64>(kint64max)) {
- valid_length_format = false;
- }
- if (payload_length > static_cast<uint64>(kint32max))
- message_too_big = true;
+ payload_length > static_cast<uint64>(kint64max))
+ websocket_error_ = WEB_SOCKET_ERR_PROTOCOL_ERROR;
mmenke 2012/08/02 14:08:22 nit: Need brackets here, since the condition take
Takashi Toyoshima 2012/08/03 05:53:14 Done.
+ else if (payload_length > static_cast<uint64>(kint32max))
+ websocket_error_ = WEB_SOCKET_ERR_MESSAGE_TOO_BIG;
}
- if (!valid_length_format || message_too_big) {
- failed_ = true;
+ if (websocket_error_ != WEB_SOCKET_OK) {
buffer_.clear();
current_read_pos_ = 0;
current_frame_header_.reset();

Powered by Google App Engine
This is Rietveld 408576698