forked from lavina/lavina
xmpp: fix message parsing when unknown elements are present
This commit is contained in:
parent
2f034284cf
commit
7c89936a87
|
@ -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<T> {
|
||||
pub from: Option<Jid>,
|
||||
pub id: Option<String>,
|
||||
pub to: Option<Jid>,
|
||||
// default is Normal
|
||||
pub r#type: MessageType,
|
||||
pub lang: Option<Str>,
|
||||
|
||||
pub subject: Option<Str>,
|
||||
pub body: Str,
|
||||
pub custom: Vec<T>,
|
||||
}
|
||||
|
||||
impl FromXmlTag for Message {
|
||||
impl<T> FromXmlTag for Message<T> {
|
||||
const NS: &'static str = XMLNS;
|
||||
const NAME: &'static str = "message";
|
||||
}
|
||||
|
||||
impl FromXml for Message {
|
||||
type P = MessageParser;
|
||||
impl<T> FromXml for Message<T> {
|
||||
type P = MessageParser<T>;
|
||||
|
||||
fn parse() -> Self::P {
|
||||
MessageParserInner::Init.into()
|
||||
|
@ -40,15 +40,16 @@ impl FromXml for Message {
|
|||
}
|
||||
|
||||
#[derive(From)]
|
||||
pub struct MessageParser(MessageParserInner);
|
||||
pub struct MessageParser<T: FromXml>(MessageParserInner<T>);
|
||||
|
||||
#[derive(Default)]
|
||||
enum MessageParserInner {
|
||||
enum MessageParserInner<T: FromXml> {
|
||||
#[default]
|
||||
Init,
|
||||
Outer(MessageParserState),
|
||||
InSubject(MessageParserState),
|
||||
InBody(MessageParserState),
|
||||
InCustom(T::P),
|
||||
}
|
||||
#[derive(Default)]
|
||||
struct MessageParserState {
|
||||
|
@ -60,8 +61,8 @@ struct MessageParserState {
|
|||
subject: Option<Str>,
|
||||
body: Option<Str>,
|
||||
}
|
||||
impl Parser for MessageParser {
|
||||
type Output = Result<Message>;
|
||||
impl<T> Parser for MessageParser<T> {
|
||||
type Output = Result<Message<T>>;
|
||||
|
||||
fn consume<'a>(
|
||||
self: Self,
|
||||
|
@ -148,7 +149,7 @@ impl Parser for MessageParser {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToXml for Message {
|
||||
impl<T: ToXml> ToXml for Message<T> {
|
||||
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
||||
let mut bytes = BytesStart::new(format!(r#"message xmlns="{}""#, XMLNS));
|
||||
if let Some(from) = &self.from {
|
||||
|
|
Loading…
Reference in New Issue