jingle_s5b: Handle the forgotten case of an empty transport element, see §2.2.

This commit is contained in:
Emmanuel Gil Peyrot 2017-05-06 13:54:16 +01:00
parent 828b88e5b2
commit bb12168c41

View file

@ -118,6 +118,7 @@ pub enum TransportPayload {
CandidateError, CandidateError,
CandidateUsed(String), CandidateUsed(String),
ProxyError, ProxyError,
None,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -210,7 +211,7 @@ impl<'a> TryFrom<&'a Element> for Transport {
return Err(Error::ParseError("Unknown child in JingleS5B transport element.")); return Err(Error::ParseError("Unknown child in JingleS5B transport element."));
}); });
} }
let payload = payload.ok_or(Error::ParseError("No child in JingleS5B transport element."))?; let payload = payload.unwrap_or(TransportPayload::None);
Ok(Transport { Ok(Transport {
sid: sid, sid: sid,
dstaddr: dstaddr, dstaddr: dstaddr,
@ -258,6 +259,7 @@ impl<'a> Into<Element> for &'a Transport {
.ns(ns::JINGLE_S5B) .ns(ns::JINGLE_S5B)
.build()) .build())
}, },
TransportPayload::None => vec!(),
}) })
.build() .build()
} }
@ -269,13 +271,13 @@ mod tests {
#[test] #[test]
fn test_simple() { fn test_simple() {
let elem: Element = "<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='coucou'><proxy-error/></transport>".parse().unwrap(); let elem: Element = "<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='coucou'/>".parse().unwrap();
let transport = Transport::try_from(&elem).unwrap(); let transport = Transport::try_from(&elem).unwrap();
assert_eq!(transport.sid, "coucou"); assert_eq!(transport.sid, "coucou");
assert_eq!(transport.dstaddr, None); assert_eq!(transport.dstaddr, None);
assert_eq!(transport.mode, Mode::Tcp); assert_eq!(transport.mode, Mode::Tcp);
match transport.payload { match transport.payload {
TransportPayload::ProxyError => (), TransportPayload::None => (),
_ => panic!("Wrong element inside transport!"), _ => panic!("Wrong element inside transport!"),
} }
} }