mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Adopt absl::string_view in function parameters under rtc_base/
This is part of a large-scale effort to increase adoption of absl::string_view across the WebRTC code base. This CL converts the majority of "const std::string&"s in function parameters under rtc_base/ to absl::string_view. Bug: webrtc:13579 Change-Id: I2b1e3776aa42326aa405f76bb324a2d233b21dca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/254081 Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Xavier Lepaul <xalep@webrtc.org> Reviewed-by: Anders Lilienthal <andersc@webrtc.org> Reviewed-by: Per Kjellander <perkj@webrtc.org> Commit-Queue: Ali Tofigh <alito@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36239}
This commit is contained in:
parent
1a08096998
commit
7fa9057a05
96 changed files with 677 additions and 495 deletions
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "absl/algorithm/container.h"
|
#include "absl/algorithm/container.h"
|
||||||
#include "absl/strings/match.h"
|
#include "absl/strings/match.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "p2p/base/connection.h"
|
#include "p2p/base/connection.h"
|
||||||
#include "p2p/base/port_allocator.h"
|
#include "p2p/base/port_allocator.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
|
@ -301,7 +302,7 @@ bool Port::MaybeObfuscateAddress(Candidate* c,
|
||||||
auto copy = *c;
|
auto copy = *c;
|
||||||
auto weak_ptr = weak_factory_.GetWeakPtr();
|
auto weak_ptr = weak_factory_.GetWeakPtr();
|
||||||
auto callback = [weak_ptr, copy, is_final](const rtc::IPAddress& addr,
|
auto callback = [weak_ptr, copy, is_final](const rtc::IPAddress& addr,
|
||||||
const std::string& name) mutable {
|
absl::string_view name) mutable {
|
||||||
RTC_DCHECK(copy.address().ipaddr() == addr);
|
RTC_DCHECK(copy.address().ipaddr() == addr);
|
||||||
rtc::SocketAddress hostname_address(name, copy.address().port());
|
rtc::SocketAddress hostname_address(name, copy.address().port());
|
||||||
// In Port and Connection, we need the IP address information to
|
// In Port and Connection, we need the IP address information to
|
||||||
|
|
|
@ -96,6 +96,7 @@ rtc_library("rtc_base_approved") {
|
||||||
absl_deps = [
|
absl_deps = [
|
||||||
"//third_party/abseil-cpp/absl/base:core_headers",
|
"//third_party/abseil-cpp/absl/base:core_headers",
|
||||||
"//third_party/abseil-cpp/absl/numeric:bits",
|
"//third_party/abseil-cpp/absl/numeric:bits",
|
||||||
|
"//third_party/abseil-cpp/absl/strings",
|
||||||
"//third_party/abseil-cpp/absl/types:optional",
|
"//third_party/abseil-cpp/absl/types:optional",
|
||||||
]
|
]
|
||||||
public_deps = [] # no-presubmit-check TODO(webrtc:8603)
|
public_deps = [] # no-presubmit-check TODO(webrtc:8603)
|
||||||
|
@ -683,6 +684,7 @@ rtc_library("rtc_json") {
|
||||||
# expected to be when building json outside of the standalone build.
|
# expected to be when building json outside of the standalone build.
|
||||||
defines += [ "WEBRTC_EXTERNAL_JSON" ]
|
defines += [ "WEBRTC_EXTERNAL_JSON" ]
|
||||||
}
|
}
|
||||||
|
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc_library("net_helpers") {
|
rtc_library("net_helpers") {
|
||||||
|
@ -730,6 +732,7 @@ rtc_library("ip_address") {
|
||||||
if (is_win) {
|
if (is_win) {
|
||||||
deps += [ ":win32" ]
|
deps += [ ":win32" ]
|
||||||
}
|
}
|
||||||
|
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc_library("socket_address") {
|
rtc_library("socket_address") {
|
||||||
|
@ -751,6 +754,7 @@ rtc_library("socket_address") {
|
||||||
if (is_win) {
|
if (is_win) {
|
||||||
deps += [ ":win32" ]
|
deps += [ ":win32" ]
|
||||||
}
|
}
|
||||||
|
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc_library("null_socket_server") {
|
rtc_library("null_socket_server") {
|
||||||
|
@ -795,6 +799,7 @@ rtc_library("threading") {
|
||||||
absl_deps = [
|
absl_deps = [
|
||||||
"//third_party/abseil-cpp/absl/algorithm:container",
|
"//third_party/abseil-cpp/absl/algorithm:container",
|
||||||
"//third_party/abseil-cpp/absl/base:core_headers",
|
"//third_party/abseil-cpp/absl/base:core_headers",
|
||||||
|
"//third_party/abseil-cpp/absl/strings",
|
||||||
]
|
]
|
||||||
deps = [
|
deps = [
|
||||||
":async_resolver_interface",
|
":async_resolver_interface",
|
||||||
|
@ -1233,6 +1238,7 @@ rtc_library("rtc_base_tests_utils") {
|
||||||
absl_deps = [
|
absl_deps = [
|
||||||
"//third_party/abseil-cpp/absl/algorithm:container",
|
"//third_party/abseil-cpp/absl/algorithm:container",
|
||||||
"//third_party/abseil-cpp/absl/memory",
|
"//third_party/abseil-cpp/absl/memory",
|
||||||
|
"//third_party/abseil-cpp/absl/strings",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1326,7 +1332,10 @@ if (rtc_include_tests) {
|
||||||
"third_party/sigslot",
|
"third_party/sigslot",
|
||||||
"//testing/gtest",
|
"//testing/gtest",
|
||||||
]
|
]
|
||||||
absl_deps = [ "//third_party/abseil-cpp/absl/memory" ]
|
absl_deps = [
|
||||||
|
"//third_party/abseil-cpp/absl/memory",
|
||||||
|
"//third_party/abseil-cpp/absl/strings",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc_library("rtc_base_approved_unittests") {
|
rtc_library("rtc_base_approved_unittests") {
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include "rtc_base/boringssl_certificate.h"
|
#include "rtc_base/boringssl_certificate.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
// Must be included first before openssl headers.
|
// Must be included first before openssl headers.
|
||||||
#include "rtc_base/win32.h" // NOLINT
|
#include "rtc_base/win32.h" // NOLINT
|
||||||
|
@ -116,7 +118,7 @@ bool AddSHA256SignatureAlgorithm(CBB* cbb, KeyType key_type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds an X.509 Common Name to `cbb`.
|
// Adds an X.509 Common Name to `cbb`.
|
||||||
bool AddCommonName(CBB* cbb, const std::string& common_name) {
|
bool AddCommonName(CBB* cbb, absl::string_view common_name) {
|
||||||
// See RFC 4519.
|
// See RFC 4519.
|
||||||
static const uint8_t kCommonName[] = {0x55, 0x04, 0x03};
|
static const uint8_t kCommonName[] = {0x55, 0x04, 0x03};
|
||||||
|
|
||||||
|
@ -138,7 +140,7 @@ bool AddCommonName(CBB* cbb, const std::string& common_name) {
|
||||||
!CBB_add_bytes(&type, kCommonName, sizeof(kCommonName)) ||
|
!CBB_add_bytes(&type, kCommonName, sizeof(kCommonName)) ||
|
||||||
!CBB_add_asn1(&attr, &value, CBS_ASN1_UTF8STRING) ||
|
!CBB_add_asn1(&attr, &value, CBS_ASN1_UTF8STRING) ||
|
||||||
!CBB_add_bytes(&value,
|
!CBB_add_bytes(&value,
|
||||||
reinterpret_cast<const uint8_t*>(common_name.c_str()),
|
reinterpret_cast<const uint8_t*>(common_name.data()),
|
||||||
common_name.size()) ||
|
common_name.size()) ||
|
||||||
!CBB_flush(cbb)) {
|
!CBB_flush(cbb)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -275,7 +277,7 @@ std::unique_ptr<BoringSSLCertificate> BoringSSLCertificate::Generate(
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<BoringSSLCertificate> BoringSSLCertificate::FromPEMString(
|
std::unique_ptr<BoringSSLCertificate> BoringSSLCertificate::FromPEMString(
|
||||||
const std::string& pem_string) {
|
absl::string_view pem_string) {
|
||||||
std::string der;
|
std::string der;
|
||||||
if (!SSLIdentity::PemToDer(kPemTypeCertificate, pem_string, &der)) {
|
if (!SSLIdentity::PemToDer(kPemTypeCertificate, pem_string, &der)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -340,7 +342,7 @@ bool BoringSSLCertificate::GetSignatureDigestAlgorithm(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BoringSSLCertificate::ComputeDigest(const std::string& algorithm,
|
bool BoringSSLCertificate::ComputeDigest(absl::string_view algorithm,
|
||||||
unsigned char* digest,
|
unsigned char* digest,
|
||||||
size_t size,
|
size_t size,
|
||||||
size_t* length) const {
|
size_t* length) const {
|
||||||
|
@ -348,7 +350,7 @@ bool BoringSSLCertificate::ComputeDigest(const std::string& algorithm,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BoringSSLCertificate::ComputeDigest(const CRYPTO_BUFFER* cert_buffer,
|
bool BoringSSLCertificate::ComputeDigest(const CRYPTO_BUFFER* cert_buffer,
|
||||||
const std::string& algorithm,
|
absl::string_view algorithm,
|
||||||
unsigned char* digest,
|
unsigned char* digest,
|
||||||
size_t size,
|
size_t size,
|
||||||
size_t* length) {
|
size_t* length) {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/buffer.h"
|
#include "rtc_base/buffer.h"
|
||||||
#include "rtc_base/ssl_certificate.h"
|
#include "rtc_base/ssl_certificate.h"
|
||||||
#include "rtc_base/ssl_identity.h"
|
#include "rtc_base/ssl_identity.h"
|
||||||
|
@ -38,7 +39,7 @@ class BoringSSLCertificate final : public SSLCertificate {
|
||||||
OpenSSLKeyPair* key_pair,
|
OpenSSLKeyPair* key_pair,
|
||||||
const SSLIdentityParams& params);
|
const SSLIdentityParams& params);
|
||||||
static std::unique_ptr<BoringSSLCertificate> FromPEMString(
|
static std::unique_ptr<BoringSSLCertificate> FromPEMString(
|
||||||
const std::string& pem_string);
|
absl::string_view pem_string);
|
||||||
|
|
||||||
~BoringSSLCertificate() override;
|
~BoringSSLCertificate() override;
|
||||||
|
|
||||||
|
@ -55,14 +56,14 @@ class BoringSSLCertificate final : public SSLCertificate {
|
||||||
bool operator!=(const BoringSSLCertificate& other) const;
|
bool operator!=(const BoringSSLCertificate& other) const;
|
||||||
|
|
||||||
// Compute the digest of the certificate given `algorithm`.
|
// Compute the digest of the certificate given `algorithm`.
|
||||||
bool ComputeDigest(const std::string& algorithm,
|
bool ComputeDigest(absl::string_view algorithm,
|
||||||
unsigned char* digest,
|
unsigned char* digest,
|
||||||
size_t size,
|
size_t size,
|
||||||
size_t* length) const override;
|
size_t* length) const override;
|
||||||
|
|
||||||
// Compute the digest of a certificate as a CRYPTO_BUFFER.
|
// Compute the digest of a certificate as a CRYPTO_BUFFER.
|
||||||
static bool ComputeDigest(const CRYPTO_BUFFER* cert_buffer,
|
static bool ComputeDigest(const CRYPTO_BUFFER* cert_buffer,
|
||||||
const std::string& algorithm,
|
absl::string_view algorithm,
|
||||||
unsigned char* digest,
|
unsigned char* digest,
|
||||||
size_t size,
|
size_t size,
|
||||||
size_t* length);
|
size_t* length);
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/memory/memory.h"
|
#include "absl/memory/memory.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/numerics/safe_conversions.h"
|
#include "rtc_base/numerics/safe_conversions.h"
|
||||||
|
@ -67,12 +68,12 @@ std::unique_ptr<BoringSSLIdentity> BoringSSLIdentity::CreateInternal(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
std::unique_ptr<BoringSSLIdentity> BoringSSLIdentity::CreateWithExpiration(
|
std::unique_ptr<BoringSSLIdentity> BoringSSLIdentity::CreateWithExpiration(
|
||||||
const std::string& common_name,
|
absl::string_view common_name,
|
||||||
const KeyParams& key_params,
|
const KeyParams& key_params,
|
||||||
time_t certificate_lifetime) {
|
time_t certificate_lifetime) {
|
||||||
SSLIdentityParams params;
|
SSLIdentityParams params;
|
||||||
params.key_params = key_params;
|
params.key_params = key_params;
|
||||||
params.common_name = common_name;
|
params.common_name = std::string(common_name);
|
||||||
time_t now = time(nullptr);
|
time_t now = time(nullptr);
|
||||||
params.not_before = now + kCertificateWindowInSeconds;
|
params.not_before = now + kCertificateWindowInSeconds;
|
||||||
params.not_after = now + certificate_lifetime;
|
params.not_after = now + certificate_lifetime;
|
||||||
|
@ -87,8 +88,8 @@ std::unique_ptr<BoringSSLIdentity> BoringSSLIdentity::CreateForTest(
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<SSLIdentity> BoringSSLIdentity::CreateFromPEMStrings(
|
std::unique_ptr<SSLIdentity> BoringSSLIdentity::CreateFromPEMStrings(
|
||||||
const std::string& private_key,
|
absl::string_view private_key,
|
||||||
const std::string& certificate) {
|
absl::string_view certificate) {
|
||||||
std::unique_ptr<BoringSSLCertificate> cert(
|
std::unique_ptr<BoringSSLCertificate> cert(
|
||||||
BoringSSLCertificate::FromPEMString(certificate));
|
BoringSSLCertificate::FromPEMString(certificate));
|
||||||
if (!cert) {
|
if (!cert) {
|
||||||
|
@ -108,8 +109,8 @@ std::unique_ptr<SSLIdentity> BoringSSLIdentity::CreateFromPEMStrings(
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<SSLIdentity> BoringSSLIdentity::CreateFromPEMChainStrings(
|
std::unique_ptr<SSLIdentity> BoringSSLIdentity::CreateFromPEMChainStrings(
|
||||||
const std::string& private_key,
|
absl::string_view private_key,
|
||||||
const std::string& certificate_chain) {
|
absl::string_view certificate_chain) {
|
||||||
bssl::UniquePtr<BIO> bio(
|
bssl::UniquePtr<BIO> bio(
|
||||||
BIO_new_mem_buf(certificate_chain.data(),
|
BIO_new_mem_buf(certificate_chain.data(),
|
||||||
rtc::dchecked_cast<int>(certificate_chain.size())));
|
rtc::dchecked_cast<int>(certificate_chain.size())));
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/boringssl_certificate.h"
|
#include "rtc_base/boringssl_certificate.h"
|
||||||
#include "rtc_base/openssl_key_pair.h"
|
#include "rtc_base/openssl_key_pair.h"
|
||||||
#include "rtc_base/ssl_certificate.h"
|
#include "rtc_base/ssl_certificate.h"
|
||||||
|
@ -30,17 +31,17 @@ namespace rtc {
|
||||||
class BoringSSLIdentity final : public SSLIdentity {
|
class BoringSSLIdentity final : public SSLIdentity {
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<BoringSSLIdentity> CreateWithExpiration(
|
static std::unique_ptr<BoringSSLIdentity> CreateWithExpiration(
|
||||||
const std::string& common_name,
|
absl::string_view common_name,
|
||||||
const KeyParams& key_params,
|
const KeyParams& key_params,
|
||||||
time_t certificate_lifetime);
|
time_t certificate_lifetime);
|
||||||
static std::unique_ptr<BoringSSLIdentity> CreateForTest(
|
static std::unique_ptr<BoringSSLIdentity> CreateForTest(
|
||||||
const SSLIdentityParams& params);
|
const SSLIdentityParams& params);
|
||||||
static std::unique_ptr<SSLIdentity> CreateFromPEMStrings(
|
static std::unique_ptr<SSLIdentity> CreateFromPEMStrings(
|
||||||
const std::string& private_key,
|
absl::string_view private_key,
|
||||||
const std::string& certificate);
|
absl::string_view certificate);
|
||||||
static std::unique_ptr<SSLIdentity> CreateFromPEMChainStrings(
|
static std::unique_ptr<SSLIdentity> CreateFromPEMChainStrings(
|
||||||
const std::string& private_key,
|
absl::string_view private_key,
|
||||||
const std::string& certificate_chain);
|
absl::string_view certificate_chain);
|
||||||
~BoringSSLIdentity() override;
|
~BoringSSLIdentity() override;
|
||||||
|
|
||||||
BoringSSLIdentity(const BoringSSLIdentity&) = delete;
|
BoringSSLIdentity(const BoringSSLIdentity&) = delete;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/buffer.h"
|
#include "rtc_base/buffer.h"
|
||||||
#include "rtc_base/byte_order.h"
|
#include "rtc_base/byte_order.h"
|
||||||
|
|
||||||
|
@ -72,8 +73,8 @@ class ByteBufferWriterT {
|
||||||
char last_byte = static_cast<char>(val);
|
char last_byte = static_cast<char>(val);
|
||||||
WriteBytes(&last_byte, 1);
|
WriteBytes(&last_byte, 1);
|
||||||
}
|
}
|
||||||
void WriteString(const std::string& val) {
|
void WriteString(absl::string_view val) {
|
||||||
WriteBytes(val.c_str(), val.size());
|
WriteBytes(val.data(), val.size());
|
||||||
}
|
}
|
||||||
void WriteBytes(const char* val, size_t len) { buffer_.AppendData(val, len); }
|
void WriteBytes(const char* val, size_t len) { buffer_.AppendData(val, len); }
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
#if defined(WEBRTC_ANDROID)
|
#if defined(WEBRTC_ANDROID)
|
||||||
#define RTC_LOG_TAG_ANDROID "rtc"
|
#define RTC_LOG_TAG_ANDROID "rtc"
|
||||||
#include <android/log.h> // NOLINT
|
#include <android/log.h> // NOLINT
|
||||||
|
@ -37,13 +39,14 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
RTC_NORETURN void WriteFatalLogAndAbort(const std::string& output) {
|
RTC_NORETURN void WriteFatalLogAndAbort(absl::string_view output) {
|
||||||
const char* output_c = output.c_str();
|
|
||||||
#if defined(WEBRTC_ANDROID)
|
#if defined(WEBRTC_ANDROID)
|
||||||
__android_log_print(ANDROID_LOG_ERROR, RTC_LOG_TAG_ANDROID, "%s\n", output_c);
|
std::string output_str = std::string(output);
|
||||||
|
__android_log_print(ANDROID_LOG_ERROR, RTC_LOG_TAG_ANDROID, "%s\n",
|
||||||
|
output_str.c_str());
|
||||||
#endif
|
#endif
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fprintf(stderr, "%s", output_c);
|
fwrite(output.data(), output.size(), 1, stderr);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
DebugBreak();
|
DebugBreak();
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
// Updates a CRC32 checksum with `len` bytes from `buf`. `initial` holds the
|
// Updates a CRC32 checksum with `len` bytes from `buf`. `initial` holds the
|
||||||
|
@ -26,8 +28,8 @@ uint32_t UpdateCrc32(uint32_t initial, const void* buf, size_t len);
|
||||||
inline uint32_t ComputeCrc32(const void* buf, size_t len) {
|
inline uint32_t ComputeCrc32(const void* buf, size_t len) {
|
||||||
return UpdateCrc32(0, buf, len);
|
return UpdateCrc32(0, buf, len);
|
||||||
}
|
}
|
||||||
inline uint32_t ComputeCrc32(const std::string& str) {
|
inline uint32_t ComputeCrc32(absl::string_view str) {
|
||||||
return ComputeCrc32(str.c_str(), str.size());
|
return ComputeCrc32(str.data(), str.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace rtc
|
} // namespace rtc
|
||||||
|
|
|
@ -157,7 +157,10 @@ rtc_library("encoder_info_settings") {
|
||||||
"../../api/video_codecs:video_codecs_api",
|
"../../api/video_codecs:video_codecs_api",
|
||||||
"../../system_wrappers:field_trial",
|
"../../system_wrappers:field_trial",
|
||||||
]
|
]
|
||||||
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
|
absl_deps = [
|
||||||
|
"//third_party/abseil-cpp/absl/strings",
|
||||||
|
"//third_party/abseil-cpp/absl/types:optional",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc_library("rtt_mult_experiment") {
|
rtc_library("rtt_mult_experiment") {
|
||||||
|
@ -296,6 +299,9 @@ if (rtc_include_tests && !build_with_chromium) {
|
||||||
"../../test:test_main",
|
"../../test:test_main",
|
||||||
"../../test:test_support",
|
"../../test:test_support",
|
||||||
]
|
]
|
||||||
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
|
absl_deps = [
|
||||||
|
"//third_party/abseil-cpp/absl/strings",
|
||||||
|
"//third_party/abseil-cpp/absl/types:optional",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/experiments/field_trial_list.h"
|
#include "rtc_base/experiments/field_trial_list.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "system_wrappers/include/field_trial.h"
|
#include "system_wrappers/include/field_trial.h"
|
||||||
|
@ -155,7 +156,7 @@ EncoderInfoSettings::GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EncoderInfoSettings::EncoderInfoSettings(std::string name)
|
EncoderInfoSettings::EncoderInfoSettings(absl::string_view name)
|
||||||
: requested_resolution_alignment_("requested_resolution_alignment"),
|
: requested_resolution_alignment_("requested_resolution_alignment"),
|
||||||
apply_alignment_to_all_simulcast_layers_(
|
apply_alignment_to_all_simulcast_layers_(
|
||||||
"apply_alignment_to_all_simulcast_layers") {
|
"apply_alignment_to_all_simulcast_layers") {
|
||||||
|
@ -174,14 +175,15 @@ EncoderInfoSettings::EncoderInfoSettings(std::string name)
|
||||||
[](BitrateLimit* b) { return &b->max_bitrate_bps; })},
|
[](BitrateLimit* b) { return &b->max_bitrate_bps; })},
|
||||||
{});
|
{});
|
||||||
|
|
||||||
if (field_trial::FindFullName(name).empty()) {
|
std::string name_str = std::string(name);
|
||||||
|
if (field_trial::FindFullName(name_str).empty()) {
|
||||||
// Encoder name not found, use common string applying to all encoders.
|
// Encoder name not found, use common string applying to all encoders.
|
||||||
name = "WebRTC-GetEncoderInfoOverride";
|
name_str = "WebRTC-GetEncoderInfoOverride";
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseFieldTrial({&bitrate_limits, &requested_resolution_alignment_,
|
ParseFieldTrial({&bitrate_limits, &requested_resolution_alignment_,
|
||||||
&apply_alignment_to_all_simulcast_layers_},
|
&apply_alignment_to_all_simulcast_layers_},
|
||||||
field_trial::FindFullName(name));
|
field_trial::FindFullName(name_str));
|
||||||
|
|
||||||
resolution_bitrate_limits_ = ToResolutionBitrateLimits(bitrate_limits.Get());
|
resolution_bitrate_limits_ = ToResolutionBitrateLimits(bitrate_limits.Get());
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
#include "api/video_codecs/video_encoder.h"
|
#include "api/video_codecs/video_encoder.h"
|
||||||
#include "rtc_base/experiments/field_trial_parser.h"
|
#include "rtc_base/experiments/field_trial_parser.h"
|
||||||
|
@ -58,7 +59,7 @@ class EncoderInfoSettings {
|
||||||
resolution_bitrate_limits);
|
resolution_bitrate_limits);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit EncoderInfoSettings(std::string name);
|
explicit EncoderInfoSettings(absl::string_view name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FieldTrialOptional<int> requested_resolution_alignment_;
|
FieldTrialOptional<int> requested_resolution_alignment_;
|
||||||
|
|
|
@ -9,9 +9,11 @@
|
||||||
*/
|
*/
|
||||||
#include "rtc_base/experiments/field_trial_list.h"
|
#include "rtc_base/experiments/field_trial_list.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
FieldTrialListBase::FieldTrialListBase(std::string key)
|
FieldTrialListBase::FieldTrialListBase(absl::string_view key)
|
||||||
: FieldTrialParameterInterface(key),
|
: FieldTrialParameterInterface(key),
|
||||||
failed_(false),
|
failed_(false),
|
||||||
parse_got_called_(false) {}
|
parse_got_called_(false) {}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/experiments/field_trial_parser.h"
|
#include "rtc_base/experiments/field_trial_parser.h"
|
||||||
#include "rtc_base/string_encode.h"
|
#include "rtc_base/string_encode.h"
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ namespace webrtc {
|
||||||
class FieldTrialListBase : public FieldTrialParameterInterface {
|
class FieldTrialListBase : public FieldTrialParameterInterface {
|
||||||
protected:
|
protected:
|
||||||
friend class FieldTrialListWrapper;
|
friend class FieldTrialListWrapper;
|
||||||
explicit FieldTrialListBase(std::string key);
|
explicit FieldTrialListBase(absl::string_view key);
|
||||||
|
|
||||||
bool Failed() const;
|
bool Failed() const;
|
||||||
bool Used() const;
|
bool Used() const;
|
||||||
|
@ -52,8 +53,8 @@ class FieldTrialListBase : public FieldTrialParameterInterface {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class FieldTrialList : public FieldTrialListBase {
|
class FieldTrialList : public FieldTrialListBase {
|
||||||
public:
|
public:
|
||||||
explicit FieldTrialList(std::string key) : FieldTrialList(key, {}) {}
|
explicit FieldTrialList(absl::string_view key) : FieldTrialList(key, {}) {}
|
||||||
FieldTrialList(std::string key, std::initializer_list<T> default_values)
|
FieldTrialList(absl::string_view key, std::initializer_list<T> default_values)
|
||||||
: FieldTrialListBase(key), values_(default_values) {}
|
: FieldTrialListBase(key), values_(default_values) {}
|
||||||
|
|
||||||
std::vector<T> Get() const { return values_; }
|
std::vector<T> Get() const { return values_; }
|
||||||
|
@ -132,7 +133,7 @@ struct LambdaTypeTraits<RetType* (ClassType::*)(SourceType*)const> {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct TypedFieldTrialListWrapper : FieldTrialListWrapper {
|
struct TypedFieldTrialListWrapper : FieldTrialListWrapper {
|
||||||
public:
|
public:
|
||||||
TypedFieldTrialListWrapper(std::string key,
|
TypedFieldTrialListWrapper(absl::string_view key,
|
||||||
std::function<void(void*, T)> sink)
|
std::function<void(void*, T)> sink)
|
||||||
: list_(key), sink_(sink) {}
|
: list_(key), sink_(sink) {}
|
||||||
|
|
||||||
|
@ -151,7 +152,8 @@ struct TypedFieldTrialListWrapper : FieldTrialListWrapper {
|
||||||
|
|
||||||
template <typename F,
|
template <typename F,
|
||||||
typename Traits = typename field_trial_list_impl::LambdaTypeTraits<F>>
|
typename Traits = typename field_trial_list_impl::LambdaTypeTraits<F>>
|
||||||
FieldTrialListWrapper* FieldTrialStructMember(std::string key, F accessor) {
|
FieldTrialListWrapper* FieldTrialStructMember(absl::string_view key,
|
||||||
|
F accessor) {
|
||||||
return new field_trial_list_impl::TypedFieldTrialListWrapper<
|
return new field_trial_list_impl::TypedFieldTrialListWrapper<
|
||||||
typename Traits::ret>(key, [accessor](void* s, typename Traits::ret t) {
|
typename Traits::ret>(key, [accessor](void* s, typename Traits::ret t) {
|
||||||
*accessor(static_cast<typename Traits::src*>(s)) = t;
|
*accessor(static_cast<typename Traits::src*>(s)) = t;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "rtc_base/experiments/field_trial_list.h"
|
#include "rtc_base/experiments/field_trial_list.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/gunit.h"
|
#include "rtc_base/gunit.h"
|
||||||
#include "test/gmock.h"
|
#include "test/gmock.h"
|
||||||
|
|
||||||
|
@ -25,7 +26,8 @@ struct Garment {
|
||||||
|
|
||||||
// Only needed for testing.
|
// Only needed for testing.
|
||||||
Garment() = default;
|
Garment() = default;
|
||||||
Garment(int p, std::string c, bool g) : price(p), color(c), has_glitter(g) {}
|
Garment(int p, absl::string_view c, bool g)
|
||||||
|
: price(p), color(c), has_glitter(g) {}
|
||||||
|
|
||||||
bool operator==(const Garment& other) const {
|
bool operator==(const Garment& other) const {
|
||||||
return price == other.price && color == other.color &&
|
return price == other.price && color == other.color &&
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
FieldTrialParameterInterface::FieldTrialParameterInterface(std::string key)
|
FieldTrialParameterInterface::FieldTrialParameterInterface(
|
||||||
|
absl::string_view key)
|
||||||
: key_(key) {}
|
: key_(key) {}
|
||||||
FieldTrialParameterInterface::~FieldTrialParameterInterface() {
|
FieldTrialParameterInterface::~FieldTrialParameterInterface() {
|
||||||
RTC_DCHECK(used_) << "Field trial parameter with key: '" << key_
|
RTC_DCHECK(used_) << "Field trial parameter with key: '" << key_
|
||||||
|
@ -111,7 +112,7 @@ void ParseFieldTrial(
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<bool> ParseTypedParameter<bool>(std::string str) {
|
absl::optional<bool> ParseTypedParameter<bool>(absl::string_view str) {
|
||||||
if (str == "true" || str == "1") {
|
if (str == "true" || str == "1") {
|
||||||
return true;
|
return true;
|
||||||
} else if (str == "false" || str == "0") {
|
} else if (str == "false" || str == "0") {
|
||||||
|
@ -121,10 +122,10 @@ absl::optional<bool> ParseTypedParameter<bool>(std::string str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<double> ParseTypedParameter<double>(std::string str) {
|
absl::optional<double> ParseTypedParameter<double>(absl::string_view str) {
|
||||||
double value;
|
double value;
|
||||||
char unit[2]{0, 0};
|
char unit[2]{0, 0};
|
||||||
if (sscanf(str.c_str(), "%lf%1s", &value, unit) >= 1) {
|
if (sscanf(std::string(str).c_str(), "%lf%1s", &value, unit) >= 1) {
|
||||||
if (unit[0] == '%')
|
if (unit[0] == '%')
|
||||||
return value / 100;
|
return value / 100;
|
||||||
return value;
|
return value;
|
||||||
|
@ -134,9 +135,9 @@ absl::optional<double> ParseTypedParameter<double>(std::string str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<int> ParseTypedParameter<int>(std::string str) {
|
absl::optional<int> ParseTypedParameter<int>(absl::string_view str) {
|
||||||
int64_t value;
|
int64_t value;
|
||||||
if (sscanf(str.c_str(), "%" SCNd64, &value) == 1) {
|
if (sscanf(std::string(str).c_str(), "%" SCNd64, &value) == 1) {
|
||||||
if (rtc::IsValueInRangeForNumericType<int, int64_t>(value)) {
|
if (rtc::IsValueInRangeForNumericType<int, int64_t>(value)) {
|
||||||
return static_cast<int>(value);
|
return static_cast<int>(value);
|
||||||
}
|
}
|
||||||
|
@ -145,9 +146,9 @@ absl::optional<int> ParseTypedParameter<int>(std::string str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<unsigned> ParseTypedParameter<unsigned>(std::string str) {
|
absl::optional<unsigned> ParseTypedParameter<unsigned>(absl::string_view str) {
|
||||||
int64_t value;
|
int64_t value;
|
||||||
if (sscanf(str.c_str(), "%" SCNd64, &value) == 1) {
|
if (sscanf(std::string(str).c_str(), "%" SCNd64, &value) == 1) {
|
||||||
if (rtc::IsValueInRangeForNumericType<unsigned, int64_t>(value)) {
|
if (rtc::IsValueInRangeForNumericType<unsigned, int64_t>(value)) {
|
||||||
return static_cast<unsigned>(value);
|
return static_cast<unsigned>(value);
|
||||||
}
|
}
|
||||||
|
@ -156,34 +157,36 @@ absl::optional<unsigned> ParseTypedParameter<unsigned>(std::string str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<std::string> ParseTypedParameter<std::string>(std::string str) {
|
absl::optional<std::string> ParseTypedParameter<std::string>(
|
||||||
return std::move(str);
|
absl::string_view str) {
|
||||||
|
return std::string(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<absl::optional<bool>> ParseTypedParameter<absl::optional<bool>>(
|
absl::optional<absl::optional<bool>> ParseTypedParameter<absl::optional<bool>>(
|
||||||
std::string str) {
|
absl::string_view str) {
|
||||||
return ParseOptionalParameter<bool>(str);
|
return ParseOptionalParameter<bool>(str);
|
||||||
}
|
}
|
||||||
template <>
|
template <>
|
||||||
absl::optional<absl::optional<int>> ParseTypedParameter<absl::optional<int>>(
|
absl::optional<absl::optional<int>> ParseTypedParameter<absl::optional<int>>(
|
||||||
std::string str) {
|
absl::string_view str) {
|
||||||
return ParseOptionalParameter<int>(str);
|
return ParseOptionalParameter<int>(str);
|
||||||
}
|
}
|
||||||
template <>
|
template <>
|
||||||
absl::optional<absl::optional<unsigned>>
|
absl::optional<absl::optional<unsigned>>
|
||||||
ParseTypedParameter<absl::optional<unsigned>>(std::string str) {
|
ParseTypedParameter<absl::optional<unsigned>>(absl::string_view str) {
|
||||||
return ParseOptionalParameter<unsigned>(str);
|
return ParseOptionalParameter<unsigned>(str);
|
||||||
}
|
}
|
||||||
template <>
|
template <>
|
||||||
absl::optional<absl::optional<double>>
|
absl::optional<absl::optional<double>>
|
||||||
ParseTypedParameter<absl::optional<double>>(std::string str) {
|
ParseTypedParameter<absl::optional<double>>(absl::string_view str) {
|
||||||
return ParseOptionalParameter<double>(str);
|
return ParseOptionalParameter<double>(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldTrialFlag::FieldTrialFlag(std::string key) : FieldTrialFlag(key, false) {}
|
FieldTrialFlag::FieldTrialFlag(absl::string_view key)
|
||||||
|
: FieldTrialFlag(key, false) {}
|
||||||
|
|
||||||
FieldTrialFlag::FieldTrialFlag(std::string key, bool default_value)
|
FieldTrialFlag::FieldTrialFlag(absl::string_view key, bool default_value)
|
||||||
: FieldTrialParameterInterface(key), value_(default_value) {}
|
: FieldTrialParameterInterface(key), value_(default_value) {}
|
||||||
|
|
||||||
bool FieldTrialFlag::Get() const {
|
bool FieldTrialFlag::Get() const {
|
||||||
|
@ -208,7 +211,7 @@ bool FieldTrialFlag::Parse(absl::optional<std::string> str_value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractFieldTrialEnum::AbstractFieldTrialEnum(
|
AbstractFieldTrialEnum::AbstractFieldTrialEnum(
|
||||||
std::string key,
|
absl::string_view key,
|
||||||
int default_value,
|
int default_value,
|
||||||
std::map<std::string, int> mapping)
|
std::map<std::string, int> mapping)
|
||||||
: FieldTrialParameterInterface(key),
|
: FieldTrialParameterInterface(key),
|
||||||
|
|
|
@ -46,7 +46,7 @@ class FieldTrialParameterInterface {
|
||||||
FieldTrialParameterInterface(const FieldTrialParameterInterface&) = default;
|
FieldTrialParameterInterface(const FieldTrialParameterInterface&) = default;
|
||||||
FieldTrialParameterInterface& operator=(const FieldTrialParameterInterface&) =
|
FieldTrialParameterInterface& operator=(const FieldTrialParameterInterface&) =
|
||||||
default;
|
default;
|
||||||
explicit FieldTrialParameterInterface(std::string key);
|
explicit FieldTrialParameterInterface(absl::string_view key);
|
||||||
friend void ParseFieldTrial(
|
friend void ParseFieldTrial(
|
||||||
std::initializer_list<FieldTrialParameterInterface*> fields,
|
std::initializer_list<FieldTrialParameterInterface*> fields,
|
||||||
absl::string_view trial_string);
|
absl::string_view trial_string);
|
||||||
|
@ -71,14 +71,14 @@ void ParseFieldTrial(
|
||||||
// Specialize this in code file for custom types. Should return absl::nullopt if
|
// Specialize this in code file for custom types. Should return absl::nullopt if
|
||||||
// the given string cannot be properly parsed.
|
// the given string cannot be properly parsed.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
absl::optional<T> ParseTypedParameter(std::string);
|
absl::optional<T> ParseTypedParameter(absl::string_view);
|
||||||
|
|
||||||
// This class uses the ParseTypedParameter function to implement a parameter
|
// This class uses the ParseTypedParameter function to implement a parameter
|
||||||
// implementation with an enforced default value.
|
// implementation with an enforced default value.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class FieldTrialParameter : public FieldTrialParameterInterface {
|
class FieldTrialParameter : public FieldTrialParameterInterface {
|
||||||
public:
|
public:
|
||||||
FieldTrialParameter(std::string key, T default_value)
|
FieldTrialParameter(absl::string_view key, T default_value)
|
||||||
: FieldTrialParameterInterface(key), value_(default_value) {}
|
: FieldTrialParameterInterface(key), value_(default_value) {}
|
||||||
T Get() const { return value_; }
|
T Get() const { return value_; }
|
||||||
operator T() const { return Get(); }
|
operator T() const { return Get(); }
|
||||||
|
@ -108,7 +108,7 @@ class FieldTrialParameter : public FieldTrialParameterInterface {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class FieldTrialConstrained : public FieldTrialParameterInterface {
|
class FieldTrialConstrained : public FieldTrialParameterInterface {
|
||||||
public:
|
public:
|
||||||
FieldTrialConstrained(std::string key,
|
FieldTrialConstrained(absl::string_view key,
|
||||||
T default_value,
|
T default_value,
|
||||||
absl::optional<T> lower_limit,
|
absl::optional<T> lower_limit,
|
||||||
absl::optional<T> upper_limit)
|
absl::optional<T> upper_limit)
|
||||||
|
@ -141,7 +141,7 @@ class FieldTrialConstrained : public FieldTrialParameterInterface {
|
||||||
|
|
||||||
class AbstractFieldTrialEnum : public FieldTrialParameterInterface {
|
class AbstractFieldTrialEnum : public FieldTrialParameterInterface {
|
||||||
public:
|
public:
|
||||||
AbstractFieldTrialEnum(std::string key,
|
AbstractFieldTrialEnum(absl::string_view key,
|
||||||
int default_value,
|
int default_value,
|
||||||
std::map<std::string, int> mapping);
|
std::map<std::string, int> mapping);
|
||||||
~AbstractFieldTrialEnum() override;
|
~AbstractFieldTrialEnum() override;
|
||||||
|
@ -162,7 +162,7 @@ class AbstractFieldTrialEnum : public FieldTrialParameterInterface {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class FieldTrialEnum : public AbstractFieldTrialEnum {
|
class FieldTrialEnum : public AbstractFieldTrialEnum {
|
||||||
public:
|
public:
|
||||||
FieldTrialEnum(std::string key,
|
FieldTrialEnum(absl::string_view key,
|
||||||
T default_value,
|
T default_value,
|
||||||
std::map<std::string, T> mapping)
|
std::map<std::string, T> mapping)
|
||||||
: AbstractFieldTrialEnum(key,
|
: AbstractFieldTrialEnum(key,
|
||||||
|
@ -185,9 +185,9 @@ class FieldTrialEnum : public AbstractFieldTrialEnum {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class FieldTrialOptional : public FieldTrialParameterInterface {
|
class FieldTrialOptional : public FieldTrialParameterInterface {
|
||||||
public:
|
public:
|
||||||
explicit FieldTrialOptional(std::string key)
|
explicit FieldTrialOptional(absl::string_view key)
|
||||||
: FieldTrialParameterInterface(key) {}
|
: FieldTrialParameterInterface(key) {}
|
||||||
FieldTrialOptional(std::string key, absl::optional<T> default_value)
|
FieldTrialOptional(absl::string_view key, absl::optional<T> default_value)
|
||||||
: FieldTrialParameterInterface(key), value_(default_value) {}
|
: FieldTrialParameterInterface(key), value_(default_value) {}
|
||||||
absl::optional<T> GetOptional() const { return value_; }
|
absl::optional<T> GetOptional() const { return value_; }
|
||||||
const T& Value() const { return value_.value(); }
|
const T& Value() const { return value_.value(); }
|
||||||
|
@ -217,8 +217,8 @@ class FieldTrialOptional : public FieldTrialParameterInterface {
|
||||||
// explicit value is provided, the flag evaluates to true.
|
// explicit value is provided, the flag evaluates to true.
|
||||||
class FieldTrialFlag : public FieldTrialParameterInterface {
|
class FieldTrialFlag : public FieldTrialParameterInterface {
|
||||||
public:
|
public:
|
||||||
explicit FieldTrialFlag(std::string key);
|
explicit FieldTrialFlag(absl::string_view key);
|
||||||
FieldTrialFlag(std::string key, bool default_value);
|
FieldTrialFlag(absl::string_view key, bool default_value);
|
||||||
bool Get() const;
|
bool Get() const;
|
||||||
explicit operator bool() const;
|
explicit operator bool() const;
|
||||||
|
|
||||||
|
@ -230,7 +230,8 @@ class FieldTrialFlag : public FieldTrialParameterInterface {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
absl::optional<absl::optional<T>> ParseOptionalParameter(std::string str) {
|
absl::optional<absl::optional<T>> ParseOptionalParameter(
|
||||||
|
absl::string_view str) {
|
||||||
if (str.empty())
|
if (str.empty())
|
||||||
return absl::optional<T>();
|
return absl::optional<T>();
|
||||||
auto parsed = ParseTypedParameter<T>(str);
|
auto parsed = ParseTypedParameter<T>(str);
|
||||||
|
@ -240,28 +241,29 @@ absl::optional<absl::optional<T>> ParseOptionalParameter(std::string str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<bool> ParseTypedParameter<bool>(std::string str);
|
absl::optional<bool> ParseTypedParameter<bool>(absl::string_view str);
|
||||||
template <>
|
template <>
|
||||||
absl::optional<double> ParseTypedParameter<double>(std::string str);
|
absl::optional<double> ParseTypedParameter<double>(absl::string_view str);
|
||||||
template <>
|
template <>
|
||||||
absl::optional<int> ParseTypedParameter<int>(std::string str);
|
absl::optional<int> ParseTypedParameter<int>(absl::string_view str);
|
||||||
template <>
|
template <>
|
||||||
absl::optional<unsigned> ParseTypedParameter<unsigned>(std::string str);
|
absl::optional<unsigned> ParseTypedParameter<unsigned>(absl::string_view str);
|
||||||
template <>
|
template <>
|
||||||
absl::optional<std::string> ParseTypedParameter<std::string>(std::string str);
|
absl::optional<std::string> ParseTypedParameter<std::string>(
|
||||||
|
absl::string_view str);
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<absl::optional<bool>> ParseTypedParameter<absl::optional<bool>>(
|
absl::optional<absl::optional<bool>> ParseTypedParameter<absl::optional<bool>>(
|
||||||
std::string str);
|
absl::string_view str);
|
||||||
template <>
|
template <>
|
||||||
absl::optional<absl::optional<int>> ParseTypedParameter<absl::optional<int>>(
|
absl::optional<absl::optional<int>> ParseTypedParameter<absl::optional<int>>(
|
||||||
std::string str);
|
absl::string_view str);
|
||||||
template <>
|
template <>
|
||||||
absl::optional<absl::optional<unsigned>>
|
absl::optional<absl::optional<unsigned>>
|
||||||
ParseTypedParameter<absl::optional<unsigned>>(std::string str);
|
ParseTypedParameter<absl::optional<unsigned>>(absl::string_view str);
|
||||||
template <>
|
template <>
|
||||||
absl::optional<absl::optional<double>>
|
absl::optional<absl::optional<double>>
|
||||||
ParseTypedParameter<absl::optional<double>>(std::string str);
|
ParseTypedParameter<absl::optional<double>>(absl::string_view str);
|
||||||
|
|
||||||
// Accepts true, false, else parsed with sscanf %i, true if != 0.
|
// Accepts true, false, else parsed with sscanf %i, true if != 0.
|
||||||
extern template class FieldTrialParameter<bool>;
|
extern template class FieldTrialParameter<bool>;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
*/
|
*/
|
||||||
#include "rtc_base/experiments/field_trial_parser.h"
|
#include "rtc_base/experiments/field_trial_parser.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/experiments/field_trial_list.h"
|
#include "rtc_base/experiments/field_trial_list.h"
|
||||||
#include "rtc_base/gunit.h"
|
#include "rtc_base/gunit.h"
|
||||||
#include "system_wrappers/include/field_trial.h"
|
#include "system_wrappers/include/field_trial.h"
|
||||||
|
@ -28,7 +29,7 @@ struct DummyExperiment {
|
||||||
FieldTrialParameter<std::string> hash =
|
FieldTrialParameter<std::string> hash =
|
||||||
FieldTrialParameter<std::string>("h", "a80");
|
FieldTrialParameter<std::string>("h", "a80");
|
||||||
|
|
||||||
explicit DummyExperiment(std::string field_trial) {
|
explicit DummyExperiment(absl::string_view field_trial) {
|
||||||
ParseFieldTrial({&enabled, &factor, &retries, &size, &ping, &hash},
|
ParseFieldTrial({&enabled, &factor, &retries, &size, &ping, &hash},
|
||||||
field_trial);
|
field_trial);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
|
|
||||||
// Large enough to fit "seconds", the longest supported unit name.
|
// Large enough to fit "seconds", the longest supported unit name.
|
||||||
|
@ -28,7 +29,7 @@ struct ValueWithUnit {
|
||||||
std::string unit;
|
std::string unit;
|
||||||
};
|
};
|
||||||
|
|
||||||
absl::optional<ValueWithUnit> ParseValueWithUnit(std::string str) {
|
absl::optional<ValueWithUnit> ParseValueWithUnit(absl::string_view str) {
|
||||||
if (str == "inf") {
|
if (str == "inf") {
|
||||||
return ValueWithUnit{std::numeric_limits<double>::infinity(), ""};
|
return ValueWithUnit{std::numeric_limits<double>::infinity(), ""};
|
||||||
} else if (str == "-inf") {
|
} else if (str == "-inf") {
|
||||||
|
@ -37,8 +38,8 @@ absl::optional<ValueWithUnit> ParseValueWithUnit(std::string str) {
|
||||||
double double_val;
|
double double_val;
|
||||||
char unit_char[RTC_TRIAL_UNIT_SIZE];
|
char unit_char[RTC_TRIAL_UNIT_SIZE];
|
||||||
unit_char[0] = 0;
|
unit_char[0] = 0;
|
||||||
if (sscanf(str.c_str(), "%lf%" RTC_TRIAL_UNIT_LENGTH_STR "s", &double_val,
|
if (sscanf(std::string(str).c_str(), "%lf%" RTC_TRIAL_UNIT_LENGTH_STR "s",
|
||||||
unit_char) >= 1) {
|
&double_val, unit_char) >= 1) {
|
||||||
return ValueWithUnit{double_val, unit_char};
|
return ValueWithUnit{double_val, unit_char};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +48,7 @@ absl::optional<ValueWithUnit> ParseValueWithUnit(std::string str) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<DataRate> ParseTypedParameter<DataRate>(std::string str) {
|
absl::optional<DataRate> ParseTypedParameter<DataRate>(absl::string_view str) {
|
||||||
absl::optional<ValueWithUnit> result = ParseValueWithUnit(str);
|
absl::optional<ValueWithUnit> result = ParseValueWithUnit(str);
|
||||||
if (result) {
|
if (result) {
|
||||||
if (result->unit.empty() || result->unit == "kbps") {
|
if (result->unit.empty() || result->unit == "kbps") {
|
||||||
|
@ -60,7 +61,7 @@ absl::optional<DataRate> ParseTypedParameter<DataRate>(std::string str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<DataSize> ParseTypedParameter<DataSize>(std::string str) {
|
absl::optional<DataSize> ParseTypedParameter<DataSize>(absl::string_view str) {
|
||||||
absl::optional<ValueWithUnit> result = ParseValueWithUnit(str);
|
absl::optional<ValueWithUnit> result = ParseValueWithUnit(str);
|
||||||
if (result) {
|
if (result) {
|
||||||
if (result->unit.empty() || result->unit == "bytes")
|
if (result->unit.empty() || result->unit == "bytes")
|
||||||
|
@ -70,7 +71,8 @@ absl::optional<DataSize> ParseTypedParameter<DataSize>(std::string str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<TimeDelta> ParseTypedParameter<TimeDelta>(std::string str) {
|
absl::optional<TimeDelta> ParseTypedParameter<TimeDelta>(
|
||||||
|
absl::string_view str) {
|
||||||
absl::optional<ValueWithUnit> result = ParseValueWithUnit(str);
|
absl::optional<ValueWithUnit> result = ParseValueWithUnit(str);
|
||||||
if (result) {
|
if (result) {
|
||||||
if (result->unit == "s" || result->unit == "seconds") {
|
if (result->unit == "s" || result->unit == "seconds") {
|
||||||
|
@ -86,17 +88,17 @@ absl::optional<TimeDelta> ParseTypedParameter<TimeDelta>(std::string str) {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<absl::optional<DataRate>>
|
absl::optional<absl::optional<DataRate>>
|
||||||
ParseTypedParameter<absl::optional<DataRate>>(std::string str) {
|
ParseTypedParameter<absl::optional<DataRate>>(absl::string_view str) {
|
||||||
return ParseOptionalParameter<DataRate>(str);
|
return ParseOptionalParameter<DataRate>(str);
|
||||||
}
|
}
|
||||||
template <>
|
template <>
|
||||||
absl::optional<absl::optional<DataSize>>
|
absl::optional<absl::optional<DataSize>>
|
||||||
ParseTypedParameter<absl::optional<DataSize>>(std::string str) {
|
ParseTypedParameter<absl::optional<DataSize>>(absl::string_view str) {
|
||||||
return ParseOptionalParameter<DataSize>(str);
|
return ParseOptionalParameter<DataSize>(str);
|
||||||
}
|
}
|
||||||
template <>
|
template <>
|
||||||
absl::optional<absl::optional<TimeDelta>>
|
absl::optional<absl::optional<TimeDelta>>
|
||||||
ParseTypedParameter<absl::optional<TimeDelta>>(std::string str) {
|
ParseTypedParameter<absl::optional<TimeDelta>>(absl::string_view str) {
|
||||||
return ParseOptionalParameter<TimeDelta>(str);
|
return ParseOptionalParameter<TimeDelta>(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#ifndef RTC_BASE_EXPERIMENTS_FIELD_TRIAL_UNITS_H_
|
#ifndef RTC_BASE_EXPERIMENTS_FIELD_TRIAL_UNITS_H_
|
||||||
#define RTC_BASE_EXPERIMENTS_FIELD_TRIAL_UNITS_H_
|
#define RTC_BASE_EXPERIMENTS_FIELD_TRIAL_UNITS_H_
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "api/units/data_rate.h"
|
#include "api/units/data_rate.h"
|
||||||
#include "api/units/data_size.h"
|
#include "api/units/data_size.h"
|
||||||
#include "api/units/time_delta.h"
|
#include "api/units/time_delta.h"
|
||||||
|
@ -18,11 +19,11 @@
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
absl::optional<DataRate> ParseTypedParameter<DataRate>(std::string str);
|
absl::optional<DataRate> ParseTypedParameter<DataRate>(absl::string_view str);
|
||||||
template <>
|
template <>
|
||||||
absl::optional<DataSize> ParseTypedParameter<DataSize>(std::string str);
|
absl::optional<DataSize> ParseTypedParameter<DataSize>(absl::string_view str);
|
||||||
template <>
|
template <>
|
||||||
absl::optional<TimeDelta> ParseTypedParameter<TimeDelta>(std::string str);
|
absl::optional<TimeDelta> ParseTypedParameter<TimeDelta>(absl::string_view str);
|
||||||
|
|
||||||
extern template class FieldTrialParameter<DataRate>;
|
extern template class FieldTrialParameter<DataRate>;
|
||||||
extern template class FieldTrialParameter<DataSize>;
|
extern template class FieldTrialParameter<DataSize>;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
#include "rtc_base/experiments/field_trial_parser.h"
|
#include "rtc_base/experiments/field_trial_parser.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
@ -25,7 +26,7 @@ struct DummyExperiment {
|
||||||
FieldTrialOptional<DataSize> max_buffer =
|
FieldTrialOptional<DataSize> max_buffer =
|
||||||
FieldTrialOptional<DataSize>("b", absl::nullopt);
|
FieldTrialOptional<DataSize>("b", absl::nullopt);
|
||||||
|
|
||||||
explicit DummyExperiment(std::string field_trial) {
|
explicit DummyExperiment(absl::string_view field_trial) {
|
||||||
ParseFieldTrial({&target_rate, &max_buffer, &period}, field_trial);
|
ParseFieldTrial({&target_rate, &max_buffer, &period}, field_trial);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,13 +11,14 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace {
|
namespace {
|
||||||
size_t FindOrEnd(absl::string_view str, size_t start, char delimiter) {
|
size_t FindOrEnd(absl::string_view str, size_t start, char delimiter) {
|
||||||
size_t pos = str.find(delimiter, start);
|
size_t pos = str.find(delimiter, start);
|
||||||
pos = (pos == std::string::npos) ? str.length() : pos;
|
pos = (pos == absl::string_view::npos) ? str.length() : pos;
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -14,12 +14,13 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/message_digest.h"
|
#include "rtc_base/message_digest.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
FakeSSLCertificate::FakeSSLCertificate(const std::string& pem_string)
|
FakeSSLCertificate::FakeSSLCertificate(absl::string_view pem_string)
|
||||||
: pem_string_(pem_string),
|
: pem_string_(pem_string),
|
||||||
digest_algorithm_(DIGEST_SHA_1),
|
digest_algorithm_(DIGEST_SHA_1),
|
||||||
expiration_time_(-1) {}
|
expiration_time_(-1) {}
|
||||||
|
@ -51,8 +52,8 @@ void FakeSSLCertificate::SetCertificateExpirationTime(int64_t expiration_time) {
|
||||||
expiration_time_ = expiration_time;
|
expiration_time_ = expiration_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeSSLCertificate::set_digest_algorithm(const std::string& algorithm) {
|
void FakeSSLCertificate::set_digest_algorithm(absl::string_view algorithm) {
|
||||||
digest_algorithm_ = algorithm;
|
digest_algorithm_ = std::string(algorithm);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FakeSSLCertificate::GetSignatureDigestAlgorithm(
|
bool FakeSSLCertificate::GetSignatureDigestAlgorithm(
|
||||||
|
@ -61,7 +62,7 @@ bool FakeSSLCertificate::GetSignatureDigestAlgorithm(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FakeSSLCertificate::ComputeDigest(const std::string& algorithm,
|
bool FakeSSLCertificate::ComputeDigest(absl::string_view algorithm,
|
||||||
unsigned char* digest,
|
unsigned char* digest,
|
||||||
size_t size,
|
size_t size,
|
||||||
size_t* length) const {
|
size_t* length) const {
|
||||||
|
@ -70,7 +71,7 @@ bool FakeSSLCertificate::ComputeDigest(const std::string& algorithm,
|
||||||
return (*length != 0);
|
return (*length != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeSSLIdentity::FakeSSLIdentity(const std::string& pem_string)
|
FakeSSLIdentity::FakeSSLIdentity(absl::string_view pem_string)
|
||||||
: FakeSSLIdentity(FakeSSLCertificate(pem_string)) {}
|
: FakeSSLIdentity(FakeSSLCertificate(pem_string)) {}
|
||||||
|
|
||||||
FakeSSLIdentity::FakeSSLIdentity(const std::vector<std::string>& pem_strings) {
|
FakeSSLIdentity::FakeSSLIdentity(const std::vector<std::string>& pem_strings) {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/ssl_certificate.h"
|
#include "rtc_base/ssl_certificate.h"
|
||||||
#include "rtc_base/ssl_identity.h"
|
#include "rtc_base/ssl_identity.h"
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ class FakeSSLCertificate : public SSLCertificate {
|
||||||
public:
|
public:
|
||||||
// SHA-1 is the default digest algorithm because it is available in all build
|
// SHA-1 is the default digest algorithm because it is available in all build
|
||||||
// configurations used for unit testing.
|
// configurations used for unit testing.
|
||||||
explicit FakeSSLCertificate(const std::string& pem_string);
|
explicit FakeSSLCertificate(absl::string_view pem_string);
|
||||||
|
|
||||||
FakeSSLCertificate(const FakeSSLCertificate&);
|
FakeSSLCertificate(const FakeSSLCertificate&);
|
||||||
~FakeSSLCertificate() override;
|
~FakeSSLCertificate() override;
|
||||||
|
@ -34,14 +35,14 @@ class FakeSSLCertificate : public SSLCertificate {
|
||||||
void ToDER(Buffer* der_buffer) const override;
|
void ToDER(Buffer* der_buffer) const override;
|
||||||
int64_t CertificateExpirationTime() const override;
|
int64_t CertificateExpirationTime() const override;
|
||||||
bool GetSignatureDigestAlgorithm(std::string* algorithm) const override;
|
bool GetSignatureDigestAlgorithm(std::string* algorithm) const override;
|
||||||
bool ComputeDigest(const std::string& algorithm,
|
bool ComputeDigest(absl::string_view algorithm,
|
||||||
unsigned char* digest,
|
unsigned char* digest,
|
||||||
size_t size,
|
size_t size,
|
||||||
size_t* length) const override;
|
size_t* length) const override;
|
||||||
|
|
||||||
void SetCertificateExpirationTime(int64_t expiration_time);
|
void SetCertificateExpirationTime(int64_t expiration_time);
|
||||||
|
|
||||||
void set_digest_algorithm(const std::string& algorithm);
|
void set_digest_algorithm(absl::string_view algorithm);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string pem_string_;
|
std::string pem_string_;
|
||||||
|
@ -52,7 +53,7 @@ class FakeSSLCertificate : public SSLCertificate {
|
||||||
|
|
||||||
class FakeSSLIdentity : public SSLIdentity {
|
class FakeSSLIdentity : public SSLIdentity {
|
||||||
public:
|
public:
|
||||||
explicit FakeSSLIdentity(const std::string& pem_string);
|
explicit FakeSSLIdentity(absl::string_view pem_string);
|
||||||
// For a certificate chain.
|
// For a certificate chain.
|
||||||
explicit FakeSSLIdentity(const std::vector<std::string>& pem_strings);
|
explicit FakeSSLIdentity(const std::vector<std::string>& pem_strings);
|
||||||
explicit FakeSSLIdentity(const FakeSSLCertificate& cert);
|
explicit FakeSSLIdentity(const FakeSSLCertificate& cert);
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
@ -29,6 +31,7 @@
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
|
#include "rtc_base/strings/string_builder.h"
|
||||||
|
|
||||||
// Note: We use fprintf for logging in the write paths of this stream to avoid
|
// Note: We use fprintf for logging in the write paths of this stream to avoid
|
||||||
// infinite loops when logging.
|
// infinite loops when logging.
|
||||||
|
@ -39,54 +42,58 @@ namespace {
|
||||||
|
|
||||||
const char kCallSessionLogPrefix[] = "webrtc_log";
|
const char kCallSessionLogPrefix[] = "webrtc_log";
|
||||||
|
|
||||||
std::string AddTrailingPathDelimiterIfNeeded(std::string directory);
|
std::string AddTrailingPathDelimiterIfNeeded(absl::string_view directory);
|
||||||
|
|
||||||
// `dir` must have a trailing delimiter. `prefix` must not include wild card
|
// `dir` must have a trailing delimiter. `prefix` must not include wild card
|
||||||
// characters.
|
// characters.
|
||||||
std::vector<std::string> GetFilesWithPrefix(const std::string& directory,
|
std::vector<std::string> GetFilesWithPrefix(absl::string_view directory,
|
||||||
const std::string& prefix);
|
absl::string_view prefix);
|
||||||
bool DeleteFile(const std::string& file);
|
bool DeleteFile(absl::string_view file);
|
||||||
bool MoveFile(const std::string& old_file, const std::string& new_file);
|
bool MoveFile(absl::string_view old_file, absl::string_view new_file);
|
||||||
bool IsFile(const std::string& file);
|
bool IsFile(absl::string_view file);
|
||||||
bool IsFolder(const std::string& file);
|
bool IsFolder(absl::string_view file);
|
||||||
absl::optional<size_t> GetFileSize(const std::string& file);
|
absl::optional<size_t> GetFileSize(absl::string_view file);
|
||||||
|
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
|
|
||||||
std::string AddTrailingPathDelimiterIfNeeded(std::string directory) {
|
std::string AddTrailingPathDelimiterIfNeeded(absl::string_view directory) {
|
||||||
if (absl::EndsWith(directory, "\\")) {
|
if (absl::EndsWith(directory, "\\")) {
|
||||||
return directory;
|
return std::string(directory);
|
||||||
}
|
}
|
||||||
return directory + "\\";
|
return std::string(directory) + "\\";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> GetFilesWithPrefix(const std::string& directory,
|
std::vector<std::string> GetFilesWithPrefix(absl::string_view directory,
|
||||||
const std::string& prefix) {
|
absl::string_view prefix) {
|
||||||
RTC_DCHECK(absl::EndsWith(directory, "\\"));
|
RTC_DCHECK(absl::EndsWith(directory, "\\"));
|
||||||
WIN32_FIND_DATAW data;
|
WIN32_FIND_DATAW data;
|
||||||
HANDLE handle;
|
HANDLE handle;
|
||||||
handle = ::FindFirstFileW(ToUtf16(directory + prefix + '*').c_str(), &data);
|
StringBuilder pattern_builder{directory};
|
||||||
|
pattern_builder << prefix << "*";
|
||||||
|
handle = ::FindFirstFileW(ToUtf16(pattern_builder.str()).c_str(), &data);
|
||||||
if (handle == INVALID_HANDLE_VALUE)
|
if (handle == INVALID_HANDLE_VALUE)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
std::vector<std::string> file_list;
|
std::vector<std::string> file_list;
|
||||||
do {
|
do {
|
||||||
file_list.emplace_back(directory + ToUtf8(data.cFileName));
|
StringBuilder file_builder{directory};
|
||||||
|
file_builder << ToUtf8(data.cFileName);
|
||||||
|
file_list.emplace_back(file_builder.Release());
|
||||||
} while (::FindNextFileW(handle, &data) == TRUE);
|
} while (::FindNextFileW(handle, &data) == TRUE);
|
||||||
|
|
||||||
::FindClose(handle);
|
::FindClose(handle);
|
||||||
return file_list;
|
return file_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeleteFile(const std::string& file) {
|
bool DeleteFile(absl::string_view file) {
|
||||||
return ::DeleteFileW(ToUtf16(file).c_str()) != 0;
|
return ::DeleteFileW(ToUtf16(file).c_str()) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MoveFile(const std::string& old_file, const std::string& new_file) {
|
bool MoveFile(absl::string_view old_file, absl::string_view new_file) {
|
||||||
return ::MoveFileW(ToUtf16(old_file).c_str(), ToUtf16(new_file).c_str()) != 0;
|
return ::MoveFileW(ToUtf16(old_file).c_str(), ToUtf16(new_file).c_str()) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsFile(const std::string& file) {
|
bool IsFile(absl::string_view file) {
|
||||||
WIN32_FILE_ATTRIBUTE_DATA data = {0};
|
WIN32_FILE_ATTRIBUTE_DATA data = {0};
|
||||||
if (0 == ::GetFileAttributesExW(ToUtf16(file).c_str(), GetFileExInfoStandard,
|
if (0 == ::GetFileAttributesExW(ToUtf16(file).c_str(), GetFileExInfoStandard,
|
||||||
&data))
|
&data))
|
||||||
|
@ -94,7 +101,7 @@ bool IsFile(const std::string& file) {
|
||||||
return (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0;
|
return (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsFolder(const std::string& file) {
|
bool IsFolder(absl::string_view file) {
|
||||||
WIN32_FILE_ATTRIBUTE_DATA data = {0};
|
WIN32_FILE_ATTRIBUTE_DATA data = {0};
|
||||||
if (0 == ::GetFileAttributesExW(ToUtf16(file).c_str(), GetFileExInfoStandard,
|
if (0 == ::GetFileAttributesExW(ToUtf16(file).c_str(), GetFileExInfoStandard,
|
||||||
&data))
|
&data))
|
||||||
|
@ -103,7 +110,7 @@ bool IsFolder(const std::string& file) {
|
||||||
FILE_ATTRIBUTE_DIRECTORY;
|
FILE_ATTRIBUTE_DIRECTORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::optional<size_t> GetFileSize(const std::string& file) {
|
absl::optional<size_t> GetFileSize(absl::string_view file) {
|
||||||
WIN32_FILE_ATTRIBUTE_DATA data = {0};
|
WIN32_FILE_ATTRIBUTE_DATA data = {0};
|
||||||
if (::GetFileAttributesExW(ToUtf16(file).c_str(), GetFileExInfoStandard,
|
if (::GetFileAttributesExW(ToUtf16(file).c_str(), GetFileExInfoStandard,
|
||||||
&data) == 0)
|
&data) == 0)
|
||||||
|
@ -113,55 +120,57 @@ absl::optional<size_t> GetFileSize(const std::string& file) {
|
||||||
|
|
||||||
#else // defined(WEBRTC_WIN)
|
#else // defined(WEBRTC_WIN)
|
||||||
|
|
||||||
std::string AddTrailingPathDelimiterIfNeeded(std::string directory) {
|
std::string AddTrailingPathDelimiterIfNeeded(absl::string_view directory) {
|
||||||
if (absl::EndsWith(directory, "/")) {
|
if (absl::EndsWith(directory, "/")) {
|
||||||
return directory;
|
return std::string(directory);
|
||||||
}
|
}
|
||||||
return directory + "/";
|
return std::string(directory) + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> GetFilesWithPrefix(const std::string& directory,
|
std::vector<std::string> GetFilesWithPrefix(absl::string_view directory,
|
||||||
const std::string& prefix) {
|
absl::string_view prefix) {
|
||||||
RTC_DCHECK(absl::EndsWith(directory, "/"));
|
RTC_DCHECK(absl::EndsWith(directory, "/"));
|
||||||
DIR* dir = ::opendir(directory.c_str());
|
std::string directory_str = std::string(directory);
|
||||||
|
DIR* dir = ::opendir(directory_str.c_str());
|
||||||
if (dir == nullptr)
|
if (dir == nullptr)
|
||||||
return {};
|
return {};
|
||||||
std::vector<std::string> file_list;
|
std::vector<std::string> file_list;
|
||||||
for (struct dirent* dirent = ::readdir(dir); dirent;
|
for (struct dirent* dirent = ::readdir(dir); dirent;
|
||||||
dirent = ::readdir(dir)) {
|
dirent = ::readdir(dir)) {
|
||||||
std::string name = dirent->d_name;
|
std::string name = dirent->d_name;
|
||||||
if (name.compare(0, prefix.size(), prefix) == 0) {
|
if (name.compare(0, prefix.size(), prefix.data(), prefix.size()) == 0) {
|
||||||
file_list.emplace_back(directory + name);
|
file_list.emplace_back(directory_str + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
::closedir(dir);
|
::closedir(dir);
|
||||||
return file_list;
|
return file_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeleteFile(const std::string& file) {
|
bool DeleteFile(absl::string_view file) {
|
||||||
return ::unlink(file.c_str()) == 0;
|
return ::unlink(std::string(file).c_str()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MoveFile(const std::string& old_file, const std::string& new_file) {
|
bool MoveFile(absl::string_view old_file, absl::string_view new_file) {
|
||||||
return ::rename(old_file.c_str(), new_file.c_str()) == 0;
|
return ::rename(std::string(old_file).c_str(),
|
||||||
|
std::string(new_file).c_str()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsFile(const std::string& file) {
|
bool IsFile(absl::string_view file) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int res = ::stat(file.c_str(), &st);
|
int res = ::stat(std::string(file).c_str(), &st);
|
||||||
// Treat symlinks, named pipes, etc. all as files.
|
// Treat symlinks, named pipes, etc. all as files.
|
||||||
return res == 0 && !S_ISDIR(st.st_mode);
|
return res == 0 && !S_ISDIR(st.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsFolder(const std::string& file) {
|
bool IsFolder(absl::string_view file) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int res = ::stat(file.c_str(), &st);
|
int res = ::stat(std::string(file).c_str(), &st);
|
||||||
return res == 0 && S_ISDIR(st.st_mode);
|
return res == 0 && S_ISDIR(st.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::optional<size_t> GetFileSize(const std::string& file) {
|
absl::optional<size_t> GetFileSize(absl::string_view file) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (::stat(file.c_str(), &st) != 0)
|
if (::stat(std::string(file).c_str(), &st) != 0)
|
||||||
return absl::nullopt;
|
return absl::nullopt;
|
||||||
return st.st_size;
|
return st.st_size;
|
||||||
}
|
}
|
||||||
|
@ -170,8 +179,8 @@ absl::optional<size_t> GetFileSize(const std::string& file) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
FileRotatingStream::FileRotatingStream(const std::string& dir_path,
|
FileRotatingStream::FileRotatingStream(absl::string_view dir_path,
|
||||||
const std::string& file_prefix,
|
absl::string_view file_prefix,
|
||||||
size_t max_file_size,
|
size_t max_file_size,
|
||||||
size_t num_files)
|
size_t num_files)
|
||||||
: dir_path_(AddTrailingPathDelimiterIfNeeded(dir_path)),
|
: dir_path_(AddTrailingPathDelimiterIfNeeded(dir_path)),
|
||||||
|
@ -331,7 +340,7 @@ std::string FileRotatingStream::GetFilePath(size_t index,
|
||||||
}
|
}
|
||||||
|
|
||||||
CallSessionFileRotatingStream::CallSessionFileRotatingStream(
|
CallSessionFileRotatingStream::CallSessionFileRotatingStream(
|
||||||
const std::string& dir_path,
|
absl::string_view dir_path,
|
||||||
size_t max_total_log_size)
|
size_t max_total_log_size)
|
||||||
: FileRotatingStream(dir_path,
|
: FileRotatingStream(dir_path,
|
||||||
kCallSessionLogPrefix,
|
kCallSessionLogPrefix,
|
||||||
|
@ -376,8 +385,8 @@ size_t CallSessionFileRotatingStream::GetNumRotatingLogFiles(
|
||||||
}
|
}
|
||||||
|
|
||||||
FileRotatingStreamReader::FileRotatingStreamReader(
|
FileRotatingStreamReader::FileRotatingStreamReader(
|
||||||
const std::string& dir_path,
|
absl::string_view dir_path,
|
||||||
const std::string& file_prefix) {
|
absl::string_view file_prefix) {
|
||||||
file_names_ = GetFilesWithPrefix(AddTrailingPathDelimiterIfNeeded(dir_path),
|
file_names_ = GetFilesWithPrefix(AddTrailingPathDelimiterIfNeeded(dir_path),
|
||||||
file_prefix);
|
file_prefix);
|
||||||
|
|
||||||
|
@ -413,7 +422,7 @@ size_t FileRotatingStreamReader::ReadAll(void* buffer, size_t size) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
CallSessionFileRotatingStreamReader::CallSessionFileRotatingStreamReader(
|
CallSessionFileRotatingStreamReader::CallSessionFileRotatingStreamReader(
|
||||||
const std::string& dir_path)
|
absl::string_view dir_path)
|
||||||
: FileRotatingStreamReader(dir_path, kCallSessionLogPrefix) {}
|
: FileRotatingStreamReader(dir_path, kCallSessionLogPrefix) {}
|
||||||
|
|
||||||
} // namespace rtc
|
} // namespace rtc
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/system/file_wrapper.h"
|
#include "rtc_base/system/file_wrapper.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
@ -29,8 +30,8 @@ class FileRotatingStream {
|
||||||
public:
|
public:
|
||||||
// Use this constructor for writing to a directory. Files in the directory
|
// Use this constructor for writing to a directory. Files in the directory
|
||||||
// matching the prefix will be deleted on open.
|
// matching the prefix will be deleted on open.
|
||||||
FileRotatingStream(const std::string& dir_path,
|
FileRotatingStream(absl::string_view dir_path,
|
||||||
const std::string& file_prefix,
|
absl::string_view file_prefix,
|
||||||
size_t max_file_size,
|
size_t max_file_size,
|
||||||
size_t num_files);
|
size_t num_files);
|
||||||
|
|
||||||
|
@ -126,7 +127,7 @@ class CallSessionFileRotatingStream : public FileRotatingStream {
|
||||||
// Use this constructor for writing to a directory. Files in the directory
|
// Use this constructor for writing to a directory. Files in the directory
|
||||||
// matching what's used by the stream will be deleted. `max_total_log_size`
|
// matching what's used by the stream will be deleted. `max_total_log_size`
|
||||||
// must be at least 4.
|
// must be at least 4.
|
||||||
CallSessionFileRotatingStream(const std::string& dir_path,
|
CallSessionFileRotatingStream(absl::string_view dir_path,
|
||||||
size_t max_total_log_size);
|
size_t max_total_log_size);
|
||||||
~CallSessionFileRotatingStream() override {}
|
~CallSessionFileRotatingStream() override {}
|
||||||
|
|
||||||
|
@ -152,8 +153,8 @@ class CallSessionFileRotatingStream : public FileRotatingStream {
|
||||||
// directory at construction time.
|
// directory at construction time.
|
||||||
class FileRotatingStreamReader {
|
class FileRotatingStreamReader {
|
||||||
public:
|
public:
|
||||||
FileRotatingStreamReader(const std::string& dir_path,
|
FileRotatingStreamReader(absl::string_view dir_path,
|
||||||
const std::string& file_prefix);
|
absl::string_view file_prefix);
|
||||||
~FileRotatingStreamReader();
|
~FileRotatingStreamReader();
|
||||||
size_t GetSize() const;
|
size_t GetSize() const;
|
||||||
size_t ReadAll(void* buffer, size_t size) const;
|
size_t ReadAll(void* buffer, size_t size) const;
|
||||||
|
@ -164,7 +165,7 @@ class FileRotatingStreamReader {
|
||||||
|
|
||||||
class CallSessionFileRotatingStreamReader : public FileRotatingStreamReader {
|
class CallSessionFileRotatingStreamReader : public FileRotatingStreamReader {
|
||||||
public:
|
public:
|
||||||
CallSessionFileRotatingStreamReader(const std::string& dir_path);
|
CallSessionFileRotatingStreamReader(absl::string_view dir_path);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace rtc
|
} // namespace rtc
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/arraysize.h"
|
#include "rtc_base/arraysize.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
#include "test/testsupport/file_utils.h"
|
#include "test/testsupport/file_utils.h"
|
||||||
|
@ -44,15 +45,15 @@ class MAYBE_FileRotatingStreamTest : public ::testing::Test {
|
||||||
static const char* kFilePrefix;
|
static const char* kFilePrefix;
|
||||||
static const size_t kMaxFileSize;
|
static const size_t kMaxFileSize;
|
||||||
|
|
||||||
void Init(const std::string& dir_name,
|
void Init(absl::string_view dir_name,
|
||||||
const std::string& file_prefix,
|
absl::string_view file_prefix,
|
||||||
size_t max_file_size,
|
size_t max_file_size,
|
||||||
size_t num_log_files,
|
size_t num_log_files,
|
||||||
bool ensure_trailing_delimiter = true) {
|
bool ensure_trailing_delimiter = true) {
|
||||||
dir_path_ = webrtc::test::OutputPath();
|
dir_path_ = webrtc::test::OutputPath();
|
||||||
|
|
||||||
// Append per-test output path in order to run within gtest parallel.
|
// Append per-test output path in order to run within gtest parallel.
|
||||||
dir_path_.append(dir_name);
|
dir_path_.append(dir_name.begin(), dir_name.end());
|
||||||
if (ensure_trailing_delimiter) {
|
if (ensure_trailing_delimiter) {
|
||||||
dir_path_.append(webrtc::test::kPathDelimiter);
|
dir_path_.append(webrtc::test::kPathDelimiter);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +81,7 @@ class MAYBE_FileRotatingStreamTest : public ::testing::Test {
|
||||||
// end of stream result.
|
// end of stream result.
|
||||||
void VerifyStreamRead(const char* expected_contents,
|
void VerifyStreamRead(const char* expected_contents,
|
||||||
const size_t expected_length,
|
const size_t expected_length,
|
||||||
const std::string& dir_path,
|
absl::string_view dir_path,
|
||||||
const char* file_prefix) {
|
const char* file_prefix) {
|
||||||
FileRotatingStreamReader reader(dir_path, file_prefix);
|
FileRotatingStreamReader reader(dir_path, file_prefix);
|
||||||
EXPECT_EQ(reader.GetSize(), expected_length);
|
EXPECT_EQ(reader.GetSize(), expected_length);
|
||||||
|
@ -92,9 +93,10 @@ class MAYBE_FileRotatingStreamTest : public ::testing::Test {
|
||||||
|
|
||||||
void VerifyFileContents(const char* expected_contents,
|
void VerifyFileContents(const char* expected_contents,
|
||||||
const size_t expected_length,
|
const size_t expected_length,
|
||||||
const std::string& file_path) {
|
absl::string_view file_path) {
|
||||||
std::unique_ptr<uint8_t[]> buffer(new uint8_t[expected_length + 1]);
|
std::unique_ptr<uint8_t[]> buffer(new uint8_t[expected_length + 1]);
|
||||||
webrtc::FileWrapper f = webrtc::FileWrapper::OpenReadOnly(file_path);
|
webrtc::FileWrapper f =
|
||||||
|
webrtc::FileWrapper::OpenReadOnly(std::string(file_path));
|
||||||
ASSERT_TRUE(f.is_open());
|
ASSERT_TRUE(f.is_open());
|
||||||
size_t size_read = f.Read(buffer.get(), expected_length + 1);
|
size_t size_read = f.Read(buffer.get(), expected_length + 1);
|
||||||
EXPECT_EQ(size_read, expected_length);
|
EXPECT_EQ(size_read, expected_length);
|
||||||
|
@ -255,11 +257,11 @@ TEST_F(MAYBE_FileRotatingStreamTest, GetFilePath) {
|
||||||
|
|
||||||
class MAYBE_CallSessionFileRotatingStreamTest : public ::testing::Test {
|
class MAYBE_CallSessionFileRotatingStreamTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
void Init(const std::string& dir_name, size_t max_total_log_size) {
|
void Init(absl::string_view dir_name, size_t max_total_log_size) {
|
||||||
dir_path_ = webrtc::test::OutputPath();
|
dir_path_ = webrtc::test::OutputPath();
|
||||||
|
|
||||||
// Append per-test output path in order to run within gtest parallel.
|
// Append per-test output path in order to run within gtest parallel.
|
||||||
dir_path_.append(dir_name);
|
dir_path_.append(dir_name.begin(), dir_name.end());
|
||||||
dir_path_.append(webrtc::test::kPathDelimiter);
|
dir_path_.append(webrtc::test::kPathDelimiter);
|
||||||
ASSERT_TRUE(webrtc::test::CreateDir(dir_path_));
|
ASSERT_TRUE(webrtc::test::CreateDir(dir_path_));
|
||||||
stream_.reset(
|
stream_.reset(
|
||||||
|
@ -285,7 +287,7 @@ class MAYBE_CallSessionFileRotatingStreamTest : public ::testing::Test {
|
||||||
// end of stream result.
|
// end of stream result.
|
||||||
void VerifyStreamRead(const char* expected_contents,
|
void VerifyStreamRead(const char* expected_contents,
|
||||||
const size_t expected_length,
|
const size_t expected_length,
|
||||||
const std::string& dir_path) {
|
absl::string_view dir_path) {
|
||||||
CallSessionFileRotatingStreamReader reader(dir_path);
|
CallSessionFileRotatingStreamReader reader(dir_path);
|
||||||
EXPECT_EQ(reader.GetSize(), expected_length);
|
EXPECT_EQ(reader.GetSize(), expected_length);
|
||||||
std::unique_ptr<uint8_t[]> buffer(new uint8_t[expected_length]);
|
std::unique_ptr<uint8_t[]> buffer(new uint8_t[expected_length]);
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "absl/strings/match.h"
|
#include "absl/strings/match.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
::testing::AssertionResult AssertStartsWith(const char* text_expr,
|
::testing::AssertionResult AssertStartsWith(const char* text_expr,
|
||||||
const char* prefix_expr,
|
const char* prefix_expr,
|
||||||
|
@ -30,9 +31,9 @@
|
||||||
|
|
||||||
::testing::AssertionResult AssertStringContains(const char* str_expr,
|
::testing::AssertionResult AssertStringContains(const char* str_expr,
|
||||||
const char* substr_expr,
|
const char* substr_expr,
|
||||||
const std::string& str,
|
absl::string_view str,
|
||||||
const std::string& substr) {
|
absl::string_view substr) {
|
||||||
if (str.find(substr) != std::string::npos) {
|
if (str.find(substr) != absl::string_view::npos) {
|
||||||
return ::testing::AssertionSuccess();
|
return ::testing::AssertionSuccess();
|
||||||
} else {
|
} else {
|
||||||
return ::testing::AssertionFailure()
|
return ::testing::AssertionFailure()
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#ifndef RTC_BASE_GUNIT_H_
|
#ifndef RTC_BASE_GUNIT_H_
|
||||||
#define RTC_BASE_GUNIT_H_
|
#define RTC_BASE_GUNIT_H_
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/fake_clock.h"
|
#include "rtc_base/fake_clock.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
|
@ -162,7 +163,7 @@ testing::AssertionResult AssertStartsWith(const char* text_expr,
|
||||||
// Usage: EXPECT_PRED_FORMAT2(AssertStringContains, str, "substring");
|
// Usage: EXPECT_PRED_FORMAT2(AssertStringContains, str, "substring");
|
||||||
testing::AssertionResult AssertStringContains(const char* str_expr,
|
testing::AssertionResult AssertStringContains(const char* str_expr,
|
||||||
const char* substr_expr,
|
const char* substr_expr,
|
||||||
const std::string& str,
|
absl::string_view str,
|
||||||
const std::string& substr);
|
absl::string_view substr);
|
||||||
|
|
||||||
#endif // RTC_BASE_GUNIT_H_
|
#endif // RTC_BASE_GUNIT_H_
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
|
|
||||||
|
@ -145,10 +146,8 @@ bool CreateRandomString(size_t len, std::string* str) {
|
||||||
return CreateRandomString(len, kBase64, 64, str);
|
return CreateRandomString(len, kBase64, 64, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CreateRandomString(size_t len,
|
bool CreateRandomString(size_t len, absl::string_view table, std::string* str) {
|
||||||
const std::string& table,
|
return CreateRandomString(len, table.data(), static_cast<int>(table.size()),
|
||||||
std::string* str) {
|
|
||||||
return CreateRandomString(len, table.c_str(), static_cast<int>(table.size()),
|
|
||||||
str);
|
str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
@ -42,7 +43,7 @@ RTC_EXPORT bool CreateRandomString(size_t length, std::string* str);
|
||||||
// For ease of implementation, the function requires that the table
|
// For ease of implementation, the function requires that the table
|
||||||
// size evenly divide 256; otherwise, it returns false.
|
// size evenly divide 256; otherwise, it returns false.
|
||||||
RTC_EXPORT bool CreateRandomString(size_t length,
|
RTC_EXPORT bool CreateRandomString(size_t length,
|
||||||
const std::string& table,
|
absl::string_view table,
|
||||||
std::string* str);
|
std::string* str);
|
||||||
|
|
||||||
// Generates (cryptographically) random data of the given length.
|
// Generates (cryptographically) random data of the given length.
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
@ -185,7 +187,7 @@ void HttpParseAttributes(const char* data,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HttpHasAttribute(const HttpAttributeList& attributes,
|
bool HttpHasAttribute(const HttpAttributeList& attributes,
|
||||||
const std::string& name,
|
absl::string_view name,
|
||||||
std::string* value) {
|
std::string* value) {
|
||||||
for (HttpAttributeList::const_iterator it = attributes.begin();
|
for (HttpAttributeList::const_iterator it = attributes.begin();
|
||||||
it != attributes.end(); ++it) {
|
it != attributes.end(); ++it) {
|
||||||
|
@ -213,7 +215,7 @@ bool HttpHasNthAttribute(HttpAttributeList& attributes,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string quote(const std::string& str) {
|
std::string quote(absl::string_view str) {
|
||||||
std::string result;
|
std::string result;
|
||||||
result.push_back('"');
|
result.push_back('"');
|
||||||
for (size_t i = 0; i < str.size(); ++i) {
|
for (size_t i = 0; i < str.size(); ++i) {
|
||||||
|
@ -232,7 +234,7 @@ struct NegotiateAuthContext : public HttpAuthContext {
|
||||||
size_t steps;
|
size_t steps;
|
||||||
bool specified_credentials;
|
bool specified_credentials;
|
||||||
|
|
||||||
NegotiateAuthContext(const std::string& auth, CredHandle c1, CtxtHandle c2)
|
NegotiateAuthContext(absl::string_view auth, CredHandle c1, CtxtHandle c2)
|
||||||
: HttpAuthContext(auth),
|
: HttpAuthContext(auth),
|
||||||
cred(c1),
|
cred(c1),
|
||||||
ctx(c2),
|
ctx(c2),
|
||||||
|
@ -251,9 +253,9 @@ struct NegotiateAuthContext : public HttpAuthContext {
|
||||||
HttpAuthResult HttpAuthenticate(const char* challenge,
|
HttpAuthResult HttpAuthenticate(const char* challenge,
|
||||||
size_t len,
|
size_t len,
|
||||||
const SocketAddress& server,
|
const SocketAddress& server,
|
||||||
const std::string& method,
|
absl::string_view method,
|
||||||
const std::string& uri,
|
absl::string_view uri,
|
||||||
const std::string& username,
|
absl::string_view username,
|
||||||
const CryptString& password,
|
const CryptString& password,
|
||||||
HttpAuthContext*& context,
|
HttpAuthContext*& context,
|
||||||
std::string& response,
|
std::string& response,
|
||||||
|
@ -326,7 +328,7 @@ HttpAuthResult HttpAuthenticate(const char* challenge,
|
||||||
pos += strcpyn(sensitive + pos, len - pos, ":");
|
pos += strcpyn(sensitive + pos, len - pos, ":");
|
||||||
password.CopyTo(sensitive + pos, true);
|
password.CopyTo(sensitive + pos, true);
|
||||||
|
|
||||||
std::string A2 = method + ":" + uri;
|
std::string A2 = std::string(method) + ":" + std::string(uri);
|
||||||
std::string middle;
|
std::string middle;
|
||||||
if (has_qop) {
|
if (has_qop) {
|
||||||
qop = "auth";
|
qop = "auth";
|
||||||
|
@ -459,11 +461,11 @@ HttpAuthResult HttpAuthenticate(const char* challenge,
|
||||||
size_t len = password.GetLength() + 1;
|
size_t len = password.GetLength() + 1;
|
||||||
char* sensitive = new char[len];
|
char* sensitive = new char[len];
|
||||||
password.CopyTo(sensitive, true);
|
password.CopyTo(sensitive, true);
|
||||||
std::string::size_type pos = username.find('\\');
|
absl::string_view::size_type pos = username.find('\\');
|
||||||
if (pos == std::string::npos) {
|
if (pos == absl::string_view::npos) {
|
||||||
auth_id.UserLength = static_cast<unsigned long>(
|
auth_id.UserLength = static_cast<unsigned long>(
|
||||||
std::min(sizeof(userbuf) - 1, username.size()));
|
std::min(sizeof(userbuf) - 1, username.size()));
|
||||||
memcpy(userbuf, username.c_str(), auth_id.UserLength);
|
memcpy(userbuf, username.data(), auth_id.UserLength);
|
||||||
userbuf[auth_id.UserLength] = 0;
|
userbuf[auth_id.UserLength] = 0;
|
||||||
auth_id.DomainLength = 0;
|
auth_id.DomainLength = 0;
|
||||||
domainbuf[auth_id.DomainLength] = 0;
|
domainbuf[auth_id.DomainLength] = 0;
|
||||||
|
@ -474,11 +476,11 @@ HttpAuthResult HttpAuthenticate(const char* challenge,
|
||||||
} else {
|
} else {
|
||||||
auth_id.UserLength = static_cast<unsigned long>(
|
auth_id.UserLength = static_cast<unsigned long>(
|
||||||
std::min(sizeof(userbuf) - 1, username.size() - pos - 1));
|
std::min(sizeof(userbuf) - 1, username.size() - pos - 1));
|
||||||
memcpy(userbuf, username.c_str() + pos + 1, auth_id.UserLength);
|
memcpy(userbuf, username.data() + pos + 1, auth_id.UserLength);
|
||||||
userbuf[auth_id.UserLength] = 0;
|
userbuf[auth_id.UserLength] = 0;
|
||||||
auth_id.DomainLength =
|
auth_id.DomainLength =
|
||||||
static_cast<unsigned long>(std::min(sizeof(domainbuf) - 1, pos));
|
static_cast<unsigned long>(std::min(sizeof(domainbuf) - 1, pos));
|
||||||
memcpy(domainbuf, username.c_str(), auth_id.DomainLength);
|
memcpy(domainbuf, username.data(), auth_id.DomainLength);
|
||||||
domainbuf[auth_id.DomainLength] = 0;
|
domainbuf[auth_id.DomainLength] = 0;
|
||||||
auth_id.PasswordLength = static_cast<unsigned long>(
|
auth_id.PasswordLength = static_cast<unsigned long>(
|
||||||
std::min(sizeof(passbuf) - 1, password.GetLength()));
|
std::min(sizeof(passbuf) - 1, password.GetLength()));
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
class CryptString;
|
class CryptString;
|
||||||
|
@ -24,7 +26,7 @@ class SocketAddress;
|
||||||
|
|
||||||
struct HttpAuthContext {
|
struct HttpAuthContext {
|
||||||
std::string auth_method;
|
std::string auth_method;
|
||||||
HttpAuthContext(const std::string& auth) : auth_method(auth) {}
|
HttpAuthContext(absl::string_view auth) : auth_method(auth) {}
|
||||||
virtual ~HttpAuthContext() {}
|
virtual ~HttpAuthContext() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -37,9 +39,9 @@ enum HttpAuthResult { HAR_RESPONSE, HAR_IGNORE, HAR_CREDENTIALS, HAR_ERROR };
|
||||||
HttpAuthResult HttpAuthenticate(const char* challenge,
|
HttpAuthResult HttpAuthenticate(const char* challenge,
|
||||||
size_t len,
|
size_t len,
|
||||||
const SocketAddress& server,
|
const SocketAddress& server,
|
||||||
const std::string& method,
|
absl::string_view method,
|
||||||
const std::string& uri,
|
absl::string_view uri,
|
||||||
const std::string& username,
|
absl::string_view username,
|
||||||
const CryptString& password,
|
const CryptString& password,
|
||||||
HttpAuthContext*& context,
|
HttpAuthContext*& context,
|
||||||
std::string& response,
|
std::string& response,
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#if defined(WEBRTC_POSIX)
|
#if defined(WEBRTC_POSIX)
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#ifdef OPENBSD
|
#ifdef OPENBSD
|
||||||
#include <netinet/in_systm.h>
|
#include <netinet/in_systm.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -276,14 +278,15 @@ bool IPFromAddrInfo(struct addrinfo* info, IPAddress* out) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IPFromString(const std::string& str, IPAddress* out) {
|
bool IPFromString(absl::string_view str, IPAddress* out) {
|
||||||
if (!out) {
|
if (!out) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
in_addr addr;
|
in_addr addr;
|
||||||
if (rtc::inet_pton(AF_INET, str.c_str(), &addr) == 0) {
|
const std::string str_copy = std::string(str);
|
||||||
|
if (rtc::inet_pton(AF_INET, str_copy.c_str(), &addr) == 0) {
|
||||||
in6_addr addr6;
|
in6_addr addr6;
|
||||||
if (rtc::inet_pton(AF_INET6, str.c_str(), &addr6) == 0) {
|
if (rtc::inet_pton(AF_INET6, str_copy.c_str(), &addr6) == 0) {
|
||||||
*out = IPAddress();
|
*out = IPAddress();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -294,7 +297,7 @@ bool IPFromString(const std::string& str, IPAddress* out) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IPFromString(const std::string& str, int flags, InterfaceAddress* out) {
|
bool IPFromString(absl::string_view str, int flags, InterfaceAddress* out) {
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
if (!IPFromString(str, &ip)) {
|
if (!IPFromString(str, &ip)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#endif
|
#endif
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
@ -29,8 +31,8 @@
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
#include "rtc_base/win32.h"
|
#include "rtc_base/win32.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
enum IPv6AddressFlag {
|
enum IPv6AddressFlag {
|
||||||
|
@ -155,8 +157,8 @@ class RTC_EXPORT InterfaceAddress : public IPAddress {
|
||||||
};
|
};
|
||||||
|
|
||||||
bool IPFromAddrInfo(struct addrinfo* info, IPAddress* out);
|
bool IPFromAddrInfo(struct addrinfo* info, IPAddress* out);
|
||||||
RTC_EXPORT bool IPFromString(const std::string& str, IPAddress* out);
|
RTC_EXPORT bool IPFromString(absl::string_view str, IPAddress* out);
|
||||||
RTC_EXPORT bool IPFromString(const std::string& str,
|
RTC_EXPORT bool IPFromString(absl::string_view str,
|
||||||
int flags,
|
int flags,
|
||||||
InterfaceAddress* out);
|
InterfaceAddress* out);
|
||||||
bool IPIsAny(const IPAddress& ip);
|
bool IPIsAny(const IPAddress& ip);
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "rtc_base/ip_address.h"
|
#include "rtc_base/ip_address.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
@ -118,7 +119,7 @@ bool AreEqual(const IPAddress& addr, const IPAddress& addr2) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BrokenIPStringFails(const std::string& broken) {
|
bool BrokenIPStringFails(absl::string_view broken) {
|
||||||
IPAddress addr(0); // Intentionally make it v4.
|
IPAddress addr(0); // Intentionally make it v4.
|
||||||
if (IPFromString(kIPv4BrokenString1, &addr)) {
|
if (IPFromString(kIPv4BrokenString1, &addr)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -126,13 +127,13 @@ bool BrokenIPStringFails(const std::string& broken) {
|
||||||
return addr.family() == AF_UNSPEC;
|
return addr.family() == AF_UNSPEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckMaskCount(const std::string& mask, int expected_length) {
|
bool CheckMaskCount(absl::string_view mask, int expected_length) {
|
||||||
IPAddress addr;
|
IPAddress addr;
|
||||||
return IPFromString(mask, &addr) &&
|
return IPFromString(mask, &addr) &&
|
||||||
(expected_length == CountIPMaskBits(addr));
|
(expected_length == CountIPMaskBits(addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TryInvalidMaskCount(const std::string& mask) {
|
bool TryInvalidMaskCount(absl::string_view mask) {
|
||||||
// We don't care about the result at all, but we do want to know if
|
// We don't care about the result at all, but we do want to know if
|
||||||
// CountIPMaskBits is going to crash or infinite loop or something.
|
// CountIPMaskBits is going to crash or infinite loop or something.
|
||||||
IPAddress addr;
|
IPAddress addr;
|
||||||
|
@ -143,9 +144,9 @@ bool TryInvalidMaskCount(const std::string& mask) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckTruncateIP(const std::string& initial,
|
bool CheckTruncateIP(absl::string_view initial,
|
||||||
int truncate_length,
|
int truncate_length,
|
||||||
const std::string& expected_result) {
|
absl::string_view expected_result) {
|
||||||
IPAddress addr, expected;
|
IPAddress addr, expected;
|
||||||
IPFromString(initial, &addr);
|
IPFromString(initial, &addr);
|
||||||
IPFromString(expected_result, &expected);
|
IPFromString(expected_result, &expected);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/ip_address.h"
|
#include "rtc_base/ip_address.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
@ -23,7 +24,7 @@ namespace webrtc {
|
||||||
class MdnsResponderInterface {
|
class MdnsResponderInterface {
|
||||||
public:
|
public:
|
||||||
using NameCreatedCallback =
|
using NameCreatedCallback =
|
||||||
std::function<void(const rtc::IPAddress&, const std::string&)>;
|
std::function<void(const rtc::IPAddress&, absl::string_view)>;
|
||||||
using NameRemovedCallback = std::function<void(bool)>;
|
using NameRemovedCallback = std::function<void(bool)>;
|
||||||
|
|
||||||
MdnsResponderInterface() = default;
|
MdnsResponderInterface() = default;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/openssl_digest.h"
|
#include "rtc_base/openssl_digest.h"
|
||||||
#include "rtc_base/string_encode.h"
|
#include "rtc_base/string_encode.h"
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ const char DIGEST_SHA_512[] = "sha-512";
|
||||||
|
|
||||||
static const size_t kBlockSize = 64; // valid for SHA-256 and down
|
static const size_t kBlockSize = 64; // valid for SHA-256 and down
|
||||||
|
|
||||||
MessageDigest* MessageDigestFactory::Create(const std::string& alg) {
|
MessageDigest* MessageDigestFactory::Create(absl::string_view alg) {
|
||||||
MessageDigest* digest = new OpenSSLDigest(alg);
|
MessageDigest* digest = new OpenSSLDigest(alg);
|
||||||
if (digest->Size() == 0) { // invalid algorithm
|
if (digest->Size() == 0) { // invalid algorithm
|
||||||
delete digest;
|
delete digest;
|
||||||
|
@ -39,7 +40,7 @@ MessageDigest* MessageDigestFactory::Create(const std::string& alg) {
|
||||||
return digest;
|
return digest;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsFips180DigestAlgorithm(const std::string& alg) {
|
bool IsFips180DigestAlgorithm(absl::string_view alg) {
|
||||||
// These are the FIPS 180 algorithms. According to RFC 4572 Section 5,
|
// These are the FIPS 180 algorithms. According to RFC 4572 Section 5,
|
||||||
// "Self-signed certificates (for which legacy certificates are not a
|
// "Self-signed certificates (for which legacy certificates are not a
|
||||||
// consideration) MUST use one of the FIPS 180 algorithms (SHA-1,
|
// consideration) MUST use one of the FIPS 180 algorithms (SHA-1,
|
||||||
|
@ -59,7 +60,7 @@ size_t ComputeDigest(MessageDigest* digest,
|
||||||
return digest->Finish(output, out_len);
|
return digest->Finish(output, out_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ComputeDigest(const std::string& alg,
|
size_t ComputeDigest(absl::string_view alg,
|
||||||
const void* input,
|
const void* input,
|
||||||
size_t in_len,
|
size_t in_len,
|
||||||
void* output,
|
void* output,
|
||||||
|
@ -69,15 +70,15 @@ size_t ComputeDigest(const std::string& alg,
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ComputeDigest(MessageDigest* digest, const std::string& input) {
|
std::string ComputeDigest(MessageDigest* digest, absl::string_view input) {
|
||||||
std::unique_ptr<char[]> output(new char[digest->Size()]);
|
std::unique_ptr<char[]> output(new char[digest->Size()]);
|
||||||
ComputeDigest(digest, input.data(), input.size(), output.get(),
|
ComputeDigest(digest, input.data(), input.size(), output.get(),
|
||||||
digest->Size());
|
digest->Size());
|
||||||
return hex_encode(output.get(), digest->Size());
|
return hex_encode(output.get(), digest->Size());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ComputeDigest(const std::string& alg,
|
bool ComputeDigest(absl::string_view alg,
|
||||||
const std::string& input,
|
absl::string_view input,
|
||||||
std::string* output) {
|
std::string* output) {
|
||||||
std::unique_ptr<MessageDigest> digest(MessageDigestFactory::Create(alg));
|
std::unique_ptr<MessageDigest> digest(MessageDigestFactory::Create(alg));
|
||||||
if (!digest) {
|
if (!digest) {
|
||||||
|
@ -87,7 +88,7 @@ bool ComputeDigest(const std::string& alg,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ComputeDigest(const std::string& alg, const std::string& input) {
|
std::string ComputeDigest(absl::string_view alg, absl::string_view input) {
|
||||||
std::string output;
|
std::string output;
|
||||||
ComputeDigest(alg, input, &output);
|
ComputeDigest(alg, input, &output);
|
||||||
return output;
|
return output;
|
||||||
|
@ -135,7 +136,7 @@ size_t ComputeHmac(MessageDigest* digest,
|
||||||
return digest->Finish(output, out_len);
|
return digest->Finish(output, out_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ComputeHmac(const std::string& alg,
|
size_t ComputeHmac(absl::string_view alg,
|
||||||
const void* key,
|
const void* key,
|
||||||
size_t key_len,
|
size_t key_len,
|
||||||
const void* input,
|
const void* input,
|
||||||
|
@ -151,17 +152,17 @@ size_t ComputeHmac(const std::string& alg,
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ComputeHmac(MessageDigest* digest,
|
std::string ComputeHmac(MessageDigest* digest,
|
||||||
const std::string& key,
|
absl::string_view key,
|
||||||
const std::string& input) {
|
absl::string_view input) {
|
||||||
std::unique_ptr<char[]> output(new char[digest->Size()]);
|
std::unique_ptr<char[]> output(new char[digest->Size()]);
|
||||||
ComputeHmac(digest, key.data(), key.size(), input.data(), input.size(),
|
ComputeHmac(digest, key.data(), key.size(), input.data(), input.size(),
|
||||||
output.get(), digest->Size());
|
output.get(), digest->Size());
|
||||||
return hex_encode(output.get(), digest->Size());
|
return hex_encode(output.get(), digest->Size());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ComputeHmac(const std::string& alg,
|
bool ComputeHmac(absl::string_view alg,
|
||||||
const std::string& key,
|
absl::string_view key,
|
||||||
const std::string& input,
|
absl::string_view input,
|
||||||
std::string* output) {
|
std::string* output) {
|
||||||
std::unique_ptr<MessageDigest> digest(MessageDigestFactory::Create(alg));
|
std::unique_ptr<MessageDigest> digest(MessageDigestFactory::Create(alg));
|
||||||
if (!digest) {
|
if (!digest) {
|
||||||
|
@ -171,9 +172,9 @@ bool ComputeHmac(const std::string& alg,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ComputeHmac(const std::string& alg,
|
std::string ComputeHmac(absl::string_view alg,
|
||||||
const std::string& key,
|
absl::string_view key,
|
||||||
const std::string& input) {
|
absl::string_view input) {
|
||||||
std::string output;
|
std::string output;
|
||||||
ComputeHmac(alg, key, input, &output);
|
ComputeHmac(alg, key, input, &output);
|
||||||
return output;
|
return output;
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
// Definitions for the digest algorithms.
|
// Definitions for the digest algorithms.
|
||||||
|
@ -42,12 +44,12 @@ class MessageDigest {
|
||||||
// A factory class for creating digest objects.
|
// A factory class for creating digest objects.
|
||||||
class MessageDigestFactory {
|
class MessageDigestFactory {
|
||||||
public:
|
public:
|
||||||
static MessageDigest* Create(const std::string& alg);
|
static MessageDigest* Create(absl::string_view alg);
|
||||||
};
|
};
|
||||||
|
|
||||||
// A check that an algorithm is in a list of approved digest algorithms
|
// A check that an algorithm is in a list of approved digest algorithms
|
||||||
// from RFC 4572 (FIPS 180).
|
// from RFC 4572 (FIPS 180).
|
||||||
bool IsFips180DigestAlgorithm(const std::string& alg);
|
bool IsFips180DigestAlgorithm(absl::string_view alg);
|
||||||
|
|
||||||
// Functions to create hashes.
|
// Functions to create hashes.
|
||||||
|
|
||||||
|
@ -63,25 +65,25 @@ size_t ComputeDigest(MessageDigest* digest,
|
||||||
// Like the previous function, but creates a digest implementation based on
|
// Like the previous function, but creates a digest implementation based on
|
||||||
// the desired digest name `alg`, e.g. DIGEST_SHA_1. Returns 0 if there is no
|
// the desired digest name `alg`, e.g. DIGEST_SHA_1. Returns 0 if there is no
|
||||||
// digest with the given name.
|
// digest with the given name.
|
||||||
size_t ComputeDigest(const std::string& alg,
|
size_t ComputeDigest(absl::string_view alg,
|
||||||
const void* input,
|
const void* input,
|
||||||
size_t in_len,
|
size_t in_len,
|
||||||
void* output,
|
void* output,
|
||||||
size_t out_len);
|
size_t out_len);
|
||||||
// Computes the hash of `input` using the `digest` hash implementation, and
|
// Computes the hash of `input` using the `digest` hash implementation, and
|
||||||
// returns it as a hex-encoded string.
|
// returns it as a hex-encoded string.
|
||||||
std::string ComputeDigest(MessageDigest* digest, const std::string& input);
|
std::string ComputeDigest(MessageDigest* digest, absl::string_view input);
|
||||||
// Like the previous function, but creates a digest implementation based on
|
// Like the previous function, but creates a digest implementation based on
|
||||||
// the desired digest name `alg`, e.g. DIGEST_SHA_1. Returns empty string if
|
// the desired digest name `alg`, e.g. DIGEST_SHA_1. Returns empty string if
|
||||||
// there is no digest with the given name.
|
// there is no digest with the given name.
|
||||||
std::string ComputeDigest(const std::string& alg, const std::string& input);
|
std::string ComputeDigest(absl::string_view alg, absl::string_view input);
|
||||||
// Like the previous function, but returns an explicit result code.
|
// Like the previous function, but returns an explicit result code.
|
||||||
bool ComputeDigest(const std::string& alg,
|
bool ComputeDigest(absl::string_view alg,
|
||||||
const std::string& input,
|
absl::string_view input,
|
||||||
std::string* output);
|
std::string* output);
|
||||||
|
|
||||||
// Shorthand way to compute a hex-encoded hash using MD5.
|
// Shorthand way to compute a hex-encoded hash using MD5.
|
||||||
inline std::string MD5(const std::string& input) {
|
inline std::string MD5(absl::string_view input) {
|
||||||
return ComputeDigest(DIGEST_MD5, input);
|
return ComputeDigest(DIGEST_MD5, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +104,7 @@ size_t ComputeHmac(MessageDigest* digest,
|
||||||
// Like the previous function, but creates a digest implementation based on
|
// Like the previous function, but creates a digest implementation based on
|
||||||
// the desired digest name `alg`, e.g. DIGEST_SHA_1. Returns 0 if there is no
|
// the desired digest name `alg`, e.g. DIGEST_SHA_1. Returns 0 if there is no
|
||||||
// digest with the given name.
|
// digest with the given name.
|
||||||
size_t ComputeHmac(const std::string& alg,
|
size_t ComputeHmac(absl::string_view alg,
|
||||||
const void* key,
|
const void* key,
|
||||||
size_t key_len,
|
size_t key_len,
|
||||||
const void* input,
|
const void* input,
|
||||||
|
@ -112,18 +114,18 @@ size_t ComputeHmac(const std::string& alg,
|
||||||
// Computes the HMAC of `input` using the `digest` hash implementation and `key`
|
// Computes the HMAC of `input` using the `digest` hash implementation and `key`
|
||||||
// to key the HMAC, and returns it as a hex-encoded string.
|
// to key the HMAC, and returns it as a hex-encoded string.
|
||||||
std::string ComputeHmac(MessageDigest* digest,
|
std::string ComputeHmac(MessageDigest* digest,
|
||||||
const std::string& key,
|
absl::string_view key,
|
||||||
const std::string& input);
|
absl::string_view input);
|
||||||
// Like the previous function, but creates a digest implementation based on
|
// Like the previous function, but creates a digest implementation based on
|
||||||
// the desired digest name `alg`, e.g. DIGEST_SHA_1. Returns empty string if
|
// the desired digest name `alg`, e.g. DIGEST_SHA_1. Returns empty string if
|
||||||
// there is no digest with the given name.
|
// there is no digest with the given name.
|
||||||
std::string ComputeHmac(const std::string& alg,
|
std::string ComputeHmac(absl::string_view alg,
|
||||||
const std::string& key,
|
absl::string_view key,
|
||||||
const std::string& input);
|
absl::string_view input);
|
||||||
// Like the previous function, but returns an explicit result code.
|
// Like the previous function, but returns an explicit result code.
|
||||||
bool ComputeHmac(const std::string& alg,
|
bool ComputeHmac(absl::string_view alg,
|
||||||
const std::string& key,
|
absl::string_view key,
|
||||||
const std::string& input,
|
absl::string_view input,
|
||||||
std::string* output);
|
std::string* output);
|
||||||
|
|
||||||
} // namespace rtc
|
} // namespace rtc
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include "rtc_base/net_helper.h"
|
#include "rtc_base/net_helper.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
namespace cricket {
|
namespace cricket {
|
||||||
|
|
||||||
const char UDP_PROTOCOL_NAME[] = "udp";
|
const char UDP_PROTOCOL_NAME[] = "udp";
|
||||||
|
@ -17,7 +19,7 @@ const char TCP_PROTOCOL_NAME[] = "tcp";
|
||||||
const char SSLTCP_PROTOCOL_NAME[] = "ssltcp";
|
const char SSLTCP_PROTOCOL_NAME[] = "ssltcp";
|
||||||
const char TLS_PROTOCOL_NAME[] = "tls";
|
const char TLS_PROTOCOL_NAME[] = "tls";
|
||||||
|
|
||||||
int GetProtocolOverhead(const std::string& protocol) {
|
int GetProtocolOverhead(absl::string_view protocol) {
|
||||||
if (protocol == TCP_PROTOCOL_NAME || protocol == SSLTCP_PROTOCOL_NAME) {
|
if (protocol == TCP_PROTOCOL_NAME || protocol == SSLTCP_PROTOCOL_NAME) {
|
||||||
return kTcpHeaderSize;
|
return kTcpHeaderSize;
|
||||||
} else if (protocol == UDP_PROTOCOL_NAME) {
|
} else if (protocol == UDP_PROTOCOL_NAME) {
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
// This header contains helper functions and constants used by different types
|
// This header contains helper functions and constants used by different types
|
||||||
// of transports.
|
// of transports.
|
||||||
namespace cricket {
|
namespace cricket {
|
||||||
|
@ -25,7 +27,7 @@ constexpr int kTcpHeaderSize = 20;
|
||||||
constexpr int kUdpHeaderSize = 8;
|
constexpr int kUdpHeaderSize = 8;
|
||||||
|
|
||||||
// Get the transport layer overhead per packet based on the protocol.
|
// Get the transport layer overhead per packet based on the protocol.
|
||||||
int GetProtocolOverhead(const std::string& protocol);
|
int GetProtocolOverhead(absl::string_view protocol);
|
||||||
|
|
||||||
} // namespace cricket
|
} // namespace cricket
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include "rtc_base/network.h"
|
#include "rtc_base/network.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
#if defined(WEBRTC_POSIX)
|
#if defined(WEBRTC_POSIX)
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#endif // WEBRTC_POSIX
|
#endif // WEBRTC_POSIX
|
||||||
|
@ -190,7 +192,7 @@ const char kPublicIPv4Host[] = "8.8.8.8";
|
||||||
const char kPublicIPv6Host[] = "2001:4860:4860::8888";
|
const char kPublicIPv6Host[] = "2001:4860:4860::8888";
|
||||||
const int kPublicPort = 53; // DNS port.
|
const int kPublicPort = 53; // DNS port.
|
||||||
|
|
||||||
std::string MakeNetworkKey(const std::string& name,
|
std::string MakeNetworkKey(absl::string_view name,
|
||||||
const IPAddress& prefix,
|
const IPAddress& prefix,
|
||||||
int prefix_length) {
|
int prefix_length) {
|
||||||
rtc::StringBuilder ost;
|
rtc::StringBuilder ost;
|
||||||
|
@ -1055,8 +1057,8 @@ NetworkBindingResult BasicNetworkManager::BindSocketToNetwork(
|
||||||
return network_monitor_->BindSocketToNetwork(socket_fd, address, if_name);
|
return network_monitor_->BindSocketToNetwork(socket_fd, address, if_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Network::Network(const std::string& name,
|
Network::Network(absl::string_view name,
|
||||||
const std::string& desc,
|
absl::string_view desc,
|
||||||
const IPAddress& prefix,
|
const IPAddress& prefix,
|
||||||
int prefix_length)
|
int prefix_length)
|
||||||
: name_(name),
|
: name_(name),
|
||||||
|
@ -1073,8 +1075,8 @@ Network::Network(const std::string& name,
|
||||||
add_network_cost_to_vpn_(
|
add_network_cost_to_vpn_(
|
||||||
webrtc::field_trial::IsEnabled("WebRTC-AddNetworkCostToVpn")) {}
|
webrtc::field_trial::IsEnabled("WebRTC-AddNetworkCostToVpn")) {}
|
||||||
|
|
||||||
Network::Network(const std::string& name,
|
Network::Network(absl::string_view name,
|
||||||
const std::string& desc,
|
absl::string_view desc,
|
||||||
const IPAddress& prefix,
|
const IPAddress& prefix,
|
||||||
int prefix_length,
|
int prefix_length,
|
||||||
AdapterType type)
|
AdapterType type)
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
#include "rtc_base/ip_address.h"
|
#include "rtc_base/ip_address.h"
|
||||||
|
@ -51,7 +52,7 @@ const int kDefaultNetworkIgnoreMask = ADAPTER_TYPE_LOOPBACK;
|
||||||
// Makes a string key for this network. Used in the network manager's maps.
|
// Makes a string key for this network. Used in the network manager's maps.
|
||||||
// Network objects are keyed on interface name, network prefix and the
|
// Network objects are keyed on interface name, network prefix and the
|
||||||
// length of that prefix.
|
// length of that prefix.
|
||||||
std::string MakeNetworkKey(const std::string& name,
|
std::string MakeNetworkKey(absl::string_view name,
|
||||||
const IPAddress& prefix,
|
const IPAddress& prefix,
|
||||||
int prefix_length);
|
int prefix_length);
|
||||||
|
|
||||||
|
@ -350,13 +351,13 @@ class RTC_EXPORT BasicNetworkManager : public NetworkManagerBase,
|
||||||
// Represents a Unix-type network interface, with a name and single address.
|
// Represents a Unix-type network interface, with a name and single address.
|
||||||
class RTC_EXPORT Network {
|
class RTC_EXPORT Network {
|
||||||
public:
|
public:
|
||||||
Network(const std::string& name,
|
Network(absl::string_view name,
|
||||||
const std::string& description,
|
absl::string_view description,
|
||||||
const IPAddress& prefix,
|
const IPAddress& prefix,
|
||||||
int prefix_length);
|
int prefix_length);
|
||||||
|
|
||||||
Network(const std::string& name,
|
Network(absl::string_view name,
|
||||||
const std::string& description,
|
absl::string_view description,
|
||||||
const IPAddress& prefix,
|
const IPAddress& prefix,
|
||||||
int prefix_length,
|
int prefix_length,
|
||||||
AdapterType type);
|
AdapterType type);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/network_constants.h"
|
#include "rtc_base/network_constants.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
@ -78,12 +79,12 @@ class NetworkMonitorInterface {
|
||||||
virtual void Start() = 0;
|
virtual void Start() = 0;
|
||||||
virtual void Stop() = 0;
|
virtual void Stop() = 0;
|
||||||
|
|
||||||
virtual AdapterType GetAdapterType(const std::string& interface_name) = 0;
|
virtual AdapterType GetAdapterType(absl::string_view interface_name) = 0;
|
||||||
virtual AdapterType GetVpnUnderlyingAdapterType(
|
virtual AdapterType GetVpnUnderlyingAdapterType(
|
||||||
const std::string& interface_name) = 0;
|
absl::string_view interface_name) = 0;
|
||||||
|
|
||||||
virtual NetworkPreference GetNetworkPreference(
|
virtual NetworkPreference GetNetworkPreference(
|
||||||
const std::string& interface_name) = 0;
|
absl::string_view interface_name) = 0;
|
||||||
|
|
||||||
// Does `this` NetworkMonitorInterface implement BindSocketToNetwork?
|
// Does `this` NetworkMonitorInterface implement BindSocketToNetwork?
|
||||||
// Only Android returns true.
|
// Only Android returns true.
|
||||||
|
@ -94,7 +95,7 @@ class NetworkMonitorInterface {
|
||||||
virtual NetworkBindingResult BindSocketToNetwork(
|
virtual NetworkBindingResult BindSocketToNetwork(
|
||||||
int socket_fd,
|
int socket_fd,
|
||||||
const IPAddress& address,
|
const IPAddress& address,
|
||||||
const std::string& interface_name) {
|
absl::string_view interface_name) {
|
||||||
return NetworkBindingResult::NOT_IMPLEMENTED;
|
return NetworkBindingResult::NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +108,7 @@ class NetworkMonitorInterface {
|
||||||
// These specific use case this was added for was a phone with two SIM cards,
|
// These specific use case this was added for was a phone with two SIM cards,
|
||||||
// where attempting to use all interfaces returned from getifaddrs caused the
|
// where attempting to use all interfaces returned from getifaddrs caused the
|
||||||
// connection to be dropped.
|
// connection to be dropped.
|
||||||
virtual bool IsAdapterAvailable(const std::string& interface_name) {
|
virtual bool IsAdapterAvailable(absl::string_view interface_name) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "absl/algorithm/container.h"
|
#include "absl/algorithm/container.h"
|
||||||
#include "absl/strings/match.h"
|
#include "absl/strings/match.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/net_helpers.h"
|
#include "rtc_base/net_helpers.h"
|
||||||
#include "rtc_base/network_monitor.h"
|
#include "rtc_base/network_monitor.h"
|
||||||
|
@ -45,7 +46,7 @@ namespace rtc {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
IPAddress IPFromString(const std::string& str) {
|
IPAddress IPFromString(absl::string_view str) {
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
RTC_CHECK(IPFromString(str, &ip));
|
RTC_CHECK(IPFromString(str, &ip));
|
||||||
return ip;
|
return ip;
|
||||||
|
@ -56,7 +57,7 @@ class FakeNetworkMonitor : public NetworkMonitorInterface {
|
||||||
void Start() override { started_ = true; }
|
void Start() override { started_ = true; }
|
||||||
void Stop() override { started_ = false; }
|
void Stop() override { started_ = false; }
|
||||||
bool started() { return started_; }
|
bool started() { return started_; }
|
||||||
AdapterType GetAdapterType(const std::string& if_name) override {
|
AdapterType GetAdapterType(absl::string_view if_name) override {
|
||||||
// Note that the name matching rules are different from the
|
// Note that the name matching rules are different from the
|
||||||
// GetAdapterTypeFromName in NetworkManager.
|
// GetAdapterTypeFromName in NetworkManager.
|
||||||
if (absl::StartsWith(if_name, "wifi")) {
|
if (absl::StartsWith(if_name, "wifi")) {
|
||||||
|
@ -67,14 +68,14 @@ class FakeNetworkMonitor : public NetworkMonitorInterface {
|
||||||
}
|
}
|
||||||
return ADAPTER_TYPE_UNKNOWN;
|
return ADAPTER_TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
AdapterType GetVpnUnderlyingAdapterType(const std::string& if_name) override {
|
AdapterType GetVpnUnderlyingAdapterType(absl::string_view if_name) override {
|
||||||
return ADAPTER_TYPE_UNKNOWN;
|
return ADAPTER_TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
NetworkPreference GetNetworkPreference(const std::string& if_name) override {
|
NetworkPreference GetNetworkPreference(absl::string_view if_name) override {
|
||||||
return NetworkPreference::NEUTRAL;
|
return NetworkPreference::NEUTRAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsAdapterAvailable(const std::string& if_name) override {
|
bool IsAdapterAvailable(absl::string_view if_name) override {
|
||||||
return absl::c_count(unavailable_adapters_, if_name) == 0;
|
return absl::c_count(unavailable_adapters_, if_name) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,16 +86,15 @@ class FakeNetworkMonitor : public NetworkMonitorInterface {
|
||||||
|
|
||||||
bool SupportsBindSocketToNetwork() const override { return true; }
|
bool SupportsBindSocketToNetwork() const override { return true; }
|
||||||
|
|
||||||
NetworkBindingResult BindSocketToNetwork(
|
NetworkBindingResult BindSocketToNetwork(int socket_fd,
|
||||||
int socket_fd,
|
const IPAddress& address,
|
||||||
const IPAddress& address,
|
absl::string_view if_name) override {
|
||||||
const std::string& if_name) override {
|
|
||||||
if (absl::c_count(addresses_, address) > 0) {
|
if (absl::c_count(addresses_, address) > 0) {
|
||||||
return NetworkBindingResult::SUCCESS;
|
return NetworkBindingResult::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto const& iter : adapters_) {
|
for (auto const& iter : adapters_) {
|
||||||
if (if_name.find(iter) != std::string::npos) {
|
if (if_name.find(iter) != absl::string_view::npos) {
|
||||||
return NetworkBindingResult::SUCCESS;
|
return NetworkBindingResult::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ class NetworkTest : public ::testing::Test, public sigslot::has_slots<> {
|
||||||
include_ignored, networks);
|
include_ignored, networks);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sockaddr_in6* CreateIpv6Addr(const std::string& ip_string,
|
struct sockaddr_in6* CreateIpv6Addr(absl::string_view ip_string,
|
||||||
uint32_t scope_id) {
|
uint32_t scope_id) {
|
||||||
struct sockaddr_in6* ipv6_addr =
|
struct sockaddr_in6* ipv6_addr =
|
||||||
static_cast<struct sockaddr_in6*>(malloc(sizeof(struct sockaddr_in6)));
|
static_cast<struct sockaddr_in6*>(malloc(sizeof(struct sockaddr_in6)));
|
||||||
|
@ -225,8 +225,8 @@ class NetworkTest : public ::testing::Test, public sigslot::has_slots<> {
|
||||||
// Pointers created here need to be released via ReleaseIfAddrs.
|
// Pointers created here need to be released via ReleaseIfAddrs.
|
||||||
struct ifaddrs* AddIpv6Address(struct ifaddrs* list,
|
struct ifaddrs* AddIpv6Address(struct ifaddrs* list,
|
||||||
char* if_name,
|
char* if_name,
|
||||||
const std::string& ipv6_address,
|
absl::string_view ipv6_address,
|
||||||
const std::string& ipv6_netmask,
|
absl::string_view ipv6_netmask,
|
||||||
uint32_t scope_id) {
|
uint32_t scope_id) {
|
||||||
struct ifaddrs* if_addr = new struct ifaddrs;
|
struct ifaddrs* if_addr = new struct ifaddrs;
|
||||||
memset(if_addr, 0, sizeof(struct ifaddrs));
|
memset(if_addr, 0, sizeof(struct ifaddrs));
|
||||||
|
@ -241,8 +241,8 @@ class NetworkTest : public ::testing::Test, public sigslot::has_slots<> {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ifaddrs* InstallIpv6Network(char* if_name,
|
struct ifaddrs* InstallIpv6Network(char* if_name,
|
||||||
const std::string& ipv6_address,
|
absl::string_view ipv6_address,
|
||||||
const std::string& ipv6_mask,
|
absl::string_view ipv6_mask,
|
||||||
BasicNetworkManager& network_manager) {
|
BasicNetworkManager& network_manager) {
|
||||||
ifaddrs* addr_list = nullptr;
|
ifaddrs* addr_list = nullptr;
|
||||||
addr_list = AddIpv6Address(addr_list, if_name, ipv6_address, ipv6_mask, 0);
|
addr_list = AddIpv6Address(addr_list, if_name, ipv6_address, ipv6_mask, 0);
|
||||||
|
@ -254,7 +254,7 @@ class NetworkTest : public ::testing::Test, public sigslot::has_slots<> {
|
||||||
return addr_list;
|
return addr_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sockaddr_in* CreateIpv4Addr(const std::string& ip_string) {
|
struct sockaddr_in* CreateIpv4Addr(absl::string_view ip_string) {
|
||||||
struct sockaddr_in* ipv4_addr =
|
struct sockaddr_in* ipv4_addr =
|
||||||
static_cast<struct sockaddr_in*>(malloc(sizeof(struct sockaddr_in)));
|
static_cast<struct sockaddr_in*>(malloc(sizeof(struct sockaddr_in)));
|
||||||
memset(ipv4_addr, 0, sizeof(struct sockaddr_in));
|
memset(ipv4_addr, 0, sizeof(struct sockaddr_in));
|
||||||
|
@ -268,8 +268,8 @@ class NetworkTest : public ::testing::Test, public sigslot::has_slots<> {
|
||||||
// Pointers created here need to be released via ReleaseIfAddrs.
|
// Pointers created here need to be released via ReleaseIfAddrs.
|
||||||
struct ifaddrs* AddIpv4Address(struct ifaddrs* list,
|
struct ifaddrs* AddIpv4Address(struct ifaddrs* list,
|
||||||
char* if_name,
|
char* if_name,
|
||||||
const std::string& ipv4_address,
|
absl::string_view ipv4_address,
|
||||||
const std::string& ipv4_netmask) {
|
absl::string_view ipv4_netmask) {
|
||||||
struct ifaddrs* if_addr = new struct ifaddrs;
|
struct ifaddrs* if_addr = new struct ifaddrs;
|
||||||
memset(if_addr, 0, sizeof(struct ifaddrs));
|
memset(if_addr, 0, sizeof(struct ifaddrs));
|
||||||
if_addr->ifa_name = if_name;
|
if_addr->ifa_name = if_name;
|
||||||
|
@ -283,8 +283,8 @@ class NetworkTest : public ::testing::Test, public sigslot::has_slots<> {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ifaddrs* InstallIpv4Network(char* if_name,
|
struct ifaddrs* InstallIpv4Network(char* if_name,
|
||||||
const std::string& ipv4_address,
|
absl::string_view ipv4_address,
|
||||||
const std::string& ipv4_mask,
|
absl::string_view ipv4_mask,
|
||||||
BasicNetworkManager& network_manager) {
|
BasicNetworkManager& network_manager) {
|
||||||
ifaddrs* addr_list = nullptr;
|
ifaddrs* addr_list = nullptr;
|
||||||
addr_list = AddIpv4Address(addr_list, if_name, ipv4_address, ipv4_mask);
|
addr_list = AddIpv4Address(addr_list, if_name, ipv4_address, ipv4_mask);
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <openssl/bio.h>
|
#include <openssl/bio.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#ifdef OPENSSL_IS_BORINGSSL
|
#ifdef OPENSSL_IS_BORINGSSL
|
||||||
#include <openssl/pool.h>
|
#include <openssl/pool.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -744,7 +746,7 @@ void OpenSSLAdapter::OnCloseEvent(Socket* socket, int err) {
|
||||||
AsyncSocketAdapter::OnCloseEvent(socket, err);
|
AsyncSocketAdapter::OnCloseEvent(socket, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenSSLAdapter::SSLPostConnectionCheck(SSL* ssl, const std::string& host) {
|
bool OpenSSLAdapter::SSLPostConnectionCheck(SSL* ssl, absl::string_view host) {
|
||||||
bool is_valid_cert_name =
|
bool is_valid_cert_name =
|
||||||
openssl::VerifyPeerCertMatchesHost(ssl, host) &&
|
openssl::VerifyPeerCertMatchesHost(ssl, host) &&
|
||||||
(SSL_get_verify_result(ssl) == X509_V_OK || custom_cert_verifier_status_);
|
(SSL_get_verify_result(ssl) == X509_V_OK || custom_cert_verifier_status_);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/buffer.h"
|
#include "rtc_base/buffer.h"
|
||||||
#include "rtc_base/message_handler.h"
|
#include "rtc_base/message_handler.h"
|
||||||
#ifdef OPENSSL_IS_BORINGSSL
|
#ifdef OPENSSL_IS_BORINGSSL
|
||||||
|
@ -116,7 +117,7 @@ class OpenSSLAdapter final : public SSLAdapter,
|
||||||
// an output parameter filled with the result of SSL_get_error.
|
// an output parameter filled with the result of SSL_get_error.
|
||||||
int DoSslWrite(const void* pv, size_t cb, int* error);
|
int DoSslWrite(const void* pv, size_t cb, int* error);
|
||||||
void OnMessage(Message* msg) override;
|
void OnMessage(Message* msg) override;
|
||||||
bool SSLPostConnectionCheck(SSL* ssl, const std::string& host);
|
bool SSLPostConnectionCheck(SSL* ssl, absl::string_view host);
|
||||||
|
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
// In debug builds, logs info about the state of the SSL connection.
|
// In debug builds, logs info about the state of the SSL connection.
|
||||||
|
|
|
@ -10,12 +10,13 @@
|
||||||
|
|
||||||
#include "rtc_base/openssl_digest.h"
|
#include "rtc_base/openssl_digest.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h" // RTC_DCHECK, RTC_CHECK
|
#include "rtc_base/checks.h" // RTC_DCHECK, RTC_CHECK
|
||||||
#include "rtc_base/openssl.h"
|
#include "rtc_base/openssl.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
OpenSSLDigest::OpenSSLDigest(const std::string& algorithm) {
|
OpenSSLDigest::OpenSSLDigest(absl::string_view algorithm) {
|
||||||
ctx_ = EVP_MD_CTX_new();
|
ctx_ = EVP_MD_CTX_new();
|
||||||
RTC_CHECK(ctx_ != nullptr);
|
RTC_CHECK(ctx_ != nullptr);
|
||||||
EVP_MD_CTX_init(ctx_);
|
EVP_MD_CTX_init(ctx_);
|
||||||
|
@ -55,7 +56,7 @@ size_t OpenSSLDigest::Finish(void* buf, size_t len) {
|
||||||
return md_len;
|
return md_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenSSLDigest::GetDigestEVP(const std::string& algorithm,
|
bool OpenSSLDigest::GetDigestEVP(absl::string_view algorithm,
|
||||||
const EVP_MD** mdp) {
|
const EVP_MD** mdp) {
|
||||||
const EVP_MD* md;
|
const EVP_MD* md;
|
||||||
if (algorithm == DIGEST_MD5) {
|
if (algorithm == DIGEST_MD5) {
|
||||||
|
@ -105,8 +106,7 @@ bool OpenSSLDigest::GetDigestName(const EVP_MD* md, std::string* algorithm) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenSSLDigest::GetDigestSize(const std::string& algorithm,
|
bool OpenSSLDigest::GetDigestSize(absl::string_view algorithm, size_t* length) {
|
||||||
size_t* length) {
|
|
||||||
const EVP_MD* md;
|
const EVP_MD* md;
|
||||||
if (!GetDigestEVP(algorithm, &md))
|
if (!GetDigestEVP(algorithm, &md))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/message_digest.h"
|
#include "rtc_base/message_digest.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
@ -24,7 +25,7 @@ namespace rtc {
|
||||||
class OpenSSLDigest final : public MessageDigest {
|
class OpenSSLDigest final : public MessageDigest {
|
||||||
public:
|
public:
|
||||||
// Creates an OpenSSLDigest with `algorithm` as the hash algorithm.
|
// Creates an OpenSSLDigest with `algorithm` as the hash algorithm.
|
||||||
explicit OpenSSLDigest(const std::string& algorithm);
|
explicit OpenSSLDigest(absl::string_view algorithm);
|
||||||
~OpenSSLDigest() override;
|
~OpenSSLDigest() override;
|
||||||
// Returns the digest output size (e.g. 16 bytes for MD5).
|
// Returns the digest output size (e.g. 16 bytes for MD5).
|
||||||
size_t Size() const override;
|
size_t Size() const override;
|
||||||
|
@ -34,11 +35,11 @@ class OpenSSLDigest final : public MessageDigest {
|
||||||
size_t Finish(void* buf, size_t len) override;
|
size_t Finish(void* buf, size_t len) override;
|
||||||
|
|
||||||
// Helper function to look up a digest's EVP by name.
|
// Helper function to look up a digest's EVP by name.
|
||||||
static bool GetDigestEVP(const std::string& algorithm, const EVP_MD** md);
|
static bool GetDigestEVP(absl::string_view algorithm, const EVP_MD** md);
|
||||||
// Helper function to look up a digest's name by EVP.
|
// Helper function to look up a digest's name by EVP.
|
||||||
static bool GetDigestName(const EVP_MD* md, std::string* algorithm);
|
static bool GetDigestName(const EVP_MD* md, std::string* algorithm);
|
||||||
// Helper function to get the length of a digest.
|
// Helper function to get the length of a digest.
|
||||||
static bool GetDigestSize(const std::string& algorithm, size_t* len);
|
static bool GetDigestSize(absl::string_view algorithm, size_t* len);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EVP_MD_CTX* ctx_ = nullptr;
|
EVP_MD_CTX* ctx_ = nullptr;
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
// Must be included first before openssl headers.
|
// Must be included first before openssl headers.
|
||||||
#include "rtc_base/win32.h" // NOLINT
|
#include "rtc_base/win32.h" // NOLINT
|
||||||
|
@ -103,7 +105,7 @@ std::unique_ptr<OpenSSLKeyPair> OpenSSLKeyPair::Generate(
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<OpenSSLKeyPair> OpenSSLKeyPair::FromPrivateKeyPEMString(
|
std::unique_ptr<OpenSSLKeyPair> OpenSSLKeyPair::FromPrivateKeyPEMString(
|
||||||
const std::string& pem_string) {
|
absl::string_view pem_string) {
|
||||||
BIO* bio =
|
BIO* bio =
|
||||||
BIO_new_mem_buf(const_cast<char*>(pem_string.data()), pem_string.size());
|
BIO_new_mem_buf(const_cast<char*>(pem_string.data()), pem_string.size());
|
||||||
if (!bio) {
|
if (!bio) {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/ssl_identity.h"
|
#include "rtc_base/ssl_identity.h"
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ class OpenSSLKeyPair final {
|
||||||
// Constructs a key pair from the private key PEM string. This must not result
|
// Constructs a key pair from the private key PEM string. This must not result
|
||||||
// in missing public key parameters. Returns null on error.
|
// in missing public key parameters. Returns null on error.
|
||||||
static std::unique_ptr<OpenSSLKeyPair> FromPrivateKeyPEMString(
|
static std::unique_ptr<OpenSSLKeyPair> FromPrivateKeyPEMString(
|
||||||
const std::string& pem_string);
|
absl::string_view pem_string);
|
||||||
|
|
||||||
~OpenSSLKeyPair();
|
~OpenSSLKeyPair();
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "rtc_base/openssl_session_cache.h"
|
#include "rtc_base/openssl_session_cache.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/openssl.h"
|
#include "rtc_base/openssl.h"
|
||||||
|
|
||||||
|
@ -30,16 +31,16 @@ OpenSSLSessionCache::~OpenSSLSessionCache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_SESSION* OpenSSLSessionCache::LookupSession(
|
SSL_SESSION* OpenSSLSessionCache::LookupSession(
|
||||||
const std::string& hostname) const {
|
absl::string_view hostname) const {
|
||||||
auto it = sessions_.find(hostname);
|
auto it = sessions_.find(hostname);
|
||||||
return (it != sessions_.end()) ? it->second : nullptr;
|
return (it != sessions_.end()) ? it->second : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenSSLSessionCache::AddSession(const std::string& hostname,
|
void OpenSSLSessionCache::AddSession(absl::string_view hostname,
|
||||||
SSL_SESSION* new_session) {
|
SSL_SESSION* new_session) {
|
||||||
SSL_SESSION* old_session = LookupSession(hostname);
|
SSL_SESSION* old_session = LookupSession(hostname);
|
||||||
SSL_SESSION_free(old_session);
|
SSL_SESSION_free(old_session);
|
||||||
sessions_[hostname] = new_session;
|
sessions_.insert_or_assign(std::string(hostname), new_session);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_CTX* OpenSSLSessionCache::GetSSLContext() const {
|
SSL_CTX* OpenSSLSessionCache::GetSSLContext() const {
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/ssl_stream_adapter.h"
|
#include "rtc_base/ssl_stream_adapter.h"
|
||||||
|
#include "rtc_base/string_utils.h"
|
||||||
|
|
||||||
#ifndef OPENSSL_IS_BORINGSSL
|
#ifndef OPENSSL_IS_BORINGSSL
|
||||||
typedef struct ssl_session_st SSL_SESSION;
|
typedef struct ssl_session_st SSL_SESSION;
|
||||||
|
@ -40,10 +42,10 @@ class OpenSSLSessionCache final {
|
||||||
OpenSSLSessionCache& operator=(const OpenSSLSessionCache&) = delete;
|
OpenSSLSessionCache& operator=(const OpenSSLSessionCache&) = delete;
|
||||||
|
|
||||||
// Looks up a session by hostname. The returned SSL_SESSION is not up_refed.
|
// Looks up a session by hostname. The returned SSL_SESSION is not up_refed.
|
||||||
SSL_SESSION* LookupSession(const std::string& hostname) const;
|
SSL_SESSION* LookupSession(absl::string_view hostname) const;
|
||||||
// Adds a session to the cache, and up_refs it. Any existing session with the
|
// Adds a session to the cache, and up_refs it. Any existing session with the
|
||||||
// same hostname is replaced.
|
// same hostname is replaced.
|
||||||
void AddSession(const std::string& hostname, SSL_SESSION* session);
|
void AddSession(absl::string_view hostname, SSL_SESSION* session);
|
||||||
// Returns the true underlying SSL Context that holds these cached sessions.
|
// Returns the true underlying SSL Context that holds these cached sessions.
|
||||||
SSL_CTX* GetSSLContext() const;
|
SSL_CTX* GetSSLContext() const;
|
||||||
// The SSL Mode tht the OpenSSLSessionCache was constructed with. This cannot
|
// The SSL Mode tht the OpenSSLSessionCache was constructed with. This cannot
|
||||||
|
@ -61,7 +63,7 @@ class OpenSSLSessionCache final {
|
||||||
// Map of hostnames to SSL_SESSIONs; holds references to the SSL_SESSIONs,
|
// Map of hostnames to SSL_SESSIONs; holds references to the SSL_SESSIONs,
|
||||||
// which are cleaned up when the factory is destroyed.
|
// which are cleaned up when the factory is destroyed.
|
||||||
// TODO(juberti): Add LRU eviction to keep the cache from growing forever.
|
// TODO(juberti): Add LRU eviction to keep the cache from growing forever.
|
||||||
std::map<std::string, SSL_SESSION*> sessions_;
|
std::map<std::string, SSL_SESSION*, rtc::AbslStringViewCmp> sessions_;
|
||||||
// The cache should never be copied or assigned directly.
|
// The cache should never be copied or assigned directly.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include <openssl/rand.h>
|
#include <openssl/rand.h>
|
||||||
#include <openssl/tls1.h>
|
#include <openssl/tls1.h>
|
||||||
#include <openssl/x509v3.h>
|
#include <openssl/x509v3.h>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#ifndef OPENSSL_IS_BORINGSSL
|
#ifndef OPENSSL_IS_BORINGSSL
|
||||||
#include <openssl/dtls1.h>
|
#include <openssl/dtls1.h>
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
@ -327,7 +329,7 @@ void OpenSSLStreamAdapter::SetServerRole(SSLRole role) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenSSLStreamAdapter::SetPeerCertificateDigest(
|
bool OpenSSLStreamAdapter::SetPeerCertificateDigest(
|
||||||
const std::string& digest_alg,
|
absl::string_view digest_alg,
|
||||||
const unsigned char* digest_val,
|
const unsigned char* digest_val,
|
||||||
size_t digest_len,
|
size_t digest_len,
|
||||||
SSLPeerCertificateDigestError* error) {
|
SSLPeerCertificateDigestError* error) {
|
||||||
|
@ -353,7 +355,7 @@ bool OpenSSLStreamAdapter::SetPeerCertificateDigest(
|
||||||
}
|
}
|
||||||
|
|
||||||
peer_certificate_digest_value_.SetData(digest_val, digest_len);
|
peer_certificate_digest_value_.SetData(digest_val, digest_len);
|
||||||
peer_certificate_digest_algorithm_ = digest_alg;
|
peer_certificate_digest_algorithm_ = std::string(digest_alg);
|
||||||
|
|
||||||
if (!peer_cert_chain_) {
|
if (!peer_cert_chain_) {
|
||||||
// Normal case, where the digest is set before we obtain the certificate
|
// Normal case, where the digest is set before we obtain the certificate
|
||||||
|
@ -445,15 +447,15 @@ bool OpenSSLStreamAdapter::GetSslVersionBytes(int* version) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key Extractor interface
|
// Key Extractor interface
|
||||||
bool OpenSSLStreamAdapter::ExportKeyingMaterial(const std::string& label,
|
bool OpenSSLStreamAdapter::ExportKeyingMaterial(absl::string_view label,
|
||||||
const uint8_t* context,
|
const uint8_t* context,
|
||||||
size_t context_len,
|
size_t context_len,
|
||||||
bool use_context,
|
bool use_context,
|
||||||
uint8_t* result,
|
uint8_t* result,
|
||||||
size_t result_len) {
|
size_t result_len) {
|
||||||
if (SSL_export_keying_material(ssl_, result, result_len, label.c_str(),
|
if (SSL_export_keying_material(ssl_, result, result_len, label.data(),
|
||||||
label.length(), const_cast<uint8_t*>(context),
|
label.length(), context, context_len,
|
||||||
context_len, use_context) != 1) {
|
use_context) != 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -1263,7 +1265,7 @@ bool OpenSSLStreamAdapter::IsAcceptableCipher(int cipher, KeyType key_type) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenSSLStreamAdapter::IsAcceptableCipher(const std::string& cipher,
|
bool OpenSSLStreamAdapter::IsAcceptableCipher(absl::string_view cipher,
|
||||||
KeyType key_type) {
|
KeyType key_type) {
|
||||||
if (key_type == KT_RSA) {
|
if (key_type == KT_RSA) {
|
||||||
for (const cipher_list& c : OK_RSA_ciphers) {
|
for (const cipher_list& c : OK_RSA_ciphers) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
#include "rtc_base/buffer.h"
|
#include "rtc_base/buffer.h"
|
||||||
#ifdef OPENSSL_IS_BORINGSSL
|
#ifdef OPENSSL_IS_BORINGSSL
|
||||||
|
@ -80,7 +81,7 @@ class OpenSSLStreamAdapter final : public SSLStreamAdapter {
|
||||||
// Default argument is for compatibility
|
// Default argument is for compatibility
|
||||||
void SetServerRole(SSLRole role = SSL_SERVER) override;
|
void SetServerRole(SSLRole role = SSL_SERVER) override;
|
||||||
bool SetPeerCertificateDigest(
|
bool SetPeerCertificateDigest(
|
||||||
const std::string& digest_alg,
|
absl::string_view digest_alg,
|
||||||
const unsigned char* digest_val,
|
const unsigned char* digest_val,
|
||||||
size_t digest_len,
|
size_t digest_len,
|
||||||
SSLPeerCertificateDigestError* error = nullptr) override;
|
SSLPeerCertificateDigestError* error = nullptr) override;
|
||||||
|
@ -113,7 +114,7 @@ class OpenSSLStreamAdapter final : public SSLStreamAdapter {
|
||||||
SSLProtocolVersion GetSslVersion() const override;
|
SSLProtocolVersion GetSslVersion() const override;
|
||||||
bool GetSslVersionBytes(int* version) const override;
|
bool GetSslVersionBytes(int* version) const override;
|
||||||
// Key Extractor interface
|
// Key Extractor interface
|
||||||
bool ExportKeyingMaterial(const std::string& label,
|
bool ExportKeyingMaterial(absl::string_view label,
|
||||||
const uint8_t* context,
|
const uint8_t* context,
|
||||||
size_t context_len,
|
size_t context_len,
|
||||||
bool use_context,
|
bool use_context,
|
||||||
|
@ -130,7 +131,7 @@ class OpenSSLStreamAdapter final : public SSLStreamAdapter {
|
||||||
static bool IsBoringSsl();
|
static bool IsBoringSsl();
|
||||||
|
|
||||||
static bool IsAcceptableCipher(int cipher, KeyType key_type);
|
static bool IsAcceptableCipher(int cipher, KeyType key_type);
|
||||||
static bool IsAcceptableCipher(const std::string& cipher, KeyType key_type);
|
static bool IsAcceptableCipher(absl::string_view cipher, KeyType key_type);
|
||||||
|
|
||||||
// Use our timeutils.h source of timing in BoringSSL, allowing us to test
|
// Use our timeutils.h source of timing in BoringSSL, allowing us to test
|
||||||
// using a fake clock.
|
// using a fake clock.
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "rtc_base/openssl_utility.h"
|
#include "rtc_base/openssl_utility.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
// Must be included first before openssl headers.
|
// Must be included first before openssl headers.
|
||||||
#include "rtc_base/win32.h" // NOLINT
|
#include "rtc_base/win32.h" // NOLINT
|
||||||
|
@ -184,7 +186,7 @@ bool ParseCertificate(CRYPTO_BUFFER* cert_buffer,
|
||||||
}
|
}
|
||||||
#endif // OPENSSL_IS_BORINGSSL
|
#endif // OPENSSL_IS_BORINGSSL
|
||||||
|
|
||||||
bool VerifyPeerCertMatchesHost(SSL* ssl, const std::string& host) {
|
bool VerifyPeerCertMatchesHost(SSL* ssl, absl::string_view host) {
|
||||||
if (host.empty()) {
|
if (host.empty()) {
|
||||||
RTC_DLOG(LS_ERROR) << "Hostname is empty. Cannot verify peer certificate.";
|
RTC_DLOG(LS_ERROR) << "Hostname is empty. Cannot verify peer certificate.";
|
||||||
return false;
|
return false;
|
||||||
|
@ -211,8 +213,7 @@ bool VerifyPeerCertMatchesHost(SSL* ssl, const std::string& host) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LogCertificates(ssl, x509.get());
|
LogCertificates(ssl, x509.get());
|
||||||
return X509_check_host(x509.get(), host.c_str(), host.size(), 0, nullptr) ==
|
return X509_check_host(x509.get(), host.data(), host.size(), 0, nullptr) == 1;
|
||||||
1;
|
|
||||||
#else // OPENSSL_IS_BORINGSSL
|
#else // OPENSSL_IS_BORINGSSL
|
||||||
X509* certificate = SSL_get_peer_certificate(ssl);
|
X509* certificate = SSL_get_peer_certificate(ssl);
|
||||||
if (certificate == nullptr) {
|
if (certificate == nullptr) {
|
||||||
|
@ -224,13 +225,13 @@ bool VerifyPeerCertMatchesHost(SSL* ssl, const std::string& host) {
|
||||||
LogCertificates(ssl, certificate);
|
LogCertificates(ssl, certificate);
|
||||||
|
|
||||||
bool is_valid_cert_name =
|
bool is_valid_cert_name =
|
||||||
X509_check_host(certificate, host.c_str(), host.size(), 0, nullptr) == 1;
|
X509_check_host(certificate, host.data(), host.size(), 0, nullptr) == 1;
|
||||||
X509_free(certificate);
|
X509_free(certificate);
|
||||||
return is_valid_cert_name;
|
return is_valid_cert_name;
|
||||||
#endif // !defined(OPENSSL_IS_BORINGSSL)
|
#endif // !defined(OPENSSL_IS_BORINGSSL)
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogSSLErrors(const std::string& prefix) {
|
void LogSSLErrors(absl::string_view prefix) {
|
||||||
char error_buf[200];
|
char error_buf[200];
|
||||||
unsigned long err; // NOLINT
|
unsigned long err; // NOLINT
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
// The openssl namespace holds static helper methods. All methods related
|
// The openssl namespace holds static helper methods. All methods related
|
||||||
// to OpenSSL that are commonly used and don't require global state should be
|
// to OpenSSL that are commonly used and don't require global state should be
|
||||||
|
@ -35,11 +37,11 @@ bool ParseCertificate(CRYPTO_BUFFER* cert_buffer,
|
||||||
// TODO(crbug.com/webrtc/11710): When OS certificate verification is available,
|
// TODO(crbug.com/webrtc/11710): When OS certificate verification is available,
|
||||||
// skip compiling this as it adds a dependency on OpenSSL X509 objects, which we
|
// skip compiling this as it adds a dependency on OpenSSL X509 objects, which we
|
||||||
// are trying to avoid in favor of CRYPTO_BUFFERs (see crbug.com/webrtc/11410).
|
// are trying to avoid in favor of CRYPTO_BUFFERs (see crbug.com/webrtc/11410).
|
||||||
bool VerifyPeerCertMatchesHost(SSL* ssl, const std::string& host);
|
bool VerifyPeerCertMatchesHost(SSL* ssl, absl::string_view host);
|
||||||
|
|
||||||
// Logs all the errors in the OpenSSL errror queue from the current thread. A
|
// Logs all the errors in the OpenSSL errror queue from the current thread. A
|
||||||
// prefix can be provided for context.
|
// prefix can be provided for context.
|
||||||
void LogSSLErrors(const std::string& prefix);
|
void LogSSLErrors(absl::string_view prefix);
|
||||||
|
|
||||||
#ifndef WEBRTC_EXCLUDE_BUILT_IN_SSL_ROOT_CERTS
|
#ifndef WEBRTC_EXCLUDE_BUILT_IN_SSL_ROOT_CERTS
|
||||||
// Attempt to add the certificates from the loader into the SSL_CTX. False is
|
// Attempt to add the certificates from the loader into the SSL_CTX. False is
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "api/scoped_refptr.h"
|
#include "api/scoped_refptr.h"
|
||||||
#include "rtc_base/ref_count.h"
|
#include "rtc_base/ref_count.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
@ -52,7 +53,7 @@ class RefClassWithRvalue : public RefCountInterface {
|
||||||
|
|
||||||
class RefClassWithMixedValues : public RefCountInterface {
|
class RefClassWithMixedValues : public RefCountInterface {
|
||||||
public:
|
public:
|
||||||
RefClassWithMixedValues(std::unique_ptr<A> a, int b, const std::string& c)
|
RefClassWithMixedValues(std::unique_ptr<A> a, int b, absl::string_view c)
|
||||||
: a_(std::move(a)), b_(b), c_(c) {}
|
: a_(std::move(a)), b_(b), c_(c) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "absl/base/attributes.h"
|
#include "absl/base/attributes.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "api/ref_counted_base.h"
|
#include "api/ref_counted_base.h"
|
||||||
#include "api/scoped_refptr.h"
|
#include "api/scoped_refptr.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
|
@ -35,8 +36,8 @@ class SSLIdentity;
|
||||||
// the string representations used by OpenSSL.
|
// the string representations used by OpenSSL.
|
||||||
class RTCCertificatePEM {
|
class RTCCertificatePEM {
|
||||||
public:
|
public:
|
||||||
RTCCertificatePEM(const std::string& private_key,
|
RTCCertificatePEM(absl::string_view private_key,
|
||||||
const std::string& certificate)
|
absl::string_view certificate)
|
||||||
: private_key_(private_key), certificate_(certificate) {}
|
: private_key_(private_key), certificate_(certificate) {}
|
||||||
|
|
||||||
const std::string& private_key() const { return private_key_; }
|
const std::string& private_key() const { return private_key_; }
|
||||||
|
|
|
@ -12,15 +12,17 @@
|
||||||
#pragma warning(disable : 4786)
|
#pragma warning(disable : 4786)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "rtc_base/socket_adapters.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "absl/strings/match.h"
|
#include "absl/strings/match.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/buffer.h"
|
#include "rtc_base/buffer.h"
|
||||||
#include "rtc_base/byte_buffer.h"
|
#include "rtc_base/byte_buffer.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/http_common.h"
|
#include "rtc_base/http_common.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/socket_adapters.h"
|
|
||||||
#include "rtc_base/strings/string_builder.h"
|
#include "rtc_base/strings/string_builder.h"
|
||||||
#include "rtc_base/zero_memory.h"
|
#include "rtc_base/zero_memory.h"
|
||||||
|
|
||||||
|
@ -217,9 +219,9 @@ void AsyncSSLSocket::ProcessInput(char* data, size_t* len) {
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
AsyncHttpsProxySocket::AsyncHttpsProxySocket(Socket* socket,
|
AsyncHttpsProxySocket::AsyncHttpsProxySocket(Socket* socket,
|
||||||
const std::string& user_agent,
|
absl::string_view user_agent,
|
||||||
const SocketAddress& proxy,
|
const SocketAddress& proxy,
|
||||||
const std::string& username,
|
absl::string_view username,
|
||||||
const CryptString& password)
|
const CryptString& password)
|
||||||
: BufferedReadAdapter(socket, 1024),
|
: BufferedReadAdapter(socket, 1024),
|
||||||
proxy_(proxy),
|
proxy_(proxy),
|
||||||
|
@ -470,7 +472,7 @@ void AsyncHttpsProxySocket::Error(int error) {
|
||||||
|
|
||||||
AsyncSocksProxySocket::AsyncSocksProxySocket(Socket* socket,
|
AsyncSocksProxySocket::AsyncSocksProxySocket(Socket* socket,
|
||||||
const SocketAddress& proxy,
|
const SocketAddress& proxy,
|
||||||
const std::string& username,
|
absl::string_view username,
|
||||||
const CryptString& password)
|
const CryptString& password)
|
||||||
: BufferedReadAdapter(socket, 1024),
|
: BufferedReadAdapter(socket, 1024),
|
||||||
state_(SS_ERROR),
|
state_(SS_ERROR),
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
#include "rtc_base/async_socket.h"
|
#include "rtc_base/async_socket.h"
|
||||||
#include "rtc_base/crypt_string.h"
|
#include "rtc_base/crypt_string.h"
|
||||||
|
@ -82,9 +83,9 @@ class AsyncSSLSocket : public BufferedReadAdapter {
|
||||||
class AsyncHttpsProxySocket : public BufferedReadAdapter {
|
class AsyncHttpsProxySocket : public BufferedReadAdapter {
|
||||||
public:
|
public:
|
||||||
AsyncHttpsProxySocket(Socket* socket,
|
AsyncHttpsProxySocket(Socket* socket,
|
||||||
const std::string& user_agent,
|
absl::string_view user_agent,
|
||||||
const SocketAddress& proxy,
|
const SocketAddress& proxy,
|
||||||
const std::string& username,
|
absl::string_view username,
|
||||||
const CryptString& password);
|
const CryptString& password);
|
||||||
~AsyncHttpsProxySocket() override;
|
~AsyncHttpsProxySocket() override;
|
||||||
|
|
||||||
|
@ -143,7 +144,7 @@ class AsyncSocksProxySocket : public BufferedReadAdapter {
|
||||||
public:
|
public:
|
||||||
AsyncSocksProxySocket(Socket* socket,
|
AsyncSocksProxySocket(Socket* socket,
|
||||||
const SocketAddress& proxy,
|
const SocketAddress& proxy,
|
||||||
const std::string& username,
|
absl::string_view username,
|
||||||
const CryptString& password);
|
const CryptString& password);
|
||||||
~AsyncSocksProxySocket() override;
|
~AsyncSocksProxySocket() override;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "rtc_base/socket_address.h"
|
#include "rtc_base/socket_address.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/numerics/safe_conversions.h"
|
#include "rtc_base/numerics/safe_conversions.h"
|
||||||
|
|
||||||
#if defined(WEBRTC_POSIX)
|
#if defined(WEBRTC_POSIX)
|
||||||
|
@ -43,7 +44,7 @@ SocketAddress::SocketAddress() {
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketAddress::SocketAddress(const std::string& hostname, int port) {
|
SocketAddress::SocketAddress(absl::string_view hostname, int port) {
|
||||||
SetIP(hostname);
|
SetIP(hostname);
|
||||||
SetPort(port);
|
SetPort(port);
|
||||||
}
|
}
|
||||||
|
@ -101,8 +102,8 @@ void SocketAddress::SetIP(const IPAddress& ip) {
|
||||||
scope_id_ = 0;
|
scope_id_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketAddress::SetIP(const std::string& hostname) {
|
void SocketAddress::SetIP(absl::string_view hostname) {
|
||||||
hostname_ = hostname;
|
hostname_ = std::string(hostname);
|
||||||
literal_ = IPFromString(hostname, &ip_);
|
literal_ = IPFromString(hostname, &ip_);
|
||||||
if (!literal_) {
|
if (!literal_) {
|
||||||
ip_ = IPAddress();
|
ip_ = IPAddress();
|
||||||
|
@ -188,23 +189,24 @@ std::string SocketAddress::ToResolvedSensitiveString() const {
|
||||||
return sb.str();
|
return sb.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketAddress::FromString(const std::string& str) {
|
bool SocketAddress::FromString(absl::string_view str) {
|
||||||
if (str.at(0) == '[') {
|
if (str.at(0) == '[') {
|
||||||
std::string::size_type closebracket = str.rfind(']');
|
absl::string_view::size_type closebracket = str.rfind(']');
|
||||||
if (closebracket != std::string::npos) {
|
if (closebracket != absl::string_view::npos) {
|
||||||
std::string::size_type colon = str.find(':', closebracket);
|
absl::string_view::size_type colon = str.find(':', closebracket);
|
||||||
if (colon != std::string::npos && colon > closebracket) {
|
if (colon != absl::string_view::npos && colon > closebracket) {
|
||||||
SetPort(strtoul(str.substr(colon + 1).c_str(), nullptr, 10));
|
SetPort(
|
||||||
|
strtoul(std::string(str.substr(colon + 1)).c_str(), nullptr, 10));
|
||||||
SetIP(str.substr(1, closebracket - 1));
|
SetIP(str.substr(1, closebracket - 1));
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::string::size_type pos = str.find(':');
|
absl::string_view::size_type pos = str.find(':');
|
||||||
if (std::string::npos == pos)
|
if (absl::string_view::npos == pos)
|
||||||
return false;
|
return false;
|
||||||
SetPort(strtoul(str.substr(pos + 1).c_str(), nullptr, 10));
|
SetPort(strtoul(std::string(str.substr(pos + 1)).c_str(), nullptr, 10));
|
||||||
SetIP(str.substr(0, pos));
|
SetIP(str.substr(0, pos));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#define RTC_BASE_SOCKET_ADDRESS_H_
|
#define RTC_BASE_SOCKET_ADDRESS_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#ifdef WEBRTC_UNIT_TEST
|
#ifdef WEBRTC_UNIT_TEST
|
||||||
#include <ostream> // no-presubmit-check TODO(webrtc:8982)
|
#include <ostream> // no-presubmit-check TODO(webrtc:8982)
|
||||||
#endif // WEBRTC_UNIT_TEST
|
#endif // WEBRTC_UNIT_TEST
|
||||||
|
@ -34,7 +36,7 @@ class RTC_EXPORT SocketAddress {
|
||||||
// Creates the address with the given host and port. Host may be a
|
// Creates the address with the given host and port. Host may be a
|
||||||
// literal IP string or a hostname to be resolved later.
|
// literal IP string or a hostname to be resolved later.
|
||||||
// DCHECKs that port is in valid range (0 to 2^16-1).
|
// DCHECKs that port is in valid range (0 to 2^16-1).
|
||||||
SocketAddress(const std::string& hostname, int port);
|
SocketAddress(absl::string_view hostname, int port);
|
||||||
|
|
||||||
// Creates the address with the given IP and port.
|
// Creates the address with the given IP and port.
|
||||||
// IP is given as an integer in host byte order. V4 only, to be deprecated.
|
// IP is given as an integer in host byte order. V4 only, to be deprecated.
|
||||||
|
@ -69,7 +71,7 @@ class RTC_EXPORT SocketAddress {
|
||||||
|
|
||||||
// Changes the hostname of this address to the given one.
|
// Changes the hostname of this address to the given one.
|
||||||
// Does not resolve the address; use Resolve to do so.
|
// Does not resolve the address; use Resolve to do so.
|
||||||
void SetIP(const std::string& hostname);
|
void SetIP(absl::string_view hostname);
|
||||||
|
|
||||||
// Sets the IP address while retaining the hostname. Useful for bypassing
|
// Sets the IP address while retaining the hostname. Useful for bypassing
|
||||||
// DNS for a pre-resolved IP.
|
// DNS for a pre-resolved IP.
|
||||||
|
@ -129,7 +131,7 @@ class RTC_EXPORT SocketAddress {
|
||||||
std::string ToResolvedSensitiveString() const;
|
std::string ToResolvedSensitiveString() const;
|
||||||
|
|
||||||
// Parses hostname:port and [hostname]:port.
|
// Parses hostname:port and [hostname]:port.
|
||||||
bool FromString(const std::string& str);
|
bool FromString(absl::string_view str);
|
||||||
|
|
||||||
#ifdef WEBRTC_UNIT_TEST
|
#ifdef WEBRTC_UNIT_TEST
|
||||||
inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
|
inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "absl/memory/memory.h"
|
#include "absl/memory/memory.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/arraysize.h"
|
#include "rtc_base/arraysize.h"
|
||||||
#include "rtc_base/async_packet_socket.h"
|
#include "rtc_base/async_packet_socket.h"
|
||||||
#include "rtc_base/async_udp_socket.h"
|
#include "rtc_base/async_udp_socket.h"
|
||||||
|
@ -287,7 +288,7 @@ void SocketTest::ConnectInternal(const IPAddress& loopback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketTest::ConnectWithDnsLookupInternal(const IPAddress& loopback,
|
void SocketTest::ConnectWithDnsLookupInternal(const IPAddress& loopback,
|
||||||
const std::string& host) {
|
absl::string_view host) {
|
||||||
StreamSink sink;
|
StreamSink sink;
|
||||||
SocketAddress accept_addr;
|
SocketAddress accept_addr;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#ifndef RTC_BASE_SOCKET_UNITTEST_H_
|
#ifndef RTC_BASE_SOCKET_UNITTEST_H_
|
||||||
#define RTC_BASE_SOCKET_UNITTEST_H_
|
#define RTC_BASE_SOCKET_UNITTEST_H_
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/gunit.h"
|
#include "rtc_base/gunit.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
|
|
||||||
|
@ -74,7 +75,7 @@ class SocketTest : public ::testing::Test {
|
||||||
private:
|
private:
|
||||||
void ConnectInternal(const IPAddress& loopback);
|
void ConnectInternal(const IPAddress& loopback);
|
||||||
void ConnectWithDnsLookupInternal(const IPAddress& loopback,
|
void ConnectWithDnsLookupInternal(const IPAddress& loopback,
|
||||||
const std::string& host);
|
absl::string_view host);
|
||||||
void ConnectFailInternal(const IPAddress& loopback);
|
void ConnectFailInternal(const IPAddress& loopback);
|
||||||
|
|
||||||
void ConnectWithDnsLookupFailInternal(const IPAddress& loopback);
|
void ConnectWithDnsLookupFailInternal(const IPAddress& loopback);
|
||||||
|
|
|
@ -8,16 +8,18 @@
|
||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "rtc_base/ssl_adapter.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "absl/memory/memory.h"
|
#include "absl/memory/memory.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/gunit.h"
|
#include "rtc_base/gunit.h"
|
||||||
#include "rtc_base/ip_address.h"
|
#include "rtc_base/ip_address.h"
|
||||||
#include "rtc_base/message_digest.h"
|
#include "rtc_base/message_digest.h"
|
||||||
#include "rtc_base/socket_stream.h"
|
#include "rtc_base/socket_stream.h"
|
||||||
#include "rtc_base/ssl_adapter.h"
|
|
||||||
#include "rtc_base/ssl_identity.h"
|
#include "rtc_base/ssl_identity.h"
|
||||||
#include "rtc_base/ssl_stream_adapter.h"
|
#include "rtc_base/ssl_stream_adapter.h"
|
||||||
#include "rtc_base/stream.h"
|
#include "rtc_base/stream.h"
|
||||||
|
@ -99,7 +101,7 @@ class SSLAdapterTestDummyClient : public sigslot::has_slots<> {
|
||||||
|
|
||||||
const std::string& GetReceivedData() const { return data_; }
|
const std::string& GetReceivedData() const { return data_; }
|
||||||
|
|
||||||
int Connect(const std::string& hostname, const rtc::SocketAddress& address) {
|
int Connect(absl::string_view hostname, const rtc::SocketAddress& address) {
|
||||||
RTC_LOG(LS_INFO) << "Initiating connection with " << address.ToString();
|
RTC_LOG(LS_INFO) << "Initiating connection with " << address.ToString();
|
||||||
|
|
||||||
int rv = ssl_adapter_->Connect(address);
|
int rv = ssl_adapter_->Connect(address);
|
||||||
|
@ -108,7 +110,7 @@ class SSLAdapterTestDummyClient : public sigslot::has_slots<> {
|
||||||
RTC_LOG(LS_INFO) << "Starting " << GetSSLProtocolName(ssl_mode_)
|
RTC_LOG(LS_INFO) << "Starting " << GetSSLProtocolName(ssl_mode_)
|
||||||
<< " handshake with " << hostname;
|
<< " handshake with " << hostname;
|
||||||
|
|
||||||
if (ssl_adapter_->StartSSL(hostname.c_str()) != 0) {
|
if (ssl_adapter_->StartSSL(std::string(hostname).c_str()) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +120,7 @@ class SSLAdapterTestDummyClient : public sigslot::has_slots<> {
|
||||||
|
|
||||||
int Close() { return ssl_adapter_->Close(); }
|
int Close() { return ssl_adapter_->Close(); }
|
||||||
|
|
||||||
int Send(const std::string& message) {
|
int Send(absl::string_view message) {
|
||||||
RTC_LOG(LS_INFO) << "Client sending '" << message << "'";
|
RTC_LOG(LS_INFO) << "Client sending '" << message << "'";
|
||||||
|
|
||||||
return ssl_adapter_->Send(message.data(), message.length());
|
return ssl_adapter_->Send(message.data(), message.length());
|
||||||
|
@ -189,7 +191,7 @@ class SSLAdapterTestDummyServer : public sigslot::has_slots<> {
|
||||||
|
|
||||||
const std::string& GetReceivedData() const { return data_; }
|
const std::string& GetReceivedData() const { return data_; }
|
||||||
|
|
||||||
int Send(const std::string& message) {
|
int Send(absl::string_view message) {
|
||||||
if (ssl_stream_adapter_ == nullptr ||
|
if (ssl_stream_adapter_ == nullptr ||
|
||||||
ssl_stream_adapter_->GetState() != rtc::SS_OPEN) {
|
ssl_stream_adapter_->GetState() != rtc::SS_OPEN) {
|
||||||
// No connection yet.
|
// No connection yet.
|
||||||
|
@ -363,7 +365,7 @@ class SSLAdapterTestBase : public ::testing::Test, public sigslot::has_slots<> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestTransfer(const std::string& message) {
|
void TestTransfer(absl::string_view message) {
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
rv = client_->Send(message);
|
rv = client_->Send(message);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "absl/algorithm/container.h"
|
#include "absl/algorithm/container.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/openssl.h"
|
#include "rtc_base/openssl.h"
|
||||||
#ifdef OPENSSL_IS_BORINGSSL
|
#ifdef OPENSSL_IS_BORINGSSL
|
||||||
|
@ -121,7 +122,7 @@ std::unique_ptr<SSLCertificateStats> SSLCertChain::GetStats() const {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
std::unique_ptr<SSLCertificate> SSLCertificate::FromPEMString(
|
std::unique_ptr<SSLCertificate> SSLCertificate::FromPEMString(
|
||||||
const std::string& pem_string) {
|
absl::string_view pem_string) {
|
||||||
#ifdef OPENSSL_IS_BORINGSSL
|
#ifdef OPENSSL_IS_BORINGSSL
|
||||||
return BoringSSLCertificate::FromPEMString(pem_string);
|
return BoringSSLCertificate::FromPEMString(pem_string);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/buffer.h"
|
#include "rtc_base/buffer.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ class RTC_EXPORT SSLCertificate {
|
||||||
// stored in *pem_length if it is non-null, and only if
|
// stored in *pem_length if it is non-null, and only if
|
||||||
// parsing was successful.
|
// parsing was successful.
|
||||||
static std::unique_ptr<SSLCertificate> FromPEMString(
|
static std::unique_ptr<SSLCertificate> FromPEMString(
|
||||||
const std::string& pem_string);
|
absl::string_view pem_string);
|
||||||
virtual ~SSLCertificate() = default;
|
virtual ~SSLCertificate() = default;
|
||||||
|
|
||||||
// Returns a new SSLCertificate object instance wrapping the same
|
// Returns a new SSLCertificate object instance wrapping the same
|
||||||
|
@ -73,7 +74,7 @@ class RTC_EXPORT SSLCertificate {
|
||||||
virtual bool GetSignatureDigestAlgorithm(std::string* algorithm) const = 0;
|
virtual bool GetSignatureDigestAlgorithm(std::string* algorithm) const = 0;
|
||||||
|
|
||||||
// Compute the digest of the certificate given algorithm
|
// Compute the digest of the certificate given algorithm
|
||||||
virtual bool ComputeDigest(const std::string& algorithm,
|
virtual bool ComputeDigest(absl::string_view algorithm,
|
||||||
unsigned char* digest,
|
unsigned char* digest,
|
||||||
size_t size,
|
size_t size,
|
||||||
size_t* length) const = 0;
|
size_t* length) const = 0;
|
||||||
|
|
|
@ -11,11 +11,13 @@
|
||||||
#include "rtc_base/ssl_fingerprint.h"
|
#include "rtc_base/ssl_fingerprint.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "absl/algorithm/container.h"
|
#include "absl/algorithm/container.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/message_digest.h"
|
#include "rtc_base/message_digest.h"
|
||||||
#include "rtc_base/rtc_certificate.h"
|
#include "rtc_base/rtc_certificate.h"
|
||||||
|
@ -25,19 +27,19 @@
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
SSLFingerprint* SSLFingerprint::Create(const std::string& algorithm,
|
SSLFingerprint* SSLFingerprint::Create(absl::string_view algorithm,
|
||||||
const rtc::SSLIdentity* identity) {
|
const rtc::SSLIdentity* identity) {
|
||||||
return CreateUnique(algorithm, *identity).release();
|
return CreateUnique(algorithm, *identity).release();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<SSLFingerprint> SSLFingerprint::CreateUnique(
|
std::unique_ptr<SSLFingerprint> SSLFingerprint::CreateUnique(
|
||||||
const std::string& algorithm,
|
absl::string_view algorithm,
|
||||||
const rtc::SSLIdentity& identity) {
|
const rtc::SSLIdentity& identity) {
|
||||||
return Create(algorithm, identity.certificate());
|
return Create(algorithm, identity.certificate());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<SSLFingerprint> SSLFingerprint::Create(
|
std::unique_ptr<SSLFingerprint> SSLFingerprint::Create(
|
||||||
const std::string& algorithm,
|
absl::string_view algorithm,
|
||||||
const rtc::SSLCertificate& cert) {
|
const rtc::SSLCertificate& cert) {
|
||||||
uint8_t digest_val[64];
|
uint8_t digest_val[64];
|
||||||
size_t digest_len;
|
size_t digest_len;
|
||||||
|
@ -51,14 +53,14 @@ std::unique_ptr<SSLFingerprint> SSLFingerprint::Create(
|
||||||
}
|
}
|
||||||
|
|
||||||
SSLFingerprint* SSLFingerprint::CreateFromRfc4572(
|
SSLFingerprint* SSLFingerprint::CreateFromRfc4572(
|
||||||
const std::string& algorithm,
|
absl::string_view algorithm,
|
||||||
const std::string& fingerprint) {
|
absl::string_view fingerprint) {
|
||||||
return CreateUniqueFromRfc4572(algorithm, fingerprint).release();
|
return CreateUniqueFromRfc4572(algorithm, fingerprint).release();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<SSLFingerprint> SSLFingerprint::CreateUniqueFromRfc4572(
|
std::unique_ptr<SSLFingerprint> SSLFingerprint::CreateUniqueFromRfc4572(
|
||||||
const std::string& algorithm,
|
absl::string_view algorithm,
|
||||||
const std::string& fingerprint) {
|
absl::string_view fingerprint) {
|
||||||
if (algorithm.empty() || !rtc::IsFips180DigestAlgorithm(algorithm))
|
if (algorithm.empty() || !rtc::IsFips180DigestAlgorithm(algorithm))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -67,7 +69,7 @@ std::unique_ptr<SSLFingerprint> SSLFingerprint::CreateUniqueFromRfc4572(
|
||||||
|
|
||||||
char value[rtc::MessageDigest::kMaxSize];
|
char value[rtc::MessageDigest::kMaxSize];
|
||||||
size_t value_len = rtc::hex_decode_with_delimiter(
|
size_t value_len = rtc::hex_decode_with_delimiter(
|
||||||
value, sizeof(value), fingerprint.c_str(), fingerprint.length(), ':');
|
value, sizeof(value), fingerprint.data(), fingerprint.length(), ':');
|
||||||
if (!value_len)
|
if (!value_len)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -94,11 +96,11 @@ std::unique_ptr<SSLFingerprint> SSLFingerprint::CreateFromCertificate(
|
||||||
return fingerprint;
|
return fingerprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSLFingerprint::SSLFingerprint(const std::string& algorithm,
|
SSLFingerprint::SSLFingerprint(absl::string_view algorithm,
|
||||||
ArrayView<const uint8_t> digest_view)
|
ArrayView<const uint8_t> digest_view)
|
||||||
: algorithm(algorithm), digest(digest_view.data(), digest_view.size()) {}
|
: algorithm(algorithm), digest(digest_view.data(), digest_view.size()) {}
|
||||||
|
|
||||||
SSLFingerprint::SSLFingerprint(const std::string& algorithm,
|
SSLFingerprint::SSLFingerprint(absl::string_view algorithm,
|
||||||
const uint8_t* digest_in,
|
const uint8_t* digest_in,
|
||||||
size_t digest_len)
|
size_t digest_len)
|
||||||
: SSLFingerprint(algorithm, MakeArrayView(digest_in, digest_len)) {}
|
: SSLFingerprint(algorithm, MakeArrayView(digest_in, digest_len)) {}
|
||||||
|
|
|
@ -13,8 +13,10 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/copy_on_write_buffer.h"
|
#include "rtc_base/copy_on_write_buffer.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
|
|
||||||
|
@ -26,34 +28,34 @@ class SSLIdentity;
|
||||||
|
|
||||||
struct RTC_EXPORT SSLFingerprint {
|
struct RTC_EXPORT SSLFingerprint {
|
||||||
// TODO(steveanton): Remove once downstream projects have moved off of this.
|
// TODO(steveanton): Remove once downstream projects have moved off of this.
|
||||||
static SSLFingerprint* Create(const std::string& algorithm,
|
static SSLFingerprint* Create(absl::string_view algorithm,
|
||||||
const rtc::SSLIdentity* identity);
|
const rtc::SSLIdentity* identity);
|
||||||
// TODO(steveanton): Rename to Create once projects have migrated.
|
// TODO(steveanton): Rename to Create once projects have migrated.
|
||||||
static std::unique_ptr<SSLFingerprint> CreateUnique(
|
static std::unique_ptr<SSLFingerprint> CreateUnique(
|
||||||
const std::string& algorithm,
|
absl::string_view algorithm,
|
||||||
const rtc::SSLIdentity& identity);
|
const rtc::SSLIdentity& identity);
|
||||||
|
|
||||||
static std::unique_ptr<SSLFingerprint> Create(
|
static std::unique_ptr<SSLFingerprint> Create(
|
||||||
const std::string& algorithm,
|
absl::string_view algorithm,
|
||||||
const rtc::SSLCertificate& cert);
|
const rtc::SSLCertificate& cert);
|
||||||
|
|
||||||
// TODO(steveanton): Remove once downstream projects have moved off of this.
|
// TODO(steveanton): Remove once downstream projects have moved off of this.
|
||||||
static SSLFingerprint* CreateFromRfc4572(const std::string& algorithm,
|
static SSLFingerprint* CreateFromRfc4572(absl::string_view algorithm,
|
||||||
const std::string& fingerprint);
|
absl::string_view fingerprint);
|
||||||
// TODO(steveanton): Rename to CreateFromRfc4572 once projects have migrated.
|
// TODO(steveanton): Rename to CreateFromRfc4572 once projects have migrated.
|
||||||
static std::unique_ptr<SSLFingerprint> CreateUniqueFromRfc4572(
|
static std::unique_ptr<SSLFingerprint> CreateUniqueFromRfc4572(
|
||||||
const std::string& algorithm,
|
absl::string_view algorithm,
|
||||||
const std::string& fingerprint);
|
absl::string_view fingerprint);
|
||||||
|
|
||||||
// Creates a fingerprint from a certificate, using the same digest algorithm
|
// Creates a fingerprint from a certificate, using the same digest algorithm
|
||||||
// as the certificate's signature.
|
// as the certificate's signature.
|
||||||
static std::unique_ptr<SSLFingerprint> CreateFromCertificate(
|
static std::unique_ptr<SSLFingerprint> CreateFromCertificate(
|
||||||
const RTCCertificate& cert);
|
const RTCCertificate& cert);
|
||||||
|
|
||||||
SSLFingerprint(const std::string& algorithm,
|
SSLFingerprint(absl::string_view algorithm,
|
||||||
ArrayView<const uint8_t> digest_view);
|
ArrayView<const uint8_t> digest_view);
|
||||||
// TODO(steveanton): Remove once downstream projects have moved off of this.
|
// TODO(steveanton): Remove once downstream projects have moved off of this.
|
||||||
SSLFingerprint(const std::string& algorithm,
|
SSLFingerprint(absl::string_view algorithm,
|
||||||
const uint8_t* digest_in,
|
const uint8_t* digest_in,
|
||||||
size_t digest_len);
|
size_t digest_len);
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#ifdef OPENSSL_IS_BORINGSSL
|
#ifdef OPENSSL_IS_BORINGSSL
|
||||||
#include "rtc_base/boringssl_identity.h"
|
#include "rtc_base/boringssl_identity.h"
|
||||||
|
@ -169,30 +170,32 @@ KeyType IntKeyTypeFamilyToKeyType(int key_type_family) {
|
||||||
// SSLIdentity
|
// SSLIdentity
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool SSLIdentity::PemToDer(const std::string& pem_type,
|
bool SSLIdentity::PemToDer(absl::string_view pem_type,
|
||||||
const std::string& pem_string,
|
absl::string_view pem_string,
|
||||||
std::string* der) {
|
std::string* der) {
|
||||||
// Find the inner body. We need this to fulfill the contract of returning
|
// Find the inner body. We need this to fulfill the contract of returning
|
||||||
// pem_length.
|
// pem_length.
|
||||||
size_t header = pem_string.find("-----BEGIN " + pem_type + "-----");
|
std::string pem_type_str = std::string(pem_type);
|
||||||
if (header == std::string::npos) {
|
size_t header = pem_string.find("-----BEGIN " + pem_type_str + "-----");
|
||||||
|
if (header == absl::string_view::npos) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
size_t body = pem_string.find('\n', header);
|
size_t body = pem_string.find('\n', header);
|
||||||
if (body == std::string::npos) {
|
if (body == absl::string_view::npos) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
size_t trailer = pem_string.find("-----END " + pem_type + "-----");
|
size_t trailer = pem_string.find("-----END " + pem_type_str + "-----");
|
||||||
if (trailer == std::string::npos) {
|
if (trailer == absl::string_view::npos) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::string inner = pem_string.substr(body + 1, trailer - (body + 1));
|
std::string inner =
|
||||||
|
std::string(pem_string.substr(body + 1, trailer - (body + 1)));
|
||||||
*der = Base64::Decode(inner, Base64::DO_PARSE_WHITE | Base64::DO_PAD_ANY |
|
*der = Base64::Decode(inner, Base64::DO_PARSE_WHITE | Base64::DO_PAD_ANY |
|
||||||
Base64::DO_TERM_BUFFER);
|
Base64::DO_TERM_BUFFER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SSLIdentity::DerToPem(const std::string& pem_type,
|
std::string SSLIdentity::DerToPem(absl::string_view pem_type,
|
||||||
const unsigned char* data,
|
const unsigned char* data,
|
||||||
size_t length) {
|
size_t length) {
|
||||||
rtc::StringBuilder result;
|
rtc::StringBuilder result;
|
||||||
|
@ -214,7 +217,7 @@ std::string SSLIdentity::DerToPem(const std::string& pem_type,
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
std::unique_ptr<SSLIdentity> SSLIdentity::Create(const std::string& common_name,
|
std::unique_ptr<SSLIdentity> SSLIdentity::Create(absl::string_view common_name,
|
||||||
const KeyParams& key_param,
|
const KeyParams& key_param,
|
||||||
time_t certificate_lifetime) {
|
time_t certificate_lifetime) {
|
||||||
#ifdef OPENSSL_IS_BORINGSSL
|
#ifdef OPENSSL_IS_BORINGSSL
|
||||||
|
@ -227,13 +230,13 @@ std::unique_ptr<SSLIdentity> SSLIdentity::Create(const std::string& common_name,
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
std::unique_ptr<SSLIdentity> SSLIdentity::Create(const std::string& common_name,
|
std::unique_ptr<SSLIdentity> SSLIdentity::Create(absl::string_view common_name,
|
||||||
const KeyParams& key_param) {
|
const KeyParams& key_param) {
|
||||||
return Create(common_name, key_param, kDefaultCertificateLifetimeInSeconds);
|
return Create(common_name, key_param, kDefaultCertificateLifetimeInSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
std::unique_ptr<SSLIdentity> SSLIdentity::Create(const std::string& common_name,
|
std::unique_ptr<SSLIdentity> SSLIdentity::Create(absl::string_view common_name,
|
||||||
KeyType key_type) {
|
KeyType key_type) {
|
||||||
return Create(common_name, KeyParams(key_type),
|
return Create(common_name, KeyParams(key_type),
|
||||||
kDefaultCertificateLifetimeInSeconds);
|
kDefaultCertificateLifetimeInSeconds);
|
||||||
|
@ -252,8 +255,8 @@ std::unique_ptr<SSLIdentity> SSLIdentity::CreateForTest(
|
||||||
// Construct an identity from a private key and a certificate.
|
// Construct an identity from a private key and a certificate.
|
||||||
// static
|
// static
|
||||||
std::unique_ptr<SSLIdentity> SSLIdentity::CreateFromPEMStrings(
|
std::unique_ptr<SSLIdentity> SSLIdentity::CreateFromPEMStrings(
|
||||||
const std::string& private_key,
|
absl::string_view private_key,
|
||||||
const std::string& certificate) {
|
absl::string_view certificate) {
|
||||||
#ifdef OPENSSL_IS_BORINGSSL
|
#ifdef OPENSSL_IS_BORINGSSL
|
||||||
return BoringSSLIdentity::CreateFromPEMStrings(private_key, certificate);
|
return BoringSSLIdentity::CreateFromPEMStrings(private_key, certificate);
|
||||||
#else
|
#else
|
||||||
|
@ -264,8 +267,8 @@ std::unique_ptr<SSLIdentity> SSLIdentity::CreateFromPEMStrings(
|
||||||
// Construct an identity from a private key and a certificate chain.
|
// Construct an identity from a private key and a certificate chain.
|
||||||
// static
|
// static
|
||||||
std::unique_ptr<SSLIdentity> SSLIdentity::CreateFromPEMChainStrings(
|
std::unique_ptr<SSLIdentity> SSLIdentity::CreateFromPEMChainStrings(
|
||||||
const std::string& private_key,
|
absl::string_view private_key,
|
||||||
const std::string& certificate_chain) {
|
absl::string_view certificate_chain) {
|
||||||
#ifdef OPENSSL_IS_BORINGSSL
|
#ifdef OPENSSL_IS_BORINGSSL
|
||||||
return BoringSSLIdentity::CreateFromPEMChainStrings(private_key,
|
return BoringSSLIdentity::CreateFromPEMChainStrings(private_key,
|
||||||
certificate_chain);
|
certificate_chain);
|
||||||
|
|
|
@ -14,10 +14,12 @@
|
||||||
#define RTC_BASE_SSL_IDENTITY_H_
|
#define RTC_BASE_SSL_IDENTITY_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
@ -108,12 +110,12 @@ class RTC_EXPORT SSLIdentity {
|
||||||
// should be a non-negative number.
|
// should be a non-negative number.
|
||||||
// Returns null on failure.
|
// Returns null on failure.
|
||||||
// Caller is responsible for freeing the returned object.
|
// Caller is responsible for freeing the returned object.
|
||||||
static std::unique_ptr<SSLIdentity> Create(const std::string& common_name,
|
static std::unique_ptr<SSLIdentity> Create(absl::string_view common_name,
|
||||||
const KeyParams& key_param,
|
const KeyParams& key_param,
|
||||||
time_t certificate_lifetime);
|
time_t certificate_lifetime);
|
||||||
static std::unique_ptr<SSLIdentity> Create(const std::string& common_name,
|
static std::unique_ptr<SSLIdentity> Create(absl::string_view common_name,
|
||||||
const KeyParams& key_param);
|
const KeyParams& key_param);
|
||||||
static std::unique_ptr<SSLIdentity> Create(const std::string& common_name,
|
static std::unique_ptr<SSLIdentity> Create(absl::string_view common_name,
|
||||||
KeyType key_type);
|
KeyType key_type);
|
||||||
|
|
||||||
// Allows fine-grained control over expiration time.
|
// Allows fine-grained control over expiration time.
|
||||||
|
@ -122,13 +124,13 @@ class RTC_EXPORT SSLIdentity {
|
||||||
|
|
||||||
// Construct an identity from a private key and a certificate.
|
// Construct an identity from a private key and a certificate.
|
||||||
static std::unique_ptr<SSLIdentity> CreateFromPEMStrings(
|
static std::unique_ptr<SSLIdentity> CreateFromPEMStrings(
|
||||||
const std::string& private_key,
|
absl::string_view private_key,
|
||||||
const std::string& certificate);
|
absl::string_view certificate);
|
||||||
|
|
||||||
// Construct an identity from a private key and a certificate chain.
|
// Construct an identity from a private key and a certificate chain.
|
||||||
static std::unique_ptr<SSLIdentity> CreateFromPEMChainStrings(
|
static std::unique_ptr<SSLIdentity> CreateFromPEMChainStrings(
|
||||||
const std::string& private_key,
|
absl::string_view private_key,
|
||||||
const std::string& certificate_chain);
|
absl::string_view certificate_chain);
|
||||||
|
|
||||||
virtual ~SSLIdentity() {}
|
virtual ~SSLIdentity() {}
|
||||||
|
|
||||||
|
@ -144,10 +146,10 @@ class RTC_EXPORT SSLIdentity {
|
||||||
virtual std::string PublicKeyToPEMString() const = 0;
|
virtual std::string PublicKeyToPEMString() const = 0;
|
||||||
|
|
||||||
// Helpers for parsing converting between PEM and DER format.
|
// Helpers for parsing converting between PEM and DER format.
|
||||||
static bool PemToDer(const std::string& pem_type,
|
static bool PemToDer(absl::string_view pem_type,
|
||||||
const std::string& pem_string,
|
absl::string_view pem_string,
|
||||||
std::string* der);
|
std::string* der);
|
||||||
static std::string DerToPem(const std::string& pem_type,
|
static std::string DerToPem(absl::string_view pem_type,
|
||||||
const unsigned char* data,
|
const unsigned char* data,
|
||||||
size_t length);
|
size_t length);
|
||||||
|
|
||||||
|
|
|
@ -8,19 +8,22 @@
|
||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "rtc_base/ssl_identity.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/strings/str_replace.h"
|
#include "absl/strings/str_replace.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/fake_ssl_identity.h"
|
#include "rtc_base/fake_ssl_identity.h"
|
||||||
#include "rtc_base/helpers.h"
|
#include "rtc_base/helpers.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/message_digest.h"
|
#include "rtc_base/message_digest.h"
|
||||||
#include "rtc_base/ssl_fingerprint.h"
|
#include "rtc_base/ssl_fingerprint.h"
|
||||||
#include "rtc_base/ssl_identity.h"
|
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
|
||||||
using rtc::SSLIdentity;
|
using rtc::SSLIdentity;
|
||||||
|
@ -236,7 +239,7 @@ class SSLIdentityTest : public ::testing::Test {
|
||||||
|
|
||||||
void TestDigestHelper(DigestType digest,
|
void TestDigestHelper(DigestType digest,
|
||||||
const SSLIdentity* identity,
|
const SSLIdentity* identity,
|
||||||
const std::string& algorithm,
|
absl::string_view algorithm,
|
||||||
size_t expected_len) {
|
size_t expected_len) {
|
||||||
DigestType digest1;
|
DigestType digest1;
|
||||||
size_t digest_len;
|
size_t digest_len;
|
||||||
|
@ -258,7 +261,7 @@ class SSLIdentityTest : public ::testing::Test {
|
||||||
EXPECT_EQ(0, memcmp(digest, digest1, expected_len));
|
EXPECT_EQ(0, memcmp(digest, digest1, expected_len));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestDigestForGeneratedCert(const std::string& algorithm,
|
void TestDigestForGeneratedCert(absl::string_view algorithm,
|
||||||
size_t expected_len) {
|
size_t expected_len) {
|
||||||
DigestType digest[4];
|
DigestType digest[4];
|
||||||
|
|
||||||
|
@ -281,7 +284,7 @@ class SSLIdentityTest : public ::testing::Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestDigestForFixedCert(const std::string& algorithm,
|
void TestDigestForFixedCert(absl::string_view algorithm,
|
||||||
size_t expected_len,
|
size_t expected_len,
|
||||||
const unsigned char* expected_digest) {
|
const unsigned char* expected_digest) {
|
||||||
bool rv;
|
bool rv;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "rtc_base/ssl_stream_adapter.h"
|
#include "rtc_base/ssl_stream_adapter.h"
|
||||||
|
|
||||||
#include "absl/memory/memory.h"
|
#include "absl/memory/memory.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/openssl_stream_adapter.h"
|
#include "rtc_base/openssl_stream_adapter.h"
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -39,7 +40,7 @@ std::string SrtpCryptoSuiteToName(int crypto_suite) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrtpCryptoSuiteFromName(const std::string& crypto_suite) {
|
int SrtpCryptoSuiteFromName(absl::string_view crypto_suite) {
|
||||||
if (crypto_suite == kCsAesCm128HmacSha1_32)
|
if (crypto_suite == kCsAesCm128HmacSha1_32)
|
||||||
return kSrtpAes128CmSha1_32;
|
return kSrtpAes128CmSha1_32;
|
||||||
if (crypto_suite == kCsAesCm128HmacSha1_80)
|
if (crypto_suite == kCsAesCm128HmacSha1_80)
|
||||||
|
@ -85,7 +86,7 @@ bool IsGcmCryptoSuite(int crypto_suite) {
|
||||||
crypto_suite == kSrtpAeadAes128Gcm);
|
crypto_suite == kSrtpAeadAes128Gcm);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsGcmCryptoSuiteName(const std::string& crypto_suite) {
|
bool IsGcmCryptoSuiteName(absl::string_view crypto_suite) {
|
||||||
return (crypto_suite == kCsAeadAes256Gcm || crypto_suite == kCsAeadAes128Gcm);
|
return (crypto_suite == kCsAeadAes256Gcm || crypto_suite == kCsAeadAes128Gcm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +99,7 @@ bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SSLStreamAdapter::ExportKeyingMaterial(const std::string& label,
|
bool SSLStreamAdapter::ExportKeyingMaterial(absl::string_view label,
|
||||||
const uint8_t* context,
|
const uint8_t* context,
|
||||||
size_t context_len,
|
size_t context_len,
|
||||||
bool use_context,
|
bool use_context,
|
||||||
|
@ -122,7 +123,7 @@ bool SSLStreamAdapter::IsBoringSsl() {
|
||||||
bool SSLStreamAdapter::IsAcceptableCipher(int cipher, KeyType key_type) {
|
bool SSLStreamAdapter::IsAcceptableCipher(int cipher, KeyType key_type) {
|
||||||
return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type);
|
return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type);
|
||||||
}
|
}
|
||||||
bool SSLStreamAdapter::IsAcceptableCipher(const std::string& cipher,
|
bool SSLStreamAdapter::IsAcceptableCipher(absl::string_view cipher,
|
||||||
KeyType key_type) {
|
KeyType key_type) {
|
||||||
return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type);
|
return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,13 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/memory/memory.h"
|
#include "absl/memory/memory.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/ssl_certificate.h"
|
#include "rtc_base/ssl_certificate.h"
|
||||||
#include "rtc_base/ssl_identity.h"
|
#include "rtc_base/ssl_identity.h"
|
||||||
#include "rtc_base/stream.h"
|
#include "rtc_base/stream.h"
|
||||||
|
@ -53,7 +55,7 @@ extern const char kCsAeadAes256Gcm[];
|
||||||
std::string SrtpCryptoSuiteToName(int crypto_suite);
|
std::string SrtpCryptoSuiteToName(int crypto_suite);
|
||||||
|
|
||||||
// The reverse of above conversion.
|
// The reverse of above conversion.
|
||||||
int SrtpCryptoSuiteFromName(const std::string& crypto_suite);
|
int SrtpCryptoSuiteFromName(absl::string_view crypto_suite);
|
||||||
|
|
||||||
// Get key length and salt length for given crypto suite. Returns true for
|
// Get key length and salt length for given crypto suite. Returns true for
|
||||||
// valid suites, otherwise false.
|
// valid suites, otherwise false.
|
||||||
|
@ -65,7 +67,7 @@ bool GetSrtpKeyAndSaltLengths(int crypto_suite,
|
||||||
bool IsGcmCryptoSuite(int crypto_suite);
|
bool IsGcmCryptoSuite(int crypto_suite);
|
||||||
|
|
||||||
// Returns true if the given crypto suite name uses a GCM cipher.
|
// Returns true if the given crypto suite name uses a GCM cipher.
|
||||||
bool IsGcmCryptoSuiteName(const std::string& crypto_suite);
|
bool IsGcmCryptoSuiteName(absl::string_view crypto_suite);
|
||||||
|
|
||||||
// SSLStreamAdapter : A StreamInterfaceAdapter that does SSL/TLS.
|
// SSLStreamAdapter : A StreamInterfaceAdapter that does SSL/TLS.
|
||||||
// After SSL has been started, the stream will only open on successful
|
// After SSL has been started, the stream will only open on successful
|
||||||
|
@ -176,7 +178,7 @@ class SSLStreamAdapter : public StreamInterface, public sigslot::has_slots<> {
|
||||||
// Returns true if successful.
|
// Returns true if successful.
|
||||||
// `error` is optional and provides more information about the failure.
|
// `error` is optional and provides more information about the failure.
|
||||||
virtual bool SetPeerCertificateDigest(
|
virtual bool SetPeerCertificateDigest(
|
||||||
const std::string& digest_alg,
|
absl::string_view digest_alg,
|
||||||
const unsigned char* digest_val,
|
const unsigned char* digest_val,
|
||||||
size_t digest_len,
|
size_t digest_len,
|
||||||
SSLPeerCertificateDigestError* error = nullptr) = 0;
|
SSLPeerCertificateDigestError* error = nullptr) = 0;
|
||||||
|
@ -208,7 +210,7 @@ class SSLStreamAdapter : public StreamInterface, public sigslot::has_slots<> {
|
||||||
// zero-length ones).
|
// zero-length ones).
|
||||||
// result -- where to put the computed value
|
// result -- where to put the computed value
|
||||||
// result_len -- the length of the computed value
|
// result_len -- the length of the computed value
|
||||||
virtual bool ExportKeyingMaterial(const std::string& label,
|
virtual bool ExportKeyingMaterial(absl::string_view label,
|
||||||
const uint8_t* context,
|
const uint8_t* context,
|
||||||
size_t context_len,
|
size_t context_len,
|
||||||
bool use_context,
|
bool use_context,
|
||||||
|
@ -233,7 +235,7 @@ class SSLStreamAdapter : public StreamInterface, public sigslot::has_slots<> {
|
||||||
// Returns true iff the supplied cipher is deemed to be strong.
|
// Returns true iff the supplied cipher is deemed to be strong.
|
||||||
// TODO(torbjorng): Consider removing the KeyType argument.
|
// TODO(torbjorng): Consider removing the KeyType argument.
|
||||||
static bool IsAcceptableCipher(int cipher, KeyType key_type);
|
static bool IsAcceptableCipher(int cipher, KeyType key_type);
|
||||||
static bool IsAcceptableCipher(const std::string& cipher, KeyType key_type);
|
static bool IsAcceptableCipher(absl::string_view cipher, KeyType key_type);
|
||||||
|
|
||||||
// TODO(guoweis): Move this away from a static class method. Currently this is
|
// TODO(guoweis): Move this away from a static class method. Currently this is
|
||||||
// introduced such that any caller could depend on sslstreamadapter.h without
|
// introduced such that any caller could depend on sslstreamadapter.h without
|
||||||
|
|
|
@ -8,12 +8,15 @@
|
||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "rtc_base/ssl_stream_adapter.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "absl/memory/memory.h"
|
#include "absl/memory/memory.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/buffer_queue.h"
|
#include "rtc_base/buffer_queue.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/gunit.h"
|
#include "rtc_base/gunit.h"
|
||||||
|
@ -24,7 +27,6 @@
|
||||||
#include "rtc_base/openssl_stream_adapter.h"
|
#include "rtc_base/openssl_stream_adapter.h"
|
||||||
#include "rtc_base/ssl_adapter.h"
|
#include "rtc_base/ssl_adapter.h"
|
||||||
#include "rtc_base/ssl_identity.h"
|
#include "rtc_base/ssl_identity.h"
|
||||||
#include "rtc_base/ssl_stream_adapter.h"
|
|
||||||
#include "rtc_base/stream.h"
|
#include "rtc_base/stream.h"
|
||||||
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
||||||
#include "rtc_base/task_utils/to_queued_task.h"
|
#include "rtc_base/task_utils/to_queued_task.h"
|
||||||
|
@ -147,7 +149,7 @@ class SSLDummyStreamBase : public rtc::StreamInterface,
|
||||||
public sigslot::has_slots<> {
|
public sigslot::has_slots<> {
|
||||||
public:
|
public:
|
||||||
SSLDummyStreamBase(SSLStreamAdapterTestBase* test,
|
SSLDummyStreamBase(SSLStreamAdapterTestBase* test,
|
||||||
const std::string& side,
|
absl::string_view side,
|
||||||
rtc::StreamInterface* in,
|
rtc::StreamInterface* in,
|
||||||
rtc::StreamInterface* out)
|
rtc::StreamInterface* out)
|
||||||
: test_base_(test), side_(side), in_(in), out_(out), first_packet_(true) {
|
: test_base_(test), side_(side), in_(in), out_(out), first_packet_(true) {
|
||||||
|
@ -235,7 +237,7 @@ class SSLDummyStreamBase : public rtc::StreamInterface,
|
||||||
class SSLDummyStreamTLS : public SSLDummyStreamBase {
|
class SSLDummyStreamTLS : public SSLDummyStreamBase {
|
||||||
public:
|
public:
|
||||||
SSLDummyStreamTLS(SSLStreamAdapterTestBase* test,
|
SSLDummyStreamTLS(SSLStreamAdapterTestBase* test,
|
||||||
const std::string& side,
|
absl::string_view side,
|
||||||
rtc::FifoBuffer* in,
|
rtc::FifoBuffer* in,
|
||||||
rtc::FifoBuffer* out)
|
rtc::FifoBuffer* out)
|
||||||
: SSLDummyStreamBase(test, side, in, out) {}
|
: SSLDummyStreamBase(test, side, in, out) {}
|
||||||
|
@ -303,7 +305,7 @@ class BufferQueueStream : public rtc::StreamInterface {
|
||||||
class SSLDummyStreamDTLS : public SSLDummyStreamBase {
|
class SSLDummyStreamDTLS : public SSLDummyStreamBase {
|
||||||
public:
|
public:
|
||||||
SSLDummyStreamDTLS(SSLStreamAdapterTestBase* test,
|
SSLDummyStreamDTLS(SSLStreamAdapterTestBase* test,
|
||||||
const std::string& side,
|
absl::string_view side,
|
||||||
BufferQueueStream* in,
|
BufferQueueStream* in,
|
||||||
BufferQueueStream* out)
|
BufferQueueStream* out)
|
||||||
: SSLDummyStreamBase(test, side, in, out) {}
|
: SSLDummyStreamBase(test, side, in, out) {}
|
||||||
|
@ -317,8 +319,8 @@ class SSLStreamAdapterTestBase : public ::testing::Test,
|
||||||
public sigslot::has_slots<> {
|
public sigslot::has_slots<> {
|
||||||
public:
|
public:
|
||||||
SSLStreamAdapterTestBase(
|
SSLStreamAdapterTestBase(
|
||||||
const std::string& client_cert_pem,
|
absl::string_view client_cert_pem,
|
||||||
const std::string& client_private_key_pem,
|
absl::string_view client_private_key_pem,
|
||||||
bool dtls,
|
bool dtls,
|
||||||
rtc::KeyParams client_key_type = rtc::KeyParams(rtc::KT_DEFAULT),
|
rtc::KeyParams client_key_type = rtc::KeyParams(rtc::KT_DEFAULT),
|
||||||
rtc::KeyParams server_key_type = rtc::KeyParams(rtc::KT_DEFAULT))
|
rtc::KeyParams server_key_type = rtc::KeyParams(rtc::KT_DEFAULT))
|
||||||
|
@ -864,8 +866,8 @@ class SSLStreamAdapterTestDTLSBase : public SSLStreamAdapterTestBase {
|
||||||
count_(0),
|
count_(0),
|
||||||
sent_(0) {}
|
sent_(0) {}
|
||||||
|
|
||||||
SSLStreamAdapterTestDTLSBase(const std::string& cert_pem,
|
SSLStreamAdapterTestDTLSBase(absl::string_view cert_pem,
|
||||||
const std::string& private_key_pem)
|
absl::string_view private_key_pem)
|
||||||
: SSLStreamAdapterTestBase(cert_pem, private_key_pem, true),
|
: SSLStreamAdapterTestBase(cert_pem, private_key_pem, true),
|
||||||
client_buffer_(kBufferCapacity, kDefaultBufferSize),
|
client_buffer_(kBufferCapacity, kDefaultBufferSize),
|
||||||
server_buffer_(kBufferCapacity, kDefaultBufferSize),
|
server_buffer_(kBufferCapacity, kDefaultBufferSize),
|
||||||
|
@ -983,8 +985,8 @@ class SSLStreamAdapterTestDTLS
|
||||||
: SSLStreamAdapterTestDTLSBase(::testing::get<0>(GetParam()),
|
: SSLStreamAdapterTestDTLSBase(::testing::get<0>(GetParam()),
|
||||||
::testing::get<1>(GetParam())) {}
|
::testing::get<1>(GetParam())) {}
|
||||||
|
|
||||||
SSLStreamAdapterTestDTLS(const std::string& cert_pem,
|
SSLStreamAdapterTestDTLS(absl::string_view cert_pem,
|
||||||
const std::string& private_key_pem)
|
absl::string_view private_key_pem)
|
||||||
: SSLStreamAdapterTestDTLSBase(cert_pem, private_key_pem) {}
|
: SSLStreamAdapterTestDTLSBase(cert_pem, private_key_pem) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1551,8 +1553,8 @@ class SSLStreamAdapterTestDTLSLegacyProtocols
|
||||||
// initialized, so we set the experiment while creationg client_ssl_
|
// initialized, so we set the experiment while creationg client_ssl_
|
||||||
// and server_ssl_.
|
// and server_ssl_.
|
||||||
|
|
||||||
void ConfigureClient(std::string experiment) {
|
void ConfigureClient(absl::string_view experiment) {
|
||||||
webrtc::test::ScopedFieldTrials trial(experiment);
|
webrtc::test::ScopedFieldTrials trial{std::string(experiment)};
|
||||||
client_stream_ =
|
client_stream_ =
|
||||||
new SSLDummyStreamDTLS(this, "c2s", &client_buffer_, &server_buffer_);
|
new SSLDummyStreamDTLS(this, "c2s", &client_buffer_, &server_buffer_);
|
||||||
client_ssl_ =
|
client_ssl_ =
|
||||||
|
@ -1564,8 +1566,8 @@ class SSLStreamAdapterTestDTLSLegacyProtocols
|
||||||
client_ssl_->SetIdentity(std::move(client_identity));
|
client_ssl_->SetIdentity(std::move(client_identity));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureServer(std::string experiment) {
|
void ConfigureServer(absl::string_view experiment) {
|
||||||
webrtc::test::ScopedFieldTrials trial(experiment);
|
webrtc::test::ScopedFieldTrials trial{std::string(experiment)};
|
||||||
server_stream_ =
|
server_stream_ =
|
||||||
new SSLDummyStreamDTLS(this, "s2c", &server_buffer_, &client_buffer_);
|
new SSLDummyStreamDTLS(this, "s2c", &server_buffer_, &client_buffer_);
|
||||||
server_ssl_ =
|
server_ssl_ =
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/arraysize.h"
|
#include "rtc_base/arraysize.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
|
|
||||||
|
@ -77,8 +78,8 @@ void hex_encode_with_delimiter(char* buffer,
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
std::string hex_encode(const std::string& str) {
|
std::string hex_encode(absl::string_view str) {
|
||||||
return hex_encode(str.c_str(), str.size());
|
return hex_encode(str.data(), str.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string hex_encode(const char* source, size_t srclen) {
|
std::string hex_encode(const char* source, size_t srclen) {
|
||||||
|
@ -141,14 +142,14 @@ size_t hex_decode_with_delimiter(char* cbuffer,
|
||||||
return bufpos;
|
return bufpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t hex_decode(char* buffer, size_t buflen, const std::string& source) {
|
size_t hex_decode(char* buffer, size_t buflen, absl::string_view source) {
|
||||||
return hex_decode_with_delimiter(buffer, buflen, source, 0);
|
return hex_decode_with_delimiter(buffer, buflen, source, 0);
|
||||||
}
|
}
|
||||||
size_t hex_decode_with_delimiter(char* buffer,
|
size_t hex_decode_with_delimiter(char* buffer,
|
||||||
size_t buflen,
|
size_t buflen,
|
||||||
const std::string& source,
|
absl::string_view source,
|
||||||
char delimiter) {
|
char delimiter) {
|
||||||
return hex_decode_with_delimiter(buffer, buflen, source.c_str(),
|
return hex_decode_with_delimiter(buffer, buflen, source.data(),
|
||||||
source.length(), delimiter);
|
source.length(), delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +178,7 @@ bool tokenize_first(absl::string_view source,
|
||||||
std::string* rest) {
|
std::string* rest) {
|
||||||
// Find the first delimiter
|
// Find the first delimiter
|
||||||
size_t left_pos = source.find(delimiter);
|
size_t left_pos = source.find(delimiter);
|
||||||
if (left_pos == std::string::npos) {
|
if (left_pos == absl::string_view::npos) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,8 +246,9 @@ std::string ToString(const bool b) {
|
||||||
std::string ToString(const char* const s) {
|
std::string ToString(const char* const s) {
|
||||||
return std::string(s);
|
return std::string(s);
|
||||||
}
|
}
|
||||||
std::string ToString(const std::string s) {
|
|
||||||
return s;
|
std::string ToString(absl::string_view s) {
|
||||||
|
return std::string(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ToString(const short s) {
|
std::string ToString(const short s) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace rtc {
|
||||||
// String Encoding Utilities
|
// String Encoding Utilities
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::string hex_encode(const std::string& str);
|
std::string hex_encode(absl::string_view str);
|
||||||
std::string hex_encode(const char* source, size_t srclen);
|
std::string hex_encode(const char* source, size_t srclen);
|
||||||
std::string hex_encode_with_delimiter(const char* source,
|
std::string hex_encode_with_delimiter(const char* source,
|
||||||
size_t srclen,
|
size_t srclen,
|
||||||
|
@ -51,10 +51,10 @@ size_t hex_decode_with_delimiter(char* buffer,
|
||||||
char delimiter);
|
char delimiter);
|
||||||
|
|
||||||
// Helper functions for hex_decode.
|
// Helper functions for hex_decode.
|
||||||
size_t hex_decode(char* buffer, size_t buflen, const std::string& source);
|
size_t hex_decode(char* buffer, size_t buflen, absl::string_view source);
|
||||||
size_t hex_decode_with_delimiter(char* buffer,
|
size_t hex_decode_with_delimiter(char* buffer,
|
||||||
size_t buflen,
|
size_t buflen,
|
||||||
const std::string& source,
|
absl::string_view source,
|
||||||
char delimiter);
|
char delimiter);
|
||||||
|
|
||||||
// Joins the source vector of strings into a single string, with each
|
// Joins the source vector of strings into a single string, with each
|
||||||
|
@ -89,7 +89,7 @@ bool tokenize_first(absl::string_view source,
|
||||||
std::string ToString(bool b);
|
std::string ToString(bool b);
|
||||||
|
|
||||||
std::string ToString(const char* s);
|
std::string ToString(const char* s);
|
||||||
std::string ToString(std::string t);
|
std::string ToString(absl::string_view s);
|
||||||
|
|
||||||
std::string ToString(short s);
|
std::string ToString(short s);
|
||||||
std::string ToString(unsigned short s);
|
std::string ToString(unsigned short s);
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include "rtc_base/string_utils.h"
|
#include "rtc_base/string_utils.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
size_t strcpyn(char* buffer,
|
size_t strcpyn(char* buffer,
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
@ -30,10 +32,24 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
const size_t SIZE_UNKNOWN = static_cast<size_t>(-1);
|
const size_t SIZE_UNKNOWN = static_cast<size_t>(-1);
|
||||||
|
|
||||||
|
// An absl::string_view comparator functor for use with container types such as
|
||||||
|
// std::map that support heterogenous lookup.
|
||||||
|
//
|
||||||
|
// Example usage:
|
||||||
|
// std::map<std::string, int, rtc::AbslStringViewCmp> my_map;
|
||||||
|
struct AbslStringViewCmp {
|
||||||
|
using is_transparent = void;
|
||||||
|
bool operator()(absl::string_view a, absl::string_view b) const {
|
||||||
|
return a < b;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Safe version of strncpy that always nul-terminate.
|
// Safe version of strncpy that always nul-terminate.
|
||||||
size_t strcpyn(char* buffer,
|
size_t strcpyn(char* buffer,
|
||||||
size_t buflen,
|
size_t buflen,
|
||||||
|
@ -57,7 +73,7 @@ inline std::wstring ToUtf16(const char* utf8, size_t len) {
|
||||||
return ws;
|
return ws;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::wstring ToUtf16(const std::string& str) {
|
inline std::wstring ToUtf16(absl::string_view str) {
|
||||||
return ToUtf16(str.data(), str.length());
|
return ToUtf16(str.data(), str.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/string_encode.h"
|
#include "rtc_base/string_encode.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
@ -240,46 +241,47 @@ bool GetDoubleFromJsonArray(const Json::Value& in, size_t n, double* out) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetValueFromJsonObject(const Json::Value& in,
|
bool GetValueFromJsonObject(const Json::Value& in,
|
||||||
const std::string& k,
|
absl::string_view k,
|
||||||
Json::Value* out) {
|
Json::Value* out) {
|
||||||
if (!in.isObject() || !in.isMember(k)) {
|
std::string k_str = std::string(k);
|
||||||
|
if (!in.isObject() || !in.isMember(k_str)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*out = in[k];
|
*out = in[k_str];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetIntFromJsonObject(const Json::Value& in,
|
bool GetIntFromJsonObject(const Json::Value& in,
|
||||||
const std::string& k,
|
absl::string_view k,
|
||||||
int* out) {
|
int* out) {
|
||||||
Json::Value x;
|
Json::Value x;
|
||||||
return GetValueFromJsonObject(in, k, &x) && GetIntFromJson(x, out);
|
return GetValueFromJsonObject(in, k, &x) && GetIntFromJson(x, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetUIntFromJsonObject(const Json::Value& in,
|
bool GetUIntFromJsonObject(const Json::Value& in,
|
||||||
const std::string& k,
|
absl::string_view k,
|
||||||
unsigned int* out) {
|
unsigned int* out) {
|
||||||
Json::Value x;
|
Json::Value x;
|
||||||
return GetValueFromJsonObject(in, k, &x) && GetUIntFromJson(x, out);
|
return GetValueFromJsonObject(in, k, &x) && GetUIntFromJson(x, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetStringFromJsonObject(const Json::Value& in,
|
bool GetStringFromJsonObject(const Json::Value& in,
|
||||||
const std::string& k,
|
absl::string_view k,
|
||||||
std::string* out) {
|
std::string* out) {
|
||||||
Json::Value x;
|
Json::Value x;
|
||||||
return GetValueFromJsonObject(in, k, &x) && GetStringFromJson(x, out);
|
return GetValueFromJsonObject(in, k, &x) && GetStringFromJson(x, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetBoolFromJsonObject(const Json::Value& in,
|
bool GetBoolFromJsonObject(const Json::Value& in,
|
||||||
const std::string& k,
|
absl::string_view k,
|
||||||
bool* out) {
|
bool* out) {
|
||||||
Json::Value x;
|
Json::Value x;
|
||||||
return GetValueFromJsonObject(in, k, &x) && GetBoolFromJson(x, out);
|
return GetValueFromJsonObject(in, k, &x) && GetBoolFromJson(x, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetDoubleFromJsonObject(const Json::Value& in,
|
bool GetDoubleFromJsonObject(const Json::Value& in,
|
||||||
const std::string& k,
|
absl::string_view k,
|
||||||
double* out) {
|
double* out) {
|
||||||
Json::Value x;
|
Json::Value x;
|
||||||
return GetValueFromJsonObject(in, k, &x) && GetDoubleFromJson(x, out);
|
return GetValueFromJsonObject(in, k, &x) && GetDoubleFromJson(x, out);
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
#if !defined(WEBRTC_EXTERNAL_JSON)
|
#if !defined(WEBRTC_EXTERNAL_JSON)
|
||||||
#include "json/json.h"
|
#include "json/json.h"
|
||||||
#else
|
#else
|
||||||
|
@ -62,22 +64,20 @@ Json::Value DoubleVectorToJsonArray(const std::vector<double>& in);
|
||||||
|
|
||||||
// Pull values out of a JSON object.
|
// Pull values out of a JSON object.
|
||||||
bool GetValueFromJsonObject(const Json::Value& in,
|
bool GetValueFromJsonObject(const Json::Value& in,
|
||||||
const std::string& k,
|
absl::string_view k,
|
||||||
Json::Value* out);
|
Json::Value* out);
|
||||||
bool GetIntFromJsonObject(const Json::Value& in,
|
bool GetIntFromJsonObject(const Json::Value& in, absl::string_view k, int* out);
|
||||||
const std::string& k,
|
|
||||||
int* out);
|
|
||||||
bool GetUIntFromJsonObject(const Json::Value& in,
|
bool GetUIntFromJsonObject(const Json::Value& in,
|
||||||
const std::string& k,
|
absl::string_view k,
|
||||||
unsigned int* out);
|
unsigned int* out);
|
||||||
bool GetStringFromJsonObject(const Json::Value& in,
|
bool GetStringFromJsonObject(const Json::Value& in,
|
||||||
const std::string& k,
|
absl::string_view k,
|
||||||
std::string* out);
|
std::string* out);
|
||||||
bool GetBoolFromJsonObject(const Json::Value& in,
|
bool GetBoolFromJsonObject(const Json::Value& in,
|
||||||
const std::string& k,
|
absl::string_view k,
|
||||||
bool* out);
|
bool* out);
|
||||||
bool GetDoubleFromJsonObject(const Json::Value& in,
|
bool GetDoubleFromJsonObject(const Json::Value& in,
|
||||||
const std::string& k,
|
absl::string_view k,
|
||||||
double* out);
|
double* out);
|
||||||
|
|
||||||
// Writes out a Json value as a string.
|
// Writes out a Json value as a string.
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/numerics/safe_minmax.h"
|
#include "rtc_base/numerics/safe_minmax.h"
|
||||||
|
|
||||||
|
@ -26,16 +27,12 @@ SimpleStringBuilder::SimpleStringBuilder(rtc::ArrayView<char> buffer)
|
||||||
RTC_DCHECK(IsConsistent());
|
RTC_DCHECK(IsConsistent());
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleStringBuilder& SimpleStringBuilder::operator<<(const char* str) {
|
|
||||||
return Append(str, strlen(str));
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleStringBuilder& SimpleStringBuilder::operator<<(char ch) {
|
SimpleStringBuilder& SimpleStringBuilder::operator<<(char ch) {
|
||||||
return Append(&ch, 1);
|
return Append(&ch, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleStringBuilder& SimpleStringBuilder::operator<<(const std::string& str) {
|
SimpleStringBuilder& SimpleStringBuilder::operator<<(absl::string_view str) {
|
||||||
return Append(str.c_str(), str.length());
|
return Append(str.data(), str.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Numeric conversion routines.
|
// Numeric conversion routines.
|
||||||
|
|
|
@ -32,9 +32,8 @@ class SimpleStringBuilder {
|
||||||
SimpleStringBuilder(const SimpleStringBuilder&) = delete;
|
SimpleStringBuilder(const SimpleStringBuilder&) = delete;
|
||||||
SimpleStringBuilder& operator=(const SimpleStringBuilder&) = delete;
|
SimpleStringBuilder& operator=(const SimpleStringBuilder&) = delete;
|
||||||
|
|
||||||
SimpleStringBuilder& operator<<(const char* str);
|
|
||||||
SimpleStringBuilder& operator<<(char ch);
|
SimpleStringBuilder& operator<<(char ch);
|
||||||
SimpleStringBuilder& operator<<(const std::string& str);
|
SimpleStringBuilder& operator<<(absl::string_view str);
|
||||||
SimpleStringBuilder& operator<<(int i);
|
SimpleStringBuilder& operator<<(int i);
|
||||||
SimpleStringBuilder& operator<<(unsigned i);
|
SimpleStringBuilder& operator<<(unsigned i);
|
||||||
SimpleStringBuilder& operator<<(long i); // NOLINT
|
SimpleStringBuilder& operator<<(long i); // NOLINT
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
#include <comdef.h>
|
#include <comdef.h>
|
||||||
#elif defined(WEBRTC_POSIX)
|
#elif defined(WEBRTC_POSIX)
|
||||||
|
@ -744,10 +746,10 @@ bool Thread::SleepMs(int milliseconds) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Thread::SetName(const std::string& name, const void* obj) {
|
bool Thread::SetName(absl::string_view name, const void* obj) {
|
||||||
RTC_DCHECK(!IsRunning());
|
RTC_DCHECK(!IsRunning());
|
||||||
|
|
||||||
name_ = name;
|
name_ = std::string(name);
|
||||||
if (obj) {
|
if (obj) {
|
||||||
// The %p specifier typically produce at most 16 hex digits, possibly with a
|
// The %p specifier typically produce at most 16 hex digits, possibly with a
|
||||||
// 0x prefix. But format is implementation defined, so add some margin.
|
// 0x prefix. But format is implementation defined, so add some margin.
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
#if defined(WEBRTC_POSIX)
|
#if defined(WEBRTC_POSIX)
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -348,7 +350,7 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase {
|
||||||
// Sets the thread's name, for debugging. Must be called before Start().
|
// Sets the thread's name, for debugging. Must be called before Start().
|
||||||
// If `obj` is non-null, its value is appended to `name`.
|
// If `obj` is non-null, its value is appended to `name`.
|
||||||
const std::string& name() const { return name_; }
|
const std::string& name() const { return name_; }
|
||||||
bool SetName(const std::string& name, const void* obj);
|
bool SetName(absl::string_view name, const void* obj);
|
||||||
|
|
||||||
// Sets the expected processing time in ms. The thread will write
|
// Sets the expected processing time in ms. The thread will write
|
||||||
// log messages when Invoke() takes more time than this.
|
// log messages when Invoke() takes more time than this.
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/helpers.h"
|
#include "rtc_base/helpers.h"
|
||||||
#include "rtc_base/string_encode.h"
|
#include "rtc_base/string_encode.h"
|
||||||
#include "rtc_base/string_to_number.h"
|
#include "rtc_base/string_to_number.h"
|
||||||
|
@ -55,8 +56,11 @@ std::string UniqueStringGenerator::GenerateString() {
|
||||||
return ToString(unique_number_generator_.GenerateNumber());
|
return ToString(unique_number_generator_.GenerateNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UniqueStringGenerator::AddKnownId(const std::string& value) {
|
bool UniqueStringGenerator::AddKnownId(absl::string_view value) {
|
||||||
absl::optional<uint32_t> int_value = StringToNumber<uint32_t>(value);
|
// TODO(webrtc:13579): remove string copy here once absl::string_view version
|
||||||
|
// of StringToNumber is available.
|
||||||
|
absl::optional<uint32_t> int_value =
|
||||||
|
StringToNumber<uint32_t>(std::string(value));
|
||||||
// The underlying generator works for uint32_t values, so if the provided
|
// The underlying generator works for uint32_t values, so if the provided
|
||||||
// value is not a uint32_t it will never be generated anyway.
|
// value is not a uint32_t it will never be generated anyway.
|
||||||
if (int_value.has_value()) {
|
if (int_value.has_value()) {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
#include "rtc_base/synchronization/mutex.h"
|
#include "rtc_base/synchronization/mutex.h"
|
||||||
|
@ -103,7 +104,7 @@ class UniqueStringGenerator {
|
||||||
|
|
||||||
// Adds an id that this generator should no longer generate.
|
// Adds an id that this generator should no longer generate.
|
||||||
// Return value indicates whether the ID was hitherto unknown.
|
// Return value indicates whether the ID was hitherto unknown.
|
||||||
bool AddKnownId(const std::string& value);
|
bool AddKnownId(absl::string_view value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// This implementation will be simple and will generate "0", "1", ...
|
// This implementation will be simple and will generate "0", "1", ...
|
||||||
|
|
|
@ -355,6 +355,8 @@ if (is_ios || is_mac) {
|
||||||
"../rtc_base:network_constants",
|
"../rtc_base:network_constants",
|
||||||
"../rtc_base:threading",
|
"../rtc_base:threading",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc_library("network_monitor_objc") {
|
rtc_library("network_monitor_objc") {
|
||||||
|
@ -374,6 +376,7 @@ if (is_ios || is_mac) {
|
||||||
":base_objc",
|
":base_objc",
|
||||||
":helpers_objc",
|
":helpers_objc",
|
||||||
":network_monitor_observer",
|
":network_monitor_observer",
|
||||||
|
"../rtc_base:stringutils",
|
||||||
"../rtc_base/system:gcd_helpers",
|
"../rtc_base/system:gcd_helpers",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1581,6 +1584,8 @@ if (is_ios || is_mac) {
|
||||||
"../rtc_base/task_utils:pending_task_safety_flag",
|
"../rtc_base/task_utils:pending_task_safety_flag",
|
||||||
"../rtc_base/task_utils:to_queued_task",
|
"../rtc_base/task_utils:to_queued_task",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -592,7 +592,10 @@ if (current_os == "linux" || is_android) {
|
||||||
"../../system_wrappers:field_trial",
|
"../../system_wrappers:field_trial",
|
||||||
"../../system_wrappers:metrics",
|
"../../system_wrappers:metrics",
|
||||||
]
|
]
|
||||||
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
|
absl_deps = [
|
||||||
|
"//third_party/abseil-cpp/absl/strings",
|
||||||
|
"//third_party/abseil-cpp/absl/types:optional",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc_library("audio_jni") {
|
rtc_library("audio_jni") {
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include "sdk/android/src/jni/android_network_monitor.h"
|
#include "sdk/android/src/jni/android_network_monitor.h"
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#ifndef RTLD_NOLOAD
|
#ifndef RTLD_NOLOAD
|
||||||
// This was added in Lollipop to dlfcn.h
|
// This was added in Lollipop to dlfcn.h
|
||||||
#define RTLD_NOLOAD 4
|
#define RTLD_NOLOAD 4
|
||||||
|
@ -284,7 +286,7 @@ void AndroidNetworkMonitor::Stop() {
|
||||||
rtc::NetworkBindingResult AndroidNetworkMonitor::BindSocketToNetwork(
|
rtc::NetworkBindingResult AndroidNetworkMonitor::BindSocketToNetwork(
|
||||||
int socket_fd,
|
int socket_fd,
|
||||||
const rtc::IPAddress& address,
|
const rtc::IPAddress& address,
|
||||||
const std::string& if_name) {
|
absl::string_view if_name) {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
|
|
||||||
// Android prior to Lollipop didn't have support for binding sockets to
|
// Android prior to Lollipop didn't have support for binding sockets to
|
||||||
|
@ -417,7 +419,7 @@ void AndroidNetworkMonitor::OnNetworkConnected_n(
|
||||||
absl::optional<NetworkHandle>
|
absl::optional<NetworkHandle>
|
||||||
AndroidNetworkMonitor::FindNetworkHandleFromAddressOrName(
|
AndroidNetworkMonitor::FindNetworkHandleFromAddressOrName(
|
||||||
const rtc::IPAddress& ip_address,
|
const rtc::IPAddress& ip_address,
|
||||||
const std::string& if_name) const {
|
absl::string_view if_name) const {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
RTC_LOG(LS_INFO) << "Find network handle.";
|
RTC_LOG(LS_INFO) << "Find network handle.";
|
||||||
if (find_network_handle_without_ipv6_temporary_part_) {
|
if (find_network_handle_without_ipv6_temporary_part_) {
|
||||||
|
@ -443,11 +445,11 @@ AndroidNetworkMonitor::FindNetworkHandleFromAddressOrName(
|
||||||
|
|
||||||
absl::optional<NetworkHandle>
|
absl::optional<NetworkHandle>
|
||||||
AndroidNetworkMonitor::FindNetworkHandleFromIfname(
|
AndroidNetworkMonitor::FindNetworkHandleFromIfname(
|
||||||
const std::string& if_name) const {
|
absl::string_view if_name) const {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
if (bind_using_ifname_) {
|
if (bind_using_ifname_) {
|
||||||
for (auto const& iter : network_info_by_handle_) {
|
for (auto const& iter : network_info_by_handle_) {
|
||||||
if (if_name.find(iter.second.interface_name) != std::string::npos) {
|
if (if_name.find(iter.second.interface_name) != absl::string_view::npos) {
|
||||||
// Use partial match so that e.g if_name="v4-wlan0" is matched
|
// Use partial match so that e.g if_name="v4-wlan0" is matched
|
||||||
// agains iter.first="wlan0"
|
// agains iter.first="wlan0"
|
||||||
return absl::make_optional(iter.first);
|
return absl::make_optional(iter.first);
|
||||||
|
@ -495,7 +497,7 @@ void AndroidNetworkMonitor::SetNetworkInfos(
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::AdapterType AndroidNetworkMonitor::GetAdapterType(
|
rtc::AdapterType AndroidNetworkMonitor::GetAdapterType(
|
||||||
const std::string& if_name) {
|
absl::string_view if_name) {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
auto iter = adapter_type_by_name_.find(if_name);
|
auto iter = adapter_type_by_name_.find(if_name);
|
||||||
rtc::AdapterType type = (iter == adapter_type_by_name_.end())
|
rtc::AdapterType type = (iter == adapter_type_by_name_.end())
|
||||||
|
@ -506,7 +508,7 @@ rtc::AdapterType AndroidNetworkMonitor::GetAdapterType(
|
||||||
for (auto const& iter : adapter_type_by_name_) {
|
for (auto const& iter : adapter_type_by_name_) {
|
||||||
// Use partial match so that e.g if_name="v4-wlan0" is matched
|
// Use partial match so that e.g if_name="v4-wlan0" is matched
|
||||||
// agains iter.first="wlan0"
|
// agains iter.first="wlan0"
|
||||||
if (if_name.find(iter.first) != std::string::npos) {
|
if (if_name.find(iter.first) != absl::string_view::npos) {
|
||||||
type = iter.second;
|
type = iter.second;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -520,7 +522,7 @@ rtc::AdapterType AndroidNetworkMonitor::GetAdapterType(
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::AdapterType AndroidNetworkMonitor::GetVpnUnderlyingAdapterType(
|
rtc::AdapterType AndroidNetworkMonitor::GetVpnUnderlyingAdapterType(
|
||||||
const std::string& if_name) {
|
absl::string_view if_name) {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
auto iter = vpn_underlying_adapter_type_by_name_.find(if_name);
|
auto iter = vpn_underlying_adapter_type_by_name_.find(if_name);
|
||||||
rtc::AdapterType type = (iter == vpn_underlying_adapter_type_by_name_.end())
|
rtc::AdapterType type = (iter == vpn_underlying_adapter_type_by_name_.end())
|
||||||
|
@ -530,7 +532,7 @@ rtc::AdapterType AndroidNetworkMonitor::GetVpnUnderlyingAdapterType(
|
||||||
// Use partial match so that e.g if_name="v4-wlan0" is matched
|
// Use partial match so that e.g if_name="v4-wlan0" is matched
|
||||||
// agains iter.first="wlan0"
|
// agains iter.first="wlan0"
|
||||||
for (auto const& iter : vpn_underlying_adapter_type_by_name_) {
|
for (auto const& iter : vpn_underlying_adapter_type_by_name_) {
|
||||||
if (if_name.find(iter.first) != std::string::npos) {
|
if (if_name.find(iter.first) != absl::string_view::npos) {
|
||||||
type = iter.second;
|
type = iter.second;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -541,7 +543,7 @@ rtc::AdapterType AndroidNetworkMonitor::GetVpnUnderlyingAdapterType(
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::NetworkPreference AndroidNetworkMonitor::GetNetworkPreference(
|
rtc::NetworkPreference AndroidNetworkMonitor::GetNetworkPreference(
|
||||||
const std::string& if_name) {
|
absl::string_view if_name) {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
auto iter = adapter_type_by_name_.find(if_name);
|
auto iter = adapter_type_by_name_.find(if_name);
|
||||||
if (iter == adapter_type_by_name_.end()) {
|
if (iter == adapter_type_by_name_.end()) {
|
||||||
|
|
|
@ -17,9 +17,11 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
#include "rtc_base/network_monitor.h"
|
#include "rtc_base/network_monitor.h"
|
||||||
#include "rtc_base/network_monitor_factory.h"
|
#include "rtc_base/network_monitor_factory.h"
|
||||||
|
#include "rtc_base/string_utils.h"
|
||||||
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
#include "rtc_base/thread_annotations.h"
|
#include "rtc_base/thread_annotations.h"
|
||||||
|
@ -83,12 +85,12 @@ class AndroidNetworkMonitor : public rtc::NetworkMonitorInterface {
|
||||||
rtc::NetworkBindingResult BindSocketToNetwork(
|
rtc::NetworkBindingResult BindSocketToNetwork(
|
||||||
int socket_fd,
|
int socket_fd,
|
||||||
const rtc::IPAddress& address,
|
const rtc::IPAddress& address,
|
||||||
const std::string& if_name) override;
|
absl::string_view if_name) override;
|
||||||
rtc::AdapterType GetAdapterType(const std::string& if_name) override;
|
rtc::AdapterType GetAdapterType(absl::string_view if_name) override;
|
||||||
rtc::AdapterType GetVpnUnderlyingAdapterType(
|
rtc::AdapterType GetVpnUnderlyingAdapterType(
|
||||||
const std::string& if_name) override;
|
absl::string_view if_name) override;
|
||||||
rtc::NetworkPreference GetNetworkPreference(
|
rtc::NetworkPreference GetNetworkPreference(
|
||||||
const std::string& if_name) override;
|
absl::string_view if_name) override;
|
||||||
|
|
||||||
// Always expected to be called on the network thread.
|
// Always expected to be called on the network thread.
|
||||||
void SetNetworkInfos(const std::vector<NetworkInformation>& network_infos);
|
void SetNetworkInfos(const std::vector<NetworkInformation>& network_infos);
|
||||||
|
@ -112,7 +114,7 @@ class AndroidNetworkMonitor : public rtc::NetworkMonitorInterface {
|
||||||
// Visible for testing.
|
// Visible for testing.
|
||||||
absl::optional<NetworkHandle> FindNetworkHandleFromAddressOrName(
|
absl::optional<NetworkHandle> FindNetworkHandleFromAddressOrName(
|
||||||
const rtc::IPAddress& address,
|
const rtc::IPAddress& address,
|
||||||
const std::string& ifname) const;
|
absl::string_view ifname) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnNetworkConnected_n(const NetworkInformation& network_info);
|
void OnNetworkConnected_n(const NetworkInformation& network_info);
|
||||||
|
@ -121,17 +123,17 @@ class AndroidNetworkMonitor : public rtc::NetworkMonitorInterface {
|
||||||
rtc::NetworkPreference preference);
|
rtc::NetworkPreference preference);
|
||||||
|
|
||||||
absl::optional<NetworkHandle> FindNetworkHandleFromIfname(
|
absl::optional<NetworkHandle> FindNetworkHandleFromIfname(
|
||||||
const std::string& ifname) const;
|
absl::string_view ifname) const;
|
||||||
|
|
||||||
const int android_sdk_int_;
|
const int android_sdk_int_;
|
||||||
ScopedJavaGlobalRef<jobject> j_application_context_;
|
ScopedJavaGlobalRef<jobject> j_application_context_;
|
||||||
ScopedJavaGlobalRef<jobject> j_network_monitor_;
|
ScopedJavaGlobalRef<jobject> j_network_monitor_;
|
||||||
rtc::Thread* const network_thread_;
|
rtc::Thread* const network_thread_;
|
||||||
bool started_ RTC_GUARDED_BY(network_thread_) = false;
|
bool started_ RTC_GUARDED_BY(network_thread_) = false;
|
||||||
std::map<std::string, rtc::AdapterType> adapter_type_by_name_
|
std::map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp>
|
||||||
RTC_GUARDED_BY(network_thread_);
|
adapter_type_by_name_ RTC_GUARDED_BY(network_thread_);
|
||||||
std::map<std::string, rtc::AdapterType> vpn_underlying_adapter_type_by_name_
|
std::map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp>
|
||||||
RTC_GUARDED_BY(network_thread_);
|
vpn_underlying_adapter_type_by_name_ RTC_GUARDED_BY(network_thread_);
|
||||||
std::map<rtc::IPAddress, NetworkHandle> network_handle_by_address_
|
std::map<rtc::IPAddress, NetworkHandle> network_handle_by_address_
|
||||||
RTC_GUARDED_BY(network_thread_);
|
RTC_GUARDED_BY(network_thread_);
|
||||||
std::map<NetworkHandle, NetworkInformation> network_info_by_handle_
|
std::map<NetworkHandle, NetworkInformation> network_info_by_handle_
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#import "base/RTCLogging.h"
|
#import "base/RTCLogging.h"
|
||||||
#import "helpers/RTCDispatcher+Private.h"
|
#import "helpers/RTCDispatcher+Private.h"
|
||||||
|
|
||||||
|
#include "rtc_base/string_utils.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
rtc::AdapterType AdapterTypeFromInterfaceType(nw_interface_type_t interfaceType) {
|
rtc::AdapterType AdapterTypeFromInterfaceType(nw_interface_type_t interfaceType) {
|
||||||
|
@ -78,8 +80,8 @@ rtc::AdapterType AdapterTypeFromInterfaceType(nw_interface_type_t interfaceType)
|
||||||
} else if (status == nw_path_status_satisfiable) {
|
} else if (status == nw_path_status_satisfiable) {
|
||||||
RTCLog(@"NW path monitor status: satisfiable.");
|
RTCLog(@"NW path monitor status: satisfiable.");
|
||||||
}
|
}
|
||||||
std::map<std::string, rtc::AdapterType> *map =
|
std::map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp> *map =
|
||||||
new std::map<std::string, rtc::AdapterType>();
|
new std::map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp>();
|
||||||
nw_path_enumerate_interfaces(
|
nw_path_enumerate_interfaces(
|
||||||
path, (nw_path_enumerate_interfaces_block_t) ^ (nw_interface_t interface) {
|
path, (nw_path_enumerate_interfaces_block_t) ^ (nw_interface_t interface) {
|
||||||
const char *name = nw_interface_get_name(interface);
|
const char *name = nw_interface_get_name(interface);
|
||||||
|
|
|
@ -14,7 +14,9 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/network_constants.h"
|
#include "rtc_base/network_constants.h"
|
||||||
|
#include "rtc_base/string_utils.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
@ -28,7 +30,8 @@ class NetworkMonitorObserver {
|
||||||
// adapter type, for all available interfaces on the current path. If an
|
// adapter type, for all available interfaces on the current path. If an
|
||||||
// interface name isn't present it can be assumed to be unavailable.
|
// interface name isn't present it can be assumed to be unavailable.
|
||||||
virtual void OnPathUpdate(
|
virtual void OnPathUpdate(
|
||||||
std::map<std::string, rtc::AdapterType> adapter_type_by_name) = 0;
|
std::map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp>
|
||||||
|
adapter_type_by_name) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~NetworkMonitorObserver() {}
|
virtual ~NetworkMonitorObserver() {}
|
||||||
|
|
|
@ -13,9 +13,11 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
#include "rtc_base/network_monitor.h"
|
#include "rtc_base/network_monitor.h"
|
||||||
#include "rtc_base/network_monitor_factory.h"
|
#include "rtc_base/network_monitor_factory.h"
|
||||||
|
#include "rtc_base/string_utils.h"
|
||||||
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
#include "rtc_base/thread_annotations.h"
|
#include "rtc_base/thread_annotations.h"
|
||||||
|
@ -41,23 +43,24 @@ class ObjCNetworkMonitor : public rtc::NetworkMonitorInterface,
|
||||||
void Start() override;
|
void Start() override;
|
||||||
void Stop() override;
|
void Stop() override;
|
||||||
|
|
||||||
rtc::AdapterType GetAdapterType(const std::string& interface_name) override;
|
rtc::AdapterType GetAdapterType(absl::string_view interface_name) override;
|
||||||
rtc::AdapterType GetVpnUnderlyingAdapterType(
|
rtc::AdapterType GetVpnUnderlyingAdapterType(
|
||||||
const std::string& interface_name) override;
|
absl::string_view interface_name) override;
|
||||||
rtc::NetworkPreference GetNetworkPreference(
|
rtc::NetworkPreference GetNetworkPreference(
|
||||||
const std::string& interface_name) override;
|
absl::string_view interface_name) override;
|
||||||
bool IsAdapterAvailable(const std::string& interface_name) override;
|
bool IsAdapterAvailable(absl::string_view interface_name) override;
|
||||||
|
|
||||||
// NetworkMonitorObserver override.
|
// NetworkMonitorObserver override.
|
||||||
// Fans out updates to observers on the correct thread.
|
// Fans out updates to observers on the correct thread.
|
||||||
void OnPathUpdate(
|
void OnPathUpdate(
|
||||||
std::map<std::string, rtc::AdapterType> adapter_type_by_name) override;
|
std::map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp>
|
||||||
|
adapter_type_by_name) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
rtc::Thread* thread_ = nullptr;
|
rtc::Thread* thread_ = nullptr;
|
||||||
bool started_ = false;
|
bool started_ = false;
|
||||||
std::map<std::string, rtc::AdapterType> adapter_type_by_name_
|
std::map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp>
|
||||||
RTC_GUARDED_BY(thread_);
|
adapter_type_by_name_ RTC_GUARDED_BY(thread_);
|
||||||
rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag_;
|
rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag_;
|
||||||
RTCNetworkMonitor* network_monitor_ = nil;
|
RTCNetworkMonitor* network_monitor_ = nil;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,12 +9,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sdk/objc/native/src/objc_network_monitor.h"
|
#include "sdk/objc/native/src/objc_network_monitor.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
#include "rtc_base/task_utils/to_queued_task.h"
|
#include "rtc_base/task_utils/to_queued_task.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
|
#include "rtc_base/string_utils.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
|
@ -56,24 +58,24 @@ void ObjCNetworkMonitor::Stop() {
|
||||||
started_ = false;
|
started_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::AdapterType ObjCNetworkMonitor::GetAdapterType(const std::string& interface_name) {
|
rtc::AdapterType ObjCNetworkMonitor::GetAdapterType(absl::string_view interface_name) {
|
||||||
RTC_DCHECK_RUN_ON(thread_);
|
RTC_DCHECK_RUN_ON(thread_);
|
||||||
if (adapter_type_by_name_.find(interface_name) == adapter_type_by_name_.end()) {
|
auto iter = adapter_type_by_name_.find(interface_name);
|
||||||
|
if (iter == adapter_type_by_name_.end()) {
|
||||||
return rtc::ADAPTER_TYPE_UNKNOWN;
|
return rtc::ADAPTER_TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
return adapter_type_by_name_.at(interface_name);
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::AdapterType ObjCNetworkMonitor::GetVpnUnderlyingAdapterType(
|
rtc::AdapterType ObjCNetworkMonitor::GetVpnUnderlyingAdapterType(absl::string_view interface_name) {
|
||||||
const std::string& interface_name) {
|
|
||||||
return rtc::ADAPTER_TYPE_UNKNOWN;
|
return rtc::ADAPTER_TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::NetworkPreference ObjCNetworkMonitor::GetNetworkPreference(const std::string& interface_name) {
|
rtc::NetworkPreference ObjCNetworkMonitor::GetNetworkPreference(absl::string_view interface_name) {
|
||||||
return rtc::NetworkPreference::NEUTRAL;
|
return rtc::NetworkPreference::NEUTRAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ObjCNetworkMonitor::IsAdapterAvailable(const std::string& interface_name) {
|
bool ObjCNetworkMonitor::IsAdapterAvailable(absl::string_view interface_name) {
|
||||||
RTC_DCHECK_RUN_ON(thread_);
|
RTC_DCHECK_RUN_ON(thread_);
|
||||||
if (adapter_type_by_name_.empty()) {
|
if (adapter_type_by_name_.empty()) {
|
||||||
// If we have no path update, assume everything's available, because it's
|
// If we have no path update, assume everything's available, because it's
|
||||||
|
@ -84,7 +86,7 @@ bool ObjCNetworkMonitor::IsAdapterAvailable(const std::string& interface_name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjCNetworkMonitor::OnPathUpdate(
|
void ObjCNetworkMonitor::OnPathUpdate(
|
||||||
std::map<std::string, rtc::AdapterType> adapter_type_by_name) {
|
std::map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp> adapter_type_by_name) {
|
||||||
RTC_DCHECK(network_monitor_ != nil);
|
RTC_DCHECK(network_monitor_ != nil);
|
||||||
thread_->PostTask(ToQueuedTask(safety_flag_, [this, adapter_type_by_name] {
|
thread_->PostTask(ToQueuedTask(safety_flag_, [this, adapter_type_by_name] {
|
||||||
RTC_DCHECK_RUN_ON(thread_);
|
RTC_DCHECK_RUN_ON(thread_);
|
||||||
|
|
Loading…
Reference in a new issue