| 1 |
# webrtc-sdp |
| 2 |
|
| 3 |
[](https://crates.io/crates/webrtc-sdp) |
| 4 |
[](https://travis-ci.org/mozilla/webrtc-sdp) |
| 5 |
[](https://codecov.io/gh/webrtc-sdp/webrtc-sdp) |
| 6 |
[](#License) |
| 7 |
[](https://deps.rs/repo/github/mozilla/webrtc-sdp) |
| 8 |
|
| 9 |
A SDP parser written in Rust specifically aimed to handle WebRTC SDP offers and answers. |
| 10 |
|
| 11 |
## Dependecies |
| 12 |
|
| 13 |
* Rust >= 1.70.0 |
| 14 |
* log module |
| 15 |
* serde module |
| 16 |
* serde-derive module |
| 17 |
|
| 18 |
Cargo installs the missing modules automatically when building webrtc-sdp for the first time. |
| 19 |
|
| 20 |
## The webrtc-sdp API |
| 21 |
|
| 22 |
The main function is: |
| 23 |
```rust |
| 24 |
fn parse_sdp(sdp: &str, fail_on_warning: bool) -> Result<SdpSession, SdpParserError> |
| 25 |
``` |
| 26 |
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: |
| 27 |
|
| 28 |
* Fatal error preventing further parsing or processing of the SDP |
| 29 |
* Warning which don't block further processing of the SDP |
| 30 |
|
| 31 |
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`. |
| 32 |
|
| 33 |
`parse_sdp()` returns either an `SdpSession` struct ([code](https://github.com/mozilla/webrtc-sdp/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/mozilla/webrtc-sdp/blob/master/src/error.rs#L117)) will be returned as a `Result`. |
| 34 |
|
| 35 |
## Examples |
| 36 |
|
| 37 |
The [file parser](https://github.com/mozilla/webrtc-sdp/blob/master/examples/file_parser.rs) in the webrtc-sdp package gives you an easy example of how to invoke the webrtc-sdp parser. |
| 38 |
|
| 39 |
## Contributing |
| 40 |
|
| 41 |
As the Travis CI runs are checking for code formating and clippy warnings please run the following commands locally, before submitting a Pull Request. |
| 42 |
|
| 43 |
If you haven't clippy and Rust format installed already you add them like this: |
| 44 |
``` |
| 45 |
rustup component add rustfmt-preview |
| 46 |
rustup component add clippy |
| 47 |
``` |
| 48 |
|
| 49 |
Check with clippy for warnings in the code: |
| 50 |
``` |
| 51 |
cargo clippy |
| 52 |
``` |
| 53 |
|
| 54 |
And format all of the code according to Rust code style convention: |
| 55 |
``` |
| 56 |
cargo fmt --all |
| 57 |
``` |
| 58 |
|
| 59 |
## Fuzzing |
| 60 |
|
| 61 |
Install cargo-fuzz like this: |
| 62 |
``` |
| 63 |
cargo install cargo-fuzz |
| 64 |
``` |
| 65 |
|
| 66 |
With rust nightly you can start fuzzing like this: |
| 67 |
``` |
| 68 |
cargo fuzz run fuzz_target_parse_sdp |
| 69 |
``` |
| 70 |
|
| 71 |
## License |
| 72 |
|
| 73 |
Licensed under [MPL-2.0](https://www.mozilla.org/MPL/2.0/) |