| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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_alt_svc_wire_format.h" | 5 #include "net/spdy/spdy_alt_svc_wire_format.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 return (c == end && *value > 0); | 34 return (c == end && *value > 0); |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 SpdyAltSvcWireFormat::AlternativeService::AlternativeService() {} | 39 SpdyAltSvcWireFormat::AlternativeService::AlternativeService() {} |
| 40 | 40 |
| 41 SpdyAltSvcWireFormat::AlternativeService::AlternativeService( | 41 SpdyAltSvcWireFormat::AlternativeService::AlternativeService( |
| 42 const std::string& protocol_id, | 42 const std::string& protocol_id, |
| 43 const std::string& host, | 43 const std::string& host, |
| 44 uint16 port, | 44 uint16_t port, |
| 45 uint32 max_age, | 45 uint32_t max_age, |
| 46 double probability, | 46 double probability, |
| 47 VersionVector version) | 47 VersionVector version) |
| 48 : protocol_id(protocol_id), | 48 : protocol_id(protocol_id), |
| 49 host(host), | 49 host(host), |
| 50 port(port), | 50 port(port), |
| 51 max_age(max_age), | 51 max_age(max_age), |
| 52 probability(probability), | 52 probability(probability), |
| 53 version(version) {} | 53 version(version) {} |
| 54 | 54 |
| 55 SpdyAltSvcWireFormat::AlternativeService::~AlternativeService() {} | 55 SpdyAltSvcWireFormat::AlternativeService::~AlternativeService() {} |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 ++c; | 96 ++c; |
| 97 if (c == value.end()) { | 97 if (c == value.end()) { |
| 98 return false; | 98 return false; |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 if (c == alt_authority_begin || c == value.end()) { | 101 if (c == alt_authority_begin || c == value.end()) { |
| 102 return false; | 102 return false; |
| 103 } | 103 } |
| 104 DCHECK_EQ('"', *c); | 104 DCHECK_EQ('"', *c); |
| 105 std::string host; | 105 std::string host; |
| 106 uint16 port; | 106 uint16_t port; |
| 107 if (!ParseAltAuthority(alt_authority_begin, c, &host, &port)) { | 107 if (!ParseAltAuthority(alt_authority_begin, c, &host, &port)) { |
| 108 return false; | 108 return false; |
| 109 } | 109 } |
| 110 ++c; | 110 ++c; |
| 111 // Parse parameters. | 111 // Parse parameters. |
| 112 uint32 max_age = 86400; | 112 uint32_t max_age = 86400; |
| 113 double probability = 1.0; | 113 double probability = 1.0; |
| 114 VersionVector version; | 114 VersionVector version; |
| 115 StringPiece::const_iterator parameters_end = std::find(c, value.end(), ','); | 115 StringPiece::const_iterator parameters_end = std::find(c, value.end(), ','); |
| 116 while (c != parameters_end) { | 116 while (c != parameters_end) { |
| 117 SkipWhiteSpace(&c, parameters_end); | 117 SkipWhiteSpace(&c, parameters_end); |
| 118 if (c == parameters_end) { | 118 if (c == parameters_end) { |
| 119 break; | 119 break; |
| 120 } | 120 } |
| 121 if (*c != ';') { | 121 if (*c != ';') { |
| 122 return false; | 122 return false; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 return false; | 167 return false; |
| 168 } | 168 } |
| 169 ++c; | 169 ++c; |
| 170 parameters_end = std::find(c, value.end(), ','); | 170 parameters_end = std::find(c, value.end(), ','); |
| 171 StringPiece::const_iterator v_begin = parameter_value_begin + 1; | 171 StringPiece::const_iterator v_begin = parameter_value_begin + 1; |
| 172 while (v_begin < c) { | 172 while (v_begin < c) { |
| 173 StringPiece::const_iterator v_end = v_begin; | 173 StringPiece::const_iterator v_end = v_begin; |
| 174 while (v_end < c - 1 && *v_end != ',') { | 174 while (v_end < c - 1 && *v_end != ',') { |
| 175 ++v_end; | 175 ++v_end; |
| 176 } | 176 } |
| 177 uint16 v; | 177 uint16_t v; |
| 178 if (!ParsePositiveInteger16(v_begin, v_end, &v)) { | 178 if (!ParsePositiveInteger16(v_begin, v_end, &v)) { |
| 179 return false; | 179 return false; |
| 180 } | 180 } |
| 181 version.push_back(v); | 181 version.push_back(v); |
| 182 v_begin = v_end + 1; | 182 v_begin = v_end + 1; |
| 183 if (v_begin == c - 1) { | 183 if (v_begin == c - 1) { |
| 184 // List ends in comma. | 184 // List ends in comma. |
| 185 return false; | 185 return false; |
| 186 } | 186 } |
| 187 } | 187 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 decoded += isdigit(*c) ? (0 - '0') : (10 - 'a'); | 305 decoded += isdigit(*c) ? (0 - '0') : (10 - 'a'); |
| 306 output->push_back(decoded); | 306 output->push_back(decoded); |
| 307 } | 307 } |
| 308 return true; | 308 return true; |
| 309 } | 309 } |
| 310 | 310 |
| 311 // static | 311 // static |
| 312 bool SpdyAltSvcWireFormat::ParseAltAuthority(StringPiece::const_iterator c, | 312 bool SpdyAltSvcWireFormat::ParseAltAuthority(StringPiece::const_iterator c, |
| 313 StringPiece::const_iterator end, | 313 StringPiece::const_iterator end, |
| 314 std::string* host, | 314 std::string* host, |
| 315 uint16* port) { | 315 uint16_t* port) { |
| 316 host->clear(); | 316 host->clear(); |
| 317 for (; c != end && *c != ':'; ++c) { | 317 for (; c != end && *c != ':'; ++c) { |
| 318 if (*c == '"') { | 318 if (*c == '"') { |
| 319 // Port is mandatory. | 319 // Port is mandatory. |
| 320 return false; | 320 return false; |
| 321 } | 321 } |
| 322 if (*c == '\\') { | 322 if (*c == '\\') { |
| 323 ++c; | 323 ++c; |
| 324 if (c == end) { | 324 if (c == end) { |
| 325 return false; | 325 return false; |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 host->push_back(*c); | 328 host->push_back(*c); |
| 329 } | 329 } |
| 330 if (c == end) { | 330 if (c == end) { |
| 331 return false; | 331 return false; |
| 332 } | 332 } |
| 333 DCHECK_EQ(':', *c); | 333 DCHECK_EQ(':', *c); |
| 334 ++c; | 334 ++c; |
| 335 return ParsePositiveInteger16(c, end, port); | 335 return ParsePositiveInteger16(c, end, port); |
| 336 } | 336 } |
| 337 | 337 |
| 338 // static | 338 // static |
| 339 bool SpdyAltSvcWireFormat::ParsePositiveInteger16( | 339 bool SpdyAltSvcWireFormat::ParsePositiveInteger16( |
| 340 StringPiece::const_iterator c, | 340 StringPiece::const_iterator c, |
| 341 StringPiece::const_iterator end, | 341 StringPiece::const_iterator end, |
| 342 uint16* value) { | 342 uint16_t* value) { |
| 343 return ParsePositiveIntegerImpl<uint16>(c, end, value); | 343 return ParsePositiveIntegerImpl<uint16_t>(c, end, value); |
| 344 } | 344 } |
| 345 | 345 |
| 346 // static | 346 // static |
| 347 bool SpdyAltSvcWireFormat::ParsePositiveInteger32( | 347 bool SpdyAltSvcWireFormat::ParsePositiveInteger32( |
| 348 StringPiece::const_iterator c, | 348 StringPiece::const_iterator c, |
| 349 StringPiece::const_iterator end, | 349 StringPiece::const_iterator end, |
| 350 uint32* value) { | 350 uint32_t* value) { |
| 351 return ParsePositiveIntegerImpl<uint32>(c, end, value); | 351 return ParsePositiveIntegerImpl<uint32_t>(c, end, value); |
| 352 } | 352 } |
| 353 | 353 |
| 354 // Probability is a decimal fraction between 0.0 and 1.0, inclusive, with | 354 // Probability is a decimal fraction between 0.0 and 1.0, inclusive, with |
| 355 // optional leading zero, optional decimal point, and optional digits following | 355 // optional leading zero, optional decimal point, and optional digits following |
| 356 // the decimal point, with the restriction that there has to be at least one | 356 // the decimal point, with the restriction that there has to be at least one |
| 357 // digit (that is, "" and "." are not valid). | 357 // digit (that is, "" and "." are not valid). |
| 358 // static | 358 // static |
| 359 bool SpdyAltSvcWireFormat::ParseProbability(StringPiece::const_iterator c, | 359 bool SpdyAltSvcWireFormat::ParseProbability(StringPiece::const_iterator c, |
| 360 StringPiece::const_iterator end, | 360 StringPiece::const_iterator end, |
| 361 double* probability) { | 361 double* probability) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 386 ++c; | 386 ++c; |
| 387 double place_value = 0.1; | 387 double place_value = 0.1; |
| 388 for (; c != end && isdigit(*c); ++c) { | 388 for (; c != end && isdigit(*c); ++c) { |
| 389 *probability += place_value * (*c - '0'); | 389 *probability += place_value * (*c - '0'); |
| 390 place_value *= 0.1; | 390 place_value *= 0.1; |
| 391 } | 391 } |
| 392 return (c == end && *probability <= 1.0); | 392 return (c == end && *probability <= 1.0); |
| 393 } | 393 } |
| 394 | 394 |
| 395 } // namespace net | 395 } // namespace net |
| OLD | NEW |