| 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 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't | 5 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't |
| 6 // constantly adding and subtracting header sizes; this is ugly and error- | 6 // constantly adding and subtracting header sizes; this is ugly and error- |
| 7 // prone. | 7 // prone. |
| 8 | 8 |
| 9 #include "net/spdy/spdy_framer.h" | 9 #include "net/spdy/spdy_framer.h" |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 const SpdyStreamId SpdyFramer::kInvalidStream = -1; | 54 const SpdyStreamId SpdyFramer::kInvalidStream = -1; |
| 55 const size_t SpdyFramer::kHeaderDataChunkMaxSize = 1024; | 55 const size_t SpdyFramer::kHeaderDataChunkMaxSize = 1024; |
| 56 // The size of the control frame buffer. Must be >= the minimum size of the | 56 // The size of the control frame buffer. Must be >= the minimum size of the |
| 57 // largest control frame, which is SYN_STREAM. See GetSynStreamMinimumSize() for | 57 // largest control frame, which is SYN_STREAM. See GetSynStreamMinimumSize() for |
| 58 // calculation details. | 58 // calculation details. |
| 59 const size_t SpdyFramer::kControlFrameBufferSize = 18; | 59 const size_t SpdyFramer::kControlFrameBufferSize = 18; |
| 60 | 60 |
| 61 #ifdef DEBUG_SPDY_STATE_CHANGES | 61 #ifdef DEBUG_SPDY_STATE_CHANGES |
| 62 #define CHANGE_STATE(newstate) \ | 62 #define CHANGE_STATE(newstate) \ |
| 63 do { \ | 63 do { \ |
| 64 LOG(INFO) << "Changing state from: " \ | 64 VLOG(0) << "Changing state from: " \ |
| 65 << StateToString(state_) \ | 65 << StateToString(state_) \ |
| 66 << " to " << StateToString(newstate) << "\n"; \ | 66 << " to " << StateToString(newstate) << "\n"; \ |
| 67 DCHECK(state_ != SPDY_ERROR); \ | 67 DCHECK(state_ != SPDY_ERROR); \ |
| 68 DCHECK_EQ(previous_state_, state_); \ | 68 DCHECK_EQ(previous_state_, state_); \ |
| 69 previous_state_ = state_; \ | 69 previous_state_ = state_; \ |
| 70 state_ = newstate; \ | 70 state_ = newstate; \ |
| 71 } while (false) | 71 } while (false) |
| 72 #else | 72 #else |
| 73 #define CHANGE_STATE(newstate) \ | 73 #define CHANGE_STATE(newstate) \ |
| 74 do { \ | 74 do { \ |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 if (current_frame_flags_ & DATA_FLAG_FIN) { | 645 if (current_frame_flags_ & DATA_FLAG_FIN) { |
| 646 visitor_->OnStreamFrameData( | 646 visitor_->OnStreamFrameData( |
| 647 current_frame_stream_id_, NULL, 0, true); | 647 current_frame_stream_id_, NULL, 0, true); |
| 648 } | 648 } |
| 649 CHANGE_STATE(SPDY_AUTO_RESET); | 649 CHANGE_STATE(SPDY_AUTO_RESET); |
| 650 } | 650 } |
| 651 } | 651 } |
| 652 } else if (version != spdy_version_) { | 652 } else if (version != spdy_version_) { |
| 653 // We check version before we check validity: version can never be | 653 // We check version before we check validity: version can never be |
| 654 // 'invalid', it can only be unsupported. | 654 // 'invalid', it can only be unsupported. |
| 655 DLOG(INFO) << "Unsupported SPDY version " << version | 655 DVLOG(0) << "Unsupported SPDY version " << version |
| 656 << " (expected " << spdy_version_ << ")"; | 656 << " (expected " << spdy_version_ << ")"; |
| 657 set_error(SPDY_UNSUPPORTED_VERSION); | 657 set_error(SPDY_UNSUPPORTED_VERSION); |
| 658 } else { | 658 } else { |
| 659 ProcessControlFrameHeader(control_frame_type_field); | 659 ProcessControlFrameHeader(control_frame_type_field); |
| 660 } | 660 } |
| 661 | 661 |
| 662 return original_len - len; | 662 return original_len - len; |
| 663 } | 663 } |
| 664 | 664 |
| 665 void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) { | 665 void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) { |
| 666 DCHECK_EQ(SPDY_NO_ERROR, error_code_); | 666 DCHECK_EQ(SPDY_NO_ERROR, error_code_); |
| 667 DCHECK_LE(GetControlFrameHeaderSize(), current_frame_buffer_length_); | 667 DCHECK_LE(GetControlFrameHeaderSize(), current_frame_buffer_length_); |
| 668 | 668 |
| 669 if (control_frame_type_field < FIRST_CONTROL_TYPE || | 669 if (control_frame_type_field < FIRST_CONTROL_TYPE || |
| 670 control_frame_type_field > LAST_CONTROL_TYPE) { | 670 control_frame_type_field > LAST_CONTROL_TYPE) { |
| 671 set_error(SPDY_INVALID_CONTROL_FRAME); | 671 set_error(SPDY_INVALID_CONTROL_FRAME); |
| 672 return; | 672 return; |
| 673 } | 673 } |
| 674 | 674 |
| 675 current_frame_type_ = static_cast<SpdyFrameType>(control_frame_type_field); | 675 current_frame_type_ = static_cast<SpdyFrameType>(control_frame_type_field); |
| 676 | 676 |
| 677 if (current_frame_type_ == NOOP) { | 677 if (current_frame_type_ == NOOP) { |
| 678 DLOG(INFO) << "NOOP control frame found. Ignoring."; | 678 DVLOG(0) << "NOOP control frame found. Ignoring."; |
| 679 CHANGE_STATE(SPDY_AUTO_RESET); | 679 CHANGE_STATE(SPDY_AUTO_RESET); |
| 680 return; | 680 return; |
| 681 } | 681 } |
| 682 | 682 |
| 683 // Do some sanity checking on the control frame sizes and flags. | 683 // Do some sanity checking on the control frame sizes and flags. |
| 684 switch (current_frame_type_) { | 684 switch (current_frame_type_) { |
| 685 case SYN_STREAM: | 685 case SYN_STREAM: |
| 686 if (current_frame_length_ < GetSynStreamMinimumSize()) { | 686 if (current_frame_length_ < GetSynStreamMinimumSize()) { |
| 687 set_error(SPDY_INVALID_CONTROL_FRAME); | 687 set_error(SPDY_INVALID_CONTROL_FRAME); |
| 688 } else if (current_frame_flags_ & | 688 } else if (current_frame_flags_ & |
| (...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1510 size_t SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data, | 1510 size_t SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data, |
| 1511 size_t header_length, | 1511 size_t header_length, |
| 1512 SpdyHeaderBlock* block) const { | 1512 SpdyHeaderBlock* block) const { |
| 1513 SpdyFrameReader reader(header_data, header_length); | 1513 SpdyFrameReader reader(header_data, header_length); |
| 1514 | 1514 |
| 1515 // Read number of headers. | 1515 // Read number of headers. |
| 1516 uint32 num_headers; | 1516 uint32 num_headers; |
| 1517 if (spdy_version_ < 3) { | 1517 if (spdy_version_ < 3) { |
| 1518 uint16 temp; | 1518 uint16 temp; |
| 1519 if (!reader.ReadUInt16(&temp)) { | 1519 if (!reader.ReadUInt16(&temp)) { |
| 1520 DLOG(INFO) << "Unable to read number of headers."; | 1520 DVLOG(0) << "Unable to read number of headers."; |
| 1521 return 0; | 1521 return 0; |
| 1522 } | 1522 } |
| 1523 num_headers = temp; | 1523 num_headers = temp; |
| 1524 } else { | 1524 } else { |
| 1525 if (!reader.ReadUInt32(&num_headers)) { | 1525 if (!reader.ReadUInt32(&num_headers)) { |
| 1526 DLOG(INFO) << "Unable to read number of headers."; | 1526 DVLOG(0) << "Unable to read number of headers."; |
| 1527 return 0; | 1527 return 0; |
| 1528 } | 1528 } |
| 1529 } | 1529 } |
| 1530 | 1530 |
| 1531 // Read each header. | 1531 // Read each header. |
| 1532 for (uint32 index = 0; index < num_headers; ++index) { | 1532 for (uint32 index = 0; index < num_headers; ++index) { |
| 1533 base::StringPiece temp; | 1533 base::StringPiece temp; |
| 1534 | 1534 |
| 1535 // Read header name. | 1535 // Read header name. |
| 1536 if ((spdy_version_ < 3) ? !reader.ReadStringPiece16(&temp) | 1536 if ((spdy_version_ < 3) ? !reader.ReadStringPiece16(&temp) |
| 1537 : !reader.ReadStringPiece32(&temp)) { | 1537 : !reader.ReadStringPiece32(&temp)) { |
| 1538 DLOG(INFO) << "Unable to read header name (" << index + 1 << " of " | 1538 DVLOG(0) << "Unable to read header name (" << index + 1 << " of " |
| 1539 << num_headers << ")."; | 1539 << num_headers << ")."; |
| 1540 return 0; | 1540 return 0; |
| 1541 } | 1541 } |
| 1542 std::string name = temp.as_string(); | 1542 std::string name = temp.as_string(); |
| 1543 | 1543 |
| 1544 // Read header value. | 1544 // Read header value. |
| 1545 if ((spdy_version_ < 3) ? !reader.ReadStringPiece16(&temp) | 1545 if ((spdy_version_ < 3) ? !reader.ReadStringPiece16(&temp) |
| 1546 : !reader.ReadStringPiece32(&temp)) { | 1546 : !reader.ReadStringPiece32(&temp)) { |
| 1547 DLOG(INFO) << "Unable to read header value (" << index + 1 << " of " | 1547 DVLOG(0) << "Unable to read header value (" << index + 1 << " of " |
| 1548 << num_headers << ")."; | 1548 << num_headers << ")."; |
| 1549 return 0; | 1549 return 0; |
| 1550 } | 1550 } |
| 1551 std::string value = temp.as_string(); | 1551 std::string value = temp.as_string(); |
| 1552 | 1552 |
| 1553 // Ensure no duplicates. | 1553 // Ensure no duplicates. |
| 1554 if (block->find(name) != block->end()) { | 1554 if (block->find(name) != block->end()) { |
| 1555 DLOG(INFO) << "Duplicate header '" << name << "' (" << index + 1 << " of " | 1555 DVLOG(0) << "Duplicate header '" << name << "' (" << index + 1 << " of " |
| 1556 << num_headers << ")."; | 1556 << num_headers << ")."; |
| 1557 return 0; | 1557 return 0; |
| 1558 } | 1558 } |
| 1559 | 1559 |
| 1560 // Store header. | 1560 // Store header. |
| 1561 (*block)[name] = value; | 1561 (*block)[name] = value; |
| 1562 } | 1562 } |
| 1563 return reader.GetBytesConsumed(); | 1563 return reader.GetBytesConsumed(); |
| 1564 } | 1564 } |
| 1565 | 1565 |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2352 builder->Seek(compressed_size); | 2352 builder->Seek(compressed_size); |
| 2353 builder->RewriteLength(*this); | 2353 builder->RewriteLength(*this); |
| 2354 | 2354 |
| 2355 pre_compress_bytes.Add(uncompressed_len); | 2355 pre_compress_bytes.Add(uncompressed_len); |
| 2356 post_compress_bytes.Add(compressed_size); | 2356 post_compress_bytes.Add(compressed_size); |
| 2357 | 2357 |
| 2358 compressed_frames.Increment(); | 2358 compressed_frames.Increment(); |
| 2359 } | 2359 } |
| 2360 | 2360 |
| 2361 } // namespace net | 2361 } // namespace net |
| OLD | NEW |