OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_headers_block_parser.h" | 5 #include "net/spdy/spdy_headers_block_parser.h" |
6 | 6 |
7 #include "base/sys_byteorder.h" | 7 #include "base/sys_byteorder.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 namespace { | 10 namespace { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 161 |
162 void SpdyHeadersBlockParser::ParseLength(Reader* reader, | 162 void SpdyHeadersBlockParser::ParseLength(Reader* reader, |
163 uint32_t* parsed_length) { | 163 uint32_t* parsed_length) { |
164 char buffer[] = {0, 0, 0, 0}; | 164 char buffer[] = {0, 0, 0, 0}; |
165 if (!reader->ReadN(length_field_size_, buffer)) { | 165 if (!reader->ReadN(length_field_size_, buffer)) { |
166 error_ = NEED_MORE_DATA; | 166 error_ = NEED_MORE_DATA; |
167 return; | 167 return; |
168 } | 168 } |
169 // Convert from network to host order and return the parsed out integer. | 169 // Convert from network to host order and return the parsed out integer. |
170 if (length_field_size_ == sizeof(uint32_t)) { | 170 if (length_field_size_ == sizeof(uint32_t)) { |
171 *parsed_length = ntohl(*reinterpret_cast<const uint32_t *>(buffer)); | 171 *parsed_length = |
| 172 base::NetToHost32(*reinterpret_cast<const uint32_t *>(buffer)); |
172 } else { | 173 } else { |
173 *parsed_length = ntohs(*reinterpret_cast<const uint16_t *>(buffer)); | 174 *parsed_length = |
| 175 base::NetToHost16(*reinterpret_cast<const uint16_t *>(buffer)); |
174 } | 176 } |
175 } | 177 } |
176 | 178 |
177 size_t SpdyHeadersBlockParser::LengthFieldSizeForVersion( | 179 size_t SpdyHeadersBlockParser::LengthFieldSizeForVersion( |
178 SpdyMajorVersion spdy_version) { | 180 SpdyMajorVersion spdy_version) { |
179 if (spdy_version < SPDY3) { | 181 if (spdy_version < SPDY3) { |
180 return sizeof(uint16_t); | 182 return sizeof(uint16_t); |
181 } | 183 } |
182 return sizeof(uint32_t); | 184 return sizeof(uint32_t); |
183 } | 185 } |
184 | 186 |
185 size_t SpdyHeadersBlockParser::MaxNumberOfHeadersForVersion( | 187 size_t SpdyHeadersBlockParser::MaxNumberOfHeadersForVersion( |
186 SpdyMajorVersion spdy_version) { | 188 SpdyMajorVersion spdy_version) { |
187 // Account for the length of the header block field. | 189 // Account for the length of the header block field. |
188 size_t max_bytes_for_headers = | 190 size_t max_bytes_for_headers = |
189 kMaximumFieldLength - LengthFieldSizeForVersion(spdy_version); | 191 kMaximumFieldLength - LengthFieldSizeForVersion(spdy_version); |
190 | 192 |
191 // A minimal size header is twice the length field size (and has a | 193 // A minimal size header is twice the length field size (and has a |
192 // zero-lengthed key and a zero-lengthed value). | 194 // zero-lengthed key and a zero-lengthed value). |
193 return max_bytes_for_headers / (2 * LengthFieldSizeForVersion(spdy_version)); | 195 return max_bytes_for_headers / (2 * LengthFieldSizeForVersion(spdy_version)); |
194 } | 196 } |
195 | 197 |
196 } // namespace net | 198 } // namespace net |
OLD | NEW |