Bug 1580908 - Part 8: Update rsdparsa. r=ng

I just copied all the files from the upstream repository into the
rsdparsa directory

Differential Revision: https://phabricator.services.mozilla.com/D45717

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Bastien Orivel 2019-09-12 21:46:25 +00:00
parent d843925e5f
commit 59f8fe9fee
10 changed files with 876 additions and 538 deletions

47
Cargo.lock generated
View File

@ -1018,15 +1018,6 @@ dependencies = [
"packed_simd 0.3.3 (git+https://github.com/hsivonen/packed_simd?branch=rust_1_32)",
]
[[package]]
name = "enum-display-derive"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "env_logger"
version = "0.6.2"
@ -2334,11 +2325,6 @@ name = "quick-error"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
version = "0.6.11"
@ -2604,7 +2590,7 @@ dependencies = [
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"nserror 0.1.0",
"webrtc-sdp 0.2.2",
"webrtc-sdp 0.3.0",
]
[[package]]
@ -3049,16 +3035,6 @@ name = "svg_fmt"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syn"
version = "0.11.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "0.15.30"
@ -3069,14 +3045,6 @@ dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "synom"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "synstructure"
version = "0.10.1"
@ -3447,11 +3415,6 @@ name = "unicode-width"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.1.0"
@ -3672,9 +3635,8 @@ dependencies = [
[[package]]
name = "webrtc-sdp"
version = "0.2.2"
version = "0.3.0"
dependencies = [
"enum-display-derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3951,7 +3913,6 @@ dependencies = [
"checksum encoding_c 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "decad88e2d121fb223f5395c57772318616642fabbbcb19faa83204ba492cfa3"
"checksum encoding_c_mem 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9516d857aa9e070e02890ed3906f678ffca7fac8d82bd53c3567d96337f256"
"checksum encoding_rs 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "4155785c79f2f6701f185eb2e6b4caf0555ec03477cb4c70db67b465311620ed"
"checksum enum-display-derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "53f76eb63c4bfc6fce5000f106254701b741fc9a65ee08445fde0ff39e583f1c"
"checksum env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3"
"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
"checksum euclid 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4786521fec183792e755bf32cd0188e4e7628c6d0fcfd51426435b9081a106"
@ -4061,7 +4022,6 @@ dependencies = [
"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915"
"checksum procedural-masquerade 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9f566249236c6ca4340f7ca78968271f0ed2b0f234007a61b66f9ecd0af09260"
"checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1"
"checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1"
"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd"
@ -4128,9 +4088,7 @@ dependencies = [
"checksum string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00caf261d6f90f588f8450b8e1230fa0d5be49ee6140fdfbcb55335aff350970"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum svg_fmt 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c666f0fed8e1e20e057af770af9077d72f3d5a33157b8537c1475dd8ffd6d32b"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)" = "66c8865bf5a7cbb662d8b011950060b3c8743dca141b054bf7195b20d314d8e2"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
"checksum target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0ab4982b8945c35cc1c46a83a9094c414f6828a099ce5dcaa8ee2b04642dcb"
"checksum target-lexicon 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7975cb2c6f37d77b190bc5004a2bb015971464756fde9514651a525ada2a741a"
@ -4168,7 +4126,6 @@ dependencies = [
"checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f"
"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1"
"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61"

View File

@ -1,7 +1,18 @@
# Changelog
## [Unreleased]
## [0.3.0] - 2019-08-08
### Changed
- Unsafe code is forbidden now
### Fixed
- Fixed panic from slicing unicode character in image attr braces
### Added
- Added support for FQDN addresses
- Added support for parsing ice-pacing
- Added fuzzing target
## [0.2.2] - 2019-06-21
### Changed

View File

@ -1,103 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "cfg-if"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "itoa"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro2"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ryu"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
version = "1.0.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_json"
version = "1.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "0.15.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "webrtc-sdp"
version = "0.1.0"
dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4"
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915"
"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db"
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
"checksum serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "aa5f7c20820475babd2c077c3ab5f8c77a31c15e16ea38687b4c02d3e48680f4"
"checksum serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "58fc82bec244f168b23d1963b45c8bf5726e9a15a9d146a067f9081aeed2de79"
"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d"
"checksum syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)" = "846620ec526c1599c070eff393bfeeeb88a93afa2513fc3b49f1fea84cf7b0ed"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"

View File

@ -1,6 +1,6 @@
[package]
name = "webrtc-sdp"
version = "0.2.2"
version = "0.3.0"
authors = ["Nils Ohlmeier <github@ohlmeier.org>"]
description = "This create parses strings in the format of the Session Description Protocol according to RFC4566. It specifically supports the subset of features required to support WebRTC according to the JSEP draft."
repository = "https://github.com/mozilla/webrtc-sdp"
@ -22,8 +22,7 @@ serialize = ["serde", "serde_derive"]
log = {version = "0.4.6"}
serde = {version = "1.0" , optional = true}
serde_derive = {version = "1.0" , optional = true}
url = {version = "2.0"}
url = {version="2.1.0"}
[dev-dependencies]
serde_json = {version = "1.0"}
enum-display-derive = "0.1.0"

View File

@ -195,14 +195,21 @@ mod tests {
use self::url::ParseError;
use super::*;
use std::error::Error;
use std::fmt::Display;
use std::net::{AddrParseError, Ipv4Addr, Ipv6Addr};
#[derive(Debug, enum_display_derive::Display)]
#[derive(Debug)]
enum ParseTestError {
Host(ParseError),
Ip(AddrParseError),
}
impl fmt::Display for ParseTestError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseTestError::Host(inner) => inner.fmt(f),
ParseTestError::Ip(inner) => inner.fmt(f),
}
}
}
impl From<ParseError> for ParseTestError {
fn from(err: ParseError) -> Self {
ParseTestError::Host(err)

View File

@ -45,6 +45,7 @@ pub struct StatefulSdpAnonymizer {
ice_users: AnonymizationStrMap,
cert_finger_prints: HashMap<Vec<u8>, Vec<u8>>,
cert_finger_print_inc: Wrapping<u64>,
cnames: AnonymizationStrMap,
}
impl Default for StatefulSdpAnonymizer {
@ -67,6 +68,7 @@ impl StatefulSdpAnonymizer {
ice_users: AnonymizationStrMap::new("ice-user-", 8),
cert_finger_prints: HashMap::new(),
cert_finger_print_inc: Wrapping(0),
cnames: AnonymizationStrMap::new("cname-", 8),
}
}
@ -147,6 +149,10 @@ impl StatefulSdpAnonymizer {
);
self.cert_finger_print_inc.0.to_byte_vec()
}
pub fn mask_cname(&mut self, cname: &str) -> String {
self.cnames.mask(cname)
}
}
struct AnonymizationStrMap {
@ -290,4 +296,16 @@ mod tests {
assert_eq!(anon.mask_cert_finger_print(&prints[2]), masked_prints[2]);
}
}
#[test]
fn test_mask_cname() {
let mut anon = StatefulSdpAnonymizer::default();
let cnames = ["mailto:foo@bar", "JohnDoe", "Jane Doe"];
let masked_cnames = ["cname-00000001", "cname-00000002", "cname-00000003"];
for _ in 0..2 {
assert_eq!(anon.mask_cname(cnames[0]), masked_cnames[0]);
assert_eq!(anon.mask_cname(cnames[1]), masked_cnames[1]);
assert_eq!(anon.mask_cname(cnames[2]), masked_cnames[2]);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -6,11 +6,10 @@ extern crate log;
#[cfg(feature = "serialize")]
#[macro_use]
extern crate serde_derive;
#[cfg(test)]
extern crate enum_display_derive;
#[cfg(feature = "serialize")]
extern crate serde;
use std::convert::TryFrom;
use std::fmt;
#[macro_use]
pub mod attribute_type;
@ -33,6 +32,10 @@ use media_type::{
};
use network::{parse_address_type, parse_network_type};
/*
* RFC4566
* bandwidth-fields = *(%x62 "=" bwtype ":" bandwidth CRLF)
*/
#[derive(Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
pub enum SdpBandwidth {
@ -42,17 +45,23 @@ pub enum SdpBandwidth {
Unknown(String, u32),
}
impl ToString for SdpBandwidth {
fn to_string(&self) -> String {
match *self {
SdpBandwidth::As(ref x) => format!("AS:{}", x.to_string()),
SdpBandwidth::Ct(ref x) => format!("CT:{}", x.to_string()),
SdpBandwidth::Tias(ref x) => format!("TIAS:{}", x.to_string()),
SdpBandwidth::Unknown(ref tp, ref x) => format!("{}:{}", tp.to_string(), x.to_string()),
}
impl fmt::Display for SdpBandwidth {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let (tp_string, value) = match *self {
SdpBandwidth::As(ref x) => ("AS", x),
SdpBandwidth::Ct(ref x) => ("CT", x),
SdpBandwidth::Tias(ref x) => ("TIAS", x),
SdpBandwidth::Unknown(ref tp, ref x) => (&tp[..], x),
};
write!(f, "{tp}:{val}", tp = tp_string, val = value)
}
}
/*
* RFC4566
* connection-field = [%x63 "=" nettype SP addrtype SP
* connection-address CRLF]
*/
#[derive(Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
pub struct SdpConnection {
@ -61,14 +70,11 @@ pub struct SdpConnection {
pub amount: Option<u32>,
}
impl ToString for SdpConnection {
fn to_string(&self) -> String {
format!(
"{address}{ttl}{amount}",
address = self.address,
ttl = option_to_string!("/{}", self.ttl),
amount = option_to_string!("/{}", self.amount)
)
impl fmt::Display for SdpConnection {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.address.fmt(f)?;
write_option_string!(f, "/{}", self.ttl)?;
write_option_string!(f, "/{}", self.amount)
}
}
@ -80,6 +86,11 @@ impl AnonymizingClone for SdpConnection {
}
}
/*
* RFC4566
* origin-field = %x6f "=" username SP sess-id SP sess-version SP
* nettype SP addrtype SP unicast-address CRLF
*/
#[derive(Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
pub struct SdpOrigin {
@ -89,13 +100,14 @@ pub struct SdpOrigin {
pub unicast_addr: ExplicitlyTypedAddress,
}
impl ToString for SdpOrigin {
fn to_string(&self) -> String {
format!(
impl fmt::Display for SdpOrigin {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{username} {sess_id} {sess_vers} {unicast_addr}",
username = self.username.clone(),
sess_id = self.session_id.to_string(),
sess_vers = self.session_version.to_string(),
username = self.username,
sess_id = self.session_id,
sess_vers = self.session_version,
unicast_addr = self.unicast_addr
)
}
@ -110,6 +122,12 @@ impl AnonymizingClone for SdpOrigin {
}
}
/*
* RFC4566
* time-fields = 1*( %x74 "=" start-time SP stop-time
* *(CRLF repeat-fields) CRLF)
* [zone-adjustments CRLF]
*/
#[derive(Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
pub struct SdpTiming {
@ -117,9 +135,9 @@ pub struct SdpTiming {
pub stop: u64,
}
impl ToString for SdpTiming {
fn to_string(&self) -> String {
format!("{} {}", self.start.to_string(), self.stop.to_string())
impl fmt::Display for SdpTiming {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{start} {stop}", start = self.start, stop = self.stop)
}
}
@ -143,6 +161,23 @@ pub struct SdpLine {
pub sdp_type: SdpType,
}
/*
* RFC4566
* ; SDP Syntax
* session-description = proto-version
* origin-field
* session-name-field
* information-field
* uri-field
* email-fields
* phone-fields
* connection-field
* bandwidth-fields
* time-fields
* key-field
* attribute-fields
* media-descriptions
*/
#[derive(Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
pub struct SdpSession {
@ -164,6 +199,30 @@ pub struct SdpSession {
// key: Option<String>
}
impl fmt::Display for SdpSession {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"v={version}\r\n\
o={origin}\r\n\
s={session}\r\n\
{timing}\
{bandwidth}\
{connection}\
{session_attributes}\
{media_sections}",
version = self.version,
origin = self.origin,
session = self.session,
timing = option_to_string!("t={}\r\n", self.timing),
bandwidth = maybe_vector_to_string!("b={}\r\n", self.bandwidth, "\r\nb="),
connection = option_to_string!("c={}\r\n", self.connection),
session_attributes = maybe_vector_to_string!("a={}\r\n", self.attribute, "\r\na="),
media_sections = maybe_vector_to_string!("{}", self.media, "\r\n")
)
}
}
impl SdpSession {
pub fn new(version: u64, origin: SdpOrigin, session: String) -> SdpSession {
SdpSession {
@ -211,7 +270,7 @@ impl SdpSession {
if !a.allowed_at_session_level() {
return Err(SdpParserInternalError::Generic(format!(
"{} not allowed at session level",
a.to_string()
a
)));
};
self.attribute.push(a);
@ -292,29 +351,6 @@ impl SdpSession {
}
}
impl ToString for SdpSession {
fn to_string(&self) -> String {
format!(
"v={version}\r\n\
o={origin}\r\n\
s={sess}\r\n\
{timing}\
{bandwidth}\
{connection}\
{sess_attributes}\
{media_sections}",
version = self.version.to_string(),
origin = self.origin.to_string(),
sess = self.session.clone(),
timing = option_to_string!("t={}\r\n", self.timing),
bandwidth = maybe_vector_to_string!("b={}\r\n", self.bandwidth, "\r\nb="),
connection = option_to_string!("c={}\r\n", self.connection),
sess_attributes = maybe_vector_to_string!("a={}\r\n", self.attribute, "\r\na="),
media_sections = maybe_vector_to_string!("{}", self.media, "\r\n")
)
}
}
impl AnonymizingClone for SdpSession {
fn masked_clone(&self, anon: &mut StatefulSdpAnonymizer) -> Self {
let mut masked: SdpSession = SdpSession {
@ -417,7 +453,7 @@ fn parse_origin(value: &str) -> Result<SdpType, SdpParserInternalError> {
session_version,
unicast_addr,
};
trace!("origin: {}", o.to_string());
trace!("origin: {}", o);
Ok(SdpType::Origin(o))
}
@ -447,7 +483,7 @@ fn parse_connection(value: &str) -> Result<SdpType, SdpParserInternalError> {
ttl,
amount,
};
trace!("connection: {}", c.address);
trace!("connection: {}", c);
Ok(SdpType::Connection(c))
}
@ -465,7 +501,7 @@ fn parse_bandwidth(value: &str) -> Result<SdpType, SdpParserInternalError> {
"TIAS" => SdpBandwidth::Tias(bandwidth),
_ => SdpBandwidth::Unknown(String::from(bv[0]), bandwidth),
};
trace!("bandwidth: {}, {}", bv[0], bandwidth);
trace!("bandwidth: {}", bw);
Ok(SdpType::Bandwidth(bw))
}
@ -479,7 +515,7 @@ fn parse_timing(value: &str) -> Result<SdpType, SdpParserInternalError> {
let start = tv[0].parse::<u64>()?;
let stop = tv[1].parse::<u64>()?;
let t = SdpTiming { start, stop };
trace!("timing: {}, {}", t.start, t.stop);
trace!("timing: {}", t);
Ok(SdpType::Timing(t))
}

View File

@ -3,8 +3,14 @@ use attribute_type::{
maybe_print_param, SdpAttribute, SdpAttributeRtpmap, SdpAttributeSctpmap, SdpAttributeType,
};
use error::{SdpParserError, SdpParserInternalError};
use std::fmt;
use {SdpBandwidth, SdpConnection, SdpLine, SdpType};
/*
* RFC4566
* media-field = %x6d "=" media SP port ["/" integer]
* SP proto 1*(SP fmt) CRLF
*/
#[derive(Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
pub struct SdpMediaLine {
@ -15,15 +21,16 @@ pub struct SdpMediaLine {
pub formats: SdpFormatList,
}
impl ToString for SdpMediaLine {
fn to_string(&self) -> String {
format!(
"{media_line} {port}{port_count} {protocol} {formats}",
media_line = self.media.to_string(),
port_count = maybe_print_param("/", self.port_count, 0),
port = self.port.to_string(),
protocol = self.proto.to_string(),
formats = self.formats.to_string()
impl fmt::Display for SdpMediaLine {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{media} {port}{pcount} {proto} {formats}",
media = self.media,
port = self.port,
pcount = maybe_print_param("/", self.port_count, 0),
proto = self.proto,
formats = self.formats
)
}
}
@ -36,35 +43,35 @@ pub enum SdpMediaValue {
Application,
}
impl ToString for SdpMediaValue {
fn to_string(&self) -> String {
impl fmt::Display for SdpMediaValue {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
SdpMediaValue::Audio => "audio",
SdpMediaValue::Video => "video",
SdpMediaValue::Application => "application",
}
.to_string()
.fmt(f)
}
}
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
pub enum SdpProtocolValue {
RtpAvp,
RtpAvpf,
RtpSavp,
RtpSavpf,
TcpDtlsRtpSavp,
TcpDtlsRtpSavpf,
UdpTlsRtpSavp,
UdpTlsRtpSavpf,
DtlsSctp,
UdpDtlsSctp,
TcpDtlsSctp,
RtpAvp, /* RTP/AVP [RFC4566] */
RtpAvpf, /* RTP/AVPF [RFC4585] */
RtpSavp, /* RTP/SAVP [RFC3711] */
RtpSavpf, /* RTP/SAVPF [RFC5124] */
TcpDtlsRtpSavp, /* TCP/DTLS/RTP/SAVP [RFC7850] */
TcpDtlsRtpSavpf, /* TCP/DTLS/RTP/SAVPF [RFC7850] */
UdpTlsRtpSavp, /* UDP/TLS/RTP/SAVP [RFC5764] */
UdpTlsRtpSavpf, /* UDP/TLS/RTP/SAVPF [RFC5764] */
DtlsSctp, /* DTLS/SCTP [draft-ietf-mmusic-sctp-sdp-07] */
UdpDtlsSctp, /* UDP/DTLS/SCTP [draft-ietf-mmusic-sctp-sdp-26] */
TcpDtlsSctp, /* TCP/DTLS/SCTP [draft-ietf-mmusic-sctp-sdp-26] */
}
impl ToString for SdpProtocolValue {
fn to_string(&self) -> String {
impl fmt::Display for SdpProtocolValue {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
SdpProtocolValue::RtpAvp => "RTP/AVP",
SdpProtocolValue::RtpAvpf => "RTP/AVPF",
@ -78,7 +85,7 @@ impl ToString for SdpProtocolValue {
SdpProtocolValue::UdpDtlsSctp => "UDP/DTLS/SCTP",
SdpProtocolValue::TcpDtlsSctp => "TCP/DTLS/SCTP",
}
.to_string()
.fmt(f)
}
}
@ -89,15 +96,25 @@ pub enum SdpFormatList {
Strings(Vec<String>),
}
impl ToString for SdpFormatList {
fn to_string(&self) -> String {
impl fmt::Display for SdpFormatList {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
SdpFormatList::Integers(ref x) => maybe_vector_to_string!("{}", x, " "),
SdpFormatList::Strings(ref x) => x.join(" "),
}
.fmt(f)
}
}
/*
* RFC4566
* media-descriptions = *( media-field
* information-field
* *connection-field
* bandwidth-fields
* key-field
* attribute-fields )
*/
#[derive(Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
pub struct SdpMedia {
@ -110,6 +127,19 @@ pub struct SdpMedia {
// key: Option<String>,
}
impl fmt::Display for SdpMedia {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"m={mline}\r\n{bw}{connection}{attributes}",
mline = self.media,
bw = maybe_vector_to_string!("b={}\r\n", self.bandwidth, "\r\nb="),
connection = option_to_string!("c={}\r\n", self.connection),
attributes = maybe_vector_to_string!("a={}\r\n", self.attribute, "\r\na=")
)
}
}
impl SdpMedia {
pub fn new(media: SdpMediaLine) -> SdpMedia {
SdpMedia {
@ -160,7 +190,7 @@ impl SdpMedia {
if !attr.allowed_at_media_level() {
return Err(SdpParserInternalError::Generic(format!(
"{} not allowed at media level",
attr.to_string()
attr
)));
}
self.attribute.push(attr);
@ -263,21 +293,6 @@ impl SdpMedia {
}
}
impl ToString for SdpMedia {
fn to_string(&self) -> String {
format!(
"m={media_line}\r\n\
{bandwidth}\
{connection}\
{attributes}",
media_line = self.media.to_string(),
connection = option_to_string!("c={}\r\n", self.connection),
bandwidth = maybe_vector_to_string!("b={}\r\n", self.bandwidth, "\r\nb="),
attributes = maybe_vector_to_string!("a={}\r\n", self.attribute, "\r\na=")
)
}
}
impl AnonymizingClone for SdpMedia {
fn masked_clone(&self, anon: &mut StatefulSdpAnonymizer) -> Self {
let mut masked = SdpMedia {
@ -391,13 +406,7 @@ pub fn parse_media(value: &str) -> Result<SdpType, SdpParserInternalError> {
proto,
formats,
};
trace!(
"media: {}, {}, {}, {}",
m.media.to_string(),
m.port.to_string(),
m.proto.to_string(),
m.formats.to_string()
);
trace!("media: {}, {}, {}, {}", m.media, m.port, m.proto, m.formats);
Ok(SdpType::Media(m))
}
@ -694,24 +703,26 @@ mod tests {
#[test]
fn test_parse_protocol_rtp_token() -> Result<(), SdpParserInternalError> {
let rtps = parse_protocol_token("rtp/avp")?;
assert_eq!(rtps, SdpProtocolValue::RtpAvp);
let rtps = parse_protocol_token("rtp/avpf")?;
assert_eq!(rtps, SdpProtocolValue::RtpAvpf);
let rtps = parse_protocol_token("rtp/savp")?;
assert_eq!(rtps, SdpProtocolValue::RtpSavp);
let rtps = parse_protocol_token("rtp/savpf")?;
assert_eq!(rtps, SdpProtocolValue::RtpSavpf);
let udps = parse_protocol_token("udp/tls/rtp/savp")?;
assert_eq!(udps, SdpProtocolValue::UdpTlsRtpSavp);
let udps = parse_protocol_token("udp/tls/rtp/savpf")?;
assert_eq!(udps, SdpProtocolValue::UdpTlsRtpSavpf);
let tcps = parse_protocol_token("TCP/dtls/rtp/savp")?;
assert_eq!(tcps, SdpProtocolValue::TcpDtlsRtpSavp);
let tcps = parse_protocol_token("TCP/dtls/rtp/savpf")?;
assert_eq!(tcps, SdpProtocolValue::TcpDtlsRtpSavpf);
let tcps = parse_protocol_token("TCP/tls/rtp/savpf")?;
assert_eq!(tcps, SdpProtocolValue::TcpTlsRtpSavpf);
fn parse_and_serialize_protocol_token(
token: &str,
result: SdpProtocolValue,
) -> Result<(), SdpParserInternalError> {
let rtps = parse_protocol_token(token)?;
assert_eq!(rtps, result);
assert_eq!(rtps.to_string(), token.to_uppercase());
Ok(())
}
parse_and_serialize_protocol_token("rtp/avp", SdpProtocolValue::RtpAvp)?;
parse_and_serialize_protocol_token("rtp/avpf", SdpProtocolValue::RtpAvpf)?;
parse_and_serialize_protocol_token("rtp/savp", SdpProtocolValue::RtpSavp)?;
parse_and_serialize_protocol_token("rtp/savpf", SdpProtocolValue::RtpSavpf)?;
parse_and_serialize_protocol_token("udp/tls/rtp/savp", SdpProtocolValue::UdpTlsRtpSavp)?;
parse_and_serialize_protocol_token("udp/tls/rtp/savpf", SdpProtocolValue::UdpTlsRtpSavpf)?;
parse_and_serialize_protocol_token("TCP/dtls/rtp/savp", SdpProtocolValue::TcpDtlsRtpSavp)?;
parse_and_serialize_protocol_token(
"tcp/DTLS/rtp/savpf",
SdpProtocolValue::TcpDtlsRtpSavpf,
)?;
assert!(parse_protocol_token("").is_err());
assert!(parse_protocol_token("foobar").is_err());
@ -720,12 +731,18 @@ mod tests {
#[test]
fn test_parse_protocol_sctp_token() -> Result<(), SdpParserInternalError> {
let dtls = parse_protocol_token("dtLs/ScTP")?;
assert_eq!(dtls, SdpProtocolValue::DtlsSctp);
let usctp = parse_protocol_token("udp/DTLS/sctp")?;
assert_eq!(usctp, SdpProtocolValue::UdpDtlsSctp);
let tsctp = parse_protocol_token("tcp/dtls/SCTP")?;
assert_eq!(tsctp, SdpProtocolValue::TcpDtlsSctp);
fn parse_and_serialize_protocol_token(
token: &str,
result: SdpProtocolValue,
) -> Result<(), SdpParserInternalError> {
let rtps = parse_protocol_token(token)?;
assert_eq!(rtps, result);
assert_eq!(rtps.to_string(), token.to_uppercase());
Ok(())
}
parse_and_serialize_protocol_token("dtLs/ScTP", SdpProtocolValue::DtlsSctp)?;
parse_and_serialize_protocol_token("udp/DTLS/sctp", SdpProtocolValue::UdpDtlsSctp)?;
parse_and_serialize_protocol_token("tcp/dtls/SCTP", SdpProtocolValue::TcpDtlsSctp)?;
Ok(())
}

View File

@ -647,6 +647,7 @@ fn parse_and_serialize_sdp_with_unusual_attributes() {
o=- 0 0 IN IP6 2001:db8::4444\r\n\
s=-\r\n\
t=0 0\r\n\
a=ice-pacing:500\r\n\
m=video 0 UDP/TLS/RTP/SAVPF 0\r\n\
b=UNSUPPORTED:12345\r\n\
c=IN IP6 ::1\r\n\