iq: Wire up the Jingle parser and serialiser.

This commit is contained in:
Emmanuel Gil Peyrot 2017-04-28 23:46:06 +01:00
parent 4fb4727357
commit 5e4ba2701b

View file

@ -8,12 +8,14 @@ use error::Error;
use ns; use ns;
use disco; use disco;
use jingle;
use ping; 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),
Jingle(jingle::Jingle),
Ping(ping::Ping), Ping(ping::Ping),
} }
@ -79,6 +81,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(jingle) = jingle::parse_jingle(elem) {
Some(IqPayload::Jingle(jingle))
} else if let Ok(ping) = ping::parse_ping(elem) { } else if let Ok(ping) = ping::parse_ping(elem) {
Some(IqPayload::Ping(ping)) Some(IqPayload::Ping(ping))
} else { } else {
@ -131,6 +135,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::Jingle(ref jingle) => jingle::serialise(jingle),
IqPayload::Ping(_) => ping::serialise_ping(), IqPayload::Ping(_) => ping::serialise_ping(),
} }
} }