diff options
author | Ali Tofigh <alito@webrtc.org> | 2022-04-13 12:55:15 +0200 |
---|---|---|
committer | WebRTC LUCI CQ <webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-04-17 12:11:56 +0000 |
commit | 2ab914c6ab73ac0f85f633a5ce499cae74e7b75a (patch) | |
tree | 5a81008847cea04ff2e18ebb1b5b3b2e418ed39e /rtc_base/http_common.cc | |
parent | a62136ac74bc0523faf7ee390854e5c363f26d4b (diff) | |
download | webrtc-2ab914c6ab73ac0f85f633a5ce499cae74e7b75a.tar.gz |
Adopt absl::string_view in rtc_base/ (straightforward cases)
Bug: webrtc:13579
Change-Id: I240db6285abb22652242bc0b2ebe9844ec4a45f0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/258723
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Ali Tofigh <alito@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36561}
Diffstat (limited to 'rtc_base/http_common.cc')
-rw-r--r-- | rtc_base/http_common.cc | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/rtc_base/http_common.cc b/rtc_base/http_common.cc index 5ac222f468..2968cf12c3 100644 --- a/rtc_base/http_common.cc +++ b/rtc_base/http_common.cc @@ -120,14 +120,14 @@ const ConstantToLabel SECURITY_ERRORS[] = { typedef std::pair<std::string, std::string> HttpAttribute; typedef std::vector<HttpAttribute> HttpAttributeList; -inline bool IsEndOfAttributeName(size_t pos, size_t len, const char* data) { - if (pos >= len) +inline bool IsEndOfAttributeName(size_t pos, absl::string_view data) { + if (pos >= data.size()) return true; if (isspace(static_cast<unsigned char>(data[pos]))) return true; // The reason for this complexity is that some attributes may contain trailing // equal signs (like base64 tokens in Negotiate auth headers) - if ((pos + 1 < len) && (data[pos] == '=') && + if ((pos + 1 < data.size()) && (data[pos] == '=') && !isspace(static_cast<unsigned char>(data[pos + 1])) && (data[pos + 1] != '=')) { return true; @@ -135,10 +135,10 @@ inline bool IsEndOfAttributeName(size_t pos, size_t len, const char* data) { return false; } -void HttpParseAttributes(const char* data, - size_t len, +void HttpParseAttributes(absl::string_view data, HttpAttributeList& attributes) { size_t pos = 0; + const size_t len = data.size(); while (true) { // Skip leading whitespace while ((pos < len) && isspace(static_cast<unsigned char>(data[pos]))) { @@ -151,12 +151,12 @@ void HttpParseAttributes(const char* data, // Find end of attribute name size_t start = pos; - while (!IsEndOfAttributeName(pos, len, data)) { + while (!IsEndOfAttributeName(pos, data)) { ++pos; } HttpAttribute attribute; - attribute.first.assign(data + start, data + pos); + attribute.first.assign(data.data() + start, data.data() + pos); // Attribute has value? if ((pos < len) && (data[pos] == '=')) { @@ -250,8 +250,7 @@ struct NegotiateAuthContext : public HttpAuthContext { } // anonymous namespace -HttpAuthResult HttpAuthenticate(const char* challenge, - size_t len, +HttpAuthResult HttpAuthenticate(absl::string_view challenge, const SocketAddress& server, absl::string_view method, absl::string_view uri, @@ -261,7 +260,7 @@ HttpAuthResult HttpAuthenticate(const char* challenge, std::string& response, std::string& auth_method) { HttpAttributeList args; - HttpParseAttributes(challenge, len, args); + HttpParseAttributes(challenge, args); HttpHasNthAttribute(args, 0, &auth_method, nullptr); if (context && (context->auth_method != auth_method)) |