diff options
Diffstat (limited to '')
-rw-r--r-- | stanza/src/client/iq.rs | 18 | ||||
-rw-r--r-- | stanza/src/client/message.rs | 74 | ||||
-rw-r--r-- | stanza/src/lib.rs | 4 | ||||
-rw-r--r-- | stanza/src/xep_0280.rs | 109 | ||||
-rw-r--r-- | stanza/src/xep_0334.rs | 83 |
5 files changed, 288 insertions, 0 deletions
diff --git a/stanza/src/client/iq.rs b/stanza/src/client/iq.rs index 478530a..f5cdf32 100644 --- a/stanza/src/client/iq.rs +++ b/stanza/src/client/iq.rs @@ -3,6 +3,8 @@ use std::str::FromStr; use jid::JID; use peanuts::{DeserializeError, Element, FromElement, IntoElement, XML_NS}; +#[cfg(feature = "xep_0280")] +use crate::xep_0280::{self, Disable, Enable}; use crate::{ bind::{self, Bind}, client::error::Error, @@ -53,6 +55,10 @@ pub enum Query { Ping(Ping), #[cfg(feature = "rfc_6121")] Roster(roster::Query), + #[cfg(feature = "xep_0280")] + CarbonsEnable(Enable), + #[cfg(feature = "xep_0280")] + CarbonsDisable(Disable), Unsupported, } @@ -80,6 +86,14 @@ impl FromElement for Query { (Some(xep_0060::owner::XMLNS), "pubsub") => Ok(Query::PubsubOwner( xep_0060::owner::Pubsub::from_element(element)?, )), + #[cfg(feature = "xep_0280")] + (Some(xep_0280::XMLNS), "enable") => { + Ok(Query::CarbonsEnable(Enable::from_element(element)?)) + } + #[cfg(feature = "xep_0280")] + (Some(xep_0280::XMLNS), "disable") => { + Ok(Query::CarbonsDisable(Disable::from_element(element)?)) + } _ => Ok(Query::Unsupported), } } @@ -103,6 +117,10 @@ impl IntoElement for Query { Query::Pubsub(pubsub) => pubsub.builder(), #[cfg(feature = "xep_0060")] Query::PubsubOwner(pubsub) => pubsub.builder(), + #[cfg(feature = "xep_0280")] + Query::CarbonsEnable(enable) => enable.builder(), + #[cfg(feature = "xep_0280")] + Query::CarbonsDisable(disable) => disable.builder(), } } } diff --git a/stanza/src/client/message.rs b/stanza/src/client/message.rs index 13ee6f1..3a7be9a 100644 --- a/stanza/src/client/message.rs +++ b/stanza/src/client/message.rs @@ -11,8 +11,12 @@ use crate::xep_0131::Headers; use crate::xep_0172::Nick; #[cfg(feature = "xep_0203")] use crate::xep_0203::Delay; +#[cfg(feature = "xep_0280")] +use crate::xep_0280::{Private, Received, Sent}; #[cfg(feature = "xep_0297")] use crate::xep_0297::Forwarded; +#[cfg(feature = "xep_0334")] +use crate::xep_0334::{NoCopy, NoPermanentStore, NoStore, Store}; use super::XMLNS; @@ -38,6 +42,20 @@ pub struct Message { pub event: Option<Event>, #[cfg(feature = "xep_0297")] pub forwarded: Option<Forwarded>, + #[cfg(feature = "xep_0280")] + pub sent: Option<Sent>, + #[cfg(feature = "xep_0280")] + pub received: Option<Received>, + #[cfg(feature = "xep_0280")] + pub private: Option<Private>, + #[cfg(feature = "xep_0334")] + pub no_permanent_store: Option<NoPermanentStore>, + #[cfg(feature = "xep_0334")] + pub no_store: Option<NoStore>, + #[cfg(feature = "xep_0334")] + pub no_copy: Option<NoCopy>, + #[cfg(feature = "xep_0334")] + pub store: Option<Store>, } impl FromElement for Message { @@ -70,6 +88,27 @@ impl FromElement for Message { #[cfg(feature = "xep_0297")] let forwarded = element.child_opt()?; + #[cfg(feature = "xep_0280")] + let sent = element.child_opt()?; + + #[cfg(feature = "xep_0280")] + let received = element.child_opt()?; + + #[cfg(feature = "xep_0280")] + let private = element.child_opt()?; + + #[cfg(feature = "xep_0334")] + let no_permanent_store = element.child_opt()?; + + #[cfg(feature = "xep_0334")] + let no_store = element.child_opt()?; + + #[cfg(feature = "xep_0334")] + let no_copy = element.child_opt()?; + + #[cfg(feature = "xep_0334")] + let store = element.child_opt()?; + Ok(Message { from, id, @@ -89,6 +128,20 @@ impl FromElement for Message { event, #[cfg(feature = "xep_0297")] forwarded, + #[cfg(feature = "xep_0280")] + sent, + #[cfg(feature = "xep_0280")] + received, + #[cfg(feature = "xep_0280")] + private, + #[cfg(feature = "xep_0334")] + no_permanent_store, + #[cfg(feature = "xep_0334")] + no_store, + #[cfg(feature = "xep_0334")] + no_copy, + #[cfg(feature = "xep_0334")] + store, }) } } @@ -126,6 +179,27 @@ impl IntoElement for Message { #[cfg(feature = "xep_0297")] let builder = builder.push_child_opt(self.forwarded.clone()); + #[cfg(feature = "xep_0280")] + let builder = builder.push_child_opt(self.sent.clone()); + + #[cfg(feature = "xep_0280")] + let builder = builder.push_child_opt(self.received.clone()); + + #[cfg(feature = "xep_0280")] + let builder = builder.push_child_opt(self.private.clone()); + + #[cfg(feature = "xep_0334")] + let builder = builder.push_child_opt(self.no_permanent_store); + + #[cfg(feature = "xep_0334")] + let builder = builder.push_child_opt(self.no_store); + + #[cfg(feature = "xep_0334")] + let builder = builder.push_child_opt(self.no_copy); + + #[cfg(feature = "xep_0334")] + let builder = builder.push_child_opt(self.store); + builder } } diff --git a/stanza/src/lib.rs b/stanza/src/lib.rs index 8f9b788..4cb62a3 100644 --- a/stanza/src/lib.rs +++ b/stanza/src/lib.rs @@ -33,10 +33,14 @@ pub mod xep_0172; pub mod xep_0199; #[cfg(feature = "xep_0203")] pub mod xep_0203; +#[cfg(feature = "xep_0280")] +pub mod xep_0280; #[cfg(feature = "xep_0297")] pub mod xep_0297; #[cfg(feature = "xep_0300")] pub mod xep_0300; +#[cfg(feature = "xep_0334")] +pub mod xep_0334; #[cfg(feature = "xep_0390")] pub mod xep_0390; diff --git a/stanza/src/xep_0280.rs b/stanza/src/xep_0280.rs new file mode 100644 index 0000000..c26793f --- /dev/null +++ b/stanza/src/xep_0280.rs @@ -0,0 +1,109 @@ +use peanuts::{Element, FromElement, IntoElement}; + +use crate::xep_0297::Forwarded; + +pub const XMLNS: &str = "urn:xmpp:carbons:2"; + +#[derive(Clone, Debug)] +pub struct Disable; + +impl FromElement for Disable { + fn from_element(element: Element) -> peanuts::DeserializeResult<Self> { + element.check_name("disable")?; + element.check_namespace(XMLNS)?; + + element.no_more_content()?; + + Ok(Self) + } +} + +impl IntoElement for Disable { + fn builder(&self) -> peanuts::ElementBuilder { + Element::builder("disable", Some(XMLNS)) + } +} + +#[derive(Clone, Debug)] +pub struct Enable; + +impl FromElement for Enable { + fn from_element(element: Element) -> peanuts::DeserializeResult<Self> { + element.check_name("enable")?; + element.check_namespace(XMLNS)?; + + element.no_more_content()?; + + Ok(Self) + } +} + +impl IntoElement for Enable { + fn builder(&self) -> peanuts::ElementBuilder { + Element::builder("enable", Some(XMLNS)) + } +} + +#[derive(Clone, Debug)] +pub struct Private; + +impl FromElement for Private { + fn from_element(element: Element) -> peanuts::DeserializeResult<Self> { + element.check_name("private")?; + element.check_namespace(XMLNS)?; + + element.no_more_content()?; + + Ok(Self) + } +} + +impl IntoElement for Private { + fn builder(&self) -> peanuts::ElementBuilder { + Element::builder("private", Some(XMLNS)) + } +} + +#[derive(Clone, Debug)] +pub struct Received { + forwarded: Forwarded, +} + +impl FromElement for Received { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { + element.check_name("received")?; + element.check_namespace(XMLNS)?; + + let forwarded = element.pop_child_one()?; + + Ok(Self { forwarded }) + } +} + +impl IntoElement for Received { + fn builder(&self) -> peanuts::ElementBuilder { + Element::builder("received", Some(XMLNS)).push_child(self.forwarded.clone()) + } +} + +#[derive(Clone, Debug)] +pub struct Sent { + forwarded: Forwarded, +} + +impl FromElement for Sent { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { + element.check_name("sent")?; + element.check_namespace(XMLNS)?; + + let forwarded = element.pop_child_one()?; + + Ok(Self { forwarded }) + } +} + +impl IntoElement for Sent { + fn builder(&self) -> peanuts::ElementBuilder { + Element::builder("sent", Some(XMLNS)).push_child(self.forwarded.clone()) + } +} diff --git a/stanza/src/xep_0334.rs b/stanza/src/xep_0334.rs new file mode 100644 index 0000000..9667ad7 --- /dev/null +++ b/stanza/src/xep_0334.rs @@ -0,0 +1,83 @@ +use peanuts::{Element, FromElement, IntoElement}; + +pub const XMLNS: &str = "urn:xmpp:hints"; + +#[derive(Clone, Copy, Debug)] +pub struct NoPermanentStore; + +impl FromElement for NoPermanentStore { + fn from_element(element: Element) -> peanuts::DeserializeResult<Self> { + element.check_name("no-permanent-store")?; + element.check_namespace(XMLNS)?; + + element.no_more_content()?; + + Ok(Self) + } +} + +impl IntoElement for NoPermanentStore { + fn builder(&self) -> peanuts::ElementBuilder { + Element::builder("no-permanent-store", Some(XMLNS)) + } +} + +#[derive(Clone, Copy, Debug)] +pub struct NoStore; + +impl FromElement for NoStore { + fn from_element(element: Element) -> peanuts::DeserializeResult<Self> { + element.check_name("no-store")?; + element.check_namespace(XMLNS)?; + + element.no_more_content()?; + + Ok(Self) + } +} + +impl IntoElement for NoStore { + fn builder(&self) -> peanuts::ElementBuilder { + Element::builder("no-store", Some(XMLNS)) + } +} + +#[derive(Clone, Copy, Debug)] +pub struct NoCopy; + +impl FromElement for NoCopy { + fn from_element(element: Element) -> peanuts::DeserializeResult<Self> { + element.check_name("no-copy")?; + element.check_namespace(XMLNS)?; + + element.no_more_content()?; + + Ok(Self) + } +} + +impl IntoElement for NoCopy { + fn builder(&self) -> peanuts::ElementBuilder { + Element::builder("no-copy", Some(XMLNS)) + } +} + +#[derive(Clone, Copy, Debug)] +pub struct Store; + +impl FromElement for Store { + fn from_element(element: Element) -> peanuts::DeserializeResult<Self> { + element.check_name("store")?; + element.check_namespace(XMLNS)?; + + element.no_more_content()?; + + Ok(Self) + } +} + +impl IntoElement for Store { + fn builder(&self) -> peanuts::ElementBuilder { + Element::builder("store", Some(XMLNS)) + } +} |