Add a ping parser.
This commit is contained in:
parent
87cd047a46
commit
fdc76eca3c
3 changed files with 55 additions and 0 deletions
|
|
@ -8,3 +8,4 @@ pub mod data_forms;
|
||||||
pub mod media_element;
|
pub mod media_element;
|
||||||
pub mod ecaps2;
|
pub mod ecaps2;
|
||||||
pub mod jingle;
|
pub mod jingle;
|
||||||
|
pub mod ping;
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@ pub const DISCO_INFO_NS: &'static str = "http://jabber.org/protocol/disco#info";
|
||||||
pub const DATA_FORMS_NS: &'static str = "jabber:x:data";
|
pub const DATA_FORMS_NS: &'static str = "jabber:x:data";
|
||||||
pub const MEDIA_ELEMENT_NS: &'static str = "urn:xmpp:media-element";
|
pub const MEDIA_ELEMENT_NS: &'static str = "urn:xmpp:media-element";
|
||||||
pub const JINGLE_NS: &'static str = "urn:xmpp:jingle:1";
|
pub const JINGLE_NS: &'static str = "urn:xmpp:jingle:1";
|
||||||
|
pub const PING_NS: &'static str = "urn:xmpp:ping";
|
||||||
|
|
|
||||||
53
src/ping.rs
Normal file
53
src/ping.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
use minidom::Element;
|
||||||
|
|
||||||
|
use error::Error;
|
||||||
|
|
||||||
|
use ns::PING_NS;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Ping {
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_ping(root: &Element) -> Result<Ping, Error> {
|
||||||
|
assert!(root.is("ping", PING_NS));
|
||||||
|
for _ in root.children() {
|
||||||
|
return Err(Error::ParseError("Unknown child in ping element."));
|
||||||
|
}
|
||||||
|
Ok(Ping { })
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use minidom::Element;
|
||||||
|
use error::Error;
|
||||||
|
use ping;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_simple() {
|
||||||
|
let elem: Element = "<ping xmlns='urn:xmpp:ping'/>".parse().unwrap();
|
||||||
|
ping::parse_ping(&elem).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_invalid() {
|
||||||
|
let elem: Element = "<ping xmlns='urn:xmpp:ping'><coucou/></ping>".parse().unwrap();
|
||||||
|
let error = ping::parse_ping(&elem).unwrap_err();
|
||||||
|
let message = match error {
|
||||||
|
Error::ParseError(string) => string,
|
||||||
|
_ => panic!(),
|
||||||
|
};
|
||||||
|
assert_eq!(message, "Unknown child in ping element.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_invalid_attribute() {
|
||||||
|
let elem: Element = "<ping xmlns='urn:xmpp:ping' coucou=''/>".parse().unwrap();
|
||||||
|
let error = ping::parse_ping(&elem).unwrap_err();
|
||||||
|
let message = match error {
|
||||||
|
Error::ParseError(string) => string,
|
||||||
|
_ => panic!(),
|
||||||
|
};
|
||||||
|
assert_eq!(message, "Unknown attribute in ping element.");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue