Skip to content

Commit

Permalink
Remove use of void** from HttpResponseHeaders::EnumerateHeader
Browse files Browse the repository at this point in the history
Remove use of of obaque void** and use instead
size_t* parameter. Logic inside is untouched.

TBR=jam@chromium.org

Review URL: https://codereview.chromium.org/1607773005

Cr-Commit-Position: refs/heads/master@{#371204}
  • Loading branch information
olli.raula authored and Commit bot committed Jan 25, 2016
1 parent 6daf965 commit ee489a5
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ TEST(ExtensionWebRequestHelpersTest,
deltas, headers1.get(), &new_headers1, &warning_set, &net_log);

EXPECT_TRUE(new_headers1->HasHeader("Foo"));
void* iter = NULL;
size_t iter = 0;
std::string cookie_string;
std::set<std::string> expected_cookies;
expected_cookies.insert("name=value; domain=google.com; secure");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ std::vector<std::string> DataReductionProxyTamperDetection::GetHeaderValues(
const std::string& header_name) {
std::vector<std::string> values;
std::string value;
void* iter = NULL;
size_t iter = 0;
while (headers->EnumerateHeader(&iter, header_name, &value)) {
values.push_back(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool GetDataReductionProxyActionValue(
DCHECK(!action_prefix.empty());
// A valid action does not include a trailing '='.
DCHECK(action_prefix[action_prefix.size() - 1] != kActionValueDelimiter);
void* iter = NULL;
size_t iter = 0;
std::string value;
std::string prefix = action_prefix + kActionValueDelimiter;

Expand All @@ -106,7 +106,7 @@ bool ParseHeadersAndSetBypassDuration(const net::HttpResponseHeaders* headers,
DCHECK(!action_prefix.empty());
// A valid action does not include a trailing '='.
DCHECK(action_prefix[action_prefix.size() - 1] != kActionValueDelimiter);
void* iter = NULL;
size_t iter = 0;
std::string value;
std::string prefix = action_prefix + kActionValueDelimiter;

Expand Down Expand Up @@ -188,7 +188,7 @@ bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers,
const size_t kVersionSize = 4;
const char kDataReductionProxyViaValue[] = "Chrome-Compression-Proxy";
size_t value_len = strlen(kDataReductionProxyViaValue);
void* iter = NULL;
size_t iter = 0;
std::string value;

// Case-sensitive comparison of |value|. Assumes the received protocol and the
Expand Down Expand Up @@ -318,7 +318,7 @@ void GetDataReductionProxyHeaderWithFingerprintRemoved(
kChromeProxyActionFingerprintChromeProxy) + kActionValueDelimiter;

std::string value;
void* iter = NULL;
size_t iter = 0;
while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) {
if (value.size() > chrome_proxy_fingerprint_prefix.size()) {
if (base::StartsWith(value, chrome_proxy_fingerprint_prefix,
Expand Down
4 changes: 2 additions & 2 deletions components/variations/service/variations_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ base::Time GetReferenceDateForExpiryChecks(PrefService* local_state) {
std::string GetHeaderValue(const net::HttpResponseHeaders* headers,
const base::StringPiece& name) {
std::string value;
headers->EnumerateHeader(NULL, name, &value);
headers->EnumerateHeader(nullptr, name, &value);
return value;
}

Expand All @@ -226,7 +226,7 @@ std::vector<std::string> GetHeaderValuesList(
const net::HttpResponseHeaders* headers,
const base::StringPiece& name) {
std::vector<std::string> values;
void* iter = NULL;
size_t iter = 0;
std::string value;
while (headers->EnumerateHeader(&iter, name, &value)) {
values.push_back(value);
Expand Down
6 changes: 3 additions & 3 deletions content/browser/appcache/appcache_update_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void AppCacheUpdateJob::URLFetcher::AddConditionalHeaders(
// Add If-Modified-Since header if response info has Last-Modified header.
const std::string last_modified = "Last-Modified";
std::string last_modified_value;
headers->EnumerateHeader(NULL, last_modified, &last_modified_value);
headers->EnumerateHeader(nullptr, last_modified, &last_modified_value);
if (!last_modified_value.empty()) {
extra_headers.SetHeader(net::HttpRequestHeaders::kIfModifiedSince,
last_modified_value);
Expand All @@ -288,7 +288,7 @@ void AppCacheUpdateJob::URLFetcher::AddConditionalHeaders(
// Add If-None-Match header if response info has ETag header.
const std::string etag = "ETag";
std::string etag_value;
headers->EnumerateHeader(NULL, etag, &etag_value);
headers->EnumerateHeader(nullptr, etag, &etag_value);
if (!etag_value.empty()) {
extra_headers.SetHeader(net::HttpRequestHeaders::kIfNoneMatch,
etag_value);
Expand Down Expand Up @@ -1474,7 +1474,7 @@ void AppCacheUpdateJob::OnResponseInfoLoaded(
// Responses with a "vary" header get treated as expired.
const std::string name = "vary";
std::string value;
void* iter = NULL;
size_t iter = 0;
if (!http_info->headers.get() ||
http_info->headers->RequiresValidation(http_info->request_time,
http_info->response_time,
Expand Down
2 changes: 1 addition & 1 deletion content/browser/fileapi/blob_url_request_job_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ TEST_F(BlobURLRequestJobTest, TestExtraHeaders) {
std::string content_type;
EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type));
EXPECT_EQ(kTestContentType, content_type);
void* iter = NULL;
size_t iter = 0;
std::string content_disposition;
EXPECT_TRUE(request_->response_headers()->EnumerateHeader(
&iter, "Content-Disposition", &content_disposition));
Expand Down
2 changes: 1 addition & 1 deletion content/child/multipart_response_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ bool MultipartResponseDelegate::ParseHeaders() {
for (size_t i = 0; i < arraysize(kReplaceHeaders); ++i) {
std::string name(kReplaceHeaders[i]);
std::string value;
void* iterator = nullptr;
size_t iterator = 0;
while (response_headers->EnumerateHeader(&iterator, name, &value)) {
response.addHTTPHeaderField(WebString::fromLatin1(name),
WebString::fromLatin1(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ WebRequestRemoveResponseHeaderAction::CreateDelta(

LinkedPtrEventResponseDelta result(
new helpers::EventResponseDelta(extension_id, extension_install_time));
void* iter = NULL;
size_t iter = 0;
std::string current_value;
while (headers->EnumerateHeader(&iter, name_, &current_value)) {
if (has_value_ && !base::EqualsCaseInsensitiveASCII(current_value, value_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ static ParsedResponseCookies GetResponseCookies(
scoped_refptr<net::HttpResponseHeaders> override_response_headers) {
ParsedResponseCookies result;

void* iter = NULL;
size_t iter = 0;
std::string value;
while (override_response_headers->EnumerateHeader(&iter, "Set-Cookie",
&value)) {
Expand Down
4 changes: 2 additions & 2 deletions net/http/http_auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void HttpAuth::ChooseBestChallenge(
scoped_ptr<HttpAuthHandler> best;
const std::string header_name = GetChallengeHeaderName(target);
std::string cur_challenge;
void* iter = NULL;
size_t iter = 0;
while (headers->EnumerateHeader(&iter, header_name, &cur_challenge)) {
scoped_ptr<HttpAuthHandler> cur;
int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
Expand Down Expand Up @@ -70,7 +70,7 @@ HttpAuth::AuthorizationResult HttpAuth::HandleChallengeResponse(
return HttpAuth::AUTHORIZATION_RESULT_REJECT;
std::string current_scheme_name = SchemeToString(current_scheme);
const std::string header_name = GetChallengeHeaderName(target);
void* iter = NULL;
size_t iter = 0;
std::string challenge;
HttpAuth::AuthorizationResult authorization_result =
HttpAuth::AUTHORIZATION_RESULT_INVALID;
Expand Down
6 changes: 3 additions & 3 deletions net/http/http_auth_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ namespace {
std::string AuthChallengeLogMessage(HttpResponseHeaders* headers) {
std::string msg;
std::string header_val;
void* iter = NULL;
size_t iter = 0;
while (headers->EnumerateHeader(&iter, "proxy-authenticate", &header_val)) {
msg.append("\n Has header Proxy-Authenticate: ");
msg.append(header_val);
}

iter = NULL;
iter = 0;
while (headers->EnumerateHeader(&iter, "www-authenticate", &header_val)) {
msg.append("\n Has header WWW-Authenticate: ");
msg.append(header_val);
Expand All @@ -44,7 +44,7 @@ std::string AuthChallengeLogMessage(HttpResponseHeaders* headers) {
// RFC 4559 requires that a proxy indicate its support of NTLM/Negotiate
// authentication with a "Proxy-Support: Session-Based-Authentication"
// response header.
iter = NULL;
iter = 0;
while (headers->EnumerateHeader(&iter, "proxy-support", &header_val)) {
msg.append("\n Has header Proxy-Support: ");
msg.append(header_val);
Expand Down
2 changes: 1 addition & 1 deletion net/http/http_network_transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void ProcessAlternativeServices(HttpNetworkSession* session,
return;

std::vector<std::string> alternate_protocol_values;
void* iter = NULL;
size_t iter = 0;
std::string alternate_protocol_str;
while (headers.EnumerateHeader(&iter, kAlternateProtocolHeader,
&alternate_protocol_str)) {
Expand Down
2 changes: 1 addition & 1 deletion net/http/http_network_transaction_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ TEST_P(HttpNetworkTransactionTest, Head) {
EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent());

std::string server_header;
void* iter = NULL;
size_t iter = 0;
bool has_server_header = response->headers->EnumerateHeader(
&iter, "Server", &server_header);
EXPECT_TRUE(has_server_header);
Expand Down
30 changes: 15 additions & 15 deletions net/http/http_response_headers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,14 @@ bool HttpResponseHeaders::EnumerateHeaderLines(size_t* iter,
return true;
}

bool HttpResponseHeaders::EnumerateHeader(void** iter,
bool HttpResponseHeaders::EnumerateHeader(size_t* iter,
const base::StringPiece& name,
std::string* value) const {
size_t i;
if (!iter || !*iter) {
i = FindHeader(0, name);
} else {
i = reinterpret_cast<size_t>(*iter);
i = *iter;
if (i >= parsed_.size()) {
i = std::string::npos;
} else if (!parsed_[i].is_continuation()) {
Expand All @@ -592,7 +592,7 @@ bool HttpResponseHeaders::EnumerateHeader(void** iter,
}

if (iter)
*iter = reinterpret_cast<void*>(i + 1);
*iter = i + 1;
value->assign(parsed_[i].value_begin, parsed_[i].value_end);
return true;
}
Expand All @@ -601,7 +601,7 @@ bool HttpResponseHeaders::HasHeaderValue(const base::StringPiece& name,
const base::StringPiece& value) const {
// The value has to be an exact match. This is important since
// 'cache-control: no-cache' != 'cache-control: no-cache="foo"'
void* iter = NULL;
size_t iter = 0;
std::string temp;
while (EnumerateHeader(&iter, name, &temp)) {
if (base::EqualsCaseInsensitiveASCII(value, temp))
Expand Down Expand Up @@ -757,7 +757,7 @@ bool HttpResponseHeaders::GetCacheControlDirective(const StringPiece& directive,

size_t directive_size = directive.size();

void* iter = NULL;
size_t iter = 0;
while (EnumerateHeader(&iter, name, &value)) {
if (value.size() > directive_size + 1 &&
base::StartsWith(value, directive,
Expand Down Expand Up @@ -814,7 +814,7 @@ void HttpResponseHeaders::AddNonCacheableHeaders(HeaderSet* result) const {
const size_t kPrefixLen = sizeof(kPrefix) - 1;

std::string value;
void* iter = NULL;
size_t iter = 0;
while (EnumerateHeader(&iter, kCacheControl, &value)) {
// If the value is smaller than the prefix and a terminal quote, skip
// it.
Expand Down Expand Up @@ -889,7 +889,7 @@ void HttpResponseHeaders::GetMimeTypeAndCharset(std::string* mime_type,

bool had_charset = false;

void* iter = NULL;
size_t iter = 0;
while (EnumerateHeader(&iter, name, &value))
HttpUtil::ParseContentType(value, mime_type, charset, &had_charset, NULL);
}
Expand Down Expand Up @@ -1152,7 +1152,7 @@ bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const {

bool HttpResponseHeaders::GetAgeValue(TimeDelta* result) const {
std::string value;
if (!EnumerateHeader(NULL, "Age", &value))
if (!EnumerateHeader(nullptr, "Age", &value))
return false;

int64_t seconds;
Expand Down Expand Up @@ -1181,7 +1181,7 @@ bool HttpResponseHeaders::GetStaleWhileRevalidateValue(
bool HttpResponseHeaders::GetTimeValuedHeader(const std::string& name,
Time* result) const {
std::string value;
if (!EnumerateHeader(NULL, name, &value))
if (!EnumerateHeader(nullptr, name, &value))
return false;

// When parsing HTTP dates it's beneficial to default to GMT because:
Expand Down Expand Up @@ -1223,7 +1223,7 @@ bool HttpResponseHeaders::IsKeepAlive() const {
return false;

for (const char* header : kConnectionHeaders) {
void* iterator = nullptr;
size_t iterator = 0;
std::string token;
while (EnumerateHeader(&iterator, header, &token)) {
for (const KeepAliveToken& keep_alive_token : kKeepAliveTokens) {
Expand All @@ -1237,11 +1237,11 @@ bool HttpResponseHeaders::IsKeepAlive() const {

bool HttpResponseHeaders::HasStrongValidators() const {
std::string etag_header;
EnumerateHeader(NULL, "etag", &etag_header);
EnumerateHeader(nullptr, "etag", &etag_header);
std::string last_modified_header;
EnumerateHeader(NULL, "Last-Modified", &last_modified_header);
EnumerateHeader(nullptr, "Last-Modified", &last_modified_header);
std::string date_header;
EnumerateHeader(NULL, "Date", &date_header);
EnumerateHeader(nullptr, "Date", &date_header);
return HttpUtil::HasStrongValidators(GetHttpVersion(),
etag_header,
last_modified_header,
Expand All @@ -1256,7 +1256,7 @@ int64_t HttpResponseHeaders::GetContentLength() const {

int64_t HttpResponseHeaders::GetInt64HeaderValue(
const std::string& header) const {
void* iter = NULL;
size_t iter = 0;
std::string content_length_val;
if (!EnumerateHeader(&iter, header, &content_length_val))
return -1;
Expand Down Expand Up @@ -1284,7 +1284,7 @@ int64_t HttpResponseHeaders::GetInt64HeaderValue(
bool HttpResponseHeaders::GetContentRange(int64_t* first_byte_position,
int64_t* last_byte_position,
int64_t* instance_length) const {
void* iter = NULL;
size_t iter = 0;
std::string content_range_spec;
*first_byte_position = *last_byte_position = *instance_length = -1;
if (!EnumerateHeader(&iter, kContentRange, &content_range_spec))
Expand Down
7 changes: 3 additions & 4 deletions net/http/http_response_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,12 @@ class NET_EXPORT HttpResponseHeaders
std::string* value) const;

// Enumerate the values of the specified header. If you are only interested
// in the first header, then you can pass NULL for the 'iter' parameter.
// in the first header, then you can pass nullptr for the 'iter' parameter.
// Otherwise, to iterate across all values for the specified header,
// initialize a 'void*' variable to NULL and pass it by address to
// initialize a 'size_t' variable to 0 and pass it by address to
// EnumerateHeader. Note that a header might have an empty value. Call
// EnumerateHeader repeatedly until it returns false.
// TODO(Olli Raula) Remove void**
bool EnumerateHeader(void** iter,
bool EnumerateHeader(size_t* iter,
const base::StringPiece& name,
std::string* value) const;

Expand Down
4 changes: 2 additions & 2 deletions net/http/http_response_headers_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ TEST(HttpResponseHeadersTest, EnumerateHeader_Coalesced) {
HeadersToRaw(&headers);
scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers));

void* iter = NULL;
size_t iter = 0;
std::string value;
EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value));
EXPECT_EQ("private", value);
Expand All @@ -478,7 +478,7 @@ TEST(HttpResponseHeadersTest, EnumerateHeader_Challenge) {
HeadersToRaw(&headers);
scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers));

void* iter = NULL;
size_t iter = 0;
std::string value;
EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value));
EXPECT_EQ("Digest realm=foobar, nonce=x, domain=y", value);
Expand Down
2 changes: 1 addition & 1 deletion net/http/http_stream_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ std::string GetResponseHeaderLines(const HttpResponseHeaders& headers) {
// values.
bool HeadersContainMultipleCopiesOfField(const HttpResponseHeaders& headers,
const std::string& field_name) {
void* it = NULL;
size_t it = 0;
std::string field_value;
if (!headers.EnumerateHeader(&it, field_name, &field_value))
return false;
Expand Down
2 changes: 1 addition & 1 deletion net/http/http_vary_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool HttpVaryData::Init(const HttpRequestInfo& request_info,
// If the Vary header contains '*' then we should not construct any vary data
// since it is all usurped by a '*'. See section 13.6 of RFC 2616.
//
void* iter = NULL;
size_t iter = 0;
std::string name = "vary", request_header;
while (response_headers.EnumerateHeader(&iter, name, &request_header)) {
if (request_header == "*")
Expand Down
2 changes: 1 addition & 1 deletion net/http/proxy_client_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace {
void CopyHeaderValues(scoped_refptr<HttpResponseHeaders> source,
scoped_refptr<HttpResponseHeaders> dest,
const std::string& header_name) {
void* iter = NULL;
size_t iter = 0;
std::string header_value;

while (source->EnumerateHeader(&iter, header_name, &header_value))
Expand Down
2 changes: 1 addition & 1 deletion net/tools/get_server_time/get_server_time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ int main(int argc, char* argv[]) {
return EXIT_FAILURE;
}

void* iter = NULL;
size_t iter = 0;
std::string date_header;
while (headers->EnumerateHeader(&iter, "Date", &date_header)) {
std::printf("Got date header: %s\n", date_header.c_str());
Expand Down
2 changes: 1 addition & 1 deletion net/url_request/url_request_backoff_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bool URLRequestBackoffManager::GetBackoffTime(HttpResponseHeaders* headers,
base::TimeDelta* result) const {
base::StringPiece name("Backoff");
std::string value;
void* iter = NULL;
size_t iter = 0;
while (headers->EnumerateHeader(&iter, name, &value)) {
int64_t seconds;
base::StringToInt64(value, &seconds);
Expand Down
Loading

0 comments on commit ee489a5

Please sign in to comment.