ibb: Add a parser for the <close/> element.
This commit is contained in:
parent
fb373c2b66
commit
189f17c569
1 changed files with 12 additions and 1 deletions
13
src/ibb.rs
13
src/ibb.rs
|
@ -37,7 +37,7 @@ impl FromStr for Stanza {
|
||||||
pub enum IBB {
|
pub enum IBB {
|
||||||
Open { block_size: u16, sid: String, stanza: Stanza },
|
Open { block_size: u16, sid: String, stanza: Stanza },
|
||||||
Data { seq: u16, sid: String, data: Vec<u8> },
|
Data { seq: u16, sid: String, data: Vec<u8> },
|
||||||
Close(String),
|
Close { sid: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
fn optional_attr<T: FromStr>(root: &Element, attr: &str) -> Option<T> {
|
fn optional_attr<T: FromStr>(root: &Element, attr: &str) -> Option<T> {
|
||||||
|
@ -76,6 +76,14 @@ pub fn parse_ibb(root: &Element) -> Result<IBB, Error> {
|
||||||
sid: sid,
|
sid: sid,
|
||||||
data: data
|
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 {
|
} else {
|
||||||
Err(Error::ParseError("This is not an ibb element."))
|
Err(Error::ParseError("This is not an ibb element."))
|
||||||
}
|
}
|
||||||
|
@ -94,6 +102,9 @@ mod tests {
|
||||||
|
|
||||||
let elem: Element = "<data xmlns='http://jabber.org/protocol/ibb' seq='0' sid='coucou'>AAAA</data>".parse().unwrap();
|
let elem: Element = "<data xmlns='http://jabber.org/protocol/ibb' seq='0' sid='coucou'>AAAA</data>".parse().unwrap();
|
||||||
ibb::parse_ibb(&elem).unwrap();
|
ibb::parse_ibb(&elem).unwrap();
|
||||||
|
|
||||||
|
let elem: Element = "<close xmlns='http://jabber.org/protocol/ibb' sid='coucou'/>".parse().unwrap();
|
||||||
|
ibb::parse_ibb(&elem).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue