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/spdy/spdy_framer.h" | 5 #include "net/spdy/spdy_framer.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/stats_counters.h" | 9 #include "base/metrics/stats_counters.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 627 |
628 uint16 control_frame_type_field = DATA; | 628 uint16 control_frame_type_field = DATA; |
629 // ProcessControlFrameHeader() will set current_frame_type_ to the | 629 // ProcessControlFrameHeader() will set current_frame_type_ to the |
630 // correct value if this is a valid control frame. | 630 // correct value if this is a valid control frame. |
631 current_frame_type_ = DATA; | 631 current_frame_type_ = DATA; |
632 if (protocol_version() <= SPDY3) { | 632 if (protocol_version() <= SPDY3) { |
633 bool successful_read = reader->ReadUInt16(&version); | 633 bool successful_read = reader->ReadUInt16(&version); |
634 DCHECK(successful_read); | 634 DCHECK(successful_read); |
635 is_control_frame = (version & kControlFlagMask) != 0; | 635 is_control_frame = (version & kControlFlagMask) != 0; |
636 version &= ~kControlFlagMask; // Only valid for control frames. | 636 version &= ~kControlFlagMask; // Only valid for control frames. |
637 if (is_control_frame && | |
638 version >= SpdyConstants::SerializeMajorVersion(SPDY_MIN_VERSION) && | |
639 version <= SpdyConstants::SerializeMajorVersion(SPDY_MAX_VERSION)) { | |
640 version = SpdyConstants::ParseMajorVersion(version); | |
641 } | |
642 | |
643 if (is_control_frame) { | 637 if (is_control_frame) { |
| 638 // We check version before we check validity: version can never be |
| 639 // 'invalid', it can only be unsupported. |
| 640 if (version < SpdyConstants::SerializeMajorVersion(SPDY_MIN_VERSION) || |
| 641 version > SpdyConstants::SerializeMajorVersion(SPDY_MAX_VERSION) || |
| 642 SpdyConstants::ParseMajorVersion(version) != protocol_version()) { |
| 643 // Version does not match the version the framer was initialized with. |
| 644 DVLOG(1) << "Unsupported SPDY version " |
| 645 << version |
| 646 << " (expected " << protocol_version() << ")"; |
| 647 set_error(SPDY_UNSUPPORTED_VERSION); |
| 648 return 0; |
| 649 } else { |
| 650 // Convert version from wire format to SpdyMajorVersion. |
| 651 version = SpdyConstants::ParseMajorVersion(version); |
| 652 } |
644 // We check control_frame_type_field's validity in | 653 // We check control_frame_type_field's validity in |
645 // ProcessControlFrameHeader(). | 654 // ProcessControlFrameHeader(). |
646 successful_read = reader->ReadUInt16(&control_frame_type_field); | 655 successful_read = reader->ReadUInt16(&control_frame_type_field); |
647 } else { | 656 } else { |
648 reader->Rewind(); | 657 reader->Rewind(); |
649 successful_read = reader->ReadUInt31(¤t_frame_stream_id_); | 658 successful_read = reader->ReadUInt31(¤t_frame_stream_id_); |
650 } | 659 } |
651 DCHECK(successful_read); | 660 DCHECK(successful_read); |
652 | 661 |
653 successful_read = reader->ReadUInt8(¤t_frame_flags_); | 662 successful_read = reader->ReadUInt8(¤t_frame_flags_); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 CHANGE_STATE(SPDY_READ_PADDING_LENGTH); | 758 CHANGE_STATE(SPDY_READ_PADDING_LENGTH); |
750 } else { | 759 } else { |
751 // Empty data frame. | 760 // Empty data frame. |
752 if (current_frame_flags_ & DATA_FLAG_FIN) { | 761 if (current_frame_flags_ & DATA_FLAG_FIN) { |
753 visitor_->OnStreamFrameData( | 762 visitor_->OnStreamFrameData( |
754 current_frame_stream_id_, NULL, 0, true); | 763 current_frame_stream_id_, NULL, 0, true); |
755 } | 764 } |
756 CHANGE_STATE(SPDY_AUTO_RESET); | 765 CHANGE_STATE(SPDY_AUTO_RESET); |
757 } | 766 } |
758 } | 767 } |
759 } else if (version != protocol_version()) { | |
760 // We check version before we check validity: version can never be | |
761 // 'invalid', it can only be unsupported. | |
762 DVLOG(1) << "Unsupported SPDY version " | |
763 << version | |
764 << " (expected " << protocol_version() << ")"; | |
765 set_error(SPDY_UNSUPPORTED_VERSION); | |
766 } else { | 768 } else { |
767 ProcessControlFrameHeader(control_frame_type_field); | 769 ProcessControlFrameHeader(control_frame_type_field); |
768 } | 770 } |
769 | 771 |
770 return original_len - len; | 772 return original_len - len; |
771 } | 773 } |
772 | 774 |
773 void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) { | 775 void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) { |
774 DCHECK_EQ(SPDY_NO_ERROR, error_code_); | 776 DCHECK_EQ(SPDY_NO_ERROR, error_code_); |
775 DCHECK_LE(GetControlFrameHeaderSize(), current_frame_buffer_length_); | 777 DCHECK_LE(GetControlFrameHeaderSize(), current_frame_buffer_length_); |
(...skipping 2210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2986 builder->Seek(compressed_size); | 2988 builder->Seek(compressed_size); |
2987 builder->RewriteLength(*this); | 2989 builder->RewriteLength(*this); |
2988 | 2990 |
2989 pre_compress_bytes.Add(uncompressed_len); | 2991 pre_compress_bytes.Add(uncompressed_len); |
2990 post_compress_bytes.Add(compressed_size); | 2992 post_compress_bytes.Add(compressed_size); |
2991 | 2993 |
2992 compressed_frames.Increment(); | 2994 compressed_frames.Increment(); |
2993 } | 2995 } |
2994 | 2996 |
2995 } // namespace net | 2997 } // namespace net |
OLD | NEW |