Support Call-Info header
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 29 Oct 2017 14:42:20 +0000 (14:42 +0000)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 29 Oct 2017 14:42:20 +0000 (14:42 +0000)
src/codec.rs
src/parser.rs
src/types.rs

index a46ec3c158c804a4712d5719a96b3f90d67fff68..36eeff78abd86cc7e426bf5ab59c8cc6d04ff850 100644 (file)
@@ -431,7 +431,8 @@ mod tests {
                            en-gb\r\nAlert-Info:<http://www.example.com/sounds/moo.wav>\r\nAllow:\
                            MESSAGE\r\nAuthentication-Info:qop=auth\r\nAuthorization:Digest \
                            username=\"Alice\"\r\nCall-ID:f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.\
-                           bar.com\r\nVia: localhost\r\n\r\n")
+                           bar.com\r\nCall-Info:<http://wwww.example.com/alice/photo.jpg>;\
+                           purpose=icon\r\nVia: localhost\r\n\r\n")
         });
 
         let finished = request.and_then(|(socket, _request)| {
index e373b5355581beddeef2c87c351b3c16a9884c0c..3e4b202d243ebbeb7352c9928c5b31b604ce571c 100644 (file)
@@ -13,7 +13,8 @@ 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, CallId};
+            AuthenticationInfo, AuthParam, Algorithm, DigestResponse, Credentials, CallId,
+            Purpose, InfoParam, Info};
 
 fn is_mark(c: u8) -> bool {
     c == b'-' || c == b'_' || c == b'.' || c == b'!' || c == b'~' || c == b'*' || c == b'\'' ||
@@ -716,6 +717,34 @@ named!(call_id_header<CallId>, preceded!(
                        tag!(b"@"),
                        word)))));
 
+named!(purpose<Purpose>, alt!(
+       tag!(b"icon") => { |_| Purpose::Icon } |
+       tag!(b"info") => { |_| Purpose::Info } |
+       tag!(b"card") => { |_| Purpose::Card } |
+       token => { |t| Purpose::Token(t) }));
+
+named!(info_param<InfoParam>, alt!(
+       preceded!(
+               tag!(b"purpose="),
+               purpose) => { |p| InfoParam::Purpose(p) } |
+       generic_param => { |g| InfoParam::Generic(g) }));
+
+named!(info<Info>, tuple!(
+       delimited!(
+               tag!(b"<"),
+               absolute_uri,
+               tag!(b">")
+       ),
+       many0!(preceded!(
+               tag!(b";"),
+               info_param))));
+
+named!(call_info_header<Vec<Info>>, preceded!(
+       tag!(b"Call-Info:"),
+       separated_nonempty_list!(
+               tag!(","),
+               info)));
+
 named!(pub header<Header>, alt!(
 // RFC 3261 Headers
        accept_header => { |a| Header::Accept(a) } |
@@ -725,5 +754,6 @@ named!(pub header<Header>, alt!(
        allow_header => { |a| Header::Allow(a) } |
        authentication_info_header => { |a| Header::AuthenticationInfo(a) } |
        authorization_header => { |a| Header::Authorization(a) } |
-       call_id_header => { |c| Header::CallId(c) }
+       call_id_header => { |c| Header::CallId(c) } |
+       call_info_header => { |c| Header::CallInfo(c) }
 ));
index e8c6f0007d1aadf2be7483d799b95341d5f50b94..e05f4e4db845e59733d6a0bb524f0ffa71b6386c 100644 (file)
@@ -233,6 +233,22 @@ pub enum Credentials {
 
 pub type CallId = (Vec<u8>, Option<Vec<u8>>);
 
+#[derive(Debug)]
+pub enum Purpose {
+    Icon,
+    Info,
+    Card,
+    Token(Vec<u8>),
+}
+
+#[derive(Debug)]
+pub enum InfoParam {
+    Purpose(Purpose),
+    Generic(GenericParam),
+}
+
+pub type Info = (AbsoluteUri, Vec<InfoParam>);
+
 #[derive(Debug)]
 pub enum Header {
     Accept(Vec<AcceptRange>),
@@ -243,6 +259,7 @@ pub enum Header {
     AuthenticationInfo(Vec<AuthenticationInfo>),
     Authorization(Credentials),
     CallId(CallId),
+    CallInfo(Vec<Info>),
     From(Uri),
     To(Uri),
     Extension { name: String, value: String },