Index: net/tools/balsa/balsa_headers.cc |
diff --git a/net/tools/balsa/balsa_headers.cc b/net/tools/balsa/balsa_headers.cc |
index 27bfd24a514713b0492375541626ae598ac0d812..f78f89462b1578b518a80dcf6da777d21344189a 100644 |
--- a/net/tools/balsa/balsa_headers.cc |
+++ b/net/tools/balsa/balsa_headers.cc |
@@ -68,11 +68,11 @@ namespace net { |
const size_t BalsaBuffer::kDefaultBlocksize; |
-BalsaHeaders::iterator_base::iterator_base() : headers_(NULL), idx_(0) { } |
+BalsaHeaders::iterator_base::iterator_base() : headers_(NULL), idx_(0) { |
+} |
BalsaHeaders::iterator_base::iterator_base(const iterator_base& it) |
- : headers_(it.headers_), |
- idx_(it.idx_) { |
+ : headers_(it.headers_), idx_(it.idx_) { |
} |
std::ostream& BalsaHeaders::iterator_base::operator<<(std::ostream& os) const { |
@@ -82,8 +82,7 @@ std::ostream& BalsaHeaders::iterator_base::operator<<(std::ostream& os) const { |
BalsaHeaders::iterator_base::iterator_base(const BalsaHeaders* headers, |
HeaderLines::size_type index) |
- : headers_(headers), |
- idx_(index) { |
+ : headers_(headers), idx_(index) { |
} |
BalsaBuffer::~BalsaBuffer() { |
@@ -93,8 +92,7 @@ BalsaBuffer::~BalsaBuffer() { |
// Returns the total amount of memory used by the buffer blocks. |
size_t BalsaBuffer::GetTotalBufferBlockSize() const { |
size_t buffer_size = 0; |
- for (Blocks::const_iterator iter = blocks_.begin(); |
- iter != blocks_.end(); |
+ for (Blocks::const_iterator iter = blocks_.begin(); iter != blocks_.end(); |
++iter) { |
buffer_size += iter->buffer_size; |
} |
@@ -140,8 +138,7 @@ base::StringPiece BalsaBuffer::Write(const base::StringPiece& sp, |
return base::StringPiece(storage, sp.size()); |
} |
-char* BalsaBuffer::Reserve(size_t size, |
- Blocks::size_type* block_buffer_idx) { |
+char* BalsaBuffer::Reserve(size_t size, Blocks::size_type* block_buffer_idx) { |
// There should always be a 'first_block', even if it |
// contains nothing. |
DCHECK_GE(blocks_.size(), 1u); |
@@ -205,8 +202,8 @@ BalsaBuffer::BalsaBuffer() |
blocks_.push_back(AllocBlock()); |
} |
-BalsaBuffer::BalsaBuffer(size_t blocksize) : |
- blocksize_(blocksize), can_write_to_contiguous_buffer_(true) { |
+BalsaBuffer::BalsaBuffer(size_t blocksize) |
+ : blocksize_(blocksize), can_write_to_contiguous_buffer_(true) { |
blocks_.push_back(AllocBlock()); |
} |
@@ -238,16 +235,14 @@ void BalsaBuffer::CleanupBlocksStartingFrom(Blocks::size_type start_idx) { |
BalsaHeaders::const_header_lines_key_iterator::const_header_lines_key_iterator( |
const const_header_lines_key_iterator& other) |
- : iterator_base(other), |
- key_(other.key_) { |
+ : iterator_base(other), key_(other.key_) { |
} |
BalsaHeaders::const_header_lines_key_iterator::const_header_lines_key_iterator( |
const BalsaHeaders* headers, |
HeaderLines::size_type index, |
const base::StringPiece& key) |
- : iterator_base(headers, index), |
- key_(key) { |
+ : iterator_base(headers, index), key_(key) { |
} |
BalsaHeaders::const_header_lines_key_iterator::const_header_lines_key_iterator( |
@@ -273,7 +268,8 @@ BalsaHeaders::BalsaHeaders() |
transfer_encoding_is_chunked_(false) { |
} |
-BalsaHeaders::~BalsaHeaders() {} |
+BalsaHeaders::~BalsaHeaders() { |
+} |
void BalsaHeaders::Clear() { |
balsa_buffer_.Clear(); |
@@ -295,7 +291,8 @@ void BalsaHeaders::Clear() { |
void BalsaHeaders::Swap(BalsaHeaders* other) { |
// Protect against swapping with self. |
- if (this == other) return; |
+ if (this == other) |
+ return; |
balsa_buffer_.Swap(&other->balsa_buffer_); |
@@ -307,8 +304,7 @@ void BalsaHeaders::Swap(BalsaHeaders* other) { |
content_length_ = other->content_length_; |
other->content_length_ = tmp_size_t; |
- BalsaHeadersEnums::ContentLengthStatus tmp_status = |
- content_length_status_; |
+ BalsaHeadersEnums::ContentLengthStatus tmp_status = content_length_status_; |
content_length_status_ = other->content_length_status_; |
other->content_length_status_ = tmp_status; |
@@ -357,7 +353,8 @@ void BalsaHeaders::Swap(BalsaHeaders* other) { |
void BalsaHeaders::CopyFrom(const BalsaHeaders& other) { |
// Protect against copying with self. |
- if (this == &other) return; |
+ if (this == &other) |
+ return; |
balsa_buffer_.CopyFrom(other.balsa_buffer_); |
transfer_encoding_is_chunked_ = other.transfer_encoding_is_chunked_; |
@@ -413,7 +410,7 @@ void BalsaHeaders::AppendOrPrependAndMakeDescription( |
return; |
} |
base::StringPiece old_value(GetPtr(d->buffer_base_idx) + d->value_begin_idx, |
- old_value_size); |
+ old_value_size); |
BalsaBuffer::Blocks::size_type block_buffer_idx = 0; |
// + 3 because we potentially need to add ": ", and "," to the line. |
@@ -529,7 +526,7 @@ base::StringPiece BalsaHeaders::GetValueFromHeaderLineDescription( |
const HeaderLineDescription& line) const { |
DCHECK_GE(line.last_char_idx, line.value_begin_idx); |
return base::StringPiece(GetPtr(line.buffer_base_idx) + line.value_begin_idx, |
- line.last_char_idx - line.value_begin_idx); |
+ line.last_char_idx - line.value_begin_idx); |
} |
const base::StringPiece BalsaHeaders::GetHeader( |
@@ -606,7 +603,8 @@ BalsaHeaders::GetConstHeaderLinesIterator( |
continue; |
} |
if (strncasecmp(GetPtr(line.buffer_base_idx) + line.first_char_idx, |
- key.data(), key_len) == 0) { |
+ key.data(), |
+ key_len) == 0) { |
DCHECK_GE(line.last_char_idx, line.value_begin_idx); |
return i; |
} |
@@ -626,7 +624,8 @@ BalsaHeaders::HeaderLines::iterator BalsaHeaders::GetHeaderLinesIteratorNoSkip( |
continue; |
} |
if (strncasecmp(GetPtr(line.buffer_base_idx) + line.first_char_idx, |
- key.data(), key_len) == 0) { |
+ key.data(), |
+ key_len) == 0) { |
DCHECK_GE(line.last_char_idx, line.value_begin_idx); |
return i; |
} |
@@ -649,7 +648,8 @@ BalsaHeaders::HeaderLines::iterator BalsaHeaders::GetHeaderLinesIterator( |
continue; |
} |
if (strncasecmp(GetPtr(line.buffer_base_idx) + line.first_char_idx, |
- key.data(), key_len) == 0) { |
+ key.data(), |
+ key_len) == 0) { |
DCHECK_GE(line.last_char_idx, line.value_begin_idx); |
return i; |
} |
@@ -657,17 +657,19 @@ BalsaHeaders::HeaderLines::iterator BalsaHeaders::GetHeaderLinesIterator( |
return end; |
} |
-void BalsaHeaders::GetAllOfHeader( |
- const base::StringPiece& key, std::vector<base::StringPiece>* out) const { |
+void BalsaHeaders::GetAllOfHeader(const base::StringPiece& key, |
+ std::vector<base::StringPiece>* out) const { |
for (const_header_lines_key_iterator it = GetIteratorForKey(key); |
- it != header_lines_end(); ++it) { |
+ it != header_lines_end(); |
+ ++it) { |
out->push_back(it->second); |
} |
} |
bool BalsaHeaders::HasNonEmptyHeader(const base::StringPiece& key) const { |
for (const_header_lines_key_iterator it = GetIteratorForKey(key); |
- it != header_lines_key_end(); ++it) { |
+ it != header_lines_key_end(); |
+ ++it) { |
if (!it->second.empty()) |
return true; |
} |
@@ -711,15 +713,15 @@ void BalsaHeaders::RemoveAllHeadersWithPrefix(const base::StringPiece& key) { |
continue; |
} |
if (!strncasecmp(GetPtr(line.buffer_base_idx) + line.first_char_idx, |
- key.data(), key.size())) { |
+ key.data(), |
+ key.size())) { |
line.skip = true; |
} |
} |
} |
size_t BalsaHeaders::GetMemoryUsedLowerBound() const { |
- return (sizeof(*this) + |
- balsa_buffer_.GetTotalBufferBlockSize() + |
+ return (sizeof(*this) + balsa_buffer_.GetTotalBufferBlockSize() + |
header_lines_.capacity() * sizeof(HeaderLineDescription)); |
} |
@@ -754,8 +756,10 @@ void BalsaHeaders::DumpToString(std::string* str) const { |
// Then check whether the header is in a partially parsed state. If so, just |
// dump the raw data. |
if (balsa_buffer_.can_write_to_contiguous_buffer()) { |
- base::StringAppendF(str, "\n<incomplete header len: %d>\n%.*s\n", |
- buffer_length, buffer_length, |
+ base::StringAppendF(str, |
+ "\n<incomplete header len: %d>\n%.*s\n", |
+ buffer_length, |
+ buffer_length, |
OriginalHeaderStreamBegin()); |
return; |
} |
@@ -763,20 +767,22 @@ void BalsaHeaders::DumpToString(std::string* str) const { |
// If the header is complete, then just dump them with the logical key value |
// pair. |
str->reserve(str->size() + GetSizeForWriteBuffer()); |
- base::StringAppendF(str, "\n %.*s\n", |
- static_cast<int>(firstline.size()), |
- firstline.data()); |
+ base::StringAppendF( |
+ str, "\n %.*s\n", static_cast<int>(firstline.size()), firstline.data()); |
BalsaHeaders::const_header_lines_iterator i = header_lines_begin(); |
for (; i != header_lines_end(); ++i) { |
- base::StringAppendF(str, " %.*s: %.*s\n", |
- static_cast<int>(i->first.size()), i->first.data(), |
- static_cast<int>(i->second.size()), i->second.data()); |
+ base::StringAppendF(str, |
+ " %.*s: %.*s\n", |
+ static_cast<int>(i->first.size()), |
+ i->first.data(), |
+ static_cast<int>(i->second.size()), |
+ i->second.data()); |
} |
} |
void BalsaHeaders::SetFirstLine(const base::StringPiece& line) { |
- base::StringPiece new_line = balsa_buffer_.Write(line, |
- &firstline_buffer_base_idx_); |
+ base::StringPiece new_line = |
+ balsa_buffer_.Write(line, &firstline_buffer_base_idx_); |
whitespace_1_idx_ = new_line.data() - GetPtr(firstline_buffer_base_idx_); |
non_whitespace_1_idx_ = whitespace_1_idx_; |
whitespace_4_idx_ = whitespace_1_idx_ + line.size(); |
@@ -807,7 +813,7 @@ void BalsaHeaders::SetContentLength(size_t length) { |
RemoveAllOfHeader(content_length); |
} else if (transfer_encoding_is_chunked_) { |
const base::StringPiece transfer_encoding(kTransferEncoding, |
- sizeof(kTransferEncoding) - 1); |
+ sizeof(kTransferEncoding) - 1); |
RemoveAllOfHeader(transfer_encoding); |
transfer_encoding_is_chunked_ = false; |
} |
@@ -831,13 +837,13 @@ void BalsaHeaders::SetChunkEncoding(bool chunk_encode) { |
// can leave this step out, since transfer-encoding overrides |
// content-length. |
const base::StringPiece content_length(kContentLength, |
- sizeof(kContentLength) - 1); |
+ sizeof(kContentLength) - 1); |
RemoveAllOfHeader(content_length); |
content_length_status_ = BalsaHeadersEnums::NO_CONTENT_LENGTH; |
content_length_ = 0; |
} |
const base::StringPiece transfer_encoding(kTransferEncoding, |
- sizeof(kTransferEncoding) - 1); |
+ sizeof(kTransferEncoding) - 1); |
if (chunk_encode) { |
const char kChunked[] = "chunked"; |
const base::StringPiece chunked(kChunked, sizeof(kChunked) - 1); |
@@ -854,10 +860,8 @@ void BalsaHeaders::SetFirstlineFromStringPieces( |
const base::StringPiece& firstline_a, |
const base::StringPiece& firstline_b, |
const base::StringPiece& firstline_c) { |
- size_t line_size = (firstline_a.size() + |
- firstline_b.size() + |
- firstline_c.size() + |
- 2); |
+ size_t line_size = |
+ (firstline_a.size() + firstline_b.size() + firstline_c.size() + 2); |
char* storage = balsa_buffer_.Reserve(line_size, &firstline_buffer_base_idx_); |
char* cur_loc = storage; |
@@ -890,9 +894,7 @@ void BalsaHeaders::SetRequestMethod(const base::StringPiece& method) { |
if (method.size() <= (whitespace_2_idx_ - non_whitespace_1_idx_)) { |
non_whitespace_1_idx_ = whitespace_2_idx_ - method.size(); |
char* stream_begin = GetPtr(firstline_buffer_base_idx_); |
- memcpy(stream_begin + non_whitespace_1_idx_, |
- method.data(), |
- method.size()); |
+ memcpy(stream_begin + non_whitespace_1_idx_, method.data(), method.size()); |
} else { |
// The new method is too large to fit in the space available for the old |
// one, so we have to reformat the firstline. |
@@ -923,8 +925,8 @@ void BalsaHeaders::SetResponseCode(const base::StringPiece& code) { |
void BalsaHeaders::SetParsedResponseCodeAndUpdateFirstline( |
size_t parsed_response_code) { |
char buffer[kFastToBufferSize]; |
- int len_converted = snprintf(buffer, sizeof(buffer), |
- "%zd", parsed_response_code); |
+ int len_converted = |
+ snprintf(buffer, sizeof(buffer), "%zd", parsed_response_code); |
CHECK_GT(len_converted, 0); |
SetResponseCode(base::StringPiece(buffer, len_converted)); |
} |
@@ -942,9 +944,8 @@ void BalsaHeaders::SetRequestVersion(const base::StringPiece& version) { |
*(stream_begin + whitespace_3_idx_) = kSpaceChar; |
non_whitespace_3_idx_ = whitespace_3_idx_ + 1; |
whitespace_4_idx_ = non_whitespace_3_idx_ + version.size(); |
- memcpy(stream_begin + non_whitespace_3_idx_, |
- version.data(), |
- version.size()); |
+ memcpy( |
+ stream_begin + non_whitespace_3_idx_, version.data(), version.size()); |
} else { |
// The new version is to large to fit in the space available for the old |
// one, so we have to reformat the firstline. |