Use string_view in BalsaVisitorInterface. Half as many arguments as (const char*, size_t) pairs! Also change BalsaHeaders::GetReadablePtrFromHeaderStream() to return string_view instead of using two outparams. PiperOrigin-RevId: 443110085
diff --git a/quiche/common/balsa/balsa_frame.cc b/quiche/common/balsa/balsa_frame.cc index 39853e3..8416b96 100644 --- a/quiche/common/balsa/balsa_frame.cc +++ b/quiche/common/balsa/balsa_frame.cc
@@ -252,26 +252,34 @@ size_t version_length = headers_->whitespace_4_idx_ - headers_->non_whitespace_3_idx_; visitor_->OnRequestFirstLineInput( - begin + headers_->non_whitespace_1_idx_, - headers_->whitespace_4_idx_ - headers_->non_whitespace_1_idx_, - begin + headers_->non_whitespace_1_idx_, - headers_->whitespace_2_idx_ - headers_->non_whitespace_1_idx_, - begin + headers_->non_whitespace_2_idx_, - headers_->whitespace_3_idx_ - headers_->non_whitespace_2_idx_, - begin + headers_->non_whitespace_3_idx_, version_length); + absl::string_view( + begin + headers_->non_whitespace_1_idx_, + headers_->whitespace_4_idx_ - headers_->non_whitespace_1_idx_), + absl::string_view( + begin + headers_->non_whitespace_1_idx_, + headers_->whitespace_2_idx_ - headers_->non_whitespace_1_idx_), + absl::string_view( + begin + headers_->non_whitespace_2_idx_, + headers_->whitespace_3_idx_ - headers_->non_whitespace_2_idx_), + absl::string_view(begin + headers_->non_whitespace_3_idx_, + version_length)); if (version_length == 0) { parse_state_ = BalsaFrameEnums::MESSAGE_FULLY_READ; } } else { visitor_->OnResponseFirstLineInput( - begin + headers_->non_whitespace_1_idx_, - headers_->whitespace_4_idx_ - headers_->non_whitespace_1_idx_, - begin + headers_->non_whitespace_1_idx_, - headers_->whitespace_2_idx_ - headers_->non_whitespace_1_idx_, - begin + headers_->non_whitespace_2_idx_, - headers_->whitespace_3_idx_ - headers_->non_whitespace_2_idx_, - begin + headers_->non_whitespace_3_idx_, - headers_->whitespace_4_idx_ - headers_->non_whitespace_3_idx_); + absl::string_view( + begin + headers_->non_whitespace_1_idx_, + headers_->whitespace_4_idx_ - headers_->non_whitespace_1_idx_), + absl::string_view( + begin + headers_->non_whitespace_1_idx_, + headers_->whitespace_2_idx_ - headers_->non_whitespace_1_idx_), + absl::string_view( + begin + headers_->non_whitespace_2_idx_, + headers_->whitespace_3_idx_ - headers_->non_whitespace_2_idx_), + absl::string_view( + begin + headers_->non_whitespace_3_idx_, + headers_->whitespace_4_idx_ - headers_->non_whitespace_3_idx_)); } } @@ -825,12 +833,7 @@ // we tell that to the headers object. The headers object may make // more efficient allocation decisions when this is signaled. headers_->DoneWritingFromFramer(); - { - const char* readable_ptr = nullptr; - size_t readable_size = 0; - headers_->GetReadablePtrFromHeaderStream(&readable_ptr, &readable_size); - visitor_->OnHeaderInput(readable_ptr, readable_size); - } + visitor_->OnHeaderInput(headers_->GetReadablePtrFromHeaderStream()); // Ok, now that we've written everything into our header buffer, it is // time to process the header lines (extract proper values for headers @@ -988,7 +991,8 @@ QUICHE_DCHECK_LE(current, end); while (true) { if (current == end) { - visitor_->OnRawBodyInput(on_entry, current - on_entry); + visitor_->OnRawBodyInput( + absl::string_view(on_entry, current - on_entry)); return current - input; } @@ -1059,7 +1063,8 @@ (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!! - visitor_->OnRawBodyInput(on_entry, current - on_entry); + visitor_->OnRawBodyInput( + absl::string_view(on_entry, current - on_entry)); HandleError(BalsaFrameEnums::CHUNK_LENGTH_OVERFLOW); return current - input; } @@ -1071,7 +1076,8 @@ // ^[0-9;A-Fa-f][ \t\n] -- was not matched, either because no // characters were converted, or an unexpected character was // seen. - visitor_->OnRawBodyInput(on_entry, current - on_entry); + visitor_->OnRawBodyInput( + absl::string_view(on_entry, current - on_entry)); HandleError(BalsaFrameEnums::INVALID_CHUNK_LENGTH); return current - input; } @@ -1092,9 +1098,10 @@ QUICHE_DCHECK_LE(current, end); while (true) { if (current == end) { - visitor_->OnChunkExtensionInput(extensions_start, - extensions_length); - visitor_->OnRawBodyInput(on_entry, current - on_entry); + visitor_->OnChunkExtensionInput( + absl::string_view(extensions_start, extensions_length)); + visitor_->OnRawBodyInput( + absl::string_view(on_entry, current - on_entry)); return current - input; } const char c = *current; @@ -1111,7 +1118,8 @@ } chunk_length_character_extracted_ = false; - visitor_->OnChunkExtensionInput(extensions_start, extensions_length); + visitor_->OnChunkExtensionInput( + absl::string_view(extensions_start, extensions_length)); if (chunk_length_remaining_ != 0) { parse_state_ = BalsaFrameEnums::READING_CHUNK_DATA; @@ -1134,8 +1142,10 @@ ? chunk_length_remaining_ : bytes_remaining; const char* tmp_current = current + consumed_bytes; - visitor_->OnRawBodyInput(on_entry, tmp_current - on_entry); - visitor_->OnBodyChunkInput(current, consumed_bytes); + visitor_->OnRawBodyInput( + absl::string_view(on_entry, tmp_current - on_entry)); + visitor_->OnBodyChunkInput( + absl::string_view(current, consumed_bytes)); on_entry = current = tmp_current; chunk_length_remaining_ -= consumed_bytes; } @@ -1145,14 +1155,16 @@ continue; } - visitor_->OnRawBodyInput(on_entry, current - on_entry); + visitor_->OnRawBodyInput( + absl::string_view(on_entry, current - on_entry)); return current - input; case BalsaFrameEnums::READING_CHUNK_TERM: QUICHE_DCHECK_LE(current, end); while (true) { if (current == end) { - visitor_->OnRawBodyInput(on_entry, current - on_entry); + visitor_->OnRawBodyInput( + absl::string_view(on_entry, current - on_entry)); return current - input; } @@ -1170,7 +1182,8 @@ QUICHE_DCHECK_LE(current, end); while (true) { if (current == end) { - visitor_->OnRawBodyInput(on_entry, current - on_entry); + visitor_->OnRawBodyInput( + absl::string_view(on_entry, current - on_entry)); return current - input; } @@ -1180,7 +1193,8 @@ // is done. ++current; parse_state_ = BalsaFrameEnums::MESSAGE_FULLY_READ; - visitor_->OnRawBodyInput(on_entry, current - on_entry); + visitor_->OnRawBodyInput( + absl::string_view(on_entry, current - on_entry)); visitor_->MessageDone(); return current - input; } @@ -1207,7 +1221,8 @@ // If (!HeaderFramingMayBeFound()), then we know that we must be // reading the first non CRLF character of a trailer. parse_state_ = BalsaFrameEnums::READING_TRAILER; - visitor_->OnRawBodyInput(on_entry, current - on_entry); + visitor_->OnRawBodyInput( + absl::string_view(on_entry, current - on_entry)); on_entry = current; continue; @@ -1243,7 +1258,8 @@ } visitor_->ProcessTrailers(*trailer_); } - visitor_->OnTrailerInput(on_entry, current - on_entry); + visitor_->OnTrailerInput( + absl::string_view(on_entry, current - on_entry)); visitor_->MessageDone(); return current - input; } @@ -1251,14 +1267,16 @@ if (trailer_ != nullptr) { trailer_->WriteFromFramer(on_entry, current - on_entry); } - visitor_->OnTrailerInput(on_entry, current - on_entry); + visitor_->OnTrailerInput( + absl::string_view(on_entry, current - on_entry)); return current - input; case BalsaFrameEnums::READING_UNTIL_CLOSE: { const size_t bytes_remaining = end - current; if (bytes_remaining > 0) { - visitor_->OnRawBodyInput(current, bytes_remaining); - visitor_->OnBodyChunkInput(current, bytes_remaining); + visitor_->OnRawBodyInput(absl::string_view(current, bytes_remaining)); + visitor_->OnBodyChunkInput( + absl::string_view(current, bytes_remaining)); current += bytes_remaining; } return current - input; @@ -1272,8 +1290,9 @@ (content_length_remaining_ < bytes_remaining) ? content_length_remaining_ : bytes_remaining; - visitor_->OnRawBodyInput(current, consumed_bytes); - visitor_->OnBodyChunkInput(current, consumed_bytes); + visitor_->OnRawBodyInput(absl::string_view(current, consumed_bytes)); + visitor_->OnBodyChunkInput( + absl::string_view(current, consumed_bytes)); current += consumed_bytes; content_length_remaining_ -= consumed_bytes; }
diff --git a/quiche/common/balsa/balsa_headers.h b/quiche/common/balsa/balsa_headers.h index e8b4efd..b605331 100644 --- a/quiche/common/balsa/balsa_headers.h +++ b/quiche/common/balsa/balsa_headers.h
@@ -1033,9 +1033,8 @@ return balsa_buffer_.GetReadableBytesOfFirstBlock(); } - void GetReadablePtrFromHeaderStream(const char** p, size_t* s) { - *p = OriginalHeaderStreamBegin(); - *s = GetReadableBytesFromHeaderStream(); + absl::string_view GetReadablePtrFromHeaderStream() { + return {OriginalHeaderStreamBegin(), GetReadableBytesFromHeaderStream()}; } absl::string_view GetValueFromHeaderLineDescription(
diff --git a/quiche/common/balsa/balsa_visitor_interface.h b/quiche/common/balsa/balsa_visitor_interface.h index a8fcce3..0202f81 100644 --- a/quiche/common/balsa/balsa_visitor_interface.h +++ b/quiche/common/balsa/balsa_visitor_interface.h
@@ -7,6 +7,7 @@ #include <cstddef> +#include "absl/strings/string_view.h" #include "quiche/common/balsa/balsa_enums.h" #include "quiche/common/platform/api/quiche_export.h" @@ -15,7 +16,7 @@ class BalsaHeaders; // By default the BalsaFrame instantiates a class derived from this interface -// which does absolutely nothing. If you'd prefer to have interesting +// that does absolutely nothing. If you'd prefer to have interesting // functionality execute when any of the below functions are called by the // BalsaFrame, then you should subclass it, and set an instantiation of your // subclass as the current visitor for the BalsaFrame class using @@ -25,49 +26,43 @@ virtual ~BalsaVisitorInterface() {} // Summary: - // This is how the BalsaFrame passes you the raw input which it knows to - // be a part of the body. To be clear, every byte of the Balsa which isn't - // part of the header (or its framing), or trailers will be passed through - // this function. This includes data as well as chunking framing. + // This is how the BalsaFrame passes you the raw input that it knows to be a + // part of the body. To be clear, every byte of the Balsa that isn't part of + // the header (or its framing), or trailers will be passed through this + // function. This includes data as well as chunking framing. // Arguments: - // input - contains the bytes available for read. - // size - contains the number of bytes it is safe to read from input. - virtual void OnRawBodyInput(const char* input, size_t size) = 0; + // input - the raw input that is part of the body. + virtual void OnRawBodyInput(absl::string_view input) = 0; // Summary: - // This is like OnRawBodyInput, but it will only include those parts of - // the body which would be stored by a program such as wget, i.e. the bytes - // indicating chunking will have been removed. Trailers will not be - // passed in through this function-- they'll be passed in through - // OnTrailerInput. + // This is like OnRawBodyInput, but it will only include those parts of the + // body that would be stored by a program such as wget, i.e. the bytes + // indicating chunking will have been removed. Trailers will not be passed + // in through this function-- they'll be passed in through OnTrailerInput. // Arguments: - // input - contains the bytes available for read. - // size - contains the number of bytes it is safe to read from input. - virtual void OnBodyChunkInput(const char* input, size_t size) = 0; + // input - the part of the body. + virtual void OnBodyChunkInput(absl::string_view input) = 0; // Summary: - // BalsaFrame passes the raw header data through this function. This is - // not cleaned up in any way. + // BalsaFrame passes the raw header data through this function. This is not + // cleaned up in any way. // Arguments: - // input - contains the bytes available for read. - // size - contains the number of bytes it is safe to read from input. - virtual void OnHeaderInput(const char* input, size_t size) = 0; + // input - raw header data. + virtual void OnHeaderInput(absl::string_view input) = 0; // Summary: - // BalsaFrame passes the raw trailer data through this function. This is - // not cleaned up in any way. Note that trailers only occur in a message - // if there was a chunked encoding, and not always then. - // + // BalsaFrame passes the raw trailer data through this function. This is not + // cleaned up in any way. Note that trailers only occur in a message if + // there was a chunked encoding, and not always then. // Arguments: - // input - contains the bytes available for read. - // size - contains the number of bytes it is safe to read from input. - virtual void OnTrailerInput(const char* input, size_t size) = 0; + // input - raw trailer data. + virtual void OnTrailerInput(absl::string_view input) = 0; // Summary: // Since the BalsaFrame already has to parse the headers in order to - // determine proper framing, it might as well pass the parsed and - // cleaned-up results to whatever might need it. This function exists for - // that purpose-- parsed headers are passed into this function. + // determine proper framing, it might as well pass the parsed and cleaned-up + // results to whatever might need it. This function exists for that + // purpose-- parsed headers are passed into this function. // Arguments: // headers - contains the parsed headers in the order in which // they occurred in the header. @@ -75,10 +70,10 @@ // Summary: // Since the BalsaFrame already has to parse the trailer, it might as well - // pass the parsed and cleaned-up results to whatever might need it. - // This function exists for that purpose-- parsed trailer is passed into - // this function. This will not be called if the trailer_ object is - // not set in the framer, even if trailer exists in request/response. + // pass the parsed and cleaned-up results to whatever might need it. This + // function exists for that purpose-- parsed trailer is passed into this + // function. This will not be called if the trailer_ object is not set in + // the framer, even if trailer exists in request/response. // Arguments: // trailer - contains the parsed headers in the order in which // they occurred in the trailer. @@ -88,47 +83,30 @@ // Called when the first line of the message is parsed, in this case, for a // request. // Arguments: - // line_input - pointer to the beginning of the first line string. - // line_length - length of the first line string. (i.e. the numer of - // bytes it is safe to read from line_ptr) - // method_input - pointer to the beginning of the method string - // method_length - length of the method string (i.e. the number - // of bytes it is safe to read from method_input) - // request_uri_input - pointer to the beginning of the request uri - // string. - // request_uri_length - length of the method string (i.e. the number - // of bytes it is safe to read from method_input) - // version_input - pointer to the beginning of the version string. - // version_length - length of the version string (i.e. the number - // of bytes it i ssafe to read from version_input) - virtual void OnRequestFirstLineInput( - const char* line_input, size_t line_length, const char* method_input, - size_t method_length, const char* request_uri_input, - size_t request_uri_length, const char* version_input, - size_t version_length) = 0; + // line_input - the first line string, + // method_input - the method substring, + // request_uri_input - request uri substring, + // version_input - the version substring. + virtual void OnRequestFirstLineInput(absl::string_view line_input, + absl::string_view method_input, + absl::string_view request_uri, + absl::string_view version_input) = 0; // Summary: // Called when the first line of the message is parsed, in this case, for a // response. // Arguments: - // line_input - pointer to the beginning of the first line string. - // line_length - length of the first line string. (i.e. the numer of - // bytes it is safe to read from line_ptr) - // version_input - pointer to the beginning of the version string. - // version_length - length of the version string (i.e. the number - // of bytes it i ssafe to read from version_input) - // status_input - pointer to the beginning of the status string - // status_length - length of the status string (i.e. the number - // of bytes it is safe to read from status_input) - // reason_input - pointer to the beginning of the reason string - // reason_length - length of the reason string (i.e. the number - // of bytes it is safe to read from reason_input) - virtual void OnResponseFirstLineInput( - const char* line_input, size_t line_length, const char* version_input, - size_t version_length, const char* status_input, size_t status_length, - const char* reason_input, size_t reason_length) = 0; + // line_input - the first line string, + // version_input - the version substring, + // status_input - the status substring, + // reason_input - the reason substring. + virtual void OnResponseFirstLineInput(absl::string_view line_input, + absl::string_view version_input, + absl::string_view status_input, + absl::string_view reason_input) = 0; - // Called when a chunk length is parsed. + // Summary: + // Called when a chunk length is parsed. // Arguments: // chunk length - the length of the next incoming chunk. virtual void OnChunkLength(size_t chunk_length) = 0; @@ -136,11 +114,9 @@ // Summary: // BalsaFrame passes the raw chunk extension data through this function. // The data is not cleaned up at all. - // // Arguments: - // input - contains the bytes available for read. - // size - contains the number of bytes it is safe to read from input. - virtual void OnChunkExtensionInput(const char* input, size_t size) = 0; + // input - contains the bytes available for read. + virtual void OnChunkExtensionInput(absl::string_view input) = 0; // Summary: // Called when the header is framed and processed. @@ -157,13 +133,13 @@ // Summary: // Called when an error is detected // Arguments: - // error_code - the error which is to be reported + // error_code - the error which is to be reported. virtual void HandleError(BalsaFrameEnums::ErrorCode error_code) = 0; // Summary: // Called when something meriting a warning is detected // Arguments: - // error_code - the warning which is to be reported + // error_code - the warning which is to be reported. virtual void HandleWarning(BalsaFrameEnums::ErrorCode error_code) = 0; };
diff --git a/quiche/common/balsa/noop_balsa_visitor.h b/quiche/common/balsa/noop_balsa_visitor.h index b107dbd..35a8be2 100644 --- a/quiche/common/balsa/noop_balsa_visitor.h +++ b/quiche/common/balsa/noop_balsa_visitor.h
@@ -7,6 +7,7 @@ #include <cstddef> +#include "absl/strings/string_view.h" #include "quiche/common/balsa/balsa_visitor_interface.h" #include "quiche/common/platform/api/quiche_export.h" @@ -26,25 +27,23 @@ ~NoOpBalsaVisitor() override {} - void OnRawBodyInput(const char* /*input*/, size_t /*size*/) override {} - void OnBodyChunkInput(const char* /*input*/, size_t /*size*/) override {} - void OnHeaderInput(const char* /*input*/, size_t /*size*/) override {} - void OnTrailerInput(const char* /*input*/, size_t /*size*/) override {} + void OnRawBodyInput(absl::string_view /*input*/) override {} + void OnBodyChunkInput(absl::string_view /*input*/) override {} + void OnHeaderInput(absl::string_view /*input*/) override {} + void OnTrailerInput(absl::string_view /*input*/) override {} void ProcessHeaders(const BalsaHeaders& /*headers*/) override {} void ProcessTrailers(const BalsaHeaders& /*trailer*/) override {} - void OnRequestFirstLineInput( - const char* /*line_input*/, size_t /*line_length*/, - const char* /*method_input*/, size_t /*method_length*/, - const char* /*request_uri_input*/, size_t /*request_uri_length*/, - const char* /*version_input*/, size_t /*version_length*/) override {} - void OnResponseFirstLineInput( - const char* /*line_input*/, size_t /*line_length*/, - const char* /*version_input*/, size_t /*version_length*/, - const char* /*status_input*/, size_t /*status_length*/, - const char* /*reason_input*/, size_t /*reason_length*/) override {} + void OnRequestFirstLineInput(absl::string_view /*line_input*/, + absl::string_view /*method_input*/, + absl::string_view /*request_uri_input*/, + absl::string_view /*version_input*/) override {} + void OnResponseFirstLineInput(absl::string_view /*line_input*/, + absl::string_view /*version_input*/, + absl::string_view /*status_input*/, + absl::string_view /*reason_input*/) override {} void OnChunkLength(size_t /*chunk_length*/) override {} - void OnChunkExtensionInput(const char* /*input*/, size_t /*size*/) override {} + void OnChunkExtensionInput(absl::string_view /*input*/) override {} void ContinueHeaderDone() override {} void HeaderDone() override {} void MessageDone() override {}