OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // This command-line program converts an effective-TLD data file in UTF-8 from | 5 // This command-line program converts an effective-TLD data file in UTF-8 from |
6 // the format provided by Mozilla to the format expected by Chrome. This | 6 // the format provided by Mozilla to the format expected by Chrome. This |
7 // program generates an intermediate file which is then used by gperf to | 7 // program generates an intermediate file which is then used by gperf to |
8 // generate a perfect hash map. The benefit of this approach is that no time is | 8 // generate a perfect hash map. The benefit of this approach is that no time is |
9 // spent on program initialization to generate the map of this data. | 9 // spent on program initialization to generate the map of this data. |
10 // | 10 // |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // Adjusts the rule to a standard form: removes single extraneous dots and | 99 // Adjusts the rule to a standard form: removes single extraneous dots and |
100 // canonicalizes it using GURL. Returns kSuccess if the rule is interpreted as | 100 // canonicalizes it using GURL. Returns kSuccess if the rule is interpreted as |
101 // valid; logs a warning and returns kWarning if it is probably invalid; and | 101 // valid; logs a warning and returns kWarning if it is probably invalid; and |
102 // logs an error and returns kError if the rule is (almost) certainly invalid. | 102 // logs an error and returns kError if the rule is (almost) certainly invalid. |
103 NormalizeResult NormalizeRule(std::string* domain, Rule* rule) { | 103 NormalizeResult NormalizeRule(std::string* domain, Rule* rule) { |
104 NormalizeResult result = kSuccess; | 104 NormalizeResult result = kSuccess; |
105 | 105 |
106 // Strip single leading and trailing dots. | 106 // Strip single leading and trailing dots. |
107 if (domain->at(0) == '.') | 107 if (domain->at(0) == '.') |
108 domain->erase(0, 1); | 108 domain->erase(0, 1); |
109 if (domain->size() == 0) { | 109 if (domain->empty()) { |
110 LOG(WARNING) << "Ignoring empty rule"; | 110 LOG(WARNING) << "Ignoring empty rule"; |
111 return kWarning; | 111 return kWarning; |
112 } | 112 } |
113 if (domain->at(domain->size() - 1) == '.') | 113 if (domain->at(domain->size() - 1) == '.') |
114 domain->erase(domain->size() - 1, 1); | 114 domain->erase(domain->size() - 1, 1); |
115 if (domain->size() == 0) { | 115 if (domain->empty()) { |
116 LOG(WARNING) << "Ignoring empty rule"; | 116 LOG(WARNING) << "Ignoring empty rule"; |
117 return kWarning; | 117 return kWarning; |
118 } | 118 } |
119 | 119 |
120 // Allow single leading '*.' or '!', saved here so it's not canonicalized. | 120 // Allow single leading '*.' or '!', saved here so it's not canonicalized. |
121 size_t start_offset = 0; | 121 size_t start_offset = 0; |
122 if (domain->at(0) == '!') { | 122 if (domain->at(0) == '!') { |
123 domain->erase(0, 1); | 123 domain->erase(0, 1); |
124 rule->exception = true; | 124 rule->exception = true; |
125 } else if (domain->find("*.") == 0) { | 125 } else if (domain->find("*.") == 0) { |
126 domain->erase(0, 2); | 126 domain->erase(0, 2); |
127 rule->wildcard = true; | 127 rule->wildcard = true; |
128 } | 128 } |
129 if (domain->size() == 0) { | 129 if (domain->empty()) { |
130 LOG(WARNING) << "Ignoring empty rule"; | 130 LOG(WARNING) << "Ignoring empty rule"; |
131 return kWarning; | 131 return kWarning; |
132 } | 132 } |
133 | 133 |
134 // Warn about additional '*.' or '!'. | 134 // Warn about additional '*.' or '!'. |
135 if (domain->find("*.", start_offset) != std::string::npos || | 135 if (domain->find("*.", start_offset) != std::string::npos || |
136 domain->find('!', start_offset) != std::string::npos) { | 136 domain->find('!', start_offset) != std::string::npos) { |
137 LOG(WARNING) << "Keeping probably invalid rule: " << *domain; | 137 LOG(WARNING) << "Keeping probably invalid rule: " << *domain; |
138 result = kWarning; | 138 result = kWarning; |
139 } | 139 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 NormalizeResult result = NormalizeFile(input_file, output_file); | 289 NormalizeResult result = NormalizeFile(input_file, output_file); |
290 if (result != kSuccess) { | 290 if (result != kSuccess) { |
291 fprintf(stderr, | 291 fprintf(stderr, |
292 "Errors or warnings processing file. See log in tld_cleanup.log."); | 292 "Errors or warnings processing file. See log in tld_cleanup.log."); |
293 } | 293 } |
294 | 294 |
295 if (result == kError) | 295 if (result == kError) |
296 return 1; | 296 return 1; |
297 return 0; | 297 return 0; |
298 } | 298 } |
OLD | NEW |