| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 utility program exists to process the False Start blacklist file into | 5 // This utility program exists to process the False Start blacklist file into |
| 6 // a static hash table so that it can be efficiently queried by Chrome. | 6 // a static hash table so that it can be efficiently queried by Chrome. |
| 7 | 7 |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 | 10 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 106 |
| 107 // CheckLengths returns true iff every host is less than 256 bytes long (not | 107 // CheckLengths returns true iff every host is less than 256 bytes long (not |
| 108 // including the terminating NUL) and contains two or more labels. | 108 // including the terminating NUL) and contains two or more labels. |
| 109 static bool CheckLengths(const std::vector<std::string>& hosts) { | 109 static bool CheckLengths(const std::vector<std::string>& hosts) { |
| 110 for (std::vector<std::string>::const_iterator | 110 for (std::vector<std::string>::const_iterator |
| 111 i = hosts.begin(); i != hosts.end(); i++) { | 111 i = hosts.begin(); i != hosts.end(); i++) { |
| 112 if (i->size() >= 256) { | 112 if (i->size() >= 256) { |
| 113 fprintf(stderr, "Entry %s is too large\n", i->c_str()); | 113 fprintf(stderr, "Entry %s is too large\n", i->c_str()); |
| 114 return false; | 114 return false; |
| 115 } | 115 } |
| 116 if (SSLFalseStartBlacklist::LastTwoLabels(i->c_str()) == NULL) { | 116 if (SSLFalseStartBlacklist::LastTwoLabels(i->c_str()).empty()) { |
| 117 fprintf(stderr, "Entry %s contains too few labels\n", i->c_str()); | 117 fprintf(stderr, "Entry %s contains too few labels\n", i->c_str()); |
| 118 return false; | 118 return false; |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 return true; | 122 return true; |
| 123 } | 123 } |
| 124 | 124 |
| 125 int main(int argc, char** argv) { | 125 int main(int argc, char** argv) { |
| 126 if (argc != 3) | 126 if (argc != 3) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 fprintf(stderr, "One or more entries is too large or too small\n"); | 200 fprintf(stderr, "One or more entries is too large or too small\n"); |
| 201 return 2; | 201 return 2; |
| 202 } | 202 } |
| 203 | 203 |
| 204 fprintf(stderr, "Using %d entry hash table\n", kBuckets); | 204 fprintf(stderr, "Using %d entry hash table\n", kBuckets); |
| 205 uint32 table[kBuckets]; | 205 uint32 table[kBuckets]; |
| 206 std::vector<std::string> buckets[kBuckets]; | 206 std::vector<std::string> buckets[kBuckets]; |
| 207 | 207 |
| 208 for (std::vector<std::string>::const_iterator | 208 for (std::vector<std::string>::const_iterator |
| 209 i = hosts.begin(); i != hosts.end(); i++) { | 209 i = hosts.begin(); i != hosts.end(); i++) { |
| 210 const char* last_two_labels = | 210 const std::string last_two_labels = |
| 211 SSLFalseStartBlacklist::LastTwoLabels(i->c_str()); | 211 SSLFalseStartBlacklist::LastTwoLabels(i->c_str()); |
| 212 const unsigned h = SSLFalseStartBlacklist::Hash(last_two_labels); | 212 const unsigned h = SSLFalseStartBlacklist::Hash(last_two_labels.c_str()); |
| 213 buckets[h & (kBuckets - 1)].push_back(*i); | 213 buckets[h & (kBuckets - 1)].push_back(*i); |
| 214 } | 214 } |
| 215 | 215 |
| 216 std::string table_data; | 216 std::string table_data; |
| 217 unsigned max_bucket_size = 0; | 217 unsigned max_bucket_size = 0; |
| 218 for (unsigned i = 0; i < kBuckets; i++) { | 218 for (unsigned i = 0; i < kBuckets; i++) { |
| 219 if (buckets[i].size() > max_bucket_size) | 219 if (buckets[i].size() > max_bucket_size) |
| 220 max_bucket_size = buckets[i].size(); | 220 max_bucket_size = buckets[i].size(); |
| 221 | 221 |
| 222 table[i] = table_data.size(); | 222 table[i] = table_data.size(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } else if (line_length >= 70) { | 262 } else if (line_length >= 70) { |
| 263 fprintf(out, "\n"); | 263 fprintf(out, "\n"); |
| 264 line_length = 0; | 264 line_length = 0; |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 fprintf(out, "\n} // namespace net\n"); | 267 fprintf(out, "\n} // namespace net\n"); |
| 268 fclose(out); | 268 fclose(out); |
| 269 | 269 |
| 270 return 0; | 270 return 0; |
| 271 } | 271 } |
| OLD | NEW |