Credentials, CallId, Purpose, InfoParam, Info, NameAddr, ContactParam, Target,
Contact, DispositionType, Handling, DispositionParam, ContentCoding, Day, Month, Date,
Time, DateTime, ErrorUri, FromParam, From, Priority, Domain, DigestChallenge,
- Challenge, OptionTag, Route, ReplyTo, RetryAfterParam, RetryAfter, Server, ToParam, To};
+ Challenge, OptionTag, Route, ReplyTo, RetryAfterParam, RetryAfter, Server, ToParam,
+ To, Protocol, SentProtocol, Received, ViaParam, Via};
pub fn float(input: &[u8]) -> IResult<&[u8], f32> {
flat_map!(input,
tag!(b" "),
server)));
+named!(protocol_name<Protocol>, alt!(
+ tag!(b"SIP") => { |_| Protocol::SIP } |
+ token => { |t| Protocol::Other(t) }
+));
+
+named!(transport<Transport>, alt!(
+ tag!(b"UDP") => { |_| Transport::Udp } |
+ tag!(b"TCP") => { |_| Transport::Tcp } |
+ tag!(b"TLS") => { |_| Transport::Tls } |
+ tag!(b"SCTP") => { |_| Transport::Sctp } |
+ token => { |t| Transport::Other(t) }));
+
+named!(sent_protocol<SentProtocol>, tuple!(
+ terminated!(protocol_name, tag!("/")),
+ terminated!(token, tag!("/")),
+ transport));
+
+use self::hostport as sent_by;
+
+named!(received<Received>, alt!(
+ ipv4_address => { |(a, b, c, d)| Received::Ipv4Address(a,b,c,d) } |
+ ipv6_address => { |i| Received::Ipv6Address(i) }
+));
+
+named!(via_param<ViaParam>, alt!(
+ preceded!(tag!(b"ttl="), number) => { |t| ViaParam::Ttl(t) } |
+ preceded!(tag!(b"maddr="), host) => { |h| ViaParam::Maddr(h) } |
+ preceded!(tag!(b"received="), received) => { |r| ViaParam::Received(r) } |
+ preceded!(tag!(b"branch="), token) => { |t| ViaParam::Branch(t) } |
+ generic_param => { |g| ViaParam::Extension(g) }
+));
+
+named!(via<Via>, tuple!(
+ terminated!(sent_protocol, tag!(b" ")),
+ sent_by,
+ many0!(preceded!(
+ tag!(b";"),
+ via_param))));
+
+named!(via_header<Vec<Via>>, preceded!(
+ alt!(tag!(b"Via:") | tag!("v:")),
+ separated_nonempty_list!(
+ tag!(b","),
+ via)));
+
named!(pub header<Header>, alt!(
// RFC 3261 Headers
accept_header => { |a| Header::Accept(a) } |
timestamp_header => { |t| Header::Timestamp(t) } |
to_header => { |t| Header::To(t) } |
unsupported_header => { |u| Header::Unsupported(u) } |
- user_agent_header => { |u| Header::UserAgent(u) }
+ user_agent_header => { |u| Header::UserAgent(u) } |
+ via_header => { |v| Header::Via(v) }
));
pub type To = (Target, Vec<ToParam>);
+#[derive(Debug)]
+pub enum Protocol {
+ SIP,
+ Other(Vec<u8>),
+}
+
+pub type SentProtocol = (Protocol, Vec<u8>, Transport);
+
+#[derive(Debug)]
+pub enum Received {
+ Ipv4Address(u8, u8, u8, u8),
+ Ipv6Address(Vec<u8>),
+}
+
+#[derive(Debug)]
+pub enum ViaParam {
+ Ttl(u32),
+ Maddr(Host),
+ Received(Received),
+ Branch(Vec<u8>),
+ Extension(GenericParam),
+}
+
+pub type Via = (SentProtocol, HostPort, Vec<ViaParam>);
+
#[derive(Debug)]
pub enum Header {
Accept(Vec<AcceptRange>),
To(To),
Unsupported(Vec<OptionTag>),
UserAgent(Vec<Server>),
+ Via(Vec<Via>),
Extension { name: String, value: String },
}