| 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 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 } | 994 } |
| 995 | 995 |
| 996 // Store header. | 996 // Store header. |
| 997 (*block)[name] = value; | 997 (*block)[name] = value; |
| 998 } | 998 } |
| 999 return true; | 999 return true; |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 /* static */ | 1002 /* static */ |
| 1003 bool SpdyFramer::ParseSettings(const SpdySettingsControlFrame* frame, | 1003 bool SpdyFramer::ParseSettings(const SpdySettingsControlFrame* frame, |
| 1004 SpdySettings* settings) { | 1004 SettingsMap* settings) { |
| 1005 DCHECK_EQ(frame->type(), SETTINGS); | 1005 DCHECK_EQ(frame->type(), SETTINGS); |
| 1006 DCHECK(settings); | 1006 DCHECK(settings); |
| 1007 | 1007 |
| 1008 SpdyFrameReader parser(frame->header_block(), frame->header_block_len()); | 1008 SpdyFrameReader parser(frame->header_block(), frame->header_block_len()); |
| 1009 for (size_t index = 0; index < frame->num_entries(); ++index) { | 1009 for (size_t index = 0; index < frame->num_entries(); ++index) { |
| 1010 uint32 id_and_flags_wire; | 1010 uint32 id_and_flags_wire; |
| 1011 uint32 value; | 1011 uint32 value; |
| 1012 // SettingsFlagsAndId accepts off-the-wire (network byte order) data, so we | 1012 // SettingsFlagsAndId accepts off-the-wire (network byte order) data, so we |
| 1013 // use ReadBytes() instead of ReadUInt32() as the latter calls ntohl(). | 1013 // use ReadBytes() instead of ReadUInt32() as the latter calls ntohl(). |
| 1014 if (!parser.ReadBytes(&id_and_flags_wire, 4)) { | 1014 if (!parser.ReadBytes(&id_and_flags_wire, 4)) { |
| 1015 return false; | 1015 return false; |
| 1016 } | 1016 } |
| 1017 if (!parser.ReadUInt32(&value)) | 1017 if (!parser.ReadUInt32(&value)) |
| 1018 return false; | 1018 return false; |
| 1019 SettingsFlagsAndId id_and_flags = | 1019 SettingsFlagsAndId flags_and_id = |
| 1020 SettingsFlagsAndId::FromWireFormat(frame->version(), id_and_flags_wire); | 1020 SettingsFlagsAndId::FromWireFormat(frame->version(), id_and_flags_wire); |
| 1021 settings->insert(settings->end(), std::make_pair(id_and_flags, value)); | 1021 SpdySettingsIds id = static_cast<SpdySettingsIds>(flags_and_id.id()); |
| 1022 SpdySettingsFlags flags = |
| 1023 static_cast<SpdySettingsFlags>(flags_and_id.flags()); |
| 1024 settings->insert(std::make_pair(id, SettingsFlagsAndValue(flags, value))); |
| 1022 } | 1025 } |
| 1023 return true; | 1026 return true; |
| 1024 } | 1027 } |
| 1025 | 1028 |
| 1026 /* static */ | 1029 /* static */ |
| 1027 bool SpdyFramer::ParseCredentialData(const char* data, size_t len, | 1030 bool SpdyFramer::ParseCredentialData(const char* data, size_t len, |
| 1028 SpdyCredential* credential) { | 1031 SpdyCredential* credential) { |
| 1029 DCHECK(credential); | 1032 DCHECK(credential); |
| 1030 | 1033 |
| 1031 SpdyFrameReader parser(data, len); | 1034 SpdyFrameReader parser(data, len); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 size_t frame_size = SpdyRstStreamControlFrame::size(); | 1135 size_t frame_size = SpdyRstStreamControlFrame::size(); |
| 1133 SpdyFrameBuilder frame(RST_STREAM, CONTROL_FLAG_NONE, spdy_version_, | 1136 SpdyFrameBuilder frame(RST_STREAM, CONTROL_FLAG_NONE, spdy_version_, |
| 1134 frame_size); | 1137 frame_size); |
| 1135 frame.WriteUInt32(stream_id); | 1138 frame.WriteUInt32(stream_id); |
| 1136 frame.WriteUInt32(status); | 1139 frame.WriteUInt32(status); |
| 1137 DCHECK_EQ(static_cast<size_t>(frame.length()), frame_size); | 1140 DCHECK_EQ(static_cast<size_t>(frame.length()), frame_size); |
| 1138 return reinterpret_cast<SpdyRstStreamControlFrame*>(frame.take()); | 1141 return reinterpret_cast<SpdyRstStreamControlFrame*>(frame.take()); |
| 1139 } | 1142 } |
| 1140 | 1143 |
| 1141 SpdySettingsControlFrame* SpdyFramer::CreateSettings( | 1144 SpdySettingsControlFrame* SpdyFramer::CreateSettings( |
| 1142 const SpdySettings& values) const { | 1145 const SettingsMap& values) const { |
| 1143 size_t frame_size = SpdySettingsControlFrame::size() + 8 * values.size(); | 1146 size_t frame_size = SpdySettingsControlFrame::size() + 8 * values.size(); |
| 1144 SpdyFrameBuilder frame(SETTINGS, CONTROL_FLAG_NONE, spdy_version_, | 1147 SpdyFrameBuilder frame(SETTINGS, CONTROL_FLAG_NONE, spdy_version_, |
| 1145 frame_size); | 1148 frame_size); |
| 1146 frame.WriteUInt32(values.size()); | 1149 frame.WriteUInt32(values.size()); |
| 1147 SpdySettings::const_iterator it = values.begin(); | 1150 SettingsMap::const_iterator it = values.begin(); |
| 1148 while (it != values.end()) { | 1151 while (it != values.end()) { |
| 1149 uint32 id_and_flags_wire = it->first.GetWireFormat(spdy_version_); | 1152 SettingsFlagsAndId flags_and_id(it->second.first, it->first); |
| 1153 uint32 id_and_flags_wire = flags_and_id.GetWireFormat(spdy_version_); |
| 1150 frame.WriteBytes(&id_and_flags_wire, 4); | 1154 frame.WriteBytes(&id_and_flags_wire, 4); |
| 1151 frame.WriteUInt32(it->second); | 1155 frame.WriteUInt32(it->second.second); |
| 1152 ++it; | 1156 ++it; |
| 1153 } | 1157 } |
| 1154 DCHECK_EQ(static_cast<size_t>(frame.length()), frame_size); | 1158 DCHECK_EQ(static_cast<size_t>(frame.length()), frame_size); |
| 1155 return reinterpret_cast<SpdySettingsControlFrame*>(frame.take()); | 1159 return reinterpret_cast<SpdySettingsControlFrame*>(frame.take()); |
| 1156 } | 1160 } |
| 1157 | 1161 |
| 1158 SpdyPingControlFrame* SpdyFramer::CreatePingFrame(uint32 unique_id) const { | 1162 SpdyPingControlFrame* SpdyFramer::CreatePingFrame(uint32 unique_id) const { |
| 1159 size_t frame_size = SpdyPingControlFrame::size(); | 1163 size_t frame_size = SpdyPingControlFrame::size(); |
| 1160 SpdyFrameBuilder frame(PING, CONTROL_FLAG_NONE, spdy_version_, frame_size); | 1164 SpdyFrameBuilder frame(PING, CONTROL_FLAG_NONE, spdy_version_, frame_size); |
| 1161 frame.WriteUInt32(unique_id); | 1165 frame.WriteUInt32(unique_id); |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1747 | 1751 |
| 1748 void SpdyFramer::set_validate_control_frame_sizes(bool value) { | 1752 void SpdyFramer::set_validate_control_frame_sizes(bool value) { |
| 1749 validate_control_frame_sizes_ = value; | 1753 validate_control_frame_sizes_ = value; |
| 1750 } | 1754 } |
| 1751 | 1755 |
| 1752 void SpdyFramer::set_enable_compression_default(bool value) { | 1756 void SpdyFramer::set_enable_compression_default(bool value) { |
| 1753 g_enable_compression_default = value; | 1757 g_enable_compression_default = value; |
| 1754 } | 1758 } |
| 1755 | 1759 |
| 1756 } // namespace net | 1760 } // namespace net |
| OLD | NEW |