From 2b8bcebfd95338fbee37fd2df018095e24b55e73 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 19 May 2017 02:09:23 +0100 Subject: [PATCH] message, iq, presence: Return an Unknown instead of an error when the element is unknown. --- src/iq.rs | 6 +++++- src/message.rs | 6 +++++- src/presence.rs | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/iq.rs b/src/iq.rs index b6216898..43624750 100644 --- a/src/iq.rs +++ b/src/iq.rs @@ -29,6 +29,8 @@ pub enum IqPayload { IBB(IBB), Jingle(Jingle), Ping(Ping), + + Unknown(Element), } impl<'a> TryFrom<&'a Element> for IqPayload { @@ -50,7 +52,7 @@ impl<'a> TryFrom<&'a Element> for IqPayload { // XEP-0199 ("ping", ns::PING) => IqPayload::Ping(Ping::try_from(elem)?), - _ => return Err(Error::ParseError("Unknown iq payload.")) + _ => IqPayload::Unknown(elem.clone()), }) } } @@ -164,6 +166,8 @@ impl<'a> Into for &'a IqPayload { IqPayload::IBB(ref ibb) => ibb.into(), IqPayload::Jingle(ref jingle) => jingle.into(), IqPayload::Ping(ref ping) => ping.into(), + + IqPayload::Unknown(ref elem) => elem.clone(), } } } diff --git a/src/message.rs b/src/message.rs index a900502b..96153cfa 100644 --- a/src/message.rs +++ b/src/message.rs @@ -36,6 +36,8 @@ pub enum MessagePayload { MessageCorrect(Replace), ExplicitMessageEncryption(ExplicitMessageEncryption), StanzaId(StanzaId), + + Unknown(Element), } impl<'a> TryFrom<&'a Element> for MessagePayload { @@ -71,7 +73,7 @@ impl<'a> TryFrom<&'a Element> for MessagePayload { // XEP-0380 ("encryption", ns::EME) => MessagePayload::ExplicitMessageEncryption(ExplicitMessageEncryption::try_from(elem)?), - _ => return Err(Error::ParseError("Unknown message payload.")) + _ => MessagePayload::Unknown(elem.clone()), }) } } @@ -87,6 +89,8 @@ impl<'a> Into for &'a MessagePayload { MessagePayload::MessageCorrect(ref replace) => replace.into(), MessagePayload::ExplicitMessageEncryption(ref eme) => eme.into(), MessagePayload::StanzaId(ref stanza_id) => stanza_id.into(), + + MessagePayload::Unknown(ref elem) => elem.clone(), } } } diff --git a/src/presence.rs b/src/presence.rs index 67ca5fa0..7eb53b41 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -51,6 +51,8 @@ pub enum PresencePayload { StanzaError(StanzaError), Delay(Delay), ECaps2(ECaps2), + + Unknown(Element), } impl<'a> TryFrom<&'a Element> for PresencePayload { @@ -66,7 +68,7 @@ impl<'a> TryFrom<&'a Element> for PresencePayload { // XEP-0390 ("c", ns::ECAPS2) => PresencePayload::ECaps2(ECaps2::try_from(elem)?), - _ => return Err(Error::ParseError("Unknown presence payload.")) + _ => PresencePayload::Unknown(elem.clone()), }) } } @@ -77,6 +79,8 @@ impl<'a> Into for &'a PresencePayload { PresencePayload::StanzaError(ref stanza_error) => stanza_error.into(), PresencePayload::Delay(ref delay) => delay.into(), PresencePayload::ECaps2(ref ecaps2) => ecaps2.into(), + + PresencePayload::Unknown(ref elem) => elem.clone(), } } }