From: Richard Whitehouse Date: Sun, 29 Oct 2017 14:10:11 +0000 (+0000) Subject: Support Call-ID header X-Git-Url: https://git.richardwhiuk.com/?a=commitdiff_plain;h=b6ef405d73ca2f026f0b989ab1bd114795ee648a;p=rust-sip.git Support Call-ID header --- diff --git a/src/codec.rs b/src/codec.rs index a30485d..a46ec3c 100644 --- a/src/codec.rs +++ b/src/codec.rs @@ -430,7 +430,8 @@ mod tests { SIP/2.0\r\nAccept:text/plain\r\nAccept-Encoding:*\r\nAccept-Language:\ en-gb\r\nAlert-Info:\r\nAllow:\ MESSAGE\r\nAuthentication-Info:qop=auth\r\nAuthorization:Digest \ - username=\"Alice\"\r\nVia: localhost\r\n\r\n") + username=\"Alice\"\r\nCall-ID:f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.\ + bar.com\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 4c8c031..e373b53 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -13,7 +13,7 @@ use types::{PathSegment, HostPort, Host, Hostname, UriParameter, UriHeader, UriH Scheme, Method, Transport, UserParam, Version, RequestLine, StatusLine, TopLine, Header, MediaType, MediaFullType, MediaParameter, MediaRange, GenericParam, AcceptParam, AcceptRange, Coding, Encoding, LanguageRange, Language, AlertParam, Qop, - AuthenticationInfo, AuthParam, Algorithm, DigestResponse, Credentials}; + AuthenticationInfo, AuthParam, Algorithm, DigestResponse, Credentials, CallId}; fn is_mark(c: u8) -> bool { c == b'-' || c == b'_' || c == b'.' || c == b'!' || c == b'~' || c == b'*' || c == b'\'' || @@ -79,11 +79,18 @@ fn is_token(c: u8) -> bool { c == b'*' || c == b'_' || c == b'+' || c == b'`' || c == b'\'' || c == b'~' } +fn is_word(c: u8) -> bool { + is_token(c) || c == b'(' || c == b')' || c == b'<' || c == b'>' || c == b':' || + c == b'\\' || c == b'"' || c == b'/' || c == b'[' || c == b']' || + c == b'?' || c == b'{' || c == b'}' +} + fn is_lhex_digit(c: u8) -> bool { nom::is_digit(c) || (c >= b'a' && c <= b'f') } named!(token>, many1!(take_1!(is_token))); +named!(word>, many1!(take_1!(is_word))); named!(method, alt!( // RFC 3261 @@ -701,6 +708,14 @@ named!(authorization_header, preceded!( tag!(b"Authorization:"), credentials)); +named!(call_id_header, preceded!( + alt!(tag!(b"Call-ID:") | tag!(b"i")), + tuple!( + word, + opt!(preceded!( + tag!(b"@"), + word))))); + named!(pub header
, alt!( // RFC 3261 Headers accept_header => { |a| Header::Accept(a) } | @@ -709,5 +724,6 @@ named!(pub header
, alt!( alert_info_header => { |a| Header::AlertInfo(a) } | allow_header => { |a| Header::Allow(a) } | authentication_info_header => { |a| Header::AuthenticationInfo(a) } | - authorization_header => { |a| Header::Authorization(a) } + authorization_header => { |a| Header::Authorization(a) } | + call_id_header => { |c| Header::CallId(c) } )); diff --git a/src/types.rs b/src/types.rs index e0e2cf1..e8c6f00 100644 --- a/src/types.rs +++ b/src/types.rs @@ -231,6 +231,8 @@ pub enum Credentials { Other(Vec, Vec), } +pub type CallId = (Vec, Option>); + #[derive(Debug)] pub enum Header { Accept(Vec), @@ -240,6 +242,7 @@ pub enum Header { Allow(Vec), AuthenticationInfo(Vec), Authorization(Credentials), + CallId(CallId), From(Uri), To(Uri), Extension { name: String, value: String },