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 "base/base64.h" | 5 #include "base/base64.h" |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_tokenizer.h" | 8 #include "base/strings/string_tokenizer.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "net/http/http_security_headers.h" | 10 #include "net/http/http_security_headers.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 190 |
191 base::StringTokenizer tokenizer(value, " \t=;"); | 191 base::StringTokenizer tokenizer(value, " \t=;"); |
192 tokenizer.set_options(base::StringTokenizer::RETURN_DELIMS); | 192 tokenizer.set_options(base::StringTokenizer::RETURN_DELIMS); |
193 tokenizer.set_quote_chars("\""); | 193 tokenizer.set_quote_chars("\""); |
194 std::string unquoted; | 194 std::string unquoted; |
195 while (tokenizer.GetNext()) { | 195 while (tokenizer.GetNext()) { |
196 DCHECK(!tokenizer.token_is_delim() || tokenizer.token().length() == 1); | 196 DCHECK(!tokenizer.token_is_delim() || tokenizer.token().length() == 1); |
197 switch (state) { | 197 switch (state) { |
198 case START: | 198 case START: |
199 case DIRECTIVE_END: | 199 case DIRECTIVE_END: |
200 if (IsAsciiWhitespace(*tokenizer.token_begin())) | 200 if (base::IsAsciiWhitespace(*tokenizer.token_begin())) |
201 continue; | 201 continue; |
202 if (base::LowerCaseEqualsASCII(tokenizer.token(), "max-age")) { | 202 if (base::LowerCaseEqualsASCII(tokenizer.token(), "max-age")) { |
203 state = AFTER_MAX_AGE_LABEL; | 203 state = AFTER_MAX_AGE_LABEL; |
204 max_age_observed++; | 204 max_age_observed++; |
205 } else if (base::LowerCaseEqualsASCII(tokenizer.token(), | 205 } else if (base::LowerCaseEqualsASCII(tokenizer.token(), |
206 "includesubdomains")) { | 206 "includesubdomains")) { |
207 state = AFTER_INCLUDE_SUBDOMAINS; | 207 state = AFTER_INCLUDE_SUBDOMAINS; |
208 include_subdomains_observed++; | 208 include_subdomains_observed++; |
209 include_subdomains_candidate = true; | 209 include_subdomains_candidate = true; |
210 } else { | 210 } else { |
211 state = AFTER_UNKNOWN_LABEL; | 211 state = AFTER_UNKNOWN_LABEL; |
212 } | 212 } |
213 break; | 213 break; |
214 | 214 |
215 case AFTER_MAX_AGE_LABEL: | 215 case AFTER_MAX_AGE_LABEL: |
216 if (IsAsciiWhitespace(*tokenizer.token_begin())) | 216 if (base::IsAsciiWhitespace(*tokenizer.token_begin())) |
217 continue; | 217 continue; |
218 if (*tokenizer.token_begin() != '=') | 218 if (*tokenizer.token_begin() != '=') |
219 return false; | 219 return false; |
220 DCHECK_EQ(tokenizer.token().length(), 1U); | 220 DCHECK_EQ(tokenizer.token().length(), 1U); |
221 state = AFTER_MAX_AGE_EQUALS; | 221 state = AFTER_MAX_AGE_EQUALS; |
222 break; | 222 break; |
223 | 223 |
224 case AFTER_MAX_AGE_EQUALS: | 224 case AFTER_MAX_AGE_EQUALS: |
225 if (IsAsciiWhitespace(*tokenizer.token_begin())) | 225 if (base::IsAsciiWhitespace(*tokenizer.token_begin())) |
226 continue; | 226 continue; |
227 unquoted = HttpUtil::Unquote(tokenizer.token()); | 227 unquoted = HttpUtil::Unquote(tokenizer.token()); |
228 if (!MaxAgeToInt(unquoted.begin(), unquoted.end(), &max_age_candidate)) | 228 if (!MaxAgeToInt(unquoted.begin(), unquoted.end(), &max_age_candidate)) |
229 return false; | 229 return false; |
230 state = AFTER_MAX_AGE; | 230 state = AFTER_MAX_AGE; |
231 break; | 231 break; |
232 | 232 |
233 case AFTER_MAX_AGE: | 233 case AFTER_MAX_AGE: |
234 case AFTER_INCLUDE_SUBDOMAINS: | 234 case AFTER_INCLUDE_SUBDOMAINS: |
235 if (IsAsciiWhitespace(*tokenizer.token_begin())) | 235 if (base::IsAsciiWhitespace(*tokenizer.token_begin())) |
236 continue; | 236 continue; |
237 else if (*tokenizer.token_begin() == ';') | 237 else if (*tokenizer.token_begin() == ';') |
238 state = DIRECTIVE_END; | 238 state = DIRECTIVE_END; |
239 else | 239 else |
240 return false; | 240 return false; |
241 break; | 241 break; |
242 | 242 |
243 case AFTER_UNKNOWN_LABEL: | 243 case AFTER_UNKNOWN_LABEL: |
244 // Consume and ignore the post-label contents (if any). | 244 // Consume and ignore the post-label contents (if any). |
245 if (*tokenizer.token_begin() != ';') | 245 if (*tokenizer.token_begin() != ';') |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 return false; | 325 return false; |
326 | 326 |
327 *max_age = base::TimeDelta::FromSeconds(max_age_candidate); | 327 *max_age = base::TimeDelta::FromSeconds(max_age_candidate); |
328 *include_subdomains = include_subdomains_candidate; | 328 *include_subdomains = include_subdomains_candidate; |
329 hashes->swap(pins); | 329 hashes->swap(pins); |
330 | 330 |
331 return true; | 331 return true; |
332 } | 332 } |
333 | 333 |
334 } // namespace net | 334 } // namespace net |
OLD | NEW |