From 189f17c5696cf26707efedaff86701fc3c3d3161 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 21 Apr 2017 03:09:10 +0100 Subject: [PATCH] ibb: Add a parser for the element. --- src/ibb.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ibb.rs b/src/ibb.rs index 6811e68c..f77541c8 100644 --- a/src/ibb.rs +++ b/src/ibb.rs @@ -37,7 +37,7 @@ impl FromStr for Stanza { pub enum IBB { Open { block_size: u16, sid: String, stanza: Stanza }, Data { seq: u16, sid: String, data: Vec }, - Close(String), + Close { sid: String }, } fn optional_attr(root: &Element, attr: &str) -> Option { @@ -76,6 +76,14 @@ pub fn parse_ibb(root: &Element) -> Result { sid: sid, data: data }) + } else if root.is("close", ns::IBB) { + let sid = required_attr(root, "sid", Error::ParseError("Required attribute 'sid' missing in data element."))?; + for _ in root.children() { + return Err(Error::ParseError("Unknown child in close element.")); + } + Ok(IBB::Close { + sid: sid, + }) } else { Err(Error::ParseError("This is not an ibb element.")) } @@ -94,6 +102,9 @@ mod tests { let elem: Element = "AAAA".parse().unwrap(); ibb::parse_ibb(&elem).unwrap(); + + let elem: Element = "".parse().unwrap(); + ibb::parse_ibb(&elem).unwrap(); } #[test]