From bb12168c4159edcb6e0d7a8511be171bc02092e1 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 6 May 2017 13:54:16 +0100 Subject: [PATCH] =?UTF-8?q?jingle=5Fs5b:=20Handle=20the=20forgotten=20case?= =?UTF-8?q?=20of=20an=20empty=20transport=20element,=20see=20=C2=A72.2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jingle_s5b.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/jingle_s5b.rs b/src/jingle_s5b.rs index 6a6ee50..b0d7266 100644 --- a/src/jingle_s5b.rs +++ b/src/jingle_s5b.rs @@ -118,6 +118,7 @@ pub enum TransportPayload { CandidateError, CandidateUsed(String), ProxyError, + None, } #[derive(Debug, Clone)] @@ -210,7 +211,7 @@ impl<'a> TryFrom<&'a Element> for Transport { 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 { sid: sid, dstaddr: dstaddr, @@ -258,6 +259,7 @@ impl<'a> Into for &'a Transport { .ns(ns::JINGLE_S5B) .build()) }, + TransportPayload::None => vec!(), }) .build() } @@ -269,13 +271,13 @@ mod tests { #[test] fn test_simple() { - let elem: Element = "".parse().unwrap(); + let elem: Element = "".parse().unwrap(); let transport = Transport::try_from(&elem).unwrap(); assert_eq!(transport.sid, "coucou"); assert_eq!(transport.dstaddr, None); assert_eq!(transport.mode, Mode::Tcp); match transport.payload { - TransportPayload::ProxyError => (), + TransportPayload::None => (), _ => panic!("Wrong element inside transport!"), } }