OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "components/auto_login_parser/auto_login_parser.h" | 5 #include "components/auto_login_parser/auto_login_parser.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 bool ParseHeader(const std::string& header, | 38 bool ParseHeader(const std::string& header, |
39 RealmRestriction realm_restriction, | 39 RealmRestriction realm_restriction, |
40 HeaderData* header_data) { | 40 HeaderData* header_data) { |
41 // TODO(pliard): Investigate/fix potential internationalization issue. It | 41 // TODO(pliard): Investigate/fix potential internationalization issue. It |
42 // seems that "account" from the x-auto-login header might contain non-ASCII | 42 // seems that "account" from the x-auto-login header might contain non-ASCII |
43 // characters. | 43 // characters. |
44 if (header.empty()) | 44 if (header.empty()) |
45 return false; | 45 return false; |
46 | 46 |
47 std::vector<std::pair<std::string, std::string> > pairs; | 47 base::StringPairs pairs; |
48 if (!base::SplitStringIntoKeyValuePairs(header, '=', '&', &pairs)) | 48 if (!base::SplitStringIntoKeyValuePairs(header, '=', '&', &pairs)) |
49 return false; | 49 return false; |
50 | 50 |
51 // Parse the information from the |header| string. | 51 // Parse the information from the |header| string. |
52 HeaderData local_params; | 52 HeaderData local_params; |
53 for (size_t i = 0; i < pairs.size(); ++i) { | 53 for (base::StringPairs::const_iterator it = pairs.begin(); it != pairs.end(); |
54 const std::pair<std::string, std::string>& pair = pairs[i]; | 54 ++it) { |
55 std::string unescaped_value(net::UnescapeURLComponent( | 55 const std::string& key = it->first; |
56 pair.second, net::UnescapeRule::URL_SPECIAL_CHARS)); | 56 const std::string& value = it->second; |
57 if (pair.first == "realm") { | 57 std::string unescaped_value( |
| 58 net::UnescapeURLComponent(value, net::UnescapeRule::URL_SPECIAL_CHARS)); |
| 59 if (key == "realm") { |
58 if (!MatchRealm(unescaped_value, realm_restriction)) | 60 if (!MatchRealm(unescaped_value, realm_restriction)) |
59 return false; | 61 return false; |
60 local_params.realm = unescaped_value; | 62 local_params.realm = unescaped_value; |
61 } else if (pair.first == "account") { | 63 } else if (key == "account") { |
62 local_params.account = unescaped_value; | 64 local_params.account = unescaped_value; |
63 } else if (pair.first == "args") { | 65 } else if (key == "args") { |
64 local_params.args = unescaped_value; | 66 local_params.args = unescaped_value; |
65 } | 67 } |
66 } | 68 } |
67 if (local_params.realm.empty() || local_params.args.empty()) | 69 if (local_params.realm.empty() || local_params.args.empty()) |
68 return false; | 70 return false; |
69 | 71 |
70 *header_data = local_params; | 72 *header_data = local_params; |
71 return true; | 73 return true; |
72 } | 74 } |
73 | 75 |
74 bool ParserHeaderInResponse(net::URLRequest* request, | 76 bool ParserHeaderInResponse(net::URLRequest* request, |
75 RealmRestriction realm_restriction, | 77 RealmRestriction realm_restriction, |
76 HeaderData* header_data) { | 78 HeaderData* header_data) { |
77 std::string header_string; | 79 std::string header_string; |
78 request->GetResponseHeaderByName(kHeaderName, &header_string); | 80 request->GetResponseHeaderByName(kHeaderName, &header_string); |
79 return ParseHeader(header_string, realm_restriction, header_data); | 81 return ParseHeader(header_string, realm_restriction, header_data); |
80 } | 82 } |
81 | 83 |
82 } // namespace auto_login_parser | 84 } // namespace auto_login_parser |
OLD | NEW |