From: Richard Whitehouse Date: Sun, 29 Oct 2017 15:32:28 +0000 (+0000) Subject: Support Content-Disposition header X-Git-Url: https://git.richardwhiuk.com/?a=commitdiff_plain;h=b5bafa199ede91e572f2142810af5e71fc54015f;p=rust-sip.git Support Content-Disposition header --- diff --git a/src/codec.rs b/src/codec.rs index adce8bc..dedd02b 100644 --- a/src/codec.rs +++ b/src/codec.rs @@ -432,7 +432,8 @@ mod tests { MESSAGE\r\nAuthentication-Info:qop=auth\r\nAuthorization:Digest \ username=\"Alice\"\r\nCall-ID:f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.\ bar.com\r\nCall-Info:;\ - purpose=icon\r\nContact:*\r\nVia: localhost\r\n\r\n") + purpose=icon\r\nContact:*\r\nContent-Disposition:session\r\nVia: \ + localhost\r\n\r\n") }); let finished = request.and_then(|(socket, _request)| { diff --git a/src/parser.rs b/src/parser.rs index 1e77e48..643b98b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -14,7 +14,8 @@ use types::{PathSegment, HostPort, Host, Hostname, UriParameter, UriHeader, UriH Header, MediaType, MediaFullType, MediaParameter, MediaRange, GenericParam, AcceptParam, AcceptRange, Coding, Encoding, LanguageRange, Language, AlertParam, Qop, AuthenticationInfo, AuthParam, Algorithm, DigestResponse, Credentials, CallId, - Purpose, InfoParam, Info, NameAddr, ContactParam, ContactTarget, Contact}; + Purpose, InfoParam, Info, NameAddr, ContactParam, ContactTarget, Contact, + DispositionType, Handling, DispositionParam}; fn is_mark(c: u8) -> bool { c == b'-' || c == b'_' || c == b'.' || c == b'!' || c == b'~' || c == b'*' || c == b'\'' || @@ -784,6 +785,31 @@ named!(contact_header, preceded!( tag!(","), contact_target) => { |c| Contact::Contact(c) }))); +named!(disp_type, alt!( + tag!(b"render") => { |_| DispositionType::Render } | + tag!(b"session") => { |_| DispositionType::Session } | + tag!(b"icon") => { |_| DispositionType::Icon } | + tag!(b"alert") => { |_| DispositionType::Alert } | + token => { |t| DispositionType::Token(t) } +)); + +named!(handling, alt!( + tag!(b"optional") => { |_| Handling::Optional } | + tag!(b"required") => { |_| Handling::Required } | + token => { |t| Handling::Token(t) })); + +named!(disp_param, alt!( + preceded!(tag!(b"handling="), handling) => { |h| DispositionParam::Handling(h) } | + generic_param => { |g| DispositionParam::Generic(g) })); + +named!(content_disposition_header<(DispositionType, Vec)>, preceded!( + tag!(b"Content-Disposition:"), + tuple!( + disp_type, + many0!(preceded!( + tag!(b";"), + disp_param))))); + named!(pub header
, alt!( // RFC 3261 Headers accept_header => { |a| Header::Accept(a) } | @@ -795,5 +821,6 @@ named!(pub header
, alt!( authorization_header => { |a| Header::Authorization(a) } | call_id_header => { |c| Header::CallId(c) } | call_info_header => { |c| Header::CallInfo(c) } | - contact_header => { |c| Header::Contact(c) } + contact_header => { |c| Header::Contact(c) } | + content_disposition_header => { |(t, p)| Header::ContentDisposition(t, p) } )); diff --git a/src/types.rs b/src/types.rs index 2278528..177a037 100644 --- a/src/types.rs +++ b/src/types.rs @@ -270,6 +270,28 @@ pub enum Contact { Contact(Vec<(ContactTarget, Vec)>), } +#[derive(Debug)] +pub enum DispositionType { + Render, + Session, + Icon, + Alert, + Token(Vec), +} + +#[derive(Debug)] +pub enum Handling { + Optional, + Required, + Token(Vec), +} + +#[derive(Debug)] +pub enum DispositionParam { + Handling(Handling), + Generic(GenericParam), +} + #[derive(Debug)] pub enum Header { Accept(Vec), @@ -282,6 +304,7 @@ pub enum Header { CallId(CallId), CallInfo(Vec), Contact(Contact), + ContentDisposition(DispositionType, Vec), From(Uri), To(Uri), Extension { name: String, value: String },