xmpp-parsers: Move the Stanza type from tokio-xmpp
It doesn’t come with the ensure_id() method, but otherwise this is a much better location for it.
This commit is contained in:
parent
e95313eedb
commit
0ef8c215d7
3 changed files with 85 additions and 0 deletions
|
|
@ -24,6 +24,8 @@ XXXX-YY-ZZ RELEASER <admin@example.com>
|
|||
not be rejected by xmpp-parsers by default anymore. The `pedantic`
|
||||
feature can be used to opt into the previous default behaviour.
|
||||
* Improvements:
|
||||
- Take the Stanza type from tokio-xmpp, it’s an enum which can wrap
|
||||
Message, Presence and Iq.
|
||||
- Make Priority’s inner i8 pub, which had been broken since the
|
||||
conversion to xso. (!632)
|
||||
- ibr::LegacyQuery now implements Default, allowing users to more
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ pub mod presence;
|
|||
/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
|
||||
pub mod sasl;
|
||||
/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
|
||||
pub mod stanza;
|
||||
/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
|
||||
pub mod stanza_error;
|
||||
/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
|
||||
pub mod starttls;
|
||||
|
|
|
|||
81
parsers/src/stanza.rs
Normal file
81
parsers/src/stanza.rs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// Copyright (c) 2024 Jonas Schäfer <jonas@zombofant.net>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
use xso::{AsXml, FromXml};
|
||||
|
||||
use crate::{iq::Iq, message::Message, presence::Presence};
|
||||
|
||||
/// A stanza sent/received over the stream.
|
||||
///
|
||||
/// WARNING: do not add variants to this enum! Adding variants which refer
|
||||
/// to anything but [`Iq`], [`Message`] or [`Presence`] stanzas will cause the
|
||||
/// stream management counters to be off.
|
||||
#[derive(FromXml, AsXml, Debug, PartialEq)]
|
||||
#[xml()]
|
||||
pub enum Stanza {
|
||||
/// IQ stanza
|
||||
#[xml(transparent)]
|
||||
Iq(Iq),
|
||||
|
||||
/// Message stanza
|
||||
#[xml(transparent)]
|
||||
Message(Message),
|
||||
|
||||
/// Presence stanza
|
||||
#[xml(transparent)]
|
||||
Presence(Presence),
|
||||
}
|
||||
|
||||
impl From<Iq> for Stanza {
|
||||
fn from(other: Iq) -> Self {
|
||||
Self::Iq(other)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Presence> for Stanza {
|
||||
fn from(other: Presence) -> Self {
|
||||
Self::Presence(other)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Message> for Stanza {
|
||||
fn from(other: Message) -> Self {
|
||||
Self::Message(other)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Stanza> for Message {
|
||||
type Error = Stanza;
|
||||
|
||||
fn try_from(other: Stanza) -> Result<Self, Stanza> {
|
||||
match other {
|
||||
Stanza::Message(st) => Ok(st),
|
||||
other => Err(other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Stanza> for Presence {
|
||||
type Error = Stanza;
|
||||
|
||||
fn try_from(other: Stanza) -> Result<Self, Stanza> {
|
||||
match other {
|
||||
Stanza::Presence(st) => Ok(st),
|
||||
other => Err(other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Stanza> for Iq {
|
||||
type Error = Stanza;
|
||||
|
||||
fn try_from(other: Stanza) -> Result<Self, Stanza> {
|
||||
match other {
|
||||
Stanza::Iq(st) => Ok(st),
|
||||
other => Err(other),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue