From 7c89936a87b3061c39d5d745704ce6df4a58f4a0 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Sun, 1 Oct 2023 17:58:59 +0200 Subject: [PATCH] xmpp: fix message parsing when unknown elements are present --- crates/proto-xmpp/src/client.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/crates/proto-xmpp/src/client.rs b/crates/proto-xmpp/src/client.rs index 2a6697f..a209127 100644 --- a/crates/proto-xmpp/src/client.rs +++ b/crates/proto-xmpp/src/client.rs @@ -14,25 +14,25 @@ use super::bind::Jid; pub const XMLNS: &'static str = "jabber:client"; #[derive(PartialEq, Eq, Debug)] -pub struct Message { +pub struct Message { pub from: Option, pub id: Option, pub to: Option, // default is Normal pub r#type: MessageType, pub lang: Option, - pub subject: Option, pub body: Str, + pub custom: Vec, } -impl FromXmlTag for Message { +impl FromXmlTag for Message { const NS: &'static str = XMLNS; const NAME: &'static str = "message"; } -impl FromXml for Message { - type P = MessageParser; +impl FromXml for Message { + type P = MessageParser; fn parse() -> Self::P { MessageParserInner::Init.into() @@ -40,15 +40,16 @@ impl FromXml for Message { } #[derive(From)] -pub struct MessageParser(MessageParserInner); +pub struct MessageParser(MessageParserInner); #[derive(Default)] -enum MessageParserInner { +enum MessageParserInner { #[default] Init, Outer(MessageParserState), InSubject(MessageParserState), InBody(MessageParserState), + InCustom(T::P), } #[derive(Default)] struct MessageParserState { @@ -60,8 +61,8 @@ struct MessageParserState { subject: Option, body: Option, } -impl Parser for MessageParser { - type Output = Result; +impl Parser for MessageParser { + type Output = Result>; fn consume<'a>( self: Self, @@ -148,7 +149,7 @@ impl Parser for MessageParser { } } -impl ToXml for Message { +impl ToXml for Message { fn serialize(&self, events: &mut Vec>) { let mut bytes = BytesStart::new(format!(r#"message xmlns="{}""#, XMLNS)); if let Some(from) = &self.from {