diff options
author | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-08 23:44:55 +0000 |
---|---|---|
committer | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-08 23:44:55 +0000 |
commit | b5a0c87bc18661fe8f4c4d2eae5716e8e072c25d (patch) | |
tree | dbafe7a58082d44a3159a435afd81e5ddcea953f /net/base/ssl_false_start_blacklist.cc | |
parent | 7291c4878d7afa5e575084d8fae75b58c11a8262 (diff) | |
download | chromium_src-b5a0c87bc18661fe8f4c4d2eae5716e8e072c25d.zip chromium_src-b5a0c87bc18661fe8f4c4d2eae5716e8e072c25d.tar.gz chromium_src-b5a0c87bc18661fe8f4c4d2eae5716e8e072c25d.tar.bz2 |
Revert 95907 - Clean up SSL false start blacklist code. Numerous changes, including:
* Handle trailing dots in LastTwoLabels() as in http://codereview.chromium.org/7518035/ . Rename this function to LastTwoComponents() to match the terminology used in the RegistryControlledDomainService and elsewhere in Chrome.
* Since callers are using std::string anyway, make the functions in the header take const std::string& instead of char*. This also allows doing string operations on them.
* Use string operations (like find_last_of()) in place of hand-written algorithms, for brevity, clarity, and safety.
* Avoid "unsigned", which the style guide forbids, and use allowed types like size_t, uint32, or int (depending on the situation).
* Avoid #define and "using".
* Use standard algorithms for similar reasons as using string ops.
* Use file_util functions to significantly abbreviate file reading/writing code.
* Use wmain() (on Windows) in combination with FilePath to avoid issues if the provided pathname has extended characters that don't flatten losslessly to the default codepage (thanks Darin for pointing out this issue).
* Avoid casting where possible. Avoid some casts for printf()-style calls by using a string stream, which also allows for slightly less boilerplate.
* Convert non-error uses of stderr to the chrome-standard VLOG(1).
* Correctly handle hostnames with trailing dots in the input file.
* In general, shorten code where possible.
Because this adds a dependency on base, and ssl_false_start_blacklist_process has the "#host" specifier in net.gyp, bradnelson tells me that base and its dependencies need an explicit "host, target" toolchain list for the Linux builds to work correctly. It would be nice if we could avoid this but I guess gyp would have to be smarter or something.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7550002
TBR=pkasting@chromium.org
Review URL: http://codereview.chromium.org/7529035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95910 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/ssl_false_start_blacklist.cc')
-rw-r--r-- | net/base/ssl_false_start_blacklist.cc | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/net/base/ssl_false_start_blacklist.cc b/net/base/ssl_false_start_blacklist.cc index d08852d..b57826b 100644 --- a/net/base/ssl_false_start_blacklist.cc +++ b/net/base/ssl_false_start_blacklist.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,19 +7,22 @@ namespace net { // static -bool SSLFalseStartBlacklist::IsMember(const std::string& host) { - const std::string last_two_components(LastTwoComponents(host)); - if (last_two_components.empty()) +bool SSLFalseStartBlacklist::IsMember(const char* host) { + const char* last_two_labels = LastTwoLabels(host); + if (!last_two_labels) return false; + const unsigned bucket = Hash(last_two_labels) & (kBuckets - 1); + const uint32 start = kHashTable[bucket]; + const uint32 end = kHashTable[bucket + 1]; + const size_t len = strlen(host); - const size_t bucket = Hash(last_two_components) & (kBuckets - 1); - for (size_t i = kHashTable[bucket]; i < kHashTable[bucket + 1]; ) { + for (size_t i = start; i < end;) { const size_t blacklist_entry_len = static_cast<uint8>(kHashData[i]); - if (host.length() >= blacklist_entry_len && - !host.compare(host.length() - blacklist_entry_len, blacklist_entry_len, - &kHashData[i + 1], blacklist_entry_len) && - (host.length() == blacklist_entry_len || - host[host.length() - blacklist_entry_len - 1] == '.')) { + if (len >= blacklist_entry_len && + memcmp(&host[len - blacklist_entry_len], &kHashData[i + 1], + blacklist_entry_len) == 0 && + (len == blacklist_entry_len || + host[len - blacklist_entry_len - 1] == '.')) { return true; } i += blacklist_entry_len + 1; |