Add string_view version of cricket::StringToProto
And deprecate old version. Bug: webrtc:13579 Change-Id: I3eda669fdaa814c0e3c75a78242279bf9e526b1c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/262241 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36999}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
f7f0b2108f
commit
4662f53285
@ -80,13 +80,21 @@ const char* ProtoToString(ProtocolType proto) {
|
||||
return PROTO_NAMES[proto];
|
||||
}
|
||||
|
||||
bool StringToProto(const char* value, ProtocolType* proto) {
|
||||
absl::optional<ProtocolType> StringToProto(absl::string_view proto_name) {
|
||||
for (size_t i = 0; i <= PROTO_LAST; ++i) {
|
||||
if (absl::EqualsIgnoreCase(PROTO_NAMES[i], value)) {
|
||||
*proto = static_cast<ProtocolType>(i);
|
||||
return true;
|
||||
if (absl::EqualsIgnoreCase(PROTO_NAMES[i], proto_name)) {
|
||||
return static_cast<ProtocolType>(i);
|
||||
}
|
||||
}
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
bool StringToProto(const char* value, ProtocolType* proto) {
|
||||
if (absl::optional<ProtocolType> type = StringToProto(value);
|
||||
type.has_value()) {
|
||||
*proto = *type;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/candidate.h"
|
||||
#include "api/field_trials_view.h"
|
||||
@ -125,7 +126,10 @@ class CandidateStats {
|
||||
typedef std::vector<CandidateStats> CandidateStatsList;
|
||||
|
||||
const char* ProtoToString(ProtocolType proto);
|
||||
bool StringToProto(const char* value, ProtocolType* proto);
|
||||
absl::optional<ProtocolType> StringToProto(absl::string_view proto_name);
|
||||
|
||||
// TODO(bugs.webrtc.org/13579): Delete once downstream usage is updated.
|
||||
[[deprecated]] bool StringToProto(const char* value, ProtocolType* proto);
|
||||
|
||||
struct ProtocolAddress {
|
||||
rtc::SocketAddress address;
|
||||
|
||||
@ -183,12 +183,15 @@ static RTCErrorType ParseIceServerUrl(
|
||||
RTC_LOG(LS_WARNING) << "Transport parameter missing value.";
|
||||
return RTCErrorType::SYNTAX_ERROR;
|
||||
}
|
||||
if (!cricket::StringToProto(tokens[1].c_str(), &turn_transport_type) ||
|
||||
(turn_transport_type != cricket::PROTO_UDP &&
|
||||
turn_transport_type != cricket::PROTO_TCP)) {
|
||||
|
||||
absl::optional<cricket::ProtocolType> proto =
|
||||
cricket::StringToProto(tokens[1]);
|
||||
if (!proto ||
|
||||
(*proto != cricket::PROTO_UDP && *proto != cricket::PROTO_TCP)) {
|
||||
RTC_LOG(LS_WARNING) << "Transport parameter should always be udp or tcp.";
|
||||
return RTCErrorType::SYNTAX_ERROR;
|
||||
}
|
||||
turn_transport_type = *proto;
|
||||
}
|
||||
|
||||
std::string hoststring;
|
||||
|
||||
@ -1112,12 +1112,13 @@ bool ParseCandidate(absl::string_view message,
|
||||
}
|
||||
SocketAddress address(connection_address, port);
|
||||
|
||||
cricket::ProtocolType protocol;
|
||||
if (!StringToProto(transport.c_str(), &protocol)) {
|
||||
absl::optional<cricket::ProtocolType> protocol =
|
||||
cricket::StringToProto(transport);
|
||||
if (!protocol) {
|
||||
return ParseFailed(first_line, "Unsupported transport type.", error);
|
||||
}
|
||||
bool tcp_protocol = false;
|
||||
switch (protocol) {
|
||||
switch (*protocol) {
|
||||
// Supported protocols.
|
||||
case cricket::PROTO_UDP:
|
||||
break;
|
||||
@ -1225,7 +1226,7 @@ bool ParseCandidate(absl::string_view message,
|
||||
}
|
||||
}
|
||||
|
||||
*candidate = Candidate(component_id, cricket::ProtoToString(protocol),
|
||||
*candidate = Candidate(component_id, cricket::ProtoToString(*protocol),
|
||||
address, priority, username, password, candidate_type,
|
||||
generation, foundation, network_id, network_cost);
|
||||
candidate->set_related_address(related_address);
|
||||
|
||||
Reference in New Issue
Block a user