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 <nisse@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27228}
This commit is contained in:
Niels Möller
2019-03-21 15:48:49 +01:00
committed by Commit Bot
parent 741daaf039
commit a7de698675
5 changed files with 29 additions and 10 deletions

View File

@ -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<const char> 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<const char> name) {
return (name.size() <= kMaxSize && name.size() > 0 &&
bool StreamId::IsLegalMidName(rtc::ArrayView<const char> 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<const char> 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);

View File

@ -15,6 +15,7 @@
#include <list>
#include <vector>
#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.