OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/server/web_socket_encoder.h" | 5 #include "net/server/web_socket_encoder.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/stringprintf.h" | |
15 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
16 #include "net/websockets/websocket_deflate_parameters.h" | 15 #include "net/websockets/websocket_deflate_parameters.h" |
17 #include "net/websockets/websocket_extension.h" | 16 #include "net/websockets/websocket_extension.h" |
18 #include "net/websockets/websocket_extension_parser.h" | 17 #include "net/websockets/websocket_extension_parser.h" |
19 | 18 |
20 namespace net { | 19 namespace net { |
21 | 20 |
22 const char WebSocketEncoder::kClientExtensions[] = | 21 const char WebSocketEncoder::kClientExtensions[] = |
23 "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits"; | 22 "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits"; |
24 | 23 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 default: | 89 default: |
91 return WebSocket::FRAME_ERROR; | 90 return WebSocket::FRAME_ERROR; |
92 } | 91 } |
93 | 92 |
94 if (client_frame && !masked) // In Hybi-17 spec client MUST mask its frame. | 93 if (client_frame && !masked) // In Hybi-17 spec client MUST mask its frame. |
95 return WebSocket::FRAME_ERROR; | 94 return WebSocket::FRAME_ERROR; |
96 | 95 |
97 uint64_t payload_length64 = second_byte & kPayloadLengthMask; | 96 uint64_t payload_length64 = second_byte & kPayloadLengthMask; |
98 if (payload_length64 > kMaxSingleBytePayloadLength) { | 97 if (payload_length64 > kMaxSingleBytePayloadLength) { |
99 int extended_payload_length_size; | 98 int extended_payload_length_size; |
100 if (payload_length64 == kTwoBytePayloadLengthField) | 99 if (payload_length64 == kTwoBytePayloadLengthField) { |
101 extended_payload_length_size = 2; | 100 extended_payload_length_size = 2; |
102 else { | 101 } else { |
103 DCHECK(payload_length64 == kEightBytePayloadLengthField); | 102 DCHECK(payload_length64 == kEightBytePayloadLengthField); |
104 extended_payload_length_size = 8; | 103 extended_payload_length_size = 8; |
105 } | 104 } |
106 if (buffer_end - p < extended_payload_length_size) | 105 if (buffer_end - p < extended_payload_length_size) |
107 return WebSocket::FRAME_INCOMPLETE; | 106 return WebSocket::FRAME_INCOMPLETE; |
108 payload_length64 = 0; | 107 payload_length64 = 0; |
109 for (int i = 0; i < extended_payload_length_size; ++i) { | 108 for (int i = 0; i < extended_payload_length_size; ++i) { |
110 payload_length64 <<= 8; | 109 payload_length64 <<= 8; |
111 payload_length64 |= static_cast<unsigned char>(*p++); | 110 payload_length64 |= static_cast<unsigned char>(*p++); |
112 } | 111 } |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 return false; | 345 return false; |
347 scoped_refptr<IOBufferWithSize> buffer = | 346 scoped_refptr<IOBufferWithSize> buffer = |
348 deflater_->GetOutput(deflater_->CurrentOutputSize()); | 347 deflater_->GetOutput(deflater_->CurrentOutputSize()); |
349 if (!buffer.get()) | 348 if (!buffer.get()) |
350 return false; | 349 return false; |
351 *output = std::string(buffer->data(), buffer->size()); | 350 *output = std::string(buffer->data(), buffer->size()); |
352 return true; | 351 return true; |
353 } | 352 } |
354 | 353 |
355 } // namespace net | 354 } // namespace net |
OLD | NEW |