From: Richard Whitehouse Date: Sun, 29 Oct 2017 13:23:25 +0000 (+0000) Subject: Support Authentication-Info header X-Git-Url: https://git.richardwhiuk.com/?a=commitdiff_plain;h=feba9a5c8db6e0a77d735744572b69ec458e68dc;p=rust-sip.git Support Authentication-Info header --- diff --git a/src/codec.rs b/src/codec.rs index 7fa20c0..0c12300 100644 --- a/src/codec.rs +++ b/src/codec.rs @@ -428,8 +428,8 @@ mod tests { io::write_all(socket, "MESSAGE sip:test.com \ SIP/2.0\r\nAccept:text/plain\r\nAccept-Encoding:*\r\nAccept-Language:\ - en-gb\r\nAlert-Info:\r\nAllow:MESSAGE\r\nVia: \ - localhost\r\n\r\n") + en-gb\r\nAlert-Info:\r\nAllow:\ + MESSAGE\r\nAuthentication-Info:qop=auth\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 fa4051d..4d6330c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -12,7 +12,8 @@ use types::{PathSegment, HostPort, Host, Hostname, UriParameter, UriHeader, UriH AbsoluteUri, Uri, HierarchicalPath, Authority, UriPath, UserInfo, AbsolutePath, Scheme, Method, Transport, UserParam, Version, RequestLine, StatusLine, TopLine, Header, MediaType, MediaFullType, MediaParameter, MediaRange, GenericParam, - AcceptParam, AcceptRange, Coding, Encoding, LanguageRange, Language, AlertParam}; + AcceptParam, AcceptRange, Coding, Encoding, LanguageRange, Language, AlertParam, Qop, + AuthenticationInfo}; fn is_mark(c: u8) -> bool { c == b'-' || c == b'_' || c == b'.' || c == b'!' || c == b'~' || c == b'*' || c == b'\'' || @@ -78,6 +79,10 @@ fn is_token(c: u8) -> bool { 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!(method, alt!( @@ -100,6 +105,7 @@ named!(alpha<&[u8], u8>, take_1!(nom::is_alphabetic)); named!(alphanumeric<&[u8], u8>, take_1!(nom::is_alphanumeric)); named!(digit<&[u8], u8>, take_1!(nom::is_digit)); named!(hex<&[u8], u8>, take_1!(nom::is_hex_digit)); +named!(lhex<&[u8], u8>, take_1!(is_lhex_digit)); fn escaped(input: &[u8]) -> IResult<&[u8], u8> { let result = preceded!(input, tag!(b"%"), pair!(hex, hex)); @@ -583,11 +589,57 @@ named!(allow_header>, preceded!( tag!(b","), method))); +named!(nextnonce>, preceded!( + tag!(b"nc="), + quoted_string)); + +named!(qop_value, alt!( + tag!(b"auth") => { |x| Qop::Auth } | + tag!(b"auth-init") => { |x| Qop::AuthInit } | + token => { |x| Qop::Token(x) })); + +named!(message_qop, preceded!( + tag!(b"qop="), + qop_value)); + +named!(response_digest>, delimited!( + tag!(b"\""), + many0!(hex), + tag!(b"\""))); + +named!(response_auth>, preceded!( + tag!(b"rspauth="), + response_digest)); + +named!(cnonce>, preceded!( + tag!(b"cnonce="), + quoted_string)); + +named!(nc_value>, many1!(lhex)); + +named!(nonce_count>, preceded!( + tag!(b"nc="), + nc_value)); + +named!(ainfo, alt!( + nextnonce => { |n| AuthenticationInfo::NextNonce(n) } | + message_qop => { |m| AuthenticationInfo::MessageQop(m) } | + response_auth => { |r| AuthenticationInfo::ResponseAuth(r) } | + cnonce => { |c| AuthenticationInfo::Cnonce(c) } | + nonce_count => { |n| AuthenticationInfo::NonceCount(n) })); + +named!(authentication_info_header>, preceded!( + tag!(b"Authentication-Info:"), + separated_nonempty_list!( + tag!(b","), + ainfo))); + named!(pub header
, alt!( // RFC 3261 Headers accept_header => { |a| Header::Accept(a) } | accept_encoding_header => { |a| Header::AcceptEncoding(a) } | accept_language_header => { |a| Header::AcceptLanguage(a) } | alert_info_header => { |a| Header::AlertInfo(a) } | - allow_header => { |a| Header::Allow(a) } + allow_header => { |a| Header::Allow(a) } | + authentication_info_header => { |a| Header::AuthenticationInfo(a) } )); diff --git a/src/types.rs b/src/types.rs index cc3c842..3920bc8 100644 --- a/src/types.rs +++ b/src/types.rs @@ -185,6 +185,22 @@ pub type Language = (LanguageRange, Vec); pub type AlertParam = (AbsoluteUri, Vec); +#[derive(Debug)] +pub enum Qop { + Auth, + AuthInit, + Token(Vec), +} + +#[derive(Debug)] +pub enum AuthenticationInfo { + NextNonce(Vec), + MessageQop(Qop), + ResponseAuth(Vec), + Cnonce(Vec), + NonceCount(Vec), +} + #[derive(Debug)] pub enum Header { Accept(Vec), @@ -192,6 +208,7 @@ pub enum Header { AcceptLanguage(Vec), AlertInfo(Vec), Allow(Vec), + AuthenticationInfo(Vec), From(Uri), To(Uri), Extension { name: String, value: String },