| 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_protocol.h" | 5 #include "net/spdy/spdy_protocol.h" |
| 6 | 6 |
| 7 namespace net { | 7 namespace net { |
| 8 | 8 |
| 9 SpdyFrameWithNameValueBlockIR::SpdyFrameWithNameValueBlockIR( | 9 SpdyFrameWithNameValueBlockIR::SpdyFrameWithNameValueBlockIR( |
| 10 SpdyStreamId stream_id) : SpdyFrameWithFinIR(stream_id) {} | 10 SpdyStreamId stream_id) : SpdyFrameWithFinIR(stream_id) {} |
| 11 | 11 |
| 12 SpdyFrameWithNameValueBlockIR::~SpdyFrameWithNameValueBlockIR() {} | 12 SpdyFrameWithNameValueBlockIR::~SpdyFrameWithNameValueBlockIR() {} |
| 13 | 13 |
| 14 SpdyDataIR::SpdyDataIR(SpdyStreamId stream_id, const base::StringPiece& data) | 14 SpdyDataIR::SpdyDataIR(SpdyStreamId stream_id, const base::StringPiece& data) |
| 15 : SpdyFrameWithFinIR(stream_id), | 15 : SpdyFrameWithFinIR(stream_id), |
| 16 pad_low_(false), | 16 padded_(false), |
| 17 pad_high_(false), | |
| 18 padding_payload_len_(0) { | 17 padding_payload_len_(0) { |
| 19 SetDataDeep(data); | 18 SetDataDeep(data); |
| 20 } | 19 } |
| 21 | 20 |
| 22 SpdyDataIR::SpdyDataIR(SpdyStreamId stream_id) | 21 SpdyDataIR::SpdyDataIR(SpdyStreamId stream_id) |
| 23 : SpdyFrameWithFinIR(stream_id), | 22 : SpdyFrameWithFinIR(stream_id), |
| 24 pad_low_(false), | 23 padded_(false), |
| 25 pad_high_(false), | |
| 26 padding_payload_len_(0) {} | 24 padding_payload_len_(0) {} |
| 27 | 25 |
| 28 SpdyDataIR::~SpdyDataIR() {} | 26 SpdyDataIR::~SpdyDataIR() {} |
| 29 | 27 |
| 30 bool SpdyConstants::IsValidFrameType(SpdyMajorVersion version, | 28 bool SpdyConstants::IsValidFrameType(SpdyMajorVersion version, |
| 31 int frame_type_field) { | 29 int frame_type_field) { |
| 32 switch (version) { | 30 switch (version) { |
| 33 case SPDY2: | 31 case SPDY2: |
| 34 case SPDY3: | 32 case SPDY3: |
| 35 // SYN_STREAM is the first valid frame. | 33 // SYN_STREAM is the first valid frame. |
| 36 if (frame_type_field < SerializeFrameType(version, SYN_STREAM)) { | 34 if (frame_type_field < SerializeFrameType(version, SYN_STREAM)) { |
| 37 return false; | 35 return false; |
| 38 } | 36 } |
| 39 | 37 |
| 40 // WINDOW_UPDATE is the last valid frame. | 38 // WINDOW_UPDATE is the last valid frame. |
| 41 if (frame_type_field > SerializeFrameType(version, WINDOW_UPDATE)) { | 39 if (frame_type_field > SerializeFrameType(version, WINDOW_UPDATE)) { |
| 42 return false; | 40 return false; |
| 43 } | 41 } |
| 44 | 42 |
| 45 // The valid range is non-contiguous. | |
| 46 if (frame_type_field == NOOP) { | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 return true; | 43 return true; |
| 51 case SPDY4: | 44 case SPDY4: |
| 52 case SPDY5: | 45 case SPDY5: |
| 53 // DATA is the first valid frame. | 46 // DATA is the first valid frame. |
| 54 if (frame_type_field < SerializeFrameType(version, DATA)) { | 47 if (frame_type_field < SerializeFrameType(version, DATA)) { |
| 55 return false; | 48 return false; |
| 56 } | 49 } |
| 57 | 50 |
| 58 // BLOCKED is the last valid frame. | 51 // BLOCKED is the last valid frame. |
| 59 if (frame_type_field > SerializeFrameType(version, BLOCKED)) { | 52 if (frame_type_field > SerializeFrameType(version, BLOCKED)) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 default: | 175 default: |
| 183 LOG(DFATAL) << "Serializing unhandled frame type " << frame_type; | 176 LOG(DFATAL) << "Serializing unhandled frame type " << frame_type; |
| 184 return -1; | 177 return -1; |
| 185 } | 178 } |
| 186 } | 179 } |
| 187 | 180 |
| 188 LOG(DFATAL) << "Unhandled SPDY version " << version; | 181 LOG(DFATAL) << "Unhandled SPDY version " << version; |
| 189 return -1; | 182 return -1; |
| 190 } | 183 } |
| 191 | 184 |
| 185 int SpdyConstants::DataFrameType(SpdyMajorVersion version) { |
| 186 switch (version) { |
| 187 case SPDY2: |
| 188 case SPDY3: |
| 189 return 0; |
| 190 case SPDY4: |
| 191 case SPDY5: |
| 192 return SerializeFrameType(version, DATA); |
| 193 } |
| 194 |
| 195 LOG(DFATAL) << "Unhandled SPDY version " << version; |
| 196 return 0; |
| 197 } |
| 198 |
| 192 bool SpdyConstants::IsValidSettingId(SpdyMajorVersion version, | 199 bool SpdyConstants::IsValidSettingId(SpdyMajorVersion version, |
| 193 int setting_id_field) { | 200 int setting_id_field) { |
| 194 switch (version) { | 201 switch (version) { |
| 195 case SPDY2: | 202 case SPDY2: |
| 196 case SPDY3: | 203 case SPDY3: |
| 197 // UPLOAD_BANDWIDTH is the first valid setting id. | 204 // UPLOAD_BANDWIDTH is the first valid setting id. |
| 198 if (setting_id_field < | 205 if (setting_id_field < |
| 199 SerializeSettingId(version, SETTINGS_UPLOAD_BANDWIDTH)) { | 206 SerializeSettingId(version, SETTINGS_UPLOAD_BANDWIDTH)) { |
| 200 return false; | 207 return false; |
| 201 } | 208 } |
| 202 | 209 |
| 203 // INITIAL_WINDOW_SIZE is the last valid setting id. | 210 // INITIAL_WINDOW_SIZE is the last valid setting id. |
| 204 if (setting_id_field > | 211 if (setting_id_field > |
| 205 SerializeSettingId(version, SETTINGS_INITIAL_WINDOW_SIZE)) { | 212 SerializeSettingId(version, SETTINGS_INITIAL_WINDOW_SIZE)) { |
| 206 return false; | 213 return false; |
| 207 } | 214 } |
| 208 | 215 |
| 209 return true; | 216 return true; |
| 210 case SPDY4: | 217 case SPDY4: |
| 211 case SPDY5: | 218 case SPDY5: |
| 212 // HEADER_TABLE_SIZE is the first valid setting id. | 219 // HEADER_TABLE_SIZE is the first valid setting id. |
| 213 if (setting_id_field < | 220 if (setting_id_field < |
| 214 SerializeSettingId(version, SETTINGS_HEADER_TABLE_SIZE)) { | 221 SerializeSettingId(version, SETTINGS_HEADER_TABLE_SIZE)) { |
| 215 return false; | 222 return false; |
| 216 } | 223 } |
| 217 | 224 |
| 218 // COMPRESS_DATA is the last valid setting id. | 225 // INITIAL_WINDOW_SIZE is the last valid setting id. |
| 219 if (setting_id_field > | 226 if (setting_id_field > |
| 220 SerializeSettingId(version, SETTINGS_COMPRESS_DATA)) { | 227 SerializeSettingId(version, SETTINGS_INITIAL_WINDOW_SIZE)) { |
| 221 return false; | 228 return false; |
| 222 } | 229 } |
| 223 | 230 |
| 224 return true; | 231 return true; |
| 225 } | 232 } |
| 226 | 233 |
| 227 LOG(DFATAL) << "Unhandled SPDY version " << version; | 234 LOG(DFATAL) << "Unhandled SPDY version " << version; |
| 228 return false; | 235 return false; |
| 229 } | 236 } |
| 230 | 237 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 254 case SPDY5: | 261 case SPDY5: |
| 255 switch (setting_id_field) { | 262 switch (setting_id_field) { |
| 256 case 1: | 263 case 1: |
| 257 return SETTINGS_HEADER_TABLE_SIZE; | 264 return SETTINGS_HEADER_TABLE_SIZE; |
| 258 case 2: | 265 case 2: |
| 259 return SETTINGS_ENABLE_PUSH; | 266 return SETTINGS_ENABLE_PUSH; |
| 260 case 3: | 267 case 3: |
| 261 return SETTINGS_MAX_CONCURRENT_STREAMS; | 268 return SETTINGS_MAX_CONCURRENT_STREAMS; |
| 262 case 4: | 269 case 4: |
| 263 return SETTINGS_INITIAL_WINDOW_SIZE; | 270 return SETTINGS_INITIAL_WINDOW_SIZE; |
| 264 case 5: | |
| 265 return SETTINGS_COMPRESS_DATA; | |
| 266 } | 271 } |
| 267 break; | 272 break; |
| 268 } | 273 } |
| 269 | 274 |
| 270 LOG(DFATAL) << "Unhandled setting ID " << setting_id_field; | 275 LOG(DFATAL) << "Unhandled setting ID " << setting_id_field; |
| 271 return SETTINGS_UPLOAD_BANDWIDTH; | 276 return SETTINGS_UPLOAD_BANDWIDTH; |
| 272 } | 277 } |
| 273 | 278 |
| 274 int SpdyConstants::SerializeSettingId(SpdyMajorVersion version, | 279 int SpdyConstants::SerializeSettingId(SpdyMajorVersion version, |
| 275 SpdySettingsIds id) { | 280 SpdySettingsIds id) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 299 case SPDY5: | 304 case SPDY5: |
| 300 switch (id) { | 305 switch (id) { |
| 301 case SETTINGS_HEADER_TABLE_SIZE: | 306 case SETTINGS_HEADER_TABLE_SIZE: |
| 302 return 1; | 307 return 1; |
| 303 case SETTINGS_ENABLE_PUSH: | 308 case SETTINGS_ENABLE_PUSH: |
| 304 return 2; | 309 return 2; |
| 305 case SETTINGS_MAX_CONCURRENT_STREAMS: | 310 case SETTINGS_MAX_CONCURRENT_STREAMS: |
| 306 return 3; | 311 return 3; |
| 307 case SETTINGS_INITIAL_WINDOW_SIZE: | 312 case SETTINGS_INITIAL_WINDOW_SIZE: |
| 308 return 4; | 313 return 4; |
| 309 case SETTINGS_COMPRESS_DATA: | |
| 310 return 5; | |
| 311 default: | 314 default: |
| 312 LOG(DFATAL) << "Serializing unhandled setting id " << id; | 315 LOG(DFATAL) << "Serializing unhandled setting id " << id; |
| 313 return -1; | 316 return -1; |
| 314 } | 317 } |
| 315 } | 318 } |
| 316 LOG(DFATAL) << "Unhandled SPDY version " << version; | 319 LOG(DFATAL) << "Unhandled SPDY version " << version; |
| 317 return -1; | 320 return -1; |
| 318 } | 321 } |
| 319 | 322 |
| 320 bool SpdyConstants::IsValidRstStreamStatus(SpdyMajorVersion version, | 323 bool SpdyConstants::IsValidRstStreamStatus(SpdyMajorVersion version, |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 } else { | 726 } else { |
| 724 // 14-bit length field. | 727 // 14-bit length field. |
| 725 return (1<<14) - 1; | 728 return (1<<14) - 1; |
| 726 } | 729 } |
| 727 } | 730 } |
| 728 | 731 |
| 729 size_t SpdyConstants::GetSizeOfSizeField(SpdyMajorVersion version) { | 732 size_t SpdyConstants::GetSizeOfSizeField(SpdyMajorVersion version) { |
| 730 return (version < SPDY3) ? sizeof(uint16) : sizeof(uint32); | 733 return (version < SPDY3) ? sizeof(uint16) : sizeof(uint32); |
| 731 } | 734 } |
| 732 | 735 |
| 736 size_t SpdyConstants::GetSettingSize(SpdyMajorVersion version) { |
| 737 return version <= SPDY3 ? 8 : 6; |
| 738 } |
| 739 |
| 733 void SpdyDataIR::Visit(SpdyFrameVisitor* visitor) const { | 740 void SpdyDataIR::Visit(SpdyFrameVisitor* visitor) const { |
| 734 return visitor->VisitData(*this); | 741 return visitor->VisitData(*this); |
| 735 } | 742 } |
| 736 | 743 |
| 737 void SpdySynStreamIR::Visit(SpdyFrameVisitor* visitor) const { | 744 void SpdySynStreamIR::Visit(SpdyFrameVisitor* visitor) const { |
| 738 return visitor->VisitSynStream(*this); | 745 return visitor->VisitSynStream(*this); |
| 739 } | 746 } |
| 740 | 747 |
| 741 void SpdySynReplyIR::Visit(SpdyFrameVisitor* visitor) const { | 748 void SpdySynReplyIR::Visit(SpdyFrameVisitor* visitor) const { |
| 742 return visitor->VisitSynReply(*this); | 749 return visitor->VisitSynReply(*this); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 | 817 |
| 811 SpdyAltSvcIR::SpdyAltSvcIR(SpdyStreamId stream_id) | 818 SpdyAltSvcIR::SpdyAltSvcIR(SpdyStreamId stream_id) |
| 812 : SpdyFrameWithStreamIdIR(stream_id), | 819 : SpdyFrameWithStreamIdIR(stream_id), |
| 813 max_age_(0), | 820 max_age_(0), |
| 814 port_(0) {} | 821 port_(0) {} |
| 815 | 822 |
| 816 void SpdyAltSvcIR::Visit(SpdyFrameVisitor* visitor) const { | 823 void SpdyAltSvcIR::Visit(SpdyFrameVisitor* visitor) const { |
| 817 return visitor->VisitAltSvc(*this); | 824 return visitor->VisitAltSvc(*this); |
| 818 } | 825 } |
| 819 | 826 |
| 827 SpdyPriorityIR::SpdyPriorityIR(SpdyStreamId stream_id) |
| 828 : SpdyFrameWithStreamIdIR(stream_id) { |
| 829 } |
| 830 |
| 831 SpdyPriorityIR::SpdyPriorityIR(SpdyStreamId stream_id, |
| 832 SpdyStreamId parent_stream_id, |
| 833 uint8 weight, |
| 834 bool exclusive) |
| 835 : SpdyFrameWithStreamIdIR(stream_id), |
| 836 parent_stream_id_(parent_stream_id), |
| 837 weight_(weight), |
| 838 exclusive_(exclusive) { |
| 839 } |
| 840 |
| 841 void SpdyPriorityIR::Visit(SpdyFrameVisitor* visitor) const { |
| 842 return visitor->VisitPriority(*this); |
| 843 } |
| 844 |
| 820 } // namespace net | 845 } // namespace net |
| OLD | NEW |