ping, iq: Implement ping::serialise_ping and link to Iq.

This commit is contained in:
Maxime “pep” Buquet 2017-04-23 21:17:26 +01:00
parent b259ab9ef2
commit c462d230f1
2 changed files with 9 additions and 0 deletions

View file

@ -8,11 +8,13 @@ use error::Error;
use ns; use ns;
use disco; use disco;
use ping;
/// Lists every known payload of a `<iq/>`. /// Lists every known payload of a `<iq/>`.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum IqPayload { pub enum IqPayload {
Disco(disco::Disco), Disco(disco::Disco),
Ping(ping::Ping),
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -77,6 +79,8 @@ pub fn parse_iq(root: &Element) -> Result<Iq, Error> {
} else { } else {
let parsed_payload = if let Ok(disco) = disco::parse_disco(elem) { let parsed_payload = if let Ok(disco) = disco::parse_disco(elem) {
Some(IqPayload::Disco(disco)) Some(IqPayload::Disco(disco))
} else if let Ok(ping) = ping::parse_ping(elem) {
Some(IqPayload::Ping(ping))
} else { } else {
None None
}; };
@ -127,6 +131,7 @@ pub fn parse_iq(root: &Element) -> Result<Iq, Error> {
pub fn serialise_payload(payload: &IqPayload) -> Element { pub fn serialise_payload(payload: &IqPayload) -> Element {
match *payload { match *payload {
IqPayload::Disco(ref disco) => disco::serialise_disco(disco), IqPayload::Disco(ref disco) => disco::serialise_disco(disco),
IqPayload::Ping(_) => ping::serialise_ping(),
} }
} }

View file

@ -18,6 +18,10 @@ pub fn parse_ping(root: &Element) -> Result<Ping, Error> {
Ok(Ping { }) Ok(Ping { })
} }
pub fn serialise_ping() -> Element {
Element::builder("ping").ns(ns::PING).build()
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use minidom::Element; use minidom::Element;