Support Priority header
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 29 Oct 2017 19:37:39 +0000 (19:37 +0000)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 29 Oct 2017 19:37:39 +0000 (19:37 +0000)
src/codec.rs
src/parser.rs
src/types.rs

index 42afee13d6d1526d10081bf066843df921a98cd8..31f9a4985c2baec0de58a91e395f72b430f2683b 100644 (file)
@@ -440,7 +440,7 @@ mod tests {
                            com>\r\nExpires:30\r\nFrom:sip:+12125551212@server.phone2net.com;\
                            tag=887s\r\nIn-Reply-To:70710@saturn.bell-tel.com,17320@saturn.\
                            bell-tel.com\r\nMax-Forwards:32\r\nMIME-Version:2.0\r\nMin-Expires:\
-                           30\r\nOrganization:Foobar\r\nVia: localhost\r\n\r\n")
+                           30\r\nOrganization:Foobar\r\nPriority:normal\r\nVia: localhost\r\n\r\n")
         });
 
         let finished = request.and_then(|(socket, _request)| {
index daccfea978caefa4d7bde97e996989e07654ac0b..59aed8e06c48ab4a57412740f4d90368b5860850 100644 (file)
@@ -16,7 +16,7 @@ use types::{PathSegment, HostPort, Host, Hostname, UriParameter, UriHeader, UriH
             Language, AlertParam, Qop, AuthenticationInfo, AuthParam, Algorithm, DigestResponse,
             Credentials, CallId, Purpose, InfoParam, Info, NameAddr, ContactParam, Target,
             Contact, DispositionType, Handling, DispositionParam, ContentCoding, Day, Month, Date,
-            Time, DateTime, ErrorUri, FromParam, From};
+            Time, DateTime, ErrorUri, FromParam, From, Priority};
 
 fn is_mark(c: u8) -> bool {
     c == b'-' || c == b'_' || c == b'.' || c == b'!' || c == b'~' || c == b'*' || c == b'\'' ||
@@ -979,6 +979,15 @@ named!(organization_header<Vec<u8>>, preceded!(
        tag!(b"Organization:"),
        word));
 
+named!(priority_header<Priority>, preceded!(
+       tag!(b"Priority:"),
+       alt!(
+               tag!(b"emergency") => { |_| Priority::Emergency } |
+               tag!(b"urgent") => { |_| Priority::Urgent } |
+               tag!(b"normal") => { |_| Priority::Normal } |
+               tag!(b"non-urgent") => { |_| Priority::NonUrgent } |
+               token => { |t| Priority::Other(t) })));
+
 named!(pub header<Header>, alt!(
 // RFC 3261 Headers
        accept_header => { |a| Header::Accept(a) } |
@@ -1005,5 +1014,6 @@ named!(pub header<Header>, alt!(
        max_forwards_header => { |m| Header::MaxForwards(m) } |
        mime_version_header => { |(m, v)| Header::MimeVersion(m, v) } |
        min_expires_header => { |m| Header::MinExpires(m) } |
-       organization_header => { |o| Header::Organization(o) }
+       organization_header => { |o| Header::Organization(o) } |
+       priority_header => { |p| Header::Priority(p) }
 ));
index 72ac56d780d9883d45e22f6c5b2a5bfa0e85ac5c..6a546d202799b05d22d165656356f247f792bffc 100644 (file)
@@ -341,6 +341,15 @@ pub enum FromParam {
 
 pub type From = (Target, Vec<FromParam>);
 
+#[derive(Debug)]
+pub enum Priority {
+       Emergency,
+       Urgent,
+       Normal,
+       NonUrgent,
+       Other(Vec<u8>)
+}
+
 #[derive(Debug)]
 pub enum Header {
     Accept(Vec<AcceptRange>),
@@ -368,6 +377,7 @@ pub enum Header {
     MimeVersion(u32, u32),
     MinExpires(u32),
     Organization(Vec<u8>),
+    Priority(Priority),
     To(Uri),
     Extension { name: String, value: String },
 }