Index: net/spdy/spdy_framer.cc |
diff --git a/net/spdy/spdy_framer.cc b/net/spdy/spdy_framer.cc |
index 4c6cdf8ad26da02611493da8c52a22c4c0ec1be2..e74a0564cd3d0c9422969fa8b43f0f25f0a1d048 100644 |
--- a/net/spdy/spdy_framer.cc |
+++ b/net/spdy/spdy_framer.cc |
@@ -81,9 +81,9 @@ const size_t SpdyFramer::kControlFrameBufferSize = 18; |
} while (false) |
#endif |
-SettingsFlagsAndId SettingsFlagsAndId::FromWireFormat(int version, |
- uint32 wire) { |
- if (version < 3) { |
+SettingsFlagsAndId SettingsFlagsAndId::FromWireFormat( |
+ SpdyMajorVersion version, uint32 wire) { |
+ if (version < SPDY3) { |
ConvertFlagsAndIdForSpdy2(&wire); |
} |
return SettingsFlagsAndId(ntohl(wire) >> 24, ntohl(wire) & 0x00ffffff); |
@@ -94,9 +94,10 @@ SettingsFlagsAndId::SettingsFlagsAndId(uint8 flags, uint32 id) |
LOG_IF(DFATAL, id > (1u << 24)) << "SPDY setting ID too large: " << id; |
} |
-uint32 SettingsFlagsAndId::GetWireFormat(int version) const { |
+uint32 SettingsFlagsAndId::GetWireFormat(SpdyMajorVersion version) |
+ const { |
uint32 wire = htonl(id_ & 0x00ffffff) | htonl(flags_ << 24); |
- if (version < 3) { |
+ if (version < SPDY3) { |
ConvertFlagsAndIdForSpdy2(&wire); |
} |
return wire; |
@@ -254,7 +255,7 @@ size_t SpdyFramer::GetGoAwayMinimumSize() const { |
size += 4; |
// 3. SPDY 3+ GOAWAY frames also contain a status (4 bytes) |
- if (protocol_version() >= 3) { |
+ if (protocol_version() >= SPDY3) { |
size += 4; |
} |
@@ -293,14 +294,14 @@ size_t SpdyFramer::GetWindowUpdateSize() const { |
} |
size_t SpdyFramer::GetBlockedSize() const { |
- DCHECK_LE(4, protocol_version()); |
+ DCHECK_LT(SPDY3, protocol_version()); |
// Size, in bytes, of a BLOCKED frame. |
// The BLOCKED frame has no payload beyond the control frame header. |
return GetControlFrameHeaderSize(); |
} |
size_t SpdyFramer::GetPushPromiseMinimumSize() const { |
- DCHECK_LE(4, protocol_version()); |
+ DCHECK_LT(SPDY3, protocol_version()); |
// Size, in bytes, of a PUSH_PROMISE frame, sans the embedded header block. |
// Calculated as frame prefix + 4 (promised stream id). |
return GetControlFrameHeaderSize() + 4; |
@@ -637,6 +638,11 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) { |
DCHECK(successful_read); |
is_control_frame = (version & kControlFlagMask) != 0; |
version &= ~kControlFlagMask; // Only valid for control frames. |
+ if (is_control_frame && |
+ version >= SpdyConstants::SerializeMajorVersion(SPDY_MIN_VERSION) && |
+ version <= SpdyConstants::SerializeMajorVersion(SPDY_MAX_VERSION)) { |
+ version = SpdyConstants::ParseMajorVersion(version); |
+ } |
if (is_control_frame) { |
// We check control_frame_type_field's validity in |
@@ -757,7 +763,8 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) { |
} else if (version != protocol_version()) { |
// We check version before we check validity: version can never be |
// 'invalid', it can only be unsupported. |
- DVLOG(1) << "Unsupported SPDY version " << version |
+ DVLOG(1) << "Unsupported SPDY version " |
+ << version |
<< " (expected " << protocol_version() << ")"; |
set_error(SPDY_UNSUPPORTED_VERSION); |
} else { |
@@ -925,7 +932,8 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) { |
} |
break; |
case CONTINUATION: |
- if (current_frame_length_ < GetContinuationMinimumSize()) { |
+ if (current_frame_length_ < GetContinuationMinimumSize() || |
+ protocol_version() <= SPDY3) { |
set_error(SPDY_INVALID_CONTROL_FRAME); |
} else if (current_frame_flags_ & ~HEADERS_FLAG_END_HEADERS) { |
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); |
@@ -1041,10 +1049,11 @@ size_t SpdyFramer::UpdateCurrentFrameBuffer(const char** data, size_t* len, |
return bytes_to_read; |
} |
-size_t SpdyFramer::GetSerializedLength(const int spdy_version, |
- const SpdyHeaderBlock* headers) { |
+size_t SpdyFramer::GetSerializedLength( |
+ const SpdyMajorVersion spdy_version, |
+ const SpdyHeaderBlock* headers) { |
const size_t num_name_value_pairs_size |
- = (spdy_version < 3) ? sizeof(uint16) : sizeof(uint32); |
+ = (spdy_version < SPDY3) ? sizeof(uint16) : sizeof(uint32); |
const size_t length_of_name_size = num_name_value_pairs_size; |
const size_t length_of_value_size = num_name_value_pairs_size; |
@@ -1061,16 +1070,16 @@ size_t SpdyFramer::GetSerializedLength(const int spdy_version, |
} |
void SpdyFramer::WriteHeaderBlock(SpdyFrameBuilder* frame, |
- const int spdy_version, |
+ const SpdyMajorVersion spdy_version, |
const SpdyHeaderBlock* headers) { |
- if (spdy_version < 3) { |
+ if (spdy_version < SPDY3) { |
frame->WriteUInt16(headers->size()); // Number of headers. |
} else { |
frame->WriteUInt32(headers->size()); // Number of headers. |
} |
SpdyHeaderBlock::const_iterator it; |
for (it = headers->begin(); it != headers->end(); ++it) { |
- if (spdy_version < 3) { |
+ if (spdy_version < SPDY3) { |
frame->WriteString(it->first); |
frame->WriteString(it->second); |
} else { |
@@ -1866,11 +1875,11 @@ size_t SpdyFramer::ProcessFramePaddingLength(const char* data, size_t len) { |
DCHECK_EQ(remaining_padding_payload_length_, 0u); |
bool pad_low = false; |
bool pad_high = false; |
- if (current_frame_flags_ & net::DATA_FLAG_PAD_LOW) { |
+ if (current_frame_flags_ & DATA_FLAG_PAD_LOW) { |
pad_low = true; |
++remaining_padding_length_fields_; |
} |
- if (current_frame_flags_ & net::DATA_FLAG_PAD_HIGH) { |
+ if (current_frame_flags_ & DATA_FLAG_PAD_HIGH) { |
pad_high = true; |
++remaining_padding_length_fields_; |
} |
@@ -2678,7 +2687,7 @@ size_t SpdyFramer::GetSerializedLength(const SpdyHeaderBlock& headers) { |
size_t SpdyFramer::GetNumberRequiredContinuationFrames(size_t size) { |
const size_t kMaxControlFrameSize = GetControlFrameBufferMaxSize(); |
- DCHECK_GT(protocol_version(), net::SPDY3); |
+ DCHECK_GT(protocol_version(), SPDY3); |
DCHECK_GT(size, kMaxControlFrameSize); |
size_t overflow = size - kMaxControlFrameSize; |
return overflow / (kMaxControlFrameSize - GetContinuationMinimumSize()) + 1; |