| 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 #include "net/websockets/websocket_frame_parser.h" | 5 #include "net/websockets/websocket_frame_parser.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/big_endian.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 15 #include "net/base/big_endian.h" | |
| 16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 17 #include "net/websockets/websocket_frame.h" | 17 #include "net/websockets/websocket_frame.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const uint8 kFinalBit = 0x80; | 21 const uint8 kFinalBit = 0x80; |
| 22 const uint8 kReserved1Bit = 0x40; | 22 const uint8 kReserved1Bit = 0x40; |
| 23 const uint8 kReserved2Bit = 0x20; | 23 const uint8 kReserved2Bit = 0x20; |
| 24 const uint8 kReserved3Bit = 0x10; | 24 const uint8 kReserved3Bit = 0x10; |
| 25 const uint8 kOpCodeMask = 0xF; | 25 const uint8 kOpCodeMask = 0xF; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 bool reserved2 = (first_byte & kReserved2Bit) != 0; | 117 bool reserved2 = (first_byte & kReserved2Bit) != 0; |
| 118 bool reserved3 = (first_byte & kReserved3Bit) != 0; | 118 bool reserved3 = (first_byte & kReserved3Bit) != 0; |
| 119 OpCode opcode = first_byte & kOpCodeMask; | 119 OpCode opcode = first_byte & kOpCodeMask; |
| 120 | 120 |
| 121 bool masked = (second_byte & kMaskBit) != 0; | 121 bool masked = (second_byte & kMaskBit) != 0; |
| 122 uint64 payload_length = second_byte & kPayloadLengthMask; | 122 uint64 payload_length = second_byte & kPayloadLengthMask; |
| 123 if (payload_length == kPayloadLengthWithTwoByteExtendedLengthField) { | 123 if (payload_length == kPayloadLengthWithTwoByteExtendedLengthField) { |
| 124 if (end - current < 2) | 124 if (end - current < 2) |
| 125 return; | 125 return; |
| 126 uint16 payload_length_16; | 126 uint16 payload_length_16; |
| 127 ReadBigEndian(current, &payload_length_16); | 127 base::ReadBigEndian(current, &payload_length_16); |
| 128 current += 2; | 128 current += 2; |
| 129 payload_length = payload_length_16; | 129 payload_length = payload_length_16; |
| 130 if (payload_length <= kMaxPayloadLengthWithoutExtendedLengthField) | 130 if (payload_length <= kMaxPayloadLengthWithoutExtendedLengthField) |
| 131 websocket_error_ = kWebSocketErrorProtocolError; | 131 websocket_error_ = kWebSocketErrorProtocolError; |
| 132 } else if (payload_length == kPayloadLengthWithEightByteExtendedLengthField) { | 132 } else if (payload_length == kPayloadLengthWithEightByteExtendedLengthField) { |
| 133 if (end - current < 8) | 133 if (end - current < 8) |
| 134 return; | 134 return; |
| 135 ReadBigEndian(current, &payload_length); | 135 base::ReadBigEndian(current, &payload_length); |
| 136 current += 8; | 136 current += 8; |
| 137 if (payload_length <= kuint16max || | 137 if (payload_length <= kuint16max || |
| 138 payload_length > static_cast<uint64>(kint64max)) { | 138 payload_length > static_cast<uint64>(kint64max)) { |
| 139 websocket_error_ = kWebSocketErrorProtocolError; | 139 websocket_error_ = kWebSocketErrorProtocolError; |
| 140 } else if (payload_length > static_cast<uint64>(kint32max)) { | 140 } else if (payload_length > static_cast<uint64>(kint32max)) { |
| 141 websocket_error_ = kWebSocketErrorMessageTooBig; | 141 websocket_error_ = kWebSocketErrorMessageTooBig; |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 if (websocket_error_ != kWebSocketNormalClosure) { | 144 if (websocket_error_ != kWebSocketNormalClosure) { |
| 145 buffer_.clear(); | 145 buffer_.clear(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 if (frame_offset_ == current_frame_header_->payload_length) { | 203 if (frame_offset_ == current_frame_header_->payload_length) { |
| 204 frame_chunk->final_chunk = true; | 204 frame_chunk->final_chunk = true; |
| 205 current_frame_header_.reset(); | 205 current_frame_header_.reset(); |
| 206 frame_offset_ = 0; | 206 frame_offset_ = 0; |
| 207 } | 207 } |
| 208 | 208 |
| 209 return frame_chunk.Pass(); | 209 return frame_chunk.Pass(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 } // namespace net | 212 } // namespace net |
| OLD | NEW |