summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authormbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-13 23:09:16 +0000
committermbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-13 23:09:16 +0000
commit8be62535d5dc911d6594b55c3c9fbfe27bacb142 (patch)
treeedb872299ed250a2f54427b20f1ea1eb236eeffa /net
parent59f9bfeec0da4208c39f52f0eb356094d89008a3 (diff)
downloadchromium_src-8be62535d5dc911d6594b55c3c9fbfe27bacb142.zip
chromium_src-8be62535d5dc911d6594b55c3c9fbfe27bacb142.tar.gz
chromium_src-8be62535d5dc911d6594b55c3c9fbfe27bacb142.tar.bz2
More changes intended to make flip_in_mem_edsm_server.cc compile and run
in the chrome tree. Checkin for Roberto Peon (fenix@google.com) BUG=none TEST=none Review URL: http://codereview.chromium.org/543029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36187 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/tools/flip_server/balsa_enums.h2
-rw-r--r--net/tools/flip_server/balsa_frame.cc129
-rw-r--r--net/tools/flip_server/balsa_frame.h25
-rw-r--r--net/tools/flip_server/balsa_headers.cc159
-rw-r--r--net/tools/flip_server/balsa_headers.h203
-rw-r--r--net/tools/flip_server/balsa_headers_token_utils.cc17
-rw-r--r--net/tools/flip_server/balsa_headers_token_utils.h10
-rw-r--r--net/tools/flip_server/create_listener.cc6
-rw-r--r--net/tools/flip_server/create_listener.h6
-rw-r--r--net/tools/flip_server/create_listener_test.cc61
-rw-r--r--net/tools/flip_server/epoll_server.cc18
-rw-r--r--net/tools/flip_server/epoll_server.h47
-rw-r--r--net/tools/flip_server/flip_in_mem_edsm_server.cc261
-rw-r--r--net/tools/flip_server/loadtime_measurement.h39
-rw-r--r--net/tools/flip_server/other_defines.h23
-rw-r--r--net/tools/flip_server/ring_buffer.h1
-rw-r--r--net/tools/flip_server/simple_buffer.cc4
-rw-r--r--net/tools/flip_server/simple_buffer.h3
-rw-r--r--net/tools/flip_server/split.cc70
-rw-r--r--net/tools/flip_server/split.h23
-rw-r--r--net/tools/flip_server/string_piece_utils.h81
-rw-r--r--net/tools/flip_server/url_to_filename_encoder.h6
-rw-r--r--net/tools/flip_server/url_utilities.h32
23 files changed, 706 insertions, 520 deletions
diff --git a/net/tools/flip_server/balsa_enums.h b/net/tools/flip_server/balsa_enums.h
index c665c16..4273ee4 100644
--- a/net/tools/flip_server/balsa_enums.h
+++ b/net/tools/flip_server/balsa_enums.h
@@ -9,7 +9,7 @@ namespace net {
struct BalsaFrameEnums {
enum ParseState {
- ERROR,
+ PARSE_ERROR,
READING_HEADER_AND_FIRSTLINE,
READING_CHUNK_LENGTH,
READING_CHUNK_EXTENSION,
diff --git a/net/tools/flip_server/balsa_frame.cc b/net/tools/flip_server/balsa_frame.cc
index fca045e..90631ce 100644
--- a/net/tools/flip_server/balsa_frame.cc
+++ b/net/tools/flip_server/balsa_frame.cc
@@ -16,17 +16,14 @@
#include "base/logging.h"
#include "base/port.h"
+#include "base/string_piece.h"
#include "net/tools/flip_server/balsa_enums.h"
#include "net/tools/flip_server/balsa_headers.h"
#include "net/tools/flip_server/balsa_visitor_interface.h"
#include "net/tools/flip_server/buffer_interface.h"
#include "net/tools/flip_server/simple_buffer.h"
-#ifdef CHROMIUM
-#else
-#include "strings/split.h"
-#include "strings/stringpiece.h" // for StringPiece
-#include "strings/stringpiece_utils.h"
-#endif
+#include "net/tools/flip_server/split.h"
+#include "net/tools/flip_server/string_piece_utils.h"
namespace net {
@@ -350,7 +347,7 @@ bool ParseHTTPFirstLine(const char* begin,
const char* parsed_response_code_current =
begin + headers->non_whitespace_2_idx_;
const char* parsed_response_code_end = begin + headers->whitespace_3_idx_;
- const size_t kMaxDiv10 = numeric_limits<size_t>::max() / 10;
+ const size_t kMaxDiv10 = std::numeric_limits<size_t>::max() / 10;
// Convert a string of [0-9]* into an int.
// Note that this allows for the conversion of response codes which
@@ -365,7 +362,7 @@ bool ParseHTTPFirstLine(const char* begin,
size_t status_code_x_10 = headers->parsed_response_code_ * 10;
uint8 c = *parsed_response_code_current - '0';
if ((headers->parsed_response_code_ > kMaxDiv10) ||
- (numeric_limits<size_t>::max() - status_code_x_10) < c) {
+ (std::numeric_limits<size_t>::max() - status_code_x_10) < c) {
// overflow.
*error_code = BalsaFrameEnums::FAILED_CONVERTING_STATUS_CODE_TO_INT;
return false;
@@ -396,7 +393,7 @@ void BalsaFrame::ProcessFirstLine(const char* begin, const char* end) {
max_request_uri_length_,
headers_,
&last_error_)) {
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
visitor_->HandleHeaderError(this);
return;
}
@@ -446,7 +443,8 @@ void BalsaFrame::CleanUpKeyValueWhitespace(
DCHECK_LT(colon_loc, line_end);
DCHECK_EQ(':', *colon_loc);
DCHECK_EQ(':', *current);
- DCHECK_GE(' ', *line_end) << "\"" << string(line_begin, line_end) << "\"";
+ DCHECK_GE(' ', *line_end)
+ << "\"" << std::string(line_begin, line_end) << "\"";
// TODO(fenix): Investigate whether or not the bounds tests in the
// while loops here are redundant, and if so, remove them.
@@ -512,7 +510,8 @@ inline void BalsaFrame::FindColonsAndParseIntoKeyValue() {
//
// We're guaranteed to have *line_end > ' ' while line_end >= line_begin.
--line_end;
- DCHECK_EQ('\n', *line_end) << "\"" << string(line_begin, line_end) << "\"";
+ DCHECK_EQ('\n', *line_end)
+ << "\"" << std::string(line_begin, line_end) << "\"";
while (*line_end <= ' ' && line_end > line_begin) {
--line_end;
}
@@ -623,11 +622,11 @@ void BalsaFrame::ProcessContentLengthLine(
#endif // DEBUGFRAMER
return;
}
- const size_t kMaxDiv10 = numeric_limits<size_t>::max() / 10;
+ const size_t kMaxDiv10 = std::numeric_limits<size_t>::max() / 10;
size_t length_x_10 = *length * 10;
- const char c = *value_begin - '0';
+ const unsigned char c = *value_begin - '0';
if (*length > kMaxDiv10 ||
- (numeric_limits<size_t>::max() - length_x_10) < c) {
+ (std::numeric_limits<size_t>::max() - length_x_10) < c) {
*status = BalsaHeadersEnums::CONTENT_LENGTH_OVERFLOW;
#if DEBUGFRAMER
LOG(INFO) << "content-length overflow";
@@ -658,15 +657,15 @@ void BalsaFrame::ProcessTransferEncodingLine(HeaderLines::size_type line_idx) {
headers_->transfer_encoding_is_chunked_ = false;
} else {
last_error_ = BalsaFrameEnums::UNKNOWN_TRANSFER_ENCODING;
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
visitor_->HandleHeaderError(this);
return;
}
}
namespace {
-bool SplitStringPiece(StringPiece original, char delim,
- StringPiece* before, StringPiece* after) {
+bool SplitStringPiece(base::StringPiece original, char delim,
+ base::StringPiece* before, base::StringPiece* after) {
const char* p = original.data();
const char* end = p + original.size();
@@ -678,11 +677,11 @@ bool SplitStringPiece(StringPiece original, char delim,
while (++p != end && *p != delim) {
// Skip to the next occurence of the delimiter.
}
- *before = StringPiece(start, p - start);
+ *before = base::StringPiece(start, p - start);
if (p != end)
- *after = StringPiece(p + 1, end - (p + 1));
+ *after = base::StringPiece(p + 1, end - (p + 1));
else
- *after = StringPiece("");
+ *after = base::StringPiece("");
StringPieceUtils::RemoveWhitespaceContext(before);
StringPieceUtils::RemoveWhitespaceContext(after);
return true;
@@ -697,15 +696,15 @@ bool SplitStringPiece(StringPiece original, char delim,
// TODO(phython): Fix this function to properly deal with quoted values.
// E.g. ";;foo", "\";;\"", or \"aa;
// The last example, the semi-colon is a separator between extensions.
-void ProcessChunkExtensionsManual(StringPiece all_extensions,
+void ProcessChunkExtensionsManual(base::StringPiece all_extensions,
BalsaHeaders* extensions) {
- StringPiece extension;
- StringPiece remaining;
+ base::StringPiece extension;
+ base::StringPiece remaining;
StringPieceUtils::RemoveWhitespaceContext(&all_extensions);
SplitStringPiece(all_extensions, ';', &extension, &remaining);
while (!extension.empty()) {
- StringPiece key;
- StringPiece value;
+ base::StringPiece key;
+ base::StringPiece value;
SplitStringPiece(extension, '=', &key, &value);
if (!value.empty()) {
// Strip quotation marks if they exist.
@@ -727,11 +726,12 @@ void ProcessChunkExtensionsManual(StringPiece all_extensions,
// The last example, the semi-colon is a separator between extensions.
void ProcessChunkExtensionsGoogle3(const char* input, size_t size,
BalsaHeaders* extensions) {
- vector<StringPiece> key_values;
- SplitStringPieceToVector(StringPiece(input, size), ";", &key_values, true);
- for (int i = 0; i < key_values.size(); ++i) {
- StringPiece key = key_values[i].substr(0, key_values[i].find('='));
- StringPiece value;
+ std::vector<base::StringPiece> key_values;
+ SplitStringPieceToVector(base::StringPiece(input, size), ";",
+ &key_values, true);
+ for (unsigned int i = 0; i < key_values.size(); ++i) {
+ base::StringPiece key = key_values[i].substr(0, key_values[i].find('='));
+ base::StringPiece value;
if (key.length() < key_values[i].length()) {
value = key_values[i].substr(key.length() + 1);
// Remove any leading and trailing whitespace.
@@ -757,7 +757,7 @@ void BalsaFrame::ProcessChunkExtensions(const char* input, size_t size,
#if 0
ProcessChunkExtensionsGoogle3(input, size, extensions);
#else
- ProcessChunkExtensionsManual(StringPiece(input, size), extensions);
+ ProcessChunkExtensionsManual(base::StringPiece(input, size), extensions);
#endif
}
@@ -795,7 +795,7 @@ void BalsaFrame::ProcessHeaderLines() {
const size_t key_len = key_end - key_begin;
const char c = *key_begin;
#if DEBUGFRAMER
- LOG(INFO) << "[" << i << "]: " << string(key_begin, key_len)
+ LOG(INFO) << "[" << i << "]: " << std::string(key_begin, key_len)
<< " c: '" << c << "' key_len: " << key_len;
#endif // DEBUGFRAMER
// If a header begins with either lowercase or uppercase 'c' or 't', then
@@ -818,7 +818,7 @@ void BalsaFrame::ProcessHeaderLines() {
BalsaHeadersEnums::VALID_CONTENT_LENGTH) &&
length != headers_->content_length_)) {
last_error_ = BalsaFrameEnums::MULTIPLE_CONTENT_LENGTH_KEYS;
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
visitor_->HandleHeaderError(this);
return;
}
@@ -837,7 +837,7 @@ void BalsaFrame::ProcessHeaderLines() {
kTransferEncodingSize)) {
if (transfer_encoding_idx != 0) {
last_error_ = BalsaFrameEnums::MULTIPLE_TRANSFER_ENCODING_KEYS;
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
visitor_->HandleHeaderError(this);
return;
}
@@ -845,7 +845,7 @@ void BalsaFrame::ProcessHeaderLines() {
}
} else if (i == 0 && (key_len == 0 || c == ' ')) {
last_error_ = BalsaFrameEnums::INVALID_HEADER_FORMAT;
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
visitor_->HandleHeaderError(this);
return;
}
@@ -899,7 +899,7 @@ void BalsaFrame::AssignParseStateAfterHeadersHaveBeenParsed() {
case BalsaHeadersEnums::INVALID_CONTENT_LENGTH:
// If there were characters left-over after parsing the
// content length, we should flag an error and stop.
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
last_error_ = BalsaFrameEnums::UNPARSABLE_CONTENT_LENGTH;
visitor_->HandleHeaderError(this);
break;
@@ -911,14 +911,14 @@ void BalsaFrame::AssignParseStateAfterHeadersHaveBeenParsed() {
// everything until the connection is closed is body.
case BalsaHeadersEnums::NO_CONTENT_LENGTH:
if (is_request_) {
- StringPiece method = headers_->request_method();
+ base::StringPiece method = headers_->request_method();
// POSTs and PUTs should have a detectable body length. If they
// do not we consider it an error.
if ((method.size() == 4 &&
strncmp(method.data(), "POST", 4) == 0) ||
(method.size() == 3 &&
strncmp(method.data(), "PUT", 3) == 0)) {
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
last_error_ =
BalsaFrameEnums::REQUIRED_BODY_BUT_NO_CONTENT_LENGTH;
visitor_->HandleHeaderError(this);
@@ -966,7 +966,7 @@ size_t BalsaFrame::ProcessHeaders(const char* message_start,
const char c = *message_current;
if (c != '\r' && c != '\n') {
if (c <= ' ') {
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
last_error_ = BalsaFrameEnums::NO_REQUEST_LINE_IN_REQUEST;
visitor_->HandleHeaderError(this);
goto bottom;
@@ -1012,20 +1012,21 @@ size_t BalsaFrame::ProcessHeaders(const char* message_start,
message_current += (ffs(newline_msk) - 1);
const size_t relative_idx = message_current - message_start;
const size_t message_current_idx = 1 + base_idx + relative_idx;
- lines_.push_back(make_pair(last_slash_n_idx_, message_current_idx));
+ lines_.push_back(std::make_pair(last_slash_n_idx_,
+ message_current_idx));
if (lines_.size() == 1) {
headers_->WriteFromFramer(checkpoint,
1 + message_current - checkpoint);
checkpoint = message_current + 1;
const char* begin = headers_->OriginalHeaderStreamBegin();
#if DEBUGFRAMER
- LOG(INFO) << "First line " << string(begin, lines_[0].second);
+ LOG(INFO) << "First line " << std::string(begin, lines_[0].second);
LOG(INFO) << "is_request_: " << is_request_;
#endif
ProcessFirstLine(begin, begin + lines_[0].second);
if (parse_state_ == BalsaFrameEnums::MESSAGE_FULLY_READ)
goto process_lines;
- else if (parse_state_ == BalsaFrameEnums::ERROR)
+ else if (parse_state_ == BalsaFrameEnums::PARSE_ERROR)
goto bottom;
}
const size_t chars_since_last_slash_n = (message_current_idx -
@@ -1055,20 +1056,21 @@ size_t BalsaFrame::ProcessHeaders(const char* message_start,
}
const size_t relative_idx = message_current - message_start;
const size_t message_current_idx = 1 + base_idx + relative_idx;
- lines_.push_back(make_pair(last_slash_n_idx_, message_current_idx));
+ lines_.push_back(std::make_pair(last_slash_n_idx_,
+ message_current_idx));
if (lines_.size() == 1) {
headers_->WriteFromFramer(checkpoint,
1 + message_current - checkpoint);
checkpoint = message_current + 1;
const char* begin = headers_->OriginalHeaderStreamBegin();
#if DEBUGFRAMER
- LOG(INFO) << "First line " << string(begin, lines_[0].second);
+ LOG(INFO) << "First line " << std::string(begin, lines_[0].second);
LOG(INFO) << "is_request_: " << is_request_;
#endif
ProcessFirstLine(begin, begin + lines_[0].second);
if (parse_state_ == BalsaFrameEnums::MESSAGE_FULLY_READ)
goto process_lines;
- else if (parse_state_ == BalsaFrameEnums::ERROR)
+ else if (parse_state_ == BalsaFrameEnums::PARSE_ERROR)
goto bottom;
}
const size_t chars_since_last_slash_n = (message_current_idx -
@@ -1102,7 +1104,7 @@ size_t BalsaFrame::ProcessHeaders(const char* message_start,
// the max_header_length_ (for example after processing the first line)
// we handle it gracefully.
if (headers_->GetReadableBytesFromHeaderStream() > max_header_length_) {
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
last_error_ = BalsaFrameEnums::HEADERS_TOO_LONG;
visitor_->HandleHeaderError(this);
goto bottom;
@@ -1123,11 +1125,11 @@ size_t BalsaFrame::ProcessHeaders(const char* message_start,
// time to process the header lines (extract proper values for headers
// which are important for framing).
ProcessHeaderLines();
- if (parse_state_ == BalsaFrameEnums::ERROR) {
+ if (parse_state_ == BalsaFrameEnums::PARSE_ERROR) {
goto bottom;
}
AssignParseStateAfterHeadersHaveBeenParsed();
- if (parse_state_ == BalsaFrameEnums::ERROR) {
+ if (parse_state_ == BalsaFrameEnums::PARSE_ERROR) {
goto bottom;
}
visitor_->ProcessHeaders(*headers_);
@@ -1156,7 +1158,7 @@ size_t BalsaFrame::BytesSafeToSplice() const {
case BalsaFrameEnums::READING_CHUNK_DATA:
return chunk_length_remaining_;
case BalsaFrameEnums::READING_UNTIL_CLOSE:
- return numeric_limits<size_t>::max();
+ return std::numeric_limits<size_t>::max();
case BalsaFrameEnums::READING_CONTENT:
return content_length_remaining_;
default:
@@ -1202,7 +1204,7 @@ void BalsaFrame::BytesSpliced(size_t bytes_spliced) {
}
error_exit:
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
visitor_->HandleBodyError(this);
};
@@ -1243,7 +1245,7 @@ size_t BalsaFrame::ProcessInput(const char* input, size_t size) {
// READING_HEADER_AND_FIRSTLINE) in which case we directly declare an error.
if (header_length > max_header_length_ ||
(header_length == max_header_length_ && size > 0)) {
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
last_error_ = BalsaFrameEnums::HEADERS_TOO_LONG;
visitor_->HandleHeaderError(this);
goto bottom;
@@ -1263,14 +1265,14 @@ size_t BalsaFrame::ProcessInput(const char* input, size_t size) {
const size_t header_length_after =
headers_->GetReadableBytesFromHeaderStream();
if (header_length_after >= max_header_length_) {
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
last_error_ = BalsaFrameEnums::HEADERS_TOO_LONG;
visitor_->HandleHeaderError(this);
}
}
goto bottom;
} else if (parse_state_ == BalsaFrameEnums::MESSAGE_FULLY_READ ||
- parse_state_ == BalsaFrameEnums::ERROR) {
+ parse_state_ == BalsaFrameEnums::PARSE_ERROR) {
// Can do nothing more 'till we're reset.
goto bottom;
}
@@ -1324,15 +1326,16 @@ size_t BalsaFrame::ProcessInput(const char* input, size_t size) {
while (current < end) {
const char c = *current;
++current;
- const signed char addition = buf[c];
+ const signed char addition = buf[static_cast<int>(c)];
if (addition >= 0) {
chunk_length_character_extracted_ = true;
size_t length_x_16 = chunk_length_remaining_ * 16;
- const size_t kMaxDiv16 = numeric_limits<size_t>::max() / 16;
+ const size_t kMaxDiv16 = std::numeric_limits<size_t>::max() / 16;
if ((chunk_length_remaining_ > kMaxDiv16) ||
- (numeric_limits<size_t>::max() - length_x_16) < addition) {
+ ((std::numeric_limits<size_t>::max() - length_x_16) <
+ static_cast<size_t>(addition))) {
// overflow -- asked for a chunk-length greater than 2^64 - 1!!
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
last_error_ = BalsaFrameEnums::CHUNK_LENGTH_OVERFLOW;
visitor_->ProcessBodyInput(on_entry, current - on_entry);
visitor_->HandleChunkingError(this);
@@ -1346,7 +1349,7 @@ size_t BalsaFrame::ProcessInput(const char* input, size_t size) {
// ^[0-9;A-Fa-f][ \t\n] -- was not matched, either because no
// characters were converted, or an unexpected character was
// seen.
- parse_state_ = BalsaFrameEnums::ERROR;
+ parse_state_ = BalsaFrameEnums::PARSE_ERROR;
last_error_ = BalsaFrameEnums::INVALID_CHUNK_LENGTH;
visitor_->ProcessBodyInput(on_entry, current - on_entry);
visitor_->HandleChunkingError(this);
@@ -1550,7 +1553,7 @@ size_t BalsaFrame::ProcessInput(const char* input, size_t size) {
bottom:
#if DEBUGFRAMER
LOG(INFO) << "\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n"
- << string(input, current)
+ << std::string(input, current)
<< "\n$$$$$$$$$$$$$$"
<< BalsaFrameEnums::ParseStateToString(parse_state_)
<< "$$$$$$$$$$$$$$$"
@@ -1562,10 +1565,10 @@ size_t BalsaFrame::ProcessInput(const char* input, size_t size) {
return current - input;
}
-const int32 BalsaFrame::kValidTerm1;
-const int32 BalsaFrame::kValidTerm1Mask;
-const int32 BalsaFrame::kValidTerm2;
-const int32 BalsaFrame::kValidTerm2Mask;
+const uint32 BalsaFrame::kValidTerm1;
+const uint32 BalsaFrame::kValidTerm1Mask;
+const uint32 BalsaFrame::kValidTerm2;
+const uint32 BalsaFrame::kValidTerm2Mask;
} // namespace net
diff --git a/net/tools/flip_server/balsa_frame.h b/net/tools/flip_server/balsa_frame.h
index 0799981..37bf5be 100644
--- a/net/tools/flip_server/balsa_frame.h
+++ b/net/tools/flip_server/balsa_frame.h
@@ -7,7 +7,6 @@
#include <strings.h>
-#include <string>
#include <utility>
#include <vector>
@@ -28,7 +27,7 @@ namespace net {
// It exists as a proof of concept headers framer.
class BalsaFrame {
public:
- typedef vector<pair<size_t, size_t> > Lines;
+ typedef std::vector<std::pair<size_t, size_t> > Lines;
typedef BalsaHeaders::HeaderLineDescription HeaderLineDescription;
typedef BalsaHeaders::HeaderLines HeaderLines;
@@ -37,16 +36,16 @@ class BalsaFrame {
// TODO(fenix): get rid of the 'kValidTerm*' stuff by using the 'since last
// index' strategy. Note that this implies getting rid of the HeaderFramed()
- static const int32 kValidTerm1 = '\n' << 16 |
- '\r' << 8 |
- '\n';
- static const int32 kValidTerm1Mask = 0xFF << 16 |
- 0xFF << 8 |
- 0xFF;
- static const int32 kValidTerm2 = '\n' << 8 |
- '\n';
- static const int32 kValidTerm2Mask = 0xFF << 8 |
- 0xFF;
+ static const uint32 kValidTerm1 = '\n' << 16 |
+ '\r' << 8 |
+ '\n';
+ static const uint32 kValidTerm1Mask = 0xFF << 16 |
+ 0xFF << 8 |
+ 0xFF;
+ static const uint32 kValidTerm2 = '\n' << 8 |
+ '\n';
+ static const uint32 kValidTerm2Mask = 0xFF << 8 |
+ 0xFF;
BalsaFrame() :
last_char_was_slash_r_(false),
saw_non_newline_char_(false),
@@ -136,7 +135,7 @@ class BalsaFrame {
bool Error() {
- return parse_state_ == BalsaFrameEnums::ERROR;
+ return parse_state_ == BalsaFrameEnums::PARSE_ERROR;
}
BalsaFrameEnums::ErrorCode ErrorCode() const { return last_error_; }
diff --git a/net/tools/flip_server/balsa_headers.cc b/net/tools/flip_server/balsa_headers.cc
index 82a0279..40e446b 100644
--- a/net/tools/flip_server/balsa_headers.cc
+++ b/net/tools/flip_server/balsa_headers.cc
@@ -7,18 +7,19 @@
#include <emmintrin.h>
#include <algorithm>
-#include <hash_set>
+#include <ext/hash_set>
#include <string>
#include <utility>
#include <vector>
-#include "base/googleinit.h"
+#include "base/logging.h"
#include "base/port.h"
+#include "base/string_piece.h"
+#include "base/string_util.h"
#include "net/tools/flip_server/balsa_enums.h"
#include "net/tools/flip_server/buffer_interface.h"
#include "net/tools/flip_server/simple_buffer.h"
-#include "strings/stringpiece.h"
-#include "strings/strutil.h"
+#include "third_party/tcmalloc/chromium/src/base/googleinit.h"
// #include "util/gtl/iterator_adaptors-inl.h"
// #include "util/gtl/map-util.h"
@@ -28,8 +29,9 @@ const char kContentLength[] = "Content-Length";
const char kTransferEncoding[] = "Transfer-Encoding";
const char kSpaceChar = ' ';
-hash_set<StringPiece, StringPieceCaseHash, StringPieceCaseEqual>
-g_multivalued_headers;
+__gnu_cxx::hash_set<base::StringPiece,
+ net::StringPieceCaseHash,
+ net::StringPieceCaseEqual> g_multivalued_headers;
void InitMultivaluedHeaders() {
g_multivalued_headers.insert("accept");
@@ -61,6 +63,8 @@ void InitMultivaluedHeaders() {
REGISTER_MODULE_INITIALIZER(multivalued_headers, InitMultivaluedHeaders());
+const int kFastToBufferSize = 32; // I think 22 is adequate, but anyway..
+
} // namespace
namespace net {
@@ -168,8 +172,8 @@ void BalsaHeaders::CopyFrom(const BalsaHeaders& other) {
header_lines_ = other.header_lines_;
}
-void BalsaHeaders::AddAndMakeDescription(const StringPiece& key,
- const StringPiece& value,
+void BalsaHeaders::AddAndMakeDescription(const base::StringPiece& key,
+ const base::StringPiece& value,
HeaderLineDescription* d) {
CHECK(d != NULL);
// + 2 to size for ": "
@@ -193,17 +197,18 @@ void BalsaHeaders::AddAndMakeDescription(const StringPiece& key,
block_buffer_idx);
}
-void BalsaHeaders::AppendOrPrependAndMakeDescription(const StringPiece& key,
- const StringPiece& value,
- bool append,
- HeaderLineDescription* d) {
+void BalsaHeaders::AppendOrPrependAndMakeDescription(
+ const base::StringPiece& key,
+ const base::StringPiece& value,
+ bool append,
+ HeaderLineDescription* d) {
// Figure out how much space we need to reserve for the new header size.
size_t old_value_size = d->last_char_idx - d->value_begin_idx;
if (old_value_size == 0) {
AddAndMakeDescription(key, value, d);
return;
}
- StringPiece old_value(GetPtr(d->buffer_base_idx) + d->value_begin_idx,
+ base::StringPiece old_value(GetPtr(d->buffer_base_idx) + d->value_begin_idx,
old_value_size);
BalsaBuffer::Blocks::size_type block_buffer_idx = 0;
@@ -212,8 +217,8 @@ void BalsaHeaders::AppendOrPrependAndMakeDescription(const StringPiece& key,
char* storage = balsa_buffer_.Reserve(new_size, &block_buffer_idx);
size_t base_idx = storage - GetPtr(block_buffer_idx);
- StringPiece first_value = old_value;
- StringPiece second_value = value;
+ base::StringPiece first_value = old_value;
+ base::StringPiece second_value = value;
if (!append) { // !append == prepend
first_value = value;
second_value = old_value;
@@ -239,7 +244,7 @@ void BalsaHeaders::AppendOrPrependAndMakeDescription(const StringPiece& key,
}
// Removes all keys value pairs with key 'key' starting at 'start'.
-void BalsaHeaders::RemoveAllOfHeaderStartingAt(const StringPiece& key,
+void BalsaHeaders::RemoveAllOfHeaderStartingAt(const base::StringPiece& key,
HeaderLines::iterator start) {
while (start != header_lines_.end()) {
start->skip = true;
@@ -248,8 +253,8 @@ void BalsaHeaders::RemoveAllOfHeaderStartingAt(const StringPiece& key,
}
}
-void BalsaHeaders::HackHeader(const StringPiece& key,
- const StringPiece& value) {
+void BalsaHeaders::HackHeader(const base::StringPiece& key,
+ const base::StringPiece& value) {
// See TODO in balsa_headers.h
const HeaderLines::iterator end = header_lines_.end();
const HeaderLines::iterator begin = header_lines_.begin();
@@ -266,8 +271,8 @@ void BalsaHeaders::HackHeader(const StringPiece& key,
AppendHeader(key, value);
}
-void BalsaHeaders::HackAppendToHeader(const StringPiece& key,
- const StringPiece& append_value) {
+void BalsaHeaders::HackAppendToHeader(const base::StringPiece& key,
+ const base::StringPiece& append_value) {
// See TODO in balsa_headers.h
const HeaderLines::iterator end = header_lines_.end();
const HeaderLines::iterator begin = header_lines_.begin();
@@ -281,8 +286,8 @@ void BalsaHeaders::HackAppendToHeader(const StringPiece& key,
AppendOrPrependAndMakeDescription(key, append_value, true, &(*i));
}
-void BalsaHeaders::ReplaceOrAppendHeader(const StringPiece& key,
- const StringPiece& value) {
+void BalsaHeaders::ReplaceOrAppendHeader(const base::StringPiece& key,
+ const base::StringPiece& value) {
const HeaderLines::iterator end = header_lines_.end();
const HeaderLines::iterator begin = header_lines_.begin();
HeaderLines::iterator i = GetHeaderLinesIterator(key, begin);
@@ -299,31 +304,32 @@ void BalsaHeaders::ReplaceOrAppendHeader(const StringPiece& key,
AppendHeader(key, value);
}
-void BalsaHeaders::AppendHeader(const StringPiece& key,
- const StringPiece& value) {
+void BalsaHeaders::AppendHeader(const base::StringPiece& key,
+ const base::StringPiece& value) {
HeaderLineDescription hld;
AddAndMakeDescription(key, value, &hld);
header_lines_.push_back(hld);
}
-void BalsaHeaders::AppendToHeader(const StringPiece& key,
- const StringPiece& value) {
+void BalsaHeaders::AppendToHeader(const base::StringPiece& key,
+ const base::StringPiece& value) {
AppendOrPrependToHeader(key, value, true);
}
-void BalsaHeaders::PrependToHeader(const StringPiece& key,
- const StringPiece& value) {
+void BalsaHeaders::PrependToHeader(const base::StringPiece& key,
+ const base::StringPiece& value) {
AppendOrPrependToHeader(key, value, false);
}
-StringPiece BalsaHeaders::GetValueFromHeaderLineDescription(
+base::StringPiece BalsaHeaders::GetValueFromHeaderLineDescription(
const HeaderLineDescription& line) const {
DCHECK_GE(line.last_char_idx, line.value_begin_idx);
- return StringPiece(GetPtr(line.buffer_base_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);
}
-const StringPiece BalsaHeaders::GetHeader(const StringPiece& key) const {
+const base::StringPiece BalsaHeaders::GetHeader(
+ const base::StringPiece& key) const {
DCHECK(!IsMultivaluedHeader(key))
<< "Header '" << key << "' may consist of multiple lines. Do not "
<< "use BalsaHeaders::GetHeader() or you may be missing some of its "
@@ -332,13 +338,13 @@ const StringPiece BalsaHeaders::GetHeader(const StringPiece& key) const {
const HeaderLines::const_iterator begin = header_lines_.begin();
HeaderLines::const_iterator i = GetConstHeaderLinesIterator(key, begin);
if (i == end) {
- return StringPiece(NULL, 0);
+ return base::StringPiece(NULL, 0);
}
return GetValueFromHeaderLineDescription(*i);
}
BalsaHeaders::const_header_lines_iterator BalsaHeaders::GetHeaderPosition(
- const StringPiece& key) const {
+ const base::StringPiece& key) const {
const HeaderLines::const_iterator end = header_lines_.end();
const HeaderLines::const_iterator begin = header_lines_.begin();
HeaderLines::const_iterator i = GetConstHeaderLinesIterator(key, begin);
@@ -350,7 +356,7 @@ BalsaHeaders::const_header_lines_iterator BalsaHeaders::GetHeaderPosition(
}
BalsaHeaders::const_header_lines_key_iterator BalsaHeaders::GetIteratorForKey(
- const StringPiece& key) const {
+ const base::StringPiece& key) const {
HeaderLines::const_iterator i =
GetConstHeaderLinesIterator(key, header_lines_.begin());
if (i == header_lines_.end()) {
@@ -361,8 +367,8 @@ BalsaHeaders::const_header_lines_key_iterator BalsaHeaders::GetIteratorForKey(
return const_header_lines_key_iterator(this, (i - begin), key);
}
-void BalsaHeaders::AppendOrPrependToHeader(const StringPiece& key,
- const StringPiece& value,
+void BalsaHeaders::AppendOrPrependToHeader(const base::StringPiece& key,
+ const base::StringPiece& value,
bool append) {
HeaderLines::iterator i = GetHeaderLinesIterator(key, header_lines_.begin());
if (i == header_lines_.end()) {
@@ -382,7 +388,7 @@ void BalsaHeaders::AppendOrPrependToHeader(const StringPiece& key,
BalsaHeaders::HeaderLines::const_iterator
BalsaHeaders::GetConstHeaderLinesIterator(
- const StringPiece& key,
+ const base::StringPiece& key,
BalsaHeaders::HeaderLines::const_iterator start) const {
const HeaderLines::const_iterator end = header_lines_.end();
for (HeaderLines::const_iterator i = start; i != end; ++i) {
@@ -405,7 +411,7 @@ BalsaHeaders::GetConstHeaderLinesIterator(
}
BalsaHeaders::HeaderLines::iterator BalsaHeaders::GetHeaderLinesIteratorNoSkip(
- const StringPiece& key,
+ const base::StringPiece& key,
BalsaHeaders::HeaderLines::iterator start) {
const HeaderLines::iterator end = header_lines_.end();
for (HeaderLines::iterator i = start; i != end; ++i) {
@@ -425,7 +431,7 @@ BalsaHeaders::HeaderLines::iterator BalsaHeaders::GetHeaderLinesIteratorNoSkip(
}
BalsaHeaders::HeaderLines::iterator BalsaHeaders::GetHeaderLinesIterator(
- const StringPiece& key,
+ const base::StringPiece& key,
BalsaHeaders::HeaderLines::iterator start) {
const HeaderLines::iterator end = header_lines_.end();
for (HeaderLines::iterator i = start; i != end; ++i) {
@@ -448,14 +454,14 @@ BalsaHeaders::HeaderLines::iterator BalsaHeaders::GetHeaderLinesIterator(
}
void BalsaHeaders::GetAllOfHeader(
- const StringPiece& key, vector<StringPiece>* out) const {
+ const base::StringPiece& key, std::vector<base::StringPiece>* out) const {
for (const_header_lines_key_iterator it = GetIteratorForKey(key);
it != header_lines_end(); ++it) {
out->push_back(it->second);
}
}
-bool BalsaHeaders::HasNonEmptyHeader(const StringPiece& key) const {
+bool BalsaHeaders::HasNonEmptyHeader(const base::StringPiece& key) const {
for (const_header_lines_key_iterator it = GetIteratorForKey(key);
it != header_lines_key_end(); ++it) {
if (!it->second.empty())
@@ -464,8 +470,8 @@ bool BalsaHeaders::HasNonEmptyHeader(const StringPiece& key) const {
return false;
}
-void BalsaHeaders::GetAllOfHeaderAsString(const StringPiece& key,
- string* out) const {
+void BalsaHeaders::GetAllOfHeaderAsString(const base::StringPiece& key,
+ std::string* out) const {
const_header_lines_iterator it = header_lines_begin();
const_header_lines_iterator end = header_lines_end();
@@ -474,22 +480,22 @@ void BalsaHeaders::GetAllOfHeaderAsString(const StringPiece& key,
if (!out->empty()) {
out->append(",");
}
- out->append(string(it->second.data(), it->second.size()));
+ out->append(std::string(it->second.data(), it->second.size()));
}
}
}
// static
-bool BalsaHeaders::IsMultivaluedHeader(const StringPiece& header) {
+bool BalsaHeaders::IsMultivaluedHeader(const base::StringPiece& header) {
return g_multivalued_headers.find(header) != g_multivalued_headers.end();
}
-void BalsaHeaders::RemoveAllOfHeader(const StringPiece& key) {
+void BalsaHeaders::RemoveAllOfHeader(const base::StringPiece& key) {
HeaderLines::iterator it = GetHeaderLinesIterator(key, header_lines_.begin());
RemoveAllOfHeaderStartingAt(key, it);
}
-void BalsaHeaders::RemoveAllHeadersWithPrefix(const StringPiece& key) {
+void BalsaHeaders::RemoveAllHeadersWithPrefix(const base::StringPiece& key) {
for (HeaderLines::size_type i = 0; i < header_lines_.size(); ++i) {
if (header_lines_[i].skip) {
continue;
@@ -531,8 +537,8 @@ size_t BalsaHeaders::GetSizeForWriteBuffer() const {
return write_buf_size + 2;
}
-void BalsaHeaders::DumpToString(string* str) const {
- const StringPiece firstline = first_line();
+void BalsaHeaders::DumpToString(std::string* str) const {
+ const base::StringPiece firstline = first_line();
const int buffer_length =
OriginalHeaderStreamEnd() - OriginalHeaderStreamBegin();
// First check whether the header object is empty.
@@ -552,17 +558,20 @@ void BalsaHeaders::DumpToString(string* str) const {
// If the header is complete, then just dump them with the logical key value
// pair.
str->reserve(str->size() + GetSizeForWriteBuffer());
- StringAppendF(str, "\n %.*s\n", firstline.size(), firstline.data());
+ 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) {
StringAppendF(str, " %.*s: %.*s\n",
- i->first.size(), i->first.data(),
- i->second.size(), i->second.data());
+ static_cast<int>(i->first.size()), i->first.data(),
+ static_cast<int>(i->second.size()), i->second.data());
}
}
-void BalsaHeaders::SetFirstLine(const StringPiece& line) {
- StringPiece new_line = balsa_buffer_.Write(line, &firstline_buffer_base_idx_);
+void BalsaHeaders::SetFirstLine(const base::StringPiece& line) {
+ 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();
@@ -579,7 +588,8 @@ void BalsaHeaders::SetContentLength(size_t length) {
content_length_ == length) {
return;
}
- const StringPiece content_length(kContentLength, sizeof(kContentLength) - 1);
+ const base::StringPiece content_length(kContentLength,
+ sizeof(kContentLength) - 1);
// If header state indicates that there is either a content length or
// transfer encoding header, remove them before adding the new content
// length. There is always the possibility that client can manually add
@@ -591,7 +601,7 @@ void BalsaHeaders::SetContentLength(size_t length) {
if (content_length_status_ != BalsaHeadersEnums::NO_CONTENT_LENGTH) {
RemoveAllOfHeader(content_length);
} else if (transfer_encoding_is_chunked_) {
- const StringPiece transfer_encoding(kTransferEncoding,
+ const base::StringPiece transfer_encoding(kTransferEncoding,
sizeof(kTransferEncoding) - 1);
RemoveAllOfHeader(transfer_encoding);
transfer_encoding_is_chunked_ = false;
@@ -600,8 +610,9 @@ void BalsaHeaders::SetContentLength(size_t length) {
content_length_ = length;
// FastUInt64ToBuffer is supposed to use a maximum of kFastToBufferSize bytes.
char buffer[kFastToBufferSize];
- const char* endp = FastUInt64ToBufferLeft(length, buffer);
- const StringPiece length_str(buffer, endp - buffer);
+ int len_converted = snprintf(buffer, sizeof(buffer), "%ld", length);
+ CHECK_GT(len_converted, 0);
+ const base::StringPiece length_str(buffer, len_converted);
AppendHeader(content_length, length_str);
}
@@ -614,17 +625,17 @@ void BalsaHeaders::SetChunkEncoding(bool chunk_encode) {
// Want to change to chunk encoding, but have content length. Arguably we
// can leave this step out, since transfer-encoding overrides
// content-length.
- const StringPiece content_length(kContentLength,
+ const base::StringPiece content_length(kContentLength,
sizeof(kContentLength) - 1);
RemoveAllOfHeader(content_length);
content_length_status_ = BalsaHeadersEnums::NO_CONTENT_LENGTH;
content_length_ = 0;
}
- const StringPiece transfer_encoding(kTransferEncoding,
+ const base::StringPiece transfer_encoding(kTransferEncoding,
sizeof(kTransferEncoding) - 1);
if (chunk_encode) {
const char kChunked[] = "chunked";
- const StringPiece chunked(kChunked, sizeof(kChunked) - 1);
+ const base::StringPiece chunked(kChunked, sizeof(kChunked) - 1);
AppendHeader(transfer_encoding, chunked);
} else {
RemoveAllOfHeader(transfer_encoding);
@@ -635,9 +646,9 @@ void BalsaHeaders::SetChunkEncoding(bool chunk_encode) {
// See the comment about this function in the header file for a
// warning about its usage.
void BalsaHeaders::SetFirstlineFromStringPieces(
- const StringPiece& firstline_a,
- const StringPiece& firstline_b,
- const StringPiece& firstline_c) {
+ 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() +
@@ -669,7 +680,7 @@ void BalsaHeaders::SetFirstlineFromStringPieces(
end_of_firstline_idx_ = whitespace_4_idx_;
}
-void BalsaHeaders::SetRequestMethod(const StringPiece& method) {
+void BalsaHeaders::SetRequestMethod(const base::StringPiece& method) {
// This is the first of the three parts of the firstline.
if (method.size() <= (whitespace_2_idx_ - non_whitespace_1_idx_)) {
non_whitespace_1_idx_ = whitespace_2_idx_ - method.size();
@@ -684,7 +695,7 @@ void BalsaHeaders::SetRequestMethod(const StringPiece& method) {
}
}
-void BalsaHeaders::SetResponseVersion(const StringPiece& version) {
+void BalsaHeaders::SetResponseVersion(const base::StringPiece& version) {
// Note: There is no difference between request_method() and
// response_Version(). Thus, a function to set one is equivalent to a
// function to set the other. We maintain two functions for this as it is
@@ -692,11 +703,11 @@ void BalsaHeaders::SetResponseVersion(const StringPiece& version) {
SetRequestMethod(version);
}
-void BalsaHeaders::SetRequestUri(const StringPiece& uri) {
+void BalsaHeaders::SetRequestUri(const base::StringPiece& uri) {
SetFirstlineFromStringPieces(request_method(), uri, request_version());
}
-void BalsaHeaders::SetResponseCode(const StringPiece& code) {
+void BalsaHeaders::SetResponseCode(const base::StringPiece& code) {
// Note: There is no difference between request_uri() and response_code().
// Thus, a function to set one is equivalent to a function to set the other.
// We maintain two functions for this as it is much more descriptive, and
@@ -707,13 +718,13 @@ void BalsaHeaders::SetResponseCode(const StringPiece& code) {
void BalsaHeaders::SetParsedResponseCodeAndUpdateFirstline(
size_t parsed_response_code) {
char buffer[kFastToBufferSize];
- const char* endp = FastUInt32ToBufferLeft(parsed_response_code, buffer);
- parsed_response_code_ = parsed_response_code;
-
- SetResponseCode(StringPiece(buffer, endp - buffer));
+ int len_converted = snprintf(buffer, sizeof(buffer),
+ "%ld", parsed_response_code);
+ CHECK_GT(len_converted, 0);
+ SetResponseCode(base::StringPiece(buffer, len_converted));
}
-void BalsaHeaders::SetRequestVersion(const StringPiece& version) {
+void BalsaHeaders::SetRequestVersion(const base::StringPiece& version) {
// This is the last of the three parts of the firstline.
// Since whitespace_3_idx and non_whitespace_3_idx may point to the same
// place, we ensure below that any available space includes space for a
@@ -736,7 +747,7 @@ void BalsaHeaders::SetRequestVersion(const StringPiece& version) {
}
}
-void BalsaHeaders::SetResponseReasonPhrase(const StringPiece& reason) {
+void BalsaHeaders::SetResponseReasonPhrase(const base::StringPiece& reason) {
// Note: There is no difference between request_version() and
// response_reason_phrase(). Thus, a function to set one is equivalent to a
// function to set the other. We maintain two functions for this as it is
diff --git a/net/tools/flip_server/balsa_headers.h b/net/tools/flip_server/balsa_headers.h
index 0eb83a5..6f590c2 100644
--- a/net/tools/flip_server/balsa_headers.h
+++ b/net/tools/flip_server/balsa_headers.h
@@ -5,6 +5,7 @@
#ifndef NET_TOOLS_FLIP_SERVER_BALSA_HEADERS_H_
#define NET_TOOLS_FLIP_SERVER_BALSA_HEADERS_H_
+#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
@@ -12,36 +13,10 @@
#include <vector>
#include "base/port.h"
-#include "net/tools/flip_server/balsa_enums.h"
-#ifdef CHROMIUM
+#include "base/logging.h"
#include "base/string_piece.h"
-
-void SplitStringPieceToVector(StringPiece, char*, vector<StringPiece>*, bool) {
- ...
-}
-
-struct StringPieceCaseHash {
- size_t operator()(const StringPiece& sp) const {
- // based on __stl_string_hash in http://www.sgi.com/tech/stl/string
- unsigned long hash_val = 0;
- for (StringPiece::const_iterator it = sp.begin();
- it != sp.end(); ++it) {
- hash_val = 5 * hash_val + ascii_tolower(*it);
- }
- return static_cast<size_t>(hash_val);
- }
-};
-
-struct StringPieceCaseEqual {
- bool operator()(const StringPiece& piece1, const StringPiece& piece2) const {
- return StringPieceUtils::EqualIgnoreCase(piece1, piece2);
- }
-};
-
-#else
-#include "strings/stringpiece.h"
-#include "strings/stringpiece_utils.h"
-#endif
+#include "net/tools/flip_server/balsa_enums.h"
+#include "net/tools/flip_server/string_piece_utils.h"
namespace net {
@@ -118,7 +93,7 @@ class BalsaBuffer {
// object.
};
- typedef vector<BufferBlock> Blocks;
+ typedef std::vector<BufferBlock> Blocks;
~BalsaBuffer() {
CleanupBlocksStartingFrom(0);
@@ -168,12 +143,12 @@ class BalsaBuffer {
// for reasons of efficiency, requires that the buffer from which it parses
// the headers be contiguous.
//
- void WriteToContiguousBuffer(const StringPiece& sp) {
+ void WriteToContiguousBuffer(const base::StringPiece& sp) {
if (sp.empty()) {
return;
}
CHECK(can_write_to_contiguous_buffer_);
- DCHECK_GE(blocks_.size(), 1);
+ DCHECK_GE(blocks_.size(), 1u);
if (blocks_[0].buffer == NULL && sp.size() <= blocksize_) {
blocks_[0] = AllocBlock();
memcpy(blocks_[0].start_of_unused_bytes(), sp.data(), sp.size());
@@ -207,14 +182,14 @@ class BalsaBuffer {
// Note that the 'permanent' storage in which it stores data may be in
// the first block IFF the NoMoreWriteToContiguousBuffer function has
// been called since the last Clear/Construction.
- StringPiece Write(const StringPiece& sp,
+ base::StringPiece Write(const base::StringPiece& sp,
Blocks::size_type* block_buffer_idx) {
if (sp.empty()) {
return sp;
}
char* storage = Reserve(sp.size(), block_buffer_idx);
memcpy(storage, sp.data(), sp.size());
- return StringPiece(storage, sp.size());
+ return base::StringPiece(storage, sp.size());
}
// Reserves "permanent" storage of the size indicated. Returns a pointer to
@@ -226,7 +201,7 @@ class BalsaBuffer {
Blocks::size_type* block_buffer_idx) {
// There should always be a 'first_block', even if it
// contains nothing.
- DCHECK_GE(blocks_.size(), 1);
+ DCHECK_GE(blocks_.size(), 1u);
BufferBlock* block = NULL;
Blocks::size_type block_idx = can_write_to_contiguous_buffer_ ? 1 : 0;
for (; block_idx < blocks_.size(); ++block_idx) {
@@ -261,14 +236,15 @@ class BalsaBuffer {
CleanupBlocksStartingFrom(0);
blocks_.push_back(AllocBlock());
}
- DCHECK_GE(blocks_.size(), 1);
+ DCHECK_GE(blocks_.size(), 1u);
can_write_to_contiguous_buffer_ = true;
}
void Swap(BalsaBuffer* b) {
blocks_.swap(b->blocks_);
- swap(can_write_to_contiguous_buffer_, b->can_write_to_contiguous_buffer_);
- swap(blocksize_, b->blocksize_);
+ std::swap(can_write_to_contiguous_buffer_,
+ b->can_write_to_contiguous_buffer_);
+ std::swap(blocksize_, b->blocksize_);
}
void CopyFrom(const BalsaBuffer& b) {
@@ -414,7 +390,7 @@ class BalsaHeaders {
bool skip;
};
- typedef vector<StringPiece> HeaderTokenList;
+ typedef std::vector<base::StringPiece> HeaderTokenList;
friend bool net::ParseHTTPFirstLine(const char* begin,
const char* end,
bool is_request,
@@ -423,7 +399,7 @@ class BalsaHeaders {
BalsaFrameEnums::ErrorCode* error_code);
protected:
- typedef vector<HeaderLineDescription> HeaderLines;
+ typedef std::vector<HeaderLineDescription> HeaderLines;
// Why these base classes (iterator_base, reverse_iterator_base)? Well, if
// we do want to export both iterator and const_iterator types (currently we
@@ -439,7 +415,7 @@ class BalsaHeaders {
public:
friend class BalsaHeaders;
friend class reverse_iterator_base;
- typedef pair<StringPiece, StringPiece> StringPiecePair;
+ typedef std::pair<base::StringPiece, base::StringPiece> StringPiecePair;
typedef StringPiecePair value_type;
typedef value_type& reference;
typedef value_type* pointer;
@@ -494,7 +470,7 @@ class BalsaHeaders {
// operator<< work for the classes it sees. It would be better if there
// was an additional traits-like system for the gUnit output... but oh
// well.
- friend ostream& operator<<(ostream& os, const iterator_base& it) {
+ friend std::ostream& operator<<(std::ostream& os, const iterator_base& it) {
os << "[" << it.headers_ << ", " << it.idx_ << "]";
return os;
}
@@ -547,9 +523,9 @@ class BalsaHeaders {
const HeaderLineDescription& line = headers_->header_lines_[index];
const char* stream_begin = headers_->GetPtr(line.buffer_base_idx);
value_ = value_type(
- StringPiece(stream_begin + line.first_char_idx,
+ base::StringPiece(stream_begin + line.first_char_idx,
line.key_end_idx - line.first_char_idx),
- StringPiece(stream_begin + line.value_begin_idx,
+ base::StringPiece(stream_begin + line.value_begin_idx,
line.last_char_idx - line.value_begin_idx));
DCHECK_GE(line.key_end_idx, line.first_char_idx);
DCHECK_GE(line.last_char_idx, line.value_begin_idx);
@@ -703,7 +679,7 @@ class BalsaHeaders {
private:
const_header_lines_key_iterator(const BalsaHeaders* headers,
HeaderLines::size_type index,
- const StringPiece& key)
+ const base::StringPiece& key)
: iterator_base(headers, index),
key_(key) {
}
@@ -718,7 +694,7 @@ class BalsaHeaders {
return *this >= headers_->header_lines_end();
}
- StringPiece key_;
+ base::StringPiece key_;
};
// TODO(fenix): Revisit the amount of bytes initially allocated to the second
@@ -779,7 +755,7 @@ class BalsaHeaders {
void erase(const const_header_lines_iterator& it) {
DCHECK_EQ(it.headers_, this);
DCHECK_LT(it.idx_, header_lines_.size());
- DCHECK_GE(it.idx_, 0);
+ DCHECK_GE(it.idx_, 0u);
header_lines_[it.idx_].skip = true;
}
@@ -789,7 +765,7 @@ class BalsaHeaders {
void CopyFrom(const BalsaHeaders& other);
- void HackHeader(const StringPiece& key, const StringPiece& value);
+ void HackHeader(const base::StringPiece& key, const base::StringPiece& value);
// Same as AppendToHeader, except that it will attempt to preserve
// header ordering.
@@ -800,7 +776,8 @@ class BalsaHeaders {
// TODO(fenix): remove this function and rename all occurances
// of it in the code to AppendToHeader when the condition above
// has been satisified.
- void HackAppendToHeader(const StringPiece& key, const StringPiece& value);
+ void HackAppendToHeader(const base::StringPiece& key,
+ const base::StringPiece& value);
// Replaces header entries with key 'key' if they exist, or appends
// a new header if none exist. See 'AppendHeader' below for additional
@@ -808,7 +785,8 @@ class BalsaHeaders {
// will allocate new storage every time that it is called.
// TODO(fenix): modify this function to reuse existing storage
// if it is available.
- void ReplaceOrAppendHeader(const StringPiece& key, const StringPiece& value);
+ void ReplaceOrAppendHeader(const base::StringPiece& key,
+ const base::StringPiece& value);
// Append a new header entry to the header object. Clients who wish to append
// Content-Length header should use SetContentLength() method instead of
@@ -818,21 +796,24 @@ class BalsaHeaders {
// Similarly, clients who wish to add or remove the transfer encoding header
// in order to apply or remove chunked encoding should use SetChunkEncoding()
// instead.
- void AppendHeader(const StringPiece& key, const StringPiece& value);
+ void AppendHeader(const base::StringPiece& key,
+ const base::StringPiece& value);
// Appends ',value' to an existing header named 'key'. If no header with the
// correct key exists, it will call AppendHeader(key, value). Calling this
// function on a key which exists several times in the headers will produce
// unpredictable results.
- void AppendToHeader(const StringPiece& key, const StringPiece& value);
+ void AppendToHeader(const base::StringPiece& key,
+ const base::StringPiece& value);
// Prepends 'value,' to an existing header named 'key'. If no header with the
// correct key exists, it will call AppendHeader(key, value). Calling this
// function on a key which exists several times in the headers will produce
// unpredictable results.
- void PrependToHeader(const StringPiece& key, const StringPiece& value);
+ void PrependToHeader(const base::StringPiece& key,
+ const base::StringPiece& value);
- const StringPiece GetHeader(const StringPiece& key) const;
+ const base::StringPiece GetHeader(const base::StringPiece& key) const;
// Iterates over all currently valid header lines, appending their
// values into the vector 'out', in top-to-bottom order.
@@ -857,27 +838,30 @@ class BalsaHeaders {
// vector out after GetAllOfHeader("key1", &out) is:
// ["foo", "v1", "", "", "v2", "v1", "v2"]
- void GetAllOfHeader(const StringPiece& key, vector<StringPiece>* out) const;
+ void GetAllOfHeader(const base::StringPiece& key,
+ std::vector<base::StringPiece>* out) const;
// Joins all values for key into a comma-separated string in out.
// More efficient than calling JoinStrings on result of GetAllOfHeader if
// you don't need the intermediate vector<StringPiece>.
- void GetAllOfHeaderAsString(const StringPiece& key, string* out) const;
+ void GetAllOfHeaderAsString(const base::StringPiece& key,
+ std::string* out) const;
// Returns true if RFC 2616 Section 14 indicates that header can
// have multiple values.
- static bool IsMultivaluedHeader(const StringPiece& header);
+ static bool IsMultivaluedHeader(const base::StringPiece& header);
// Determine if a given header is present.
- inline bool HasHeader(const StringPiece& key) const {
+ inline bool HasHeader(const base::StringPiece& key) const {
return (GetConstHeaderLinesIterator(key, header_lines_.begin()) !=
header_lines_.end());
}
// Returns true iff any header 'key' exists with non-empty value.
- bool HasNonEmptyHeader(const StringPiece& key) const;
+ bool HasNonEmptyHeader(const base::StringPiece& key) const;
- const_header_lines_iterator GetHeaderPosition(const StringPiece& key) const;
+ const_header_lines_iterator GetHeaderPosition(
+ const base::StringPiece& key) const;
// Returns a forward-only iterator that only stops at lines matching key.
// String backing 'key' must remain valid for lifetime of iterator.
@@ -885,12 +869,12 @@ class BalsaHeaders {
// Check returned iterator against header_lines_key_end() to determine when
// iteration is finished.
const_header_lines_key_iterator GetIteratorForKey(
- const StringPiece& key) const;
+ const base::StringPiece& key) const;
- void RemoveAllOfHeader(const StringPiece& key);
+ void RemoveAllOfHeader(const base::StringPiece& key);
// Removes all headers starting with 'key' [case insensitive]
- void RemoveAllHeadersWithPrefix(const StringPiece& key);
+ void RemoveAllHeadersWithPrefix(const base::StringPiece& key);
// Returns the lower bound of memory used by this header object, including
// all internal buffers and data structure. Some of the memory used cannot be
@@ -950,9 +934,9 @@ class BalsaHeaders {
const char* line_ptr = GetPtr(line.buffer_base_idx);
WriteHeaderLineToBuffer(
buffer,
- StringPiece(line_ptr + line.first_char_idx,
+ base::StringPiece(line_ptr + line.first_char_idx,
line.key_end_idx - line.first_char_idx),
- StringPiece(line_ptr + line.value_begin_idx,
+ base::StringPiece(line_ptr + line.value_begin_idx,
line.last_char_idx - line.value_begin_idx));
}
}
@@ -965,8 +949,8 @@ class BalsaHeaders {
// header in the buffer. This method is a no-op if key is empty.
template <typename Buffer>
static void WriteHeaderLineToBuffer(Buffer* buffer,
- const StringPiece& key,
- const StringPiece& value) {
+ const base::StringPiece& key,
+ const base::StringPiece& value) {
// if the key is empty, we don't want to write the rest because it
// will not be a well-formed header line.
if (key.size() > 0) {
@@ -984,11 +968,11 @@ class BalsaHeaders {
// e.g., when there was an error in the middle of parsing.
// The header content is appended to the string; the original content is not
// cleared.
- void DumpToString(string* str) const;
+ void DumpToString(std::string* str) const;
- const StringPiece first_line() const {
+ const base::StringPiece first_line() const {
DCHECK_GE(whitespace_4_idx_, non_whitespace_1_idx_);
- return StringPiece(BeginningOfFirstLine() + non_whitespace_1_idx_,
+ return base::StringPiece(BeginningOfFirstLine() + non_whitespace_1_idx_,
whitespace_4_idx_ - non_whitespace_1_idx_);
}
@@ -1000,13 +984,13 @@ class BalsaHeaders {
// the response code is one which is interpretable.
size_t parsed_response_code() const { return parsed_response_code_; }
- const StringPiece request_method() const {
+ const base::StringPiece request_method() const {
DCHECK_GE(whitespace_2_idx_, non_whitespace_1_idx_);
- return StringPiece(BeginningOfFirstLine() + non_whitespace_1_idx_,
+ return base::StringPiece(BeginningOfFirstLine() + non_whitespace_1_idx_,
whitespace_2_idx_ - non_whitespace_1_idx_);
}
- const StringPiece response_version() const {
+ const base::StringPiece response_version() const {
// Note: There is no difference between request_method() and
// response_version(). They both could be called
// GetFirstTokenFromFirstline()... but that wouldn't be anywhere near as
@@ -1014,26 +998,26 @@ class BalsaHeaders {
return request_method();
}
- const StringPiece request_uri() const {
+ const base::StringPiece request_uri() const {
DCHECK_GE(whitespace_3_idx_, non_whitespace_2_idx_);
- return StringPiece(BeginningOfFirstLine() + non_whitespace_2_idx_,
+ return base::StringPiece(BeginningOfFirstLine() + non_whitespace_2_idx_,
whitespace_3_idx_ - non_whitespace_2_idx_);
}
- const StringPiece response_code() const {
+ const base::StringPiece response_code() const {
// Note: There is no difference between request_uri() and response_code().
// They both could be called GetSecondtTokenFromFirstline(), but, as noted
// in an earlier comment, that wouldn't be as descriptive.
return request_uri();
}
- const StringPiece request_version() const {
+ const base::StringPiece request_version() const {
DCHECK_GE(whitespace_4_idx_, non_whitespace_3_idx_);
- return StringPiece(BeginningOfFirstLine() + non_whitespace_3_idx_,
+ return base::StringPiece(BeginningOfFirstLine() + non_whitespace_3_idx_,
whitespace_4_idx_ - non_whitespace_3_idx_);
}
- const StringPiece response_reason_phrase() const {
+ const base::StringPiece response_reason_phrase() const {
// Note: There is no difference between request_version() and
// response_reason_phrase(). They both could be called
// GetThirdTokenFromFirstline(), but, as noted in an earlier comment, that
@@ -1047,30 +1031,31 @@ class BalsaHeaders {
// then you should use the Set* functions, or SetFirstlineFromStringPieces,
// below, instead.
//
- void SetFirstlineFromStringPieces(const StringPiece& firstline_a,
- const StringPiece& firstline_b,
- const StringPiece& firstline_c);
+ void SetFirstlineFromStringPieces(const base::StringPiece& firstline_a,
+ const base::StringPiece& firstline_b,
+ const base::StringPiece& firstline_c);
- void SetRequestFirstlineFromStringPieces(const StringPiece& method,
- const StringPiece& uri,
- const StringPiece& version) {
+ void SetRequestFirstlineFromStringPieces(const base::StringPiece& method,
+ const base::StringPiece& uri,
+ const base::StringPiece& version) {
SetFirstlineFromStringPieces(method, uri, version);
}
- void SetResponseFirstlineFromStringPieces(const StringPiece& version,
- const StringPiece& code,
- const StringPiece& reason_phrase) {
+ void SetResponseFirstlineFromStringPieces(
+ const base::StringPiece& version,
+ const base::StringPiece& code,
+ const base::StringPiece& reason_phrase) {
SetFirstlineFromStringPieces(version, code, reason_phrase);
}
// These functions are exactly the same, except that their names are
// different. This is done so that the code using this class is more
// expressive.
- void SetRequestMethod(const StringPiece& method);
- void SetResponseVersion(const StringPiece& version);
+ void SetRequestMethod(const base::StringPiece& method);
+ void SetResponseVersion(const base::StringPiece& version);
- void SetRequestUri(const StringPiece& uri);
- void SetResponseCode(const StringPiece& code);
+ void SetRequestUri(const base::StringPiece& uri);
+ void SetResponseCode(const base::StringPiece& code);
void set_parsed_response_code(size_t parsed_response_code) {
parsed_response_code_ = parsed_response_code;
}
@@ -1079,8 +1064,8 @@ class BalsaHeaders {
// These functions are exactly the same, except that their names are
// different. This is done so that the code using this class is more
// expressive.
- void SetRequestVersion(const StringPiece& version);
- void SetResponseReasonPhrase(const StringPiece& reason_phrase);
+ void SetRequestVersion(const base::StringPiece& version);
+ void SetResponseReasonPhrase(const base::StringPiece& reason_phrase);
// The biggest problem with SetFirstLine is that we don't want to use a
// separate buffer for it. The second biggest problem with it is that the
@@ -1091,7 +1076,7 @@ class BalsaHeaders {
// accessors to work, use the Set* functions above this one.
// SetFirstLine is stuff useful, however, if all you care about is correct
// serialization with the rest of the header object.
- void SetFirstLine(const StringPiece& line);
+ void SetFirstLine(const base::StringPiece& line);
// Simple accessors to some of the internal state
bool transfer_encoding_is_chunked() const {
@@ -1149,7 +1134,7 @@ class BalsaHeaders {
}
void WriteFromFramer(const char* ptr, size_t size) {
- balsa_buffer_.WriteToContiguousBuffer(StringPiece(ptr, size));
+ balsa_buffer_.WriteToContiguousBuffer(base::StringPiece(ptr, size));
}
void DoneWritingFromFramer() {
@@ -1173,40 +1158,40 @@ class BalsaHeaders {
*s = GetReadableBytesFromHeaderStream();
}
- StringPiece GetValueFromHeaderLineDescription(
+ base::StringPiece GetValueFromHeaderLineDescription(
const HeaderLineDescription& line) const;
- void AddAndMakeDescription(const StringPiece& key,
- const StringPiece& value,
+ void AddAndMakeDescription(const base::StringPiece& key,
+ const base::StringPiece& value,
HeaderLineDescription* d);
- void AppendOrPrependAndMakeDescription(const StringPiece& key,
- const StringPiece& value,
+ void AppendOrPrependAndMakeDescription(const base::StringPiece& key,
+ const base::StringPiece& value,
bool append,
HeaderLineDescription* d);
// Removes all header lines with the given key starting at start.
- void RemoveAllOfHeaderStartingAt(const StringPiece& key,
+ void RemoveAllOfHeaderStartingAt(const base::StringPiece& key,
HeaderLines::iterator start);
// If the 'key' does not exist in the headers, calls
// AppendHeader(key, value). Otherwise if append is true, appends ',value'
// to the first existing header with key 'key'. If append is false, prepends
// 'value,' to the first existing header with key 'key'.
- void AppendOrPrependToHeader(const StringPiece& key,
- const StringPiece& value,
+ void AppendOrPrependToHeader(const base::StringPiece& key,
+ const base::StringPiece& value,
bool append);
HeaderLines::const_iterator GetConstHeaderLinesIterator(
- const StringPiece& key,
+ const base::StringPiece& key,
HeaderLines::const_iterator start) const;
HeaderLines::iterator GetHeaderLinesIteratorNoSkip(
- const StringPiece& key,
+ const base::StringPiece& key,
HeaderLines::iterator start);
HeaderLines::iterator GetHeaderLinesIterator(
- const StringPiece& key,
+ const base::StringPiece& key,
HeaderLines::iterator start);
template <typename IteratorType>
@@ -1245,8 +1230,8 @@ class BalsaHeaders {
// For this reason, it is strongly suggested that use of this function is
// only acceptable for the purpose of debugging parse errors seen by the
// BalsaFrame class.
- StringPiece OriginalHeadersForDebugging() const {
- return StringPiece(OriginalHeaderStreamBegin(),
+ base::StringPiece OriginalHeadersForDebugging() const {
+ return base::StringPiece(OriginalHeaderStreamBegin(),
OriginalHeaderStreamEnd() - OriginalHeaderStreamBegin());
}
diff --git a/net/tools/flip_server/balsa_headers_token_utils.cc b/net/tools/flip_server/balsa_headers_token_utils.cc
index 0a56c5d..b47debf 100644
--- a/net/tools/flip_server/balsa_headers_token_utils.cc
+++ b/net/tools/flip_server/balsa_headers_token_utils.cc
@@ -3,8 +3,7 @@
// found in the LICENSE file.
#include "net/tools/flip_server/balsa_headers_token_utils.h"
-
-#include "strings/stringpiece_utils.h"
+#include "net/tools/flip_server/string_piece_utils.h"
namespace net {
@@ -26,7 +25,7 @@ inline void BalsaHeadersTokenUtils::TokenizeHeaderLine(
}
void BalsaHeadersTokenUtils::RemoveLastTokenFromHeaderValue(
- const StringPiece& key, BalsaHeaders* headers) {
+ const base::StringPiece& key, BalsaHeaders* headers) {
BalsaHeaders::HeaderLines::iterator it =
headers->GetHeaderLinesIterator(key, headers->header_lines_.begin());
if (it == headers->header_lines_.end()) {
@@ -55,7 +54,7 @@ void BalsaHeadersTokenUtils::RemoveLastTokenFromHeaderValue(
header_line->skip = true; // remove the whole line
} else {
// Shrink the line size and leave the extra data in the buffer.
- const StringPiece& new_last_token = tokens[tokens.size() - 2];
+ const base::StringPiece& new_last_token = tokens[tokens.size() - 2];
const char* last_char_address =
new_last_token.data() + new_last_token.size() - 1;
const char* stream_begin = headers->GetPtr(header_line->buffer_base_idx);
@@ -66,8 +65,8 @@ void BalsaHeadersTokenUtils::RemoveLastTokenFromHeaderValue(
bool BalsaHeadersTokenUtils::CheckHeaderForLastToken(
const BalsaHeaders& headers,
- const StringPiece& key,
- const StringPiece& token) {
+ const base::StringPiece& key,
+ const base::StringPiece& token) {
BalsaHeaders::const_header_lines_key_iterator it =
headers.GetIteratorForKey(key);
if (it == headers.header_lines_key_end())
@@ -92,7 +91,7 @@ bool BalsaHeadersTokenUtils::CheckHeaderForLastToken(
void BalsaHeadersTokenUtils::TokenizeHeaderValue(
const BalsaHeaders& headers,
- const StringPiece& key,
+ const base::StringPiece& key,
BalsaHeaders::HeaderTokenList* tokens) {
CHECK(tokens);
tokens->clear();
@@ -130,12 +129,12 @@ void BalsaHeadersTokenUtils::ParseTokenList(
++start;
if (start == end) {
if (nws != start) {
- tokens->push_back(StringPiece(nws, start - nws));
+ tokens->push_back(base::StringPiece(nws, start - nws));
}
return;
}
}
- tokens->push_back(StringPiece(nws, start - nws));
+ tokens->push_back(base::StringPiece(nws, start - nws));
}
}
diff --git a/net/tools/flip_server/balsa_headers_token_utils.h b/net/tools/flip_server/balsa_headers_token_utils.h
index 31ae8ee..c2c5a68 100644
--- a/net/tools/flip_server/balsa_headers_token_utils.h
+++ b/net/tools/flip_server/balsa_headers_token_utils.h
@@ -9,7 +9,7 @@
#define NET_TOOLS_FLIP_SERVER_BALSA_HEADERS_TOKEN_UTILS_H_
#include "net/tools/flip_server/balsa_headers.h"
-#include "strings/stringpiece.h"
+#include "base/string_piece.h"
namespace net {
@@ -22,20 +22,20 @@ class BalsaHeadersTokenUtils {
// presence of multiple header lines with given key, the last token of the
// last line is compared.
static bool CheckHeaderForLastToken(const BalsaHeaders& headers,
- const StringPiece& key,
- const StringPiece& token);
+ const base::StringPiece& key,
+ const base::StringPiece& token);
// Tokenizes header value for a given key. In the presence of multiple lines
// with that key, all of them will be tokenized and tokens will be added to
// the list in the order in which they are encountered.
static void TokenizeHeaderValue(const BalsaHeaders& headers,
- const StringPiece& key,
+ const base::StringPiece& key,
BalsaHeaders::HeaderTokenList* tokens);
// Removes the last token from the header value. In the presence of multiple
// header lines with given key, will remove the last token of the last line.
// Can be useful if the last encoding has to be removed.
- static void RemoveLastTokenFromHeaderValue(const StringPiece& key,
+ static void RemoveLastTokenFromHeaderValue(const base::StringPiece& key,
BalsaHeaders* headers);
// Given a pointer to the beginning and the end of the header value
diff --git a/net/tools/flip_server/create_listener.cc b/net/tools/flip_server/create_listener.cc
index 94d7ae4..7ea5efa 100644
--- a/net/tools/flip_server/create_listener.cc
+++ b/net/tools/flip_server/create_listener.cc
@@ -64,14 +64,14 @@ bool CloseSocket(int *fd, int tries) {
////////////////////////////////////////////////////////////////////////////////
// see header for documentation of this function.
-void CreateListeningSocket(const string& host,
- const string& port,
+void CreateListeningSocket(const std::string& host,
+ const std::string& port,
bool is_numeric_host_address,
int backlog,
int * listen_fd,
bool reuseaddr,
bool reuseport,
- ostream* error_stream) {
+ std::ostream* error_stream) {
// start out by assuming things will fail.
*listen_fd = -1;
diff --git a/net/tools/flip_server/create_listener.h b/net/tools/flip_server/create_listener.h
index 7541260..06979d9 100644
--- a/net/tools/flip_server/create_listener.h
+++ b/net/tools/flip_server/create_listener.h
@@ -30,14 +30,14 @@ namespace net {
// successfully created, else it will be assigned -1.
// error_stream - in the case of errors, output describing the error will
// be written into error_stream.
-void CreateListeningSocket(const string& host,
- const string& port,
+void CreateListeningSocket(const std::string& host,
+ const std::string& port,
bool is_numeric_host_address,
int backlog,
int * listen_fd,
bool reuseaddr,
bool reuseport,
- ostream* error_stream);
+ std::ostream* error_stream);
} // namespace net
diff --git a/net/tools/flip_server/create_listener_test.cc b/net/tools/flip_server/create_listener_test.cc
index 760169f..e69de29 100644
--- a/net/tools/flip_server/create_listener_test.cc
+++ b/net/tools/flip_server/create_listener_test.cc
@@ -1,61 +0,0 @@
-// Copyright (c) 2009 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.
-
-#include <assert.h>
-
-#include <vector>
-#include <string>
-#include <algorithm>
-#include <map>
-#include <iostream>
-
-#include "net/tools/flip_server/create_listener.h"
-
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-
-struct TestCase {
- string host;
- string port;
- bool valid;
- TestCase(const string& host, const string& port, bool valid) :
- host(host), port(port), valid(valid) {
- }
-};
-
-int main(int argc, char ** argv) {
- vector<TestCase> tests;
- tests.push_back(TestCase("" , "8090" , true ));
- tests.push_back(TestCase("invalid" , "80" , false)); // bad host spec.
- tests.push_back(TestCase("127.0.0.1", "invalid", false)); // bad port spec.
- tests.push_back(TestCase("127.0.0.2", "80" , false)); // priviledged port.
- tests.push_back(TestCase("127.0.0.2", "8080" , true ));
- tests.push_back(TestCase("127.0.0.2", "8080" , false)); // already bound.
- tests.push_back(TestCase("" , "" , false)); // bad port spec.
-
- // create sockets and bind on all indicated interface/port combinations.
- for (unsigned int i = 0; i < tests.size(); ++i) {
- cerr << "test " << i << "...";
- const TestCase& test = tests[i];
-
- int socket = -2;
- CreateListeningSocket(test.host,
- test.port,
- true,
- 5,
- &socket,
- true,
- &cerr);
- assert(socket != -2);
- if (test.valid) {
- assert(socket != -1);
- }
- cerr << "...done\n";
- // it would be good to invoke a seperate process (perhaps "nc"?) to
- // talk to this process in order to verify that the listen worked.
- }
-
- return EXIT_SUCCESS;
-}
-
diff --git a/net/tools/flip_server/epoll_server.cc b/net/tools/flip_server/epoll_server.cc
index 0d8d46fd..a1d6ca1 100644
--- a/net/tools/flip_server/epoll_server.cc
+++ b/net/tools/flip_server/epoll_server.cc
@@ -13,6 +13,7 @@
#include "base/logging.h"
#include "base/timer.h"
+#include "net/tools/flip_server/other_defines.h"
// Design notes: An efficient implementation of ready list has the following
// desirable properties:
@@ -453,7 +454,7 @@ void EpollServer::RegisterAlarm(int64 timeout_time_in_us, AlarmCB* ac) {
VLOG(4) << "RegisteringAlarm at : " << timeout_time_in_us;
TimeToAlarmCBMap::iterator alarm_iter =
- alarm_map_.insert(make_pair(timeout_time_in_us, ac));
+ alarm_map_.insert(std::make_pair(timeout_time_in_us, ac));
all_alarms_.insert(ac);
// Pass the iterator to the EpollAlarmCallbackInterface.
@@ -481,15 +482,11 @@ void EpollServer::Wake() {
}
int64 EpollServer::NowInUsec() const {
-#ifdef CHROMIUM
- return Time::Now().ToInternalValue();
-#else
- return WallTimer::NowInUsec();
-#endif
+ return base::Time::Now().ToInternalValue();
}
-string EpollServer::EventMaskToString(int event_mask) {
- string s;
+std::string EpollServer::EventMaskToString(int event_mask) {
+ std::string s;
if (event_mask & EPOLLIN) s += "EPOLLIN ";
if (event_mask & EPOLLPRI) s += "EPOLLPRI ";
if (event_mask & EPOLLOUT) s += "EPOLLOUT ";
@@ -638,11 +635,6 @@ void EpollServer::WaitForEventsAndCallHandleEvents(int64 timeout_in_us,
events_size,
timeout_in_ms);
VLOG(3) << "nfds=" << nfds;
- if (nfds == events_size) {
- LOG_EVERY_N(INFO, 1000)
- << "nfds=" << nfds << " as we only handle " << events_size
- << " events at a time, so events[] should be larger.";
- }
#ifdef EPOLL_SERVER_EVENT_TRACING
event_recorder_.RecordEpollWaitEvent(timeout_in_ms, nfds);
diff --git a/net/tools/flip_server/epoll_server.h b/net/tools/flip_server/epoll_server.h
index 12c8924..262dd8a 100644
--- a/net/tools/flip_server/epoll_server.h
+++ b/net/tools/flip_server/epoll_server.h
@@ -7,8 +7,8 @@
#include <fcntl.h>
#include <sys/queue.h>
-#include <hash_map>
-#include <hash_set>
+#include <ext/hash_map> // it is annoying that gcc does this. oh well.
+#include <ext/hash_set>
#include <map>
#include <string>
#include <utility>
@@ -34,14 +34,9 @@
#include "base/logging.h"
#endif
+#include "base/basictypes.h"
#include "base/scoped_ptr.h"
-#include "util/hash/hash.h"
-
-#ifdef CHROMIUM
#include <sys/epoll.h>
-#else
-#include "net/base/epollstubs.h"
-#endif
namespace net {
@@ -123,16 +118,12 @@ class EpollCallbackInterface {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-
class EpollServer {
public:
typedef EpollAlarmCallbackInterface AlarmCB;
typedef EpollCallbackInterface CB;
- typedef multimap<int64, AlarmCB*> TimeToAlarmCBMap;
+ typedef std::multimap<int64, AlarmCB*> TimeToAlarmCBMap;
typedef TimeToAlarmCBMap::iterator AlarmRegToken;
// Summary:
@@ -456,7 +447,7 @@ class EpollServer {
return this->NowInUsec();
}
- static string EventMaskToString(int event_mask);
+ static std::string EventMaskToString(int event_mask);
// Summary:
// Logs the state of the epoll server with LOG(ERROR).
@@ -579,11 +570,11 @@ class EpollServer {
// Custom hash function to be used by hash_set.
struct CBAndEventMaskHash {
size_t operator()(const CBAndEventMask& cb_and_eventmask) const {
- return hash<int>()(cb_and_eventmask.fd);
+ return static_cast<size_t>(cb_and_eventmask.fd);
}
};
- typedef hash_set<CBAndEventMask, CBAndEventMaskHash> FDToCBMap;
+ typedef __gnu_cxx::hash_set<CBAndEventMask, CBAndEventMaskHash> FDToCBMap;
// the following four functions are OS-specific, and are likely
// to be changed in a subclass if the poll/select method is changed
@@ -684,11 +675,20 @@ class EpollServer {
// The mapping of file-descriptor to CBAndEventMasks
FDToCBMap cb_map_;
+ // Custom hash function to be used by hash_set.
+ struct AlarmCBHash {
+ size_t operator()(AlarmCB*const& p) const {
+ return reinterpret_cast<size_t>(p);
+ }
+ };
+
+
// TOOD(sushantj): Having this hash_set is avoidable. We currently have it
// only so that we can enforce stringent checks that a caller can not register
// the same alarm twice. One option is to have an implementation in which
// this hash_set is used only in the debug mode.
- hash_set<AlarmCB*> all_alarms_;
+ typedef __gnu_cxx::hash_set<AlarmCB*, AlarmCBHash> AlarmCBMap;
+ AlarmCBMap all_alarms_;
TimeToAlarmCBMap alarm_map_;
@@ -713,7 +713,7 @@ class EpollServer {
// that while calling CallAndReregisterAlarmEvents we do not call
// OnAlarm on any alarm in this set. This ensures that we do not
// go in an infinite loop.
- hash_set<AlarmCB*> alarms_reregistered_and_should_be_skipped_;
+ AlarmCBMap alarms_reregistered_and_should_be_skipped_;
LIST_HEAD(ReadyList, CBAndEventMask) ready_list_;
LIST_HEAD(TmpList, CBAndEventMask) tmp_list_;
@@ -794,7 +794,7 @@ class EpollServer {
os << "fd: " << er.unregistered_fds_[i] << "\n";
os << er.unregistered_fds_[i];
}
- for (hash_map<int, Events>::const_iterator i = er.event_counts_.begin();
+ for (EventCountsMap::const_iterator i = er.event_counts_.begin();
i != er.event_counts_.end();
++i) {
os << "fd: " << i->first << "\n";
@@ -807,7 +807,7 @@ class EpollServer {
}
void RecordUnregistration(int fd) {
- hash_map<int, Events>::iterator i = event_counts_.find(fd);
+ EventCountsMap::iterator i = event_counts_.find(fd);
if (i != event_counts_.end()) {
unregistered_fds_.push_back(i->second);
event_counts_.erase(i);
@@ -941,9 +941,10 @@ class EpollServer {
unsigned int epoll_et;
};
- vector<DebugOutput*> debug_events_;
- vector<Events> unregistered_fds_;
- hash_map<int, Events> event_counts_;
+ std::vector<DebugOutput*> debug_events_;
+ std::vector<Events> unregistered_fds_;
+ typedef __gnu_cxx::hash_map<int, Events> EventCountsMap;
+ EventCountsMap event_counts_;
int64 num_records_;
int64 record_threshold_;
};
diff --git a/net/tools/flip_server/flip_in_mem_edsm_server.cc b/net/tools/flip_server/flip_in_mem_edsm_server.cc
index a32d74b..632b52b 100644
--- a/net/tools/flip_server/flip_in_mem_edsm_server.cc
+++ b/net/tools/flip_server/flip_in_mem_edsm_server.cc
@@ -7,6 +7,7 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
+#include <openssl/ssl.h>
#include <deque>
#include <iostream>
@@ -14,13 +15,10 @@
#include <vector>
#include <list>
-#include "base/google.h"
#include "base/logging.h"
-
-// Used to get time. Can be replaced.
+#include "base/simple_thread.h"
#include "base/timer.h"
-
-// All "open-sourcable"
+#include "base/lock.h"
#include "net/flip/flip_frame_builder.h"
#include "net/flip/flip_framer.h"
#include "net/flip/flip_protocol.h"
@@ -32,79 +30,32 @@
#include "net/tools/flip_server/create_listener.h"
#include "net/tools/flip_server/epoll_server.h"
#include "net/tools/flip_server/loadtime_measurement.h"
+#include "net/tools/flip_server/other_defines.h"
#include "net/tools/flip_server/ring_buffer.h"
#include "net/tools/flip_server/simple_buffer.h"
+#include "net/tools/flip_server/split.h"
#include "net/tools/flip_server/url_to_filename_encoder.h"
#include "net/tools/flip_server/url_utilities.h"
-#include "strings/split.h"
-#include "thread/thread.h"
-#include "third_party/openssl/ssl.h"
-
-////////////////////////////////////////////////////////////////////////////////
-
-DEFINE_bool(use_ssl, true,
- "If set to true, then the server will act as an SSL server for both"
- " HTTP and FLIP");
-DEFINE_string(ssl_cert_name, "cert.pem", "The name of the cert .pem file");
-DEFINE_string(ssl_key_name, "key.pem", "The name of the key .pem file");
-DEFINE_int32(response_count_until_close, 1000 * 1000,
- "The number of responses given before the server closes the"
- " connection");
-DEFINE_bool(no_nagle, true, "If true, then disables the nagle algorithm");
-DEFINE_int32(accepts_per_wake, 0,
- "The number of times that accept() will be called when the "
- " alarm goes off when the accept_using_alarm flag is set to true."
- " If set to 0, accept() will be performed until the accept queue"
- " is completely drained and the accept() call returns an error");
-DEFINE_int32(flip_port, 10040, "The port on which the flip server listens");
-DEFINE_int32(port, 16002, "The port on which the http server listens");
-DEFINE_int32(accept_backlog_size, 1024,
- "The size of the TCP accept backlog");
-DEFINE_string(cache_base_dir, ".", "The directory where cache locates");
-DEFINE_bool(need_to_encode_url, true, "If true, then encode url to filename");
-DEFINE_bool(reuseport, false,
- "If set to false a single socket will be used. If set to true"
- " then a new socket will be created for each accept thread."
- " Note that this only works with kernels that support"
- " SO_REUSEPORT");
-
-DEFINE_double(server_think_time_in_s, 0,
- " The amount of time the server delays before sending back the"
- "reply");
-DEFINE_bool(use_xsub, false,
- "Does the server send X-Subresource headers");
-DEFINE_bool(use_xac, false,
- "Does the server send X-Associated-Content headers");
-DEFINE_bool(use_cwnd_opener, false,
- "Does the server advance cwnd by sending no-op packets");
-DEFINE_bool(use_compression, false,
- "Does the server compress data frames");
-
-DEFINE_string(urls_file, "experimental/users/fenix/flip/urls.txt",
- "The path to the urls file which includes the urls for testing");
-DEFINE_string(pageload_html_file,
- "experimental/users/fenix/flip/loadtime_measurement.html",
- "The path to the html that does the pageload in iframe");
-DEFINE_bool(record_mode, false,
- "If set to true, record requests in file named as fd used");
-DEFINE_string(record_path, ".", "The path to save the record files");
-
////////////////////////////////////////////////////////////////////////////////
+using base::StringPiece;
+using base::SimpleThread;
+// using base::Lock; // heh, this isn't in base namespace?!
+// using base::AutoLock; // ditto!
using flip::CONTROL_FLAG_NONE;
using flip::DATA_FLAG_COMPRESSED;
using flip::DATA_FLAG_FIN;
using flip::FIN_STREAM;
using flip::FlipControlFrame;
-using flip::FlipFrame;
using flip::FlipDataFlags;
using flip::FlipDataFrame;
+using flip::FlipFinStreamControlFrame;
+using flip::FlipFrame;
using flip::FlipFrameBuilder;
using flip::FlipFramer;
using flip::FlipFramerVisitorInterface;
using flip::FlipHeaderBlock;
-using flip::FlipFinStreamControlFrame;
using flip::FlipStreamId;
using flip::FlipSynReplyControlFrame;
using flip::FlipSynStreamControlFrame;
@@ -121,7 +72,91 @@ using net::EpollEvent;
using net::EpollServer;
using net::RingBuffer;
using net::SimpleBuffer;
+using net::SplitStringPieceToVector;
using net::UrlUtilities;
+using std::deque;
+using std::map;
+using std::pair;
+using std::string;
+using std::vector;
+using std::list;
+using std::ostream;
+using std::cerr;
+
+////////////////////////////////////////////////////////////////////////////////
+
+// If set to true, then the server will act as an SSL server for both
+// HTTP and FLIP);
+bool FLAGS_use_ssl = true;
+
+// The name of the cert .pem file);
+string FLAGS_ssl_cert_name = "cert.pem";
+
+// The name of the key .pem file);
+string FLAGS_ssl_key_name = "key.pem";
+
+// The number of responses given before the server closes the
+// connection);
+int32 FLAGS_response_count_until_close = 1000*1000;
+
+// If true, then disables the nagle algorithm);
+bool FLAGS_no_nagle = true;
+
+// The number of times that accept() will be called when the
+// alarm goes off when the accept_using_alarm flag is set to true.
+// If set to 0, accept() will be performed until the accept queue
+// is completely drained and the accept() call returns an error);
+int32 FLAGS_accepts_per_wake = 0;
+
+// The port on which the flip server listens);
+int32 FLAGS_flip_port = 10040;
+
+// The port on which the http server listens);
+int32 FLAGS_port = 16002;
+
+// The size of the TCP accept backlog);
+int32 FLAGS_accept_backlog_size = 1024;
+
+// The directory where cache locates);
+string FLAGS_cache_base_dir = ".";
+
+// If true, then encode url to filename);
+bool FLAGS_need_to_encode_url = true;
+
+// If set to false a single socket will be used. If set to true
+// then a new socket will be created for each accept thread.
+// Note that this only works with kernels that support
+// SO_REUSEPORT);
+bool FLAGS_reuseport = false;
+
+// The amount of time the server delays before sending back the
+// reply);
+double FLAGS_server_think_time_in_s = 0;
+
+// Does the server send X-Subresource headers);
+bool FLAGS_use_xsub = false;
+
+// Does the server send X-Associated-Content headers);
+bool FLAGS_use_xac = false;
+
+// Does the server advance cwnd by sending no-op packets);
+bool FLAGS_use_cwnd_opener = false;
+
+// Does the server compress data frames);
+bool FLAGS_use_compression = false;
+
+// The path to the urls file which includes the urls for testing);
+string FLAGS_urls_file = "experimental/users/fenix/flip/urls.txt";
+
+// The path to the html that does the pageload in iframe);
+string FLAGS_pageload_html_file =
+ "experimental/users/fenix/flip/loadtime_measurement.html";
+
+// If set to true, record requests in file named as fd used);
+bool FLAGS_record_mode = false;
+
+// The path to save the record files);
+string FLAGS_record_path = ".";
////////////////////////////////////////////////////////////////////////////////
@@ -456,7 +491,8 @@ class MemoryCache {
#endif
BalsaHeaders* headers = new BalsaHeaders;
headers->CopyFrom(visitor.headers);
- string filename_stripped = string(filename).substr(cwd_.size() + 1);
+ string filename_stripped =
+ string(filename).substr(cwd_.size() + 1);
// LOG(INFO) << "Adding file (" << visitor.body.length() << " bytes): "
// << filename_stripped;
files_[filename_stripped] = FileData();
@@ -465,17 +501,21 @@ class MemoryCache {
fd.filename = string(filename_stripped,
filename_stripped.find_first_of('/'));
if (headers->HasHeader("X-Associated-Content")) {
- string content = headers->GetHeader("X-Associated-Content").ToString();
- vector<string> urls_and_priorities;
- SplitStringUsing(content, "||", &urls_and_priorities);
+ string content =
+ headers->GetHeader("X-Associated-Content").as_string();
+ vector<StringPiece> urls_and_priorities;
+ SplitStringPieceToVector(content, "||", &urls_and_priorities, true);
VLOG(1) << "Examining X-Associated-Content header";
- for (int i = 0; i < urls_and_priorities.size(); ++i) {
- const string& url_and_priority_pair = urls_and_priorities[i];
- vector<string> url_and_priority;
- SplitStringUsing(url_and_priority_pair, "??", &url_and_priority);
+ for (unsigned int i = 0; i < urls_and_priorities.size(); ++i) {
+ const StringPiece& url_and_priority_pair = urls_and_priorities[i];
+ vector<StringPiece> url_and_priority;
+ SplitStringPieceToVector(url_and_priority_pair, "??",
+ &url_and_priority, true);
if (url_and_priority.size() >= 2) {
- string& priority_string = url_and_priority[0];
- string& filename_string = url_and_priority[1];
+ string priority_string(url_and_priority[0].data(),
+ url_and_priority[0].size());
+ string filename_string(url_and_priority[1].data(),
+ url_and_priority[1].size());
int priority;
char* last_eaten_char;
priority = strtol(priority_string.c_str(), &last_eaten_char, 0);
@@ -520,11 +560,11 @@ class MemoryCache {
// This is a hacked algorithm for figuring out what priority
// to use with pushed content.
int priority = 4;
- if (content_type.find("css") != std::string::npos)
+ if (content_type.find("css") != string::npos)
priority = 1;
- else if (content_type.find("cript") != std::string::npos)
+ else if (content_type.find("cript") != string::npos)
priority = 1;
- else if (content_type.find("html") != std::string::npos)
+ else if (content_type.find("html") != string::npos)
priority = 2;
LOG(ERROR) << "Attempting update for " << referrer_host_path;
@@ -757,8 +797,8 @@ class SMServerConnection: public EpollCallbackInterface,
}
if (FLAGS_record_mode) {
char record_file_name[1024];
- snprintf(record_file_name, 1024, "%s/%d_%lld",
- FLAGS_record_path.c_str(), fd, GetCurrentTimeMillis());
+ snprintf(record_file_name, sizeof(record_file_name), "%s/%d_%ld",
+ FLAGS_record_path.c_str(), fd, epoll_server->NowInUsec()/1000);
record_fd_ = open(record_file_name, O_CREAT|O_APPEND|O_WRONLY, S_IRWXU);
if (record_fd_ < 0) {
LOG(ERROR) << "Open record file for fd " << fd << " failed";
@@ -1247,7 +1287,7 @@ class FlipSM : public FlipFramerVisitorInterface, public SMInterface {
if (parsed_headers) {
VLOG(2) << "# headers: " << headers.size();
}
- int j = 0;
+ unsigned int j = 0;
for (FlipHeaderBlock::iterator i = headers.begin();
i != headers.end();
++i) {
@@ -1377,7 +1417,7 @@ class FlipSM : public FlipFramerVisitorInterface, public SMInterface {
char* bytes = frame->data();
size_t size = FlipFrame::size();
ssize_t bytes_written = connection_->Send(bytes, size, MSG_DONTWAIT);
- if (bytes_written != size) {
+ if (bytes_written > 0 && static_cast<size_t>(bytes_written) != size) {
LOG(ERROR) << "Trouble sending Nop packet! (" << errno << ")";
if (errno == EAGAIN)
break;
@@ -1386,7 +1426,7 @@ class FlipSM : public FlipFramerVisitorInterface, public SMInterface {
}
void AddAssociatedContent(FileData* file_data) {
- for (int i = 0; i < file_data->related_files.size(); ++i) {
+ for (unsigned int i = 0; i < file_data->related_files.size(); ++i) {
pair<int, string>& related_file = file_data->related_files[i];
MemCacheIter mci;
string filename = "GET_";
@@ -1484,11 +1524,11 @@ class FlipSM : public FlipFramerVisitorInterface, public SMInterface {
headers.header_lines_begin();
hi != headers.header_lines_end();
++hi) {
- FlipHeaderBlock::iterator fhi = dest.find(hi->first.ToString());
+ FlipHeaderBlock::iterator fhi = dest.find(hi->first.as_string());
if (fhi == dest.end()) {
- dest[hi->first.ToString()] = hi->second.ToString();
+ dest[hi->first.as_string()] = hi->second.as_string();
} else {
- dest[hi->first.ToString()] = (
+ dest[hi->first.as_string()] = (
string(fhi->second.data(), fhi->second.size()) + "," +
string(hi->second.data(), hi->second.size()));
}
@@ -1501,16 +1541,16 @@ class FlipSM : public FlipFramerVisitorInterface, public SMInterface {
size_t SendSynStreamImpl(uint32 stream_id, const BalsaHeaders& headers) {
FlipHeaderBlock block;
- block["method"] = headers.request_method().ToString();
+ block["method"] = headers.request_method().as_string();
if (!headers.HasHeader("status"))
- block["status"] = headers.response_code().ToString();
+ block["status"] = headers.response_code().as_string();
if (!headers.HasHeader("version"))
- block["version"] =headers.response_version().ToString();
+ block["version"] =headers.response_version().as_string();
if (headers.HasHeader("X-Original-Url")) {
string original_url = headers.GetHeader("X-Original-Url").as_string();
block["path"] = UrlUtilities::GetUrlPath(original_url);
} else {
- block["path"] = headers.request_uri().ToString();
+ block["path"] = headers.request_uri().as_string();
}
CopyHeaders(block, headers);
@@ -1530,9 +1570,9 @@ class FlipSM : public FlipFramerVisitorInterface, public SMInterface {
size_t SendSynReplyImpl(uint32 stream_id, const BalsaHeaders& headers) {
FlipHeaderBlock block;
CopyHeaders(block, headers);
- block["status"] = headers.response_code().ToString() + " " +
- headers.response_reason_phrase().ToString();
- block["version"] = headers.response_version().ToString();
+ block["status"] = headers.response_code().as_string() + " " +
+ headers.response_reason_phrase().as_string();
+ block["version"] = headers.response_version().as_string();
FlipSynReplyControlFrame* fsrcf =
framer_->CreateSynReply(stream_id, CONTROL_FLAG_NONE, true, &block);
@@ -1615,7 +1655,7 @@ class FlipSM : public FlipFramerVisitorInterface, public SMInterface {
if (!mci->file_data->headers->HasHeader("content-encoding")) {
if (mci->file_data->headers->HasHeader("content-type")) {
string content_type =
- mci->file_data->headers->GetHeader("content-type").ToString();
+ mci->file_data->headers->GetHeader("content-type").as_string();
if (content_type.find("image") == content_type.npos)
should_compress = true;
}
@@ -1672,22 +1712,22 @@ class HTTPSM : public BalsaVisitorInterface, public SMInterface {
VLOG(2) << "Got new request!";
// requests started with /testing are loadtime measurement related
// urls, use LoadtimeMeasurement class to handle them.
- if (headers.request_uri().ToString().find("/testing") == 0) {
+ if (headers.request_uri().as_string().find("/testing") == 0) {
string output;
global_loadtime_measurement.ProcessRequest(
- headers.request_uri().ToString(), output);
+ headers.request_uri().as_string(), output);
SendOKResponse(stream_id_, &output);
stream_id_ += 2;
} else {
string filename;
if (FLAGS_need_to_encode_url) {
filename = net::UrlToFilenameEncoder::Encode(
- headers.GetHeader("Host").ToString() +
- headers.request_uri().ToString(),
- headers.request_method().ToString() + "_/");
+ headers.GetHeader("Host").as_string() +
+ headers.request_uri().as_string(),
+ headers.request_method().as_string() + "_/");
} else {
- filename = headers.request_method().ToString() + "_" +
- headers.request_uri().ToString();
+ filename = headers.request_method().as_string() + "_" +
+ headers.request_uri().as_string();
}
NewStream(stream_id_, 0, filename);
stream_id_ += 2;
@@ -1922,7 +1962,25 @@ class HTTPSM : public BalsaVisitorInterface, public SMInterface {
////////////////////////////////////////////////////////////////////////////////
-class SMAcceptorThread : public Thread,
+class Notification {
+ public:
+ explicit Notification(bool value) : value_(value) {}
+
+ void Notify() {
+ AutoLock al(lock_);
+ value_ = true;
+ }
+ bool HasBeenNotified() {
+ AutoLock al(lock_);
+ return value_;
+ }
+ bool value_;
+ Lock lock_;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+class SMAcceptorThread : public SimpleThread,
public EpollCallbackInterface,
public SMServerConnectionPoolInterface {
EpollServer epoll_server_;
@@ -1935,19 +1993,18 @@ class SMAcceptorThread : public Thread,
Notification quitting_;
SMInterfaceFactory* sm_interface_factory_;
MemoryCache* memory_cache_;
- Mutex m_;
public:
SMAcceptorThread(int listen_fd,
int accepts_per_wake,
SMInterfaceFactory* smif,
MemoryCache* memory_cache) :
+ SimpleThread("SMAcceptorThread"),
listen_fd_(listen_fd),
accepts_per_wake_(accepts_per_wake),
quitting_(false),
sm_interface_factory_(smif),
memory_cache_(memory_cache) {
- Thread::SetJoinable(true);
}
~SMAcceptorThread() {
@@ -2130,8 +2187,6 @@ const char* BoolToStr(bool b) {
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char**argv) {
- InitGoogleExceptChangeRootAndUser(argv[0], &argc, &argv, true);
-
bool use_ssl = FLAGS_use_ssl;
int response_count_until_close = FLAGS_response_count_until_close;
int flip_port = FLAGS_flip_port;
@@ -2233,10 +2288,10 @@ int main(int argc, char**argv) {
while (true) {
if (GotQuitFromStdin()) {
- for (int i = 0; i < sm_worker_threads_.size(); ++i) {
+ for (unsigned int i = 0; i < sm_worker_threads_.size(); ++i) {
sm_worker_threads_[i]->Quit();
}
- for (int i = 0; i < sm_worker_threads_.size(); ++i) {
+ for (unsigned int i = 0; i < sm_worker_threads_.size(); ++i) {
sm_worker_threads_[i]->Join();
}
return 0;
diff --git a/net/tools/flip_server/loadtime_measurement.h b/net/tools/flip_server/loadtime_measurement.h
index e57bca7..b46217e 100644
--- a/net/tools/flip_server/loadtime_measurement.h
+++ b/net/tools/flip_server/loadtime_measurement.h
@@ -5,6 +5,7 @@
#ifndef NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H__
#define NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H__
+#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
@@ -21,10 +22,10 @@
// measure and start with downloading the html file from browser.
class LoadtimeMeasurement {
public:
- LoadtimeMeasurement(const string& urls_file,
- const string& pageload_html_file)
+ LoadtimeMeasurement(const std::string& urls_file,
+ const std::string& pageload_html_file)
: num_urls_(0), pageload_html_file_(pageload_html_file) {
- string urls_string;
+ std::string urls_string;
read_file_to_string(urls_file.c_str(), &urls_string);
split_string(urls_string, '\n', &urls_);
num_urls_ = urls_.size();
@@ -34,9 +35,10 @@ class LoadtimeMeasurement {
// It handles the request to html file, get_total_iteration to get number
// of urls in the urls file, get each url, report the loadtime for
// each url, and the test is completed.
- void ProcessRequest(const string& uri, string& output) {
- string action = uri.substr(9); // remove "/testing/" from uri to get action
- if (pageload_html_file_.find(action) != string::npos) {
+ void ProcessRequest(const std::string& uri, std::string& output) {
+ // remove "/testing/" from uri to get the action
+ std::string action = uri.substr(9);
+ if (pageload_html_file_.find(action) != std::string::npos) {
read_file_to_string(pageload_html_file_.c_str(), &output);
return;
}
@@ -48,7 +50,7 @@ class LoadtimeMeasurement {
}
if (action.find("geturl") == 0) {
size_t b = action.find_first_of('=');
- if (b != string::npos) {
+ if (b != std::string::npos) {
int num = atoi(action.substr(b + 1).c_str());
if (num < num_urls_) {
output.append(urls_[num]);
@@ -57,7 +59,7 @@ class LoadtimeMeasurement {
return;
}
if (action.find("test_complete") == 0) {
- for (map<string, int>::const_iterator it = loadtimes_.begin();
+ for (std::map<std::string, int>::const_iterator it = loadtimes_.begin();
it != loadtimes_.end(); ++it) {
LOG(INFO) << it->first << " " << it->second;
}
@@ -66,12 +68,12 @@ class LoadtimeMeasurement {
return;
}
if (action.find("record_page_load") == 0) {
- vector<string> query;
+ std::vector<std::string> query;
split_string(action, '?', &query);
- vector<string> params;
+ std::vector<std::string> params;
split_string(query[1], '&', &params);
- vector<string> url;
- vector<string> loadtime;
+ std::vector<std::string> url;
+ std::vector<std::string> loadtime;
split_string(params[1], '=', &url);
split_string(params[2], '=', &loadtime);
loadtimes_[url[1]] = atoi(loadtime[1].c_str());
@@ -81,7 +83,7 @@ class LoadtimeMeasurement {
}
private:
- void read_file_to_string(const char* filename, string* output) {
+ void read_file_to_string(const char* filename, std::string* output) {
output->clear();
int fd = open(filename, 0, "r");
if (fd == -1)
@@ -97,10 +99,11 @@ class LoadtimeMeasurement {
close(fd);
}
- void split_string(string& str, char sepa, vector<string>* sub_strs) {
+ void split_string(std::string& str, char sepa,
+ std::vector<std::string>* sub_strs) {
size_t b = 0;
size_t e = str.find_first_of(sepa, b);
- while (e != string::npos && e > b) {
+ while (e != std::string::npos && e > b) {
sub_strs->push_back(str.substr(b, e - b));
b = e + 1;
e = str.find_first_of(sepa, b);
@@ -111,9 +114,9 @@ class LoadtimeMeasurement {
}
int num_urls_;
- vector<string> urls_;
- map<string, int> loadtimes_;
- const string pageload_html_file_;
+ std::vector<std::string> urls_;
+ std::map<std::string, int> loadtimes_;
+ const std::string pageload_html_file_;
};
#endif // NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H__
diff --git a/net/tools/flip_server/other_defines.h b/net/tools/flip_server/other_defines.h
new file mode 100644
index 0000000..05545e1
--- /dev/null
+++ b/net/tools/flip_server/other_defines.h
@@ -0,0 +1,23 @@
+#ifndef NET_TOOLS_FLIP_SERVER_OTHER_DEFINES
+#define NET_TOOLS_FLIP_SERVER_OTHER_DEFINES
+
+#define CHECK_EQ(X, Y) CHECK((X) == (Y))
+#define CHECK_NE(X, Y) CHECK((X) != (Y))
+#define CHECK_GE(X, Y) CHECK((X) >= (Y))
+#define CHECK_GT(X, Y) CHECK((X) > (Y))
+#define CHECK_LE(X, Y) CHECK((X) <= (Y))
+#define CHECK_LT(X, Y) CHECK((X) < (Y))
+
+class NullStream {
+ public:
+ NullStream() {}
+ template <typename T>
+ NullStream operator<<(T t) { return *this;}
+};
+
+#define VLOG(X) NullStream()
+#define DVLOG(X) NullStream()
+
+
+#endif // NET_TOOLS_FLIP_SERVER_OTHER_DEFINES
+
diff --git a/net/tools/flip_server/ring_buffer.h b/net/tools/flip_server/ring_buffer.h
index 63d4be2..a1a5491 100644
--- a/net/tools/flip_server/ring_buffer.h
+++ b/net/tools/flip_server/ring_buffer.h
@@ -7,6 +7,7 @@
#include "base/scoped_ptr.h"
#include "net/tools/flip_server/buffer_interface.h"
+#include "net/tools/flip_server/other_defines.h"
namespace net {
diff --git a/net/tools/flip_server/simple_buffer.cc b/net/tools/flip_server/simple_buffer.cc
index 6501d54..569e505 100644
--- a/net/tools/flip_server/simple_buffer.cc
+++ b/net/tools/flip_server/simple_buffer.cc
@@ -45,8 +45,8 @@ int SimpleBuffer::ReadableBytes() const {
////////////////////////////////////////////////////////////////////////////////
-string SimpleBuffer::str() const {
- string s;
+std::string SimpleBuffer::str() const {
+ std::string s;
char * readable_ptr;
int readable_size;
GetReadablePtr(&readable_ptr, &readable_size);
diff --git a/net/tools/flip_server/simple_buffer.h b/net/tools/flip_server/simple_buffer.h
index 33a6a0c..c10558a 100644
--- a/net/tools/flip_server/simple_buffer.h
+++ b/net/tools/flip_server/simple_buffer.h
@@ -8,6 +8,7 @@
#include <string>
#include "net/tools/flip_server/buffer_interface.h"
+#include "net/tools/flip_server/other_defines.h"
namespace net {
@@ -19,7 +20,7 @@ class SimpleBuffer : public BufferInterface {
delete[] storage_;
}
- string str() const;
+ std::string str() const;
typedef char * iterator;
typedef const char * const_iterator;
diff --git a/net/tools/flip_server/split.cc b/net/tools/flip_server/split.cc
new file mode 100644
index 0000000..7e3329a
--- /dev/null
+++ b/net/tools/flip_server/split.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 2009 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.
+
+#include <string.h>
+
+#include <vector>
+
+#include "base/string_piece.h"
+
+namespace net {
+
+// Yea, this could be done with less code duplication using
+// template magic, I know.
+void SplitStringPieceToVector(const base::StringPiece& full,
+ const char* delim,
+ std::vector<base::StringPiece>* vec,
+ bool omit_empty_strings) {
+ vec->clear();
+ if (full.size() == 0 || delim[0] == '\0')
+ return;
+
+ if (delim[1] == '\0') {
+ base::StringPiece::const_iterator s = full.begin();
+ base::StringPiece::const_iterator e = s;
+ for (;e != full.end(); ++e) {
+ if (*e == delim[0]) {
+ if (e != s || !omit_empty_strings) {
+ vec->push_back(base::StringPiece(s, e - s));
+ }
+ s = e;
+ ++s;
+ }
+ }
+ if (s != e) {
+ --e;
+ if (e != s || !omit_empty_strings) {
+ vec->push_back(base::StringPiece(s, e - s));
+ }
+ }
+ } else {
+ base::StringPiece::const_iterator s = full.begin();
+ base::StringPiece::const_iterator e = s;
+ for (;e != full.end(); ++e) {
+ bool one_matched = false;
+ for (const char *d = delim; *d != '\0'; ++d) {
+ if (*d == *e) {
+ one_matched = true;
+ break;
+ }
+ }
+ if (one_matched) {
+ if (e != s || !omit_empty_strings) {
+ vec->push_back(base::StringPiece(s, e - s));
+ }
+ s = e;
+ ++s;
+ }
+ }
+ if (s != e) {
+ --e;
+ if (e != s || !omit_empty_strings) {
+ vec->push_back(base::StringPiece(s, e - s));
+ }
+ }
+ }
+}
+
+} // namespace net
+
diff --git a/net/tools/flip_server/split.h b/net/tools/flip_server/split.h
new file mode 100644
index 0000000..247fef8
--- /dev/null
+++ b/net/tools/flip_server/split.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2009 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.
+
+#ifndef NET_TOOLS_FLIP_SERVER_SPLIT_H_
+#define NET_TOOLS_FLIP_SERVER_SPLIT_H_
+
+#include <vector>
+#include "base/string_piece.h"
+
+namespace net {
+
+// Yea, this could be done with less code duplication using
+// template magic, I know.
+void SplitStringPieceToVector(const base::StringPiece& full,
+ const char* delim,
+ std::vector<base::StringPiece>* vec,
+ bool omit_empty_strings);
+
+} // namespace net
+
+#endif // NET_TOOLS_FLIP_SERVER_SPLIT_H_
+
diff --git a/net/tools/flip_server/string_piece_utils.h b/net/tools/flip_server/string_piece_utils.h
new file mode 100644
index 0000000..3f3a251
--- /dev/null
+++ b/net/tools/flip_server/string_piece_utils.h
@@ -0,0 +1,81 @@
+// 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.
+
+#ifndef NET_TOOLS_FLIP_SERVER_STRING_PIECE_UTILS_H_
+#define NET_TOOLS_FLIP_SERVER_STRING_PIECE_UTILS_H_
+
+#include <ctype.h>
+
+#include "base/port.h"
+#include "base/string_piece.h"
+
+namespace net {
+
+struct StringPieceCaseHash {
+ size_t operator()(const base::StringPiece& sp) const {
+ // based on __stl_string_hash in http://www.sgi.com/tech/stl/string
+ size_t hash_val = 0;
+ for (base::StringPiece::const_iterator it = sp.begin();
+ it != sp.end(); ++it) {
+ hash_val = 5 * hash_val + tolower(*it);
+ }
+ return hash_val;
+ }
+};
+
+struct StringPieceUtils {
+ static bool EqualIgnoreCase(const base::StringPiece& piece1,
+ const base::StringPiece& piece2) {
+ base::StringPiece::const_iterator p1i = piece1.begin();
+ base::StringPiece::const_iterator p2i = piece2.begin();
+ if (piece1.empty() && piece2.empty()) {
+ return true;
+ } else if (piece1.size() != piece2.size()) {
+ return false;
+ }
+ while (p1i != piece1.end() && p2i != piece2.begin()) {
+ if (tolower(*p1i) != tolower(*p2i))
+ return false;
+ }
+ return true;
+ }
+
+ static void RemoveWhitespaceContext(base::StringPiece* piece1) {
+ base::StringPiece::const_iterator c = piece1->begin();
+ base::StringPiece::const_iterator e = piece1->end();
+ while (c != e && isspace(*c)) {
+ ++c;
+ }
+ if (c == e) {
+ *piece1 = base::StringPiece(c, e-c);
+ return;
+ }
+ --e;
+ while (c != e &&isspace(*e)) {
+ --e;
+ }
+ ++e;
+ *piece1 = base::StringPiece(c, e-c);
+ }
+
+ static bool StartsWithIgnoreCase(const base::StringPiece& text,
+ const base::StringPiece& starts_with) {
+ if (text.size() < starts_with.size())
+ return false;
+ return EqualIgnoreCase(text.substr(0, starts_with.size()), starts_with);
+ }
+};
+struct StringPieceCaseEqual {
+ bool operator()(const base::StringPiece& piece1,
+ const base::StringPiece& piece2) const {
+ return StringPieceUtils::EqualIgnoreCase(piece1, piece2);
+ }
+};
+
+
+
+} // namespace net
+
+#endif // NET_TOOLS_FLIP_SERVER_STRING_PIECE_UTILS_H_
+
diff --git a/net/tools/flip_server/url_to_filename_encoder.h b/net/tools/flip_server/url_to_filename_encoder.h
index 25ddbd3..568c1ee 100644
--- a/net/tools/flip_server/url_to_filename_encoder.h
+++ b/net/tools/flip_server/url_to_filename_encoder.h
@@ -15,7 +15,7 @@ class UrlToFilenameEncoder {
public:
// Given a |url| and a |base_path|, returns a string which represents this
// |url|.
- static string Encode(const std::string& url, std::string base_path) {
+ static std::string Encode(const std::string& url, std::string base_path) {
std::string clean_url(url);
if (clean_url.length() && clean_url[clean_url.length()-1] == '/')
clean_url.append("index.html");
@@ -50,7 +50,7 @@ class UrlToFilenameEncoder {
}
private:
- static const int kMaximumSubdirectoryLength = 128;
+ static const unsigned int kMaximumSubdirectoryLength = 128;
// Escape the given input |path| and chop any individual components
@@ -63,7 +63,7 @@ class UrlToFilenameEncoder {
// This is due to the incompetence of the windows
// filesystem, which still hasn't figured out how
// to deal with long filenames.
- int last_slash = 0;
+ unsigned int last_slash = 0;
for (size_t index = 0; index < path.length(); index++) {
char ch = path[index];
if (ch == 0x5C)
diff --git a/net/tools/flip_server/url_utilities.h b/net/tools/flip_server/url_utilities.h
index 488753c..52a768a 100644
--- a/net/tools/flip_server/url_utilities.h
+++ b/net/tools/flip_server/url_utilities.h
@@ -11,55 +11,55 @@ namespace net {
struct UrlUtilities {
// Get the host from an url
- static string GetUrlHost(const string& url) {
+ static std::string GetUrlHost(const std::string& url) {
size_t b = url.find("//");
- if (b == string::npos)
+ if (b == std::string::npos)
b = 0;
else
b += 2;
size_t next_slash = url.find_first_of('/', b);
size_t next_colon = url.find_first_of(':', b);
- if (next_slash != string::npos
- && next_colon != string::npos
+ if (next_slash != std::string::npos
+ && next_colon != std::string::npos
&& next_colon < next_slash) {
- return string(url, b, next_colon - b);
+ return std::string(url, b, next_colon - b);
}
- if (next_slash == string::npos) {
- if (next_colon != string::npos) {
- return string(url, next_colon - b);
+ if (next_slash == std::string::npos) {
+ if (next_colon != std::string::npos) {
+ return std::string(url, next_colon - b);
} else {
next_slash = url.size();
}
}
- return string(url, b, next_slash - b);
+ return std::string(url, b, next_slash - b);
}
// Get the host + path portion of an url
// e.g http://www.foo.com/path
// returns www.foo.com/path
- static string GetUrlHostPath(const string& url) {
+ static std::string GetUrlHostPath(const std::string& url) {
size_t b = url.find("//");
- if (b == string::npos)
+ if (b == std::string::npos)
b = 0;
else
b += 2;
- return string(url, b);
+ return std::string(url, b);
}
// Get the path portion of an url
// e.g http://www.foo.com/path
// returns /path
- static string GetUrlPath(const string& url) {
+ static std::string GetUrlPath(const std::string& url) {
size_t b = url.find("//");
- if (b == string::npos)
+ if (b == std::string::npos)
b = 0;
else
b += 2;
b = url.find("/", b+1);
- if (b == string::npos)
+ if (b == std::string::npos)
return "/";
- return string(url, b);
+ return std::string(url, b);
}
};