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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 for (; c != parameters_end && *c != ';' && *c != ' ' && *c != '\t'; ++c) { | 112 for (; c != parameters_end && *c != ';' && *c != ' ' && *c != '\t'; ++c) { |
113 } | 113 } |
114 if (c == parameter_value_begin) { | 114 if (c == parameter_value_begin) { |
115 return false; | 115 return false; |
116 } | 116 } |
117 if (parameter_name.compare("ma") == 0) { | 117 if (parameter_name.compare("ma") == 0) { |
118 if (!ParsePositiveInteger32(parameter_value_begin, c, &max_age)) { | 118 if (!ParsePositiveInteger32(parameter_value_begin, c, &max_age)) { |
119 return false; | 119 return false; |
120 } | 120 } |
121 } else if (parameter_name.compare("p") == 0) { | 121 } else if (parameter_name.compare("p") == 0) { |
122 if (!ParseProbability(parameter_value_begin, c, &p)) { | 122 // Probability value is enclosed in quotation marks. |
| 123 if (*parameter_value_begin != '"' || *(c - 1) != '"') { |
| 124 return false; |
| 125 } |
| 126 if (!ParseProbability(parameter_value_begin + 1, c - 1, &p)) { |
123 return false; | 127 return false; |
124 } | 128 } |
125 } | 129 } |
126 } | 130 } |
127 altsvc_vector->push_back( | 131 altsvc_vector->push_back( |
128 AlternativeService(protocol_id, host, port, max_age, p)); | 132 AlternativeService(protocol_id, host, port, max_age, p)); |
129 for (; c != value.end() && (*c == ' ' || *c == '\t' || *c == ','); ++c) { | 133 for (; c != value.end() && (*c == ' ' || *c == '\t' || *c == ','); ++c) { |
130 } | 134 } |
131 } | 135 } |
132 return true; | 136 return true; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 if (c == '"' || c == '\\') { | 183 if (c == '"' || c == '\\') { |
180 value.push_back('\\'); | 184 value.push_back('\\'); |
181 } | 185 } |
182 value.push_back(c); | 186 value.push_back(c); |
183 } | 187 } |
184 base::StringAppendF(&value, ":%d\"", altsvc.port); | 188 base::StringAppendF(&value, ":%d\"", altsvc.port); |
185 if (altsvc.max_age != 86400) { | 189 if (altsvc.max_age != 86400) { |
186 base::StringAppendF(&value, "; ma=%d", altsvc.max_age); | 190 base::StringAppendF(&value, "; ma=%d", altsvc.max_age); |
187 } | 191 } |
188 if (altsvc.p != 1.0) { | 192 if (altsvc.p != 1.0) { |
189 base::StringAppendF(&value, "; p=%.2f", altsvc.p); | 193 base::StringAppendF(&value, "; p=\"%.2f\"", altsvc.p); |
190 } | 194 } |
191 } | 195 } |
192 return value; | 196 return value; |
193 } | 197 } |
194 | 198 |
195 // static | 199 // static |
196 void SpdyAltSvcWireFormat::SkipWhiteSpace(StringPiece::const_iterator* c, | 200 void SpdyAltSvcWireFormat::SkipWhiteSpace(StringPiece::const_iterator* c, |
197 StringPiece::const_iterator end) { | 201 StringPiece::const_iterator end) { |
198 for (; *c != end && (**c == ' ' || **c == '\t'); ++*c) { | 202 for (; *c != end && (**c == ' ' || **c == '\t'); ++*c) { |
199 } | 203 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 ++c; | 313 ++c; |
310 double place_value = 0.1; | 314 double place_value = 0.1; |
311 for (; c != end && isdigit(*c); ++c) { | 315 for (; c != end && isdigit(*c); ++c) { |
312 *p += place_value * (*c - '0'); | 316 *p += place_value * (*c - '0'); |
313 place_value *= 0.1; | 317 place_value *= 0.1; |
314 } | 318 } |
315 return (c == end && *p <= 1.0); | 319 return (c == end && *p <= 1.0); |
316 } | 320 } |
317 | 321 |
318 } // namespace net | 322 } // namespace net |
OLD | NEW |