From a7de698675b5656aea88bf1bb1f13aae53974699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Thu, 21 Mar 2019 15:48:49 +0100 Subject: [PATCH] Add functions IsLegalMidName and IsLegalRsidName This is a preparation for deleting the class StringRtpHeaderExtension. Bug: webrtc:10440 Change-Id: I3480e58d96e67d10c4d78597c8ab7f01b63e37ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128761 Commit-Queue: Niels Moller Reviewed-by: Danil Chapovalov Cr-Commit-Position: refs/heads/master@{#27228} --- call/rtcp_demuxer.cc | 3 ++- call/rtp_demuxer.cc | 4 +-- modules/rtp_rtcp/BUILD.gn | 1 + modules/rtp_rtcp/include/rtp_rtcp_defines.cc | 27 +++++++++++++++----- modules/rtp_rtcp/include/rtp_rtcp_defines.h | 4 +++ 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/call/rtcp_demuxer.cc b/call/rtcp_demuxer.cc index e181d3a555..d35548d4cb 100644 --- a/call/rtcp_demuxer.cc +++ b/call/rtcp_demuxer.cc @@ -18,6 +18,7 @@ #include "api/rtp_headers.h" #include "call/rtcp_packet_sink_interface.h" #include "call/rtp_rtcp_demuxer_helper.h" +#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "rtc_base/checks.h" namespace webrtc { @@ -39,7 +40,7 @@ void RtcpDemuxer::AddSink(uint32_t sender_ssrc, RtcpPacketSinkInterface* sink) { void RtcpDemuxer::AddSink(const std::string& rsid, RtcpPacketSinkInterface* sink) { - RTC_DCHECK(StreamId::IsLegalRsidName(rsid)); + RTC_DCHECK(IsLegalRsidName(rsid)); RTC_DCHECK(sink); RTC_DCHECK(!ContainerHasKey(broadcast_sinks_, sink)); RTC_DCHECK(!MultimapAssociationExists(rsid_sinks_, rsid, sink)); diff --git a/call/rtp_demuxer.cc b/call/rtp_demuxer.cc index 8f0e2e529d..23f605d5b2 100644 --- a/call/rtp_demuxer.cc +++ b/call/rtp_demuxer.cc @@ -38,8 +38,8 @@ bool RtpDemuxer::AddSink(const RtpDemuxerCriteria& criteria, RtpPacketSinkInterface* sink) { RTC_DCHECK(!criteria.payload_types.empty() || !criteria.ssrcs.empty() || !criteria.mid.empty() || !criteria.rsid.empty()); - RTC_DCHECK(criteria.mid.empty() || Mid::IsLegalMidName(criteria.mid)); - RTC_DCHECK(criteria.rsid.empty() || StreamId::IsLegalRsidName(criteria.rsid)); + RTC_DCHECK(criteria.mid.empty() || IsLegalMidName(criteria.mid)); + RTC_DCHECK(criteria.rsid.empty() || IsLegalRsidName(criteria.rsid)); RTC_DCHECK(sink); // We return false instead of DCHECKing for logical conflicts with the new diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index 9fe7fdc7c9..2cabd1eaf9 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -104,6 +104,7 @@ rtc_source_set("rtp_rtcp_format") { "../../rtc_base/system:unused", "../../system_wrappers", "../video_coding:codec_globals_headers", + "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:variant", ] diff --git a/modules/rtp_rtcp/include/rtp_rtcp_defines.cc b/modules/rtp_rtcp/include/rtp_rtcp_defines.cc index d23d82da48..20bd1e700d 100644 --- a/modules/rtp_rtcp/include/rtp_rtcp_defines.cc +++ b/modules/rtp_rtcp/include/rtp_rtcp_defines.cc @@ -20,9 +20,8 @@ namespace webrtc { -StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {} - -constexpr size_t StreamId::kMaxSize; +namespace { +constexpr size_t kMidRsidMaxSize = 16; // Check if passed character is a "token-char" from RFC 4566. static bool IsTokenChar(char ch) { @@ -31,16 +30,30 @@ static bool IsTokenChar(char ch) { (ch >= 0x41 && ch <= 0x5a) || (ch >= 0x5e && ch <= 0x7e); } -bool StreamId::IsLegalMidName(rtc::ArrayView name) { - return (name.size() <= kMaxSize && name.size() > 0 && +} // namespace + +StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {} + +constexpr size_t StreamId::kMaxSize; + +bool IsLegalMidName(absl::string_view name) { + return (name.size() <= kMidRsidMaxSize && name.size() > 0 && std::all_of(name.data(), name.data() + name.size(), IsTokenChar)); } -bool StreamId::IsLegalRsidName(rtc::ArrayView name) { - return (name.size() <= kMaxSize && name.size() > 0 && +bool StreamId::IsLegalMidName(rtc::ArrayView name) { + return ::webrtc::IsLegalMidName(absl::string_view(name.data(), name.size())); +} + +bool IsLegalRsidName(absl::string_view name) { + return (name.size() <= kMidRsidMaxSize && name.size() > 0 && std::all_of(name.data(), name.data() + name.size(), isalnum)); } +bool StreamId::IsLegalRsidName(rtc::ArrayView name) { + return ::webrtc::IsLegalRsidName(absl::string_view(name.data(), name.size())); +} + void StreamId::Set(const char* data, size_t size) { // If |data| contains \0, the stream id size might become less than |size|. RTC_CHECK_LE(size, kMaxSize); diff --git a/modules/rtp_rtcp/include/rtp_rtcp_defines.h b/modules/rtp_rtcp/include/rtp_rtcp_defines.h index a4e75ba687..d339ecb130 100644 --- a/modules/rtp_rtcp/include/rtp_rtcp_defines.h +++ b/modules/rtp_rtcp/include/rtp_rtcp_defines.h @@ -15,6 +15,7 @@ #include #include +#include "absl/strings/string_view.h" #include "absl/types/variant.h" #include "api/audio_codecs/audio_format.h" #include "api/rtp_headers.h" @@ -45,6 +46,9 @@ enum ProtectionType { kUnprotectedPacket, kProtectedPacket }; enum StorageType { kDontRetransmit, kAllowRetransmission }; +bool IsLegalMidName(absl::string_view name); +bool IsLegalRsidName(absl::string_view name); + // This enum must not have any gaps, i.e., all integers between // kRtpExtensionNone and kRtpExtensionNumberOfExtensions must be valid enum // entries.