Skip to content

Commit

Permalink
Bug 1553011 - update import of Rust SDP parser - r=drno
Browse files Browse the repository at this point in the history
update import of Rust SDP parser

Differential Revision: https://phabricator.services.mozilla.com/D31943
  • Loading branch information
na-g committed May 30, 2019
1 parent 7526f60 commit 0af2d00
Show file tree
Hide file tree
Showing 58 changed files with 3,272 additions and 1,965 deletions.
3 changes: 3 additions & 0 deletions media/webrtc/signaling/src/sdp/RsdparsaSdpInc.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ enum class RustSdpProtocolValue {
kRustDtlsSctp,
kRustUdpDtlsSctp,
kRustTcpDtlsSctp,
kRustRtpAvp,
kRustRtpAvpf,
kRustRtpSavp,
};

enum class RustSdpFormatType { kRustIntegers, kRustStrings };
Expand Down
7 changes: 6 additions & 1 deletion media/webrtc/signaling/src/sdp/RsdparsaSdpMediaSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ SdpMediaSection::Protocol RsdparsaSdpMediaSection::GetProtocol() const {
return kUdpDtlsSctp;
case RustSdpProtocolValue::kRustTcpDtlsSctp:
return kTcpDtlsSctp;
case RustSdpProtocolValue::kRustRtpAvp:
return kRtpAvp;
case RustSdpProtocolValue::kRustRtpAvpf:
return kRtpAvpf;
case RustSdpProtocolValue::kRustRtpSavp:
return kRtpSavp;
}

MOZ_CRASH("invalid media protocol");
}

Expand Down
49 changes: 31 additions & 18 deletions media/webrtc/signaling/src/sdp/rsdparsa/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ cache: cargo
sudo: true
os:
- linux
# Taken out temporarily because it's to slow
# - osx
- osx

env:
- FEATURES=""
- FEATURES="serialize"
rust:
- nightly
- beta
Expand All @@ -17,13 +19,12 @@ matrix:
allow_failures:
- rust: nightly

before_install:
- sudo apt-get update

addons:
apt:
packages:
- libcurl4-openssl-dev
- zlib1g-dev
- libiberty-dev
- libelf-dev
- libdw-dev
- cmake
Expand All @@ -34,34 +35,46 @@ addons:
before_script:
- export PATH=$PATH:~/.cargo/bin
- |
if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then
cargo install --force clippy;
if [[ "$TRAVIS_RUST_VERSION" == "stable" ]]; then
rustup component add rustfmt-preview
rustup component add clippy
fi
script:
- cargo build --verbose --all
- echo FEATURES="$FEATURES"
- |
if [[ "$TRAVIS_RUST_VERSION" == "stable" ]]; then
cargo fmt --all -- --check
fi
- cargo build --verbose --all --features="$FEATURES"
- |
if [[ "$TRAVIS_RUST_VERSION" == "nightly" &&
-f ~/.cargo/bin/cargo-clippy ]]; then
cargo clippy;
if [[ "$TRAVIS_RUST_VERSION" == "stable" ]]; then
cargo clippy --all-targets --all-features -- -D warnings;
fi
- cargo test --verbose --all
- |
if [[ "$TRAVIS_RUST_VERSION" == "1.17.0" ]]; then
cargo test --all-features --verbose --all
else
cargo test --all-targets --all-features --verbose --all
fi
after_success:
- |
if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_RUST_VERSION" == "stable" ]]; then
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
tar xzf master.tar.gz &&
cd kcov-master &&
if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_RUST_VERSION" == "stable" && "$FEATURES" == "serialize" ]]; then
wget https://github.com/SimonKagstrom/kcov/archive/v34.tar.gz &&
tar xzf v34.tar.gz &&
cd kcov-34 &&
mkdir build &&
cd build &&
cmake .. &&
make &&
sudo make install &&
cd ../.. &&
rm -rf kcov-master &&
rm -rf kcov-34 &&
kcov --version &&
for file in target/debug/rsdparsa-*[^\.d]; do echo "$file"; mkdir -p "target/cov/$(basename $file)"; kcov --verify --exclude-pattern=/.cargo,/usr/lib "target/cov/$(basename $file)" "$file"; done &&
(cd target/debug/ && ls -al) &&
for file in target/debug/webrtc_sdp-*[^\.d]; do echo "$file"; mkdir -p "target/cov/$(basename $file)"; kcov --verify --exclude-pattern=/.cargo,/usr/lib "target/cov/$(basename $file)" "$file"; done &&
for file in target/debug/unit_tests-*[^\.d]; do echo "$file"; mkdir -p "target/cov/$(basename $file)"; kcov --verify --exclude-pattern=/.cargo,/usr/lib "target/cov/$(basename $file)" "$file"; done &&
bash <(curl -s https://codecov.io/bash) &&
echo "Uploaded code coverage"
Expand Down
17 changes: 13 additions & 4 deletions media/webrtc/signaling/src/sdp/rsdparsa/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
[package]
name = "rsdparsa"
name = "webrtc-sdp"
version = "0.1.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."
homepage = "https://github.com/nils-ohlmeier/rsdparsa"
readme = "README.md"
keywords = ["webrtc", "sdp", "jsep"]
categories = ["parsing", "network-programming"]
license = "MPL-2.0"

[badges]
travis-ci = { repository = "nils-ohlmeier/rsdparsa", branch = "master" }
codecov = { repository = "nils-ohlmeier/rsdparsa", branch = "master", service = "github" }

[features]
default = []
# serializability
serialize = ["serde", "serde_derive"]

[dependencies]
# clippy = {version = "*", optional = true}
log = "0.4"
log = {version = "0.4.6"}
serde = {version = "1.0" , optional = true}
serde_derive = {version = "1.0" , optional = true}

[dev-dependencies]
# serde_json = {version = "1.0"}
serde_json = {version = "1.0"}
56 changes: 52 additions & 4 deletions media/webrtc/signaling/src/sdp/rsdparsa/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,61 @@
# rsdparsa
# webrtc-sdp

[![Crates.io](https://img.shields.io/crates/v/webrtc-sdp.svg)](https://crates.io/crates/webrtc-sdp)
[![Build Status](https://travis-ci.org/nils-ohlmeier/rsdparsa.svg?branch=master)](https://travis-ci.org/nils-ohlmeier/rsdparsa)
[![Codecov coverage status](https://codecov.io/gh/nils-ohlmeier/rsdparsa/branch/master/graph/badge.svg)](https://codecov.io/gh/nils-ohlmeier/rsdparsa)
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](#License)
[![dependency status](https://deps.rs/repo/github/nils-ohlmeier/rsdparsa/status.svg)](https://deps.rs/repo/github/nils-ohlmeier/rsdparsa)

A SDP parser written in Rust specifically aimed for WebRTC
A SDP parser written in Rust specifically aimed to handle WebRTC SDP offers and answers.

Requires minimum Rust 1.17
## Dependecies

* Rust >= 1.17.0
* log module
* serde module
* serde-derive module

Cargo installs the missing modules automatically when building webrtc-sdp for the first time.

## The webrtc-sdp API

The main function is:
```
fn parse_sdp(sdp: &str, fail_on_warning: bool) -> Result<SdpSession, SdpParserError>
```
The `sdp` parameter is the string which will get parsed. The `fail_on_warning` parameter determines how to treat warnings encountered during parsing. Any problems encountered during are stored until the whole string has been parsed. Any problem during parsing falls into two catgeories:

* Fatal error preventing further parsing or processing of the SDP
* Warning which don't block further processing of the SDP

Warnings will be for example unknown parameters in attributes. Setting `fail_on_warning` to `true` makes most sense during development, when you want to be aware of all potential problems. In production `fail_on_warning` is expected to be `false`.

`parse_sdp()` returns either an `SdpSession` struct ([code](https://github.com/nils-ohlmeier/rsdparsa/blob/master/src/lib.rs#L137)) which contains all the parsed information. Or in case a fatal error was encountered (or if `fail_on_warning` was set to `true` and any warnings were encountered) an `SdpParserError` ([code](https://github.com/nils-ohlmeier/rsdparsa/blob/master/src/error.rs#L117)) will be returned as a `Result`.

## Examples

The [file parser](https://github.com/nils-ohlmeier/rsdparsa/blob/master/src/bin/file_parser.rs) in the webrtc-sdp package gives you an easy example of how to invoke the webrtc-sdp parser.

## Contributing

As the Travis CI runs are checking for code formating and clippy warnings please run the following commands locally, before submitting a Pull Request.

If you haven't clippy and Rust format installed already you add them like this:
```
rustup component add rustfmt-preview
rustup component add clippy
```

Check with clippy for warnings in the code:
```
cargo clippy --all-targets --all-features
```

And format all of the code according to Rust code style convention:
```
cargo fmt --all
```

## License

Licensed under [MPL](https://www.mozilla.org/MPL/2.0/).
Licensed under [MPL-2.0](https://www.mozilla.org/MPL/2.0/)
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
use std::env;
use std::error::Error;
use std::io::prelude::*;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use std::env;
extern crate rsdparsa;
extern crate webrtc_sdp;

fn main() {
let filename = match env::args().nth(1) {
None => {
println!("Missing file name argument!");
return;
},
}
Some(x) => x,
};
let path = Path::new(filename.as_str());
let display = path.display();

let mut file = match File::open(&path) {
Err(why) => panic!("Failed to open {}: {}",
display,
why.description()),
Ok(file) => file
Err(why) => panic!("Failed to open {}: {}", display, why.description()),
Ok(file) => file,
};

let mut s = String::new();
match file.read_to_string(&mut s) {
Err(why) => panic!("couldn't read {}: {}",
display,
why.description()),
Ok(s) => s
Err(why) => panic!("couldn't read {}: {}", display, why.description()),
Ok(s) => s,
};

rsdparsa::parse_sdp(&s, true).is_ok();
webrtc_sdp::parse_sdp(&s, true).is_ok();
}
Loading

0 comments on commit 0af2d00

Please sign in to comment.