aboutsummaryrefslogtreecommitdiffstats
path: root/stanza/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'stanza/src/client')
-rw-r--r--stanza/src/client/error.rs7
-rw-r--r--stanza/src/client/iq.rs44
-rw-r--r--stanza/src/client/message.rs119
-rw-r--r--stanza/src/client/mod.rs12
-rw-r--r--stanza/src/client/presence.rs21
5 files changed, 159 insertions, 44 deletions
diff --git a/stanza/src/client/error.rs b/stanza/src/client/error.rs
index c4ab517..9cc85a9 100644
--- a/stanza/src/client/error.rs
+++ b/stanza/src/client/error.rs
@@ -1,8 +1,7 @@
use std::fmt::Display;
use std::str::FromStr;
-use peanuts::element::{FromElement, IntoElement};
-use peanuts::{DeserializeError, Element};
+use peanuts::{DeserializeError, Element, FromElement, IntoElement};
use thiserror::Error;
use crate::stanza_error::Error as StanzaError;
@@ -40,7 +39,7 @@ impl Display for Error {
}
impl FromElement for Error {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("error")?;
element.check_name(XMLNS)?;
@@ -59,7 +58,7 @@ impl FromElement for Error {
}
impl IntoElement for Error {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("error", Some(XMLNS))
.push_attribute_opt("by", self.by.clone())
.push_attribute("type", self.r#type)
diff --git a/stanza/src/client/iq.rs b/stanza/src/client/iq.rs
index 50884aa..f5cdf32 100644
--- a/stanza/src/client/iq.rs
+++ b/stanza/src/client/iq.rs
@@ -1,11 +1,10 @@
use std::str::FromStr;
use jid::JID;
-use peanuts::{
- element::{FromElement, IntoElement},
- DeserializeError, Element, XML_NS,
-};
+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,
@@ -18,7 +17,10 @@ use crate::roster;
use crate::xep_0030::{self, info, items};
#[cfg(feature = "xep_0060")]
-use crate::xep_0060::pubsub::{self, Pubsub};
+use crate::xep_0060::{
+ self,
+ pubsub::{self, Pubsub},
+};
#[cfg(feature = "xep_0199")]
use crate::xep_0199::{self, Ping};
@@ -47,15 +49,21 @@ pub enum Query {
DiscoItems(items::Query),
#[cfg(feature = "xep_0060")]
Pubsub(Pubsub),
+ #[cfg(feature = "xep_0060")]
+ PubsubOwner(xep_0060::owner::Pubsub),
#[cfg(feature = "xep_0199")]
Ping(Ping),
#[cfg(feature = "rfc_6121")]
Roster(roster::Query),
+ #[cfg(feature = "xep_0280")]
+ CarbonsEnable(Enable),
+ #[cfg(feature = "xep_0280")]
+ CarbonsDisable(Disable),
Unsupported,
}
impl FromElement for Query {
- fn from_element(element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
match element.identify() {
(Some(bind::XMLNS), "bind") => Ok(Query::Bind(Bind::from_element(element)?)),
#[cfg(feature = "xep_0199")]
@@ -74,13 +82,25 @@ impl FromElement for Query {
}
#[cfg(feature = "xep_0060")]
(Some(pubsub::XMLNS), "pubsub") => Ok(Query::Pubsub(Pubsub::from_element(element)?)),
+ #[cfg(feature = "xep_0060")]
+ (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),
}
}
}
impl IntoElement for Query {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
match self {
Query::Bind(bind) => bind.builder(),
#[cfg(feature = "xep_0199")]
@@ -95,12 +115,18 @@ impl IntoElement for Query {
Query::DiscoItems(query) => query.builder(),
#[cfg(feature = "xep_0060")]
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(),
}
}
}
impl FromElement for Iq {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("iq")?;
element.check_namespace(XMLNS)?;
@@ -125,7 +151,7 @@ impl FromElement for Iq {
}
impl IntoElement for Iq {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("iq", Some(XMLNS))
.push_attribute_opt("from", self.from.clone())
.push_attribute("id", self.id.clone())
diff --git a/stanza/src/client/message.rs b/stanza/src/client/message.rs
index d94b82e..3a7be9a 100644
--- a/stanza/src/client/message.rs
+++ b/stanza/src/client/message.rs
@@ -1,17 +1,22 @@
use std::str::FromStr;
use jid::JID;
-use peanuts::{
- element::{FromElement, IntoElement},
- DeserializeError, Element, XML_NS,
-};
+use peanuts::{DeserializeError, Element, FromElement, IntoElement, XML_NS};
+#[cfg(feature = "xep_0060")]
+use crate::xep_0060::event::Event;
#[cfg(feature = "xep_0131")]
use crate::xep_0131::Headers;
#[cfg(feature = "xep_0172")]
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;
@@ -33,10 +38,28 @@ pub struct Message {
pub headers: Option<Headers>,
#[cfg(feature = "xep_0172")]
pub nick: Option<Nick>,
+ #[cfg(feature = "xep_0060")]
+ 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 {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("message")?;
element.check_namespace(XMLNS)?;
@@ -59,6 +82,33 @@ impl FromElement for Message {
#[cfg(feature = "xep_0172")]
let nick = element.child_opt()?;
+ #[cfg(feature = "xep_0060")]
+ let event = element.child_opt()?;
+
+ #[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,
@@ -74,12 +124,30 @@ impl FromElement for Message {
headers,
#[cfg(feature = "xep_0172")]
nick,
+ #[cfg(feature = "xep_0060")]
+ 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,
})
}
}
impl IntoElement for Message {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder = Element::builder("message", Some(XMLNS))
.push_attribute_opt("from", self.from.clone())
.push_attribute_opt("id", self.id.clone())
@@ -105,6 +173,33 @@ impl IntoElement for Message {
#[cfg(feature = "xep_0172")]
let builder = builder.push_child_opt(self.nick.clone());
+ #[cfg(feature = "xep_0060")]
+ let builder = builder.push_child_opt(self.event.clone());
+
+ #[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
}
}
@@ -154,7 +249,7 @@ pub struct Body {
}
impl FromElement for Body {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("body")?;
element.check_namespace(XMLNS)?;
@@ -166,7 +261,7 @@ impl FromElement for Body {
}
impl IntoElement for Body {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("body", Some(XMLNS))
.push_attribute_opt_namespaced(XML_NS, "lang", self.lang.clone())
.push_text_opt(self.body.clone())
@@ -180,7 +275,7 @@ pub struct Subject {
}
impl FromElement for Subject {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("subject")?;
element.check_namespace(XMLNS)?;
@@ -192,7 +287,7 @@ impl FromElement for Subject {
}
impl IntoElement for Subject {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("subject", Some(XMLNS))
.push_attribute_opt_namespaced(XML_NS, "lang", self.lang.clone())
.push_text_opt(self.subject.clone())
@@ -206,7 +301,7 @@ pub struct Thread {
}
impl FromElement for Thread {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("thread")?;
element.check_namespace(XMLNS)?;
@@ -218,7 +313,7 @@ impl FromElement for Thread {
}
impl IntoElement for Thread {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("thread", Some(XMLNS))
.push_attribute_opt("parent", self.parent.clone())
.push_text_opt(self.thread.clone())
diff --git a/stanza/src/client/mod.rs b/stanza/src/client/mod.rs
index a1b2de5..aca4fad 100644
--- a/stanza/src/client/mod.rs
+++ b/stanza/src/client/mod.rs
@@ -1,9 +1,7 @@
+use peanuts::{Content, ContentBuilder, DeserializeError, FromContent, FromElement, IntoContent};
+
use iq::Iq;
use message::Message;
-use peanuts::{
- element::{Content, ContentBuilder, FromContent, FromElement, IntoContent},
- DeserializeError,
-};
use presence::Presence;
use super::stream::{self, Error as StreamError};
@@ -26,7 +24,7 @@ pub enum Stanza {
}
impl FromContent for Stanza {
- fn from_content(content: Content) -> peanuts::element::DeserializeResult<Self> {
+ fn from_content(content: Content) -> peanuts::DeserializeResult<Self> {
match content {
Content::Element(element) => Ok(Stanza::from_element(element)?),
Content::Text(_) => Ok(Stanza::OtherContent(content)),
@@ -37,7 +35,7 @@ impl FromContent for Stanza {
}
impl FromElement for Stanza {
- fn from_element(element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
match element.identify() {
(Some(XMLNS), "message") => Ok(Stanza::Message(Message::from_element(element)?)),
(Some(XMLNS), "presence") => Ok(Stanza::Presence(Presence::from_element(element)?)),
@@ -51,7 +49,7 @@ impl FromElement for Stanza {
}
impl IntoContent for Stanza {
- fn builder(&self) -> peanuts::element::ContentBuilder {
+ fn builder(&self) -> peanuts::ContentBuilder {
match self {
Stanza::Message(message) => <Message as IntoContent>::builder(message),
Stanza::Presence(presence) => <Presence as IntoContent>::builder(presence),
diff --git a/stanza/src/client/presence.rs b/stanza/src/client/presence.rs
index a8c35d0..b0a0bc0 100644
--- a/stanza/src/client/presence.rs
+++ b/stanza/src/client/presence.rs
@@ -1,10 +1,7 @@
use std::str::FromStr;
use jid::JID;
-use peanuts::{
- element::{FromElement, IntoElement},
- DeserializeError, Element, XML_NS,
-};
+use peanuts::{DeserializeError, Element, FromElement, IntoElement, XML_NS};
#[cfg(feature = "xep_0115")]
use crate::xep_0115::C;
@@ -41,7 +38,7 @@ pub struct Presence {
}
impl FromElement for Presence {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("presence")?;
element.check_namespace(XMLNS)?;
@@ -91,7 +88,7 @@ impl FromElement for Presence {
}
impl IntoElement for Presence {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder = Element::builder("presence", Some(XMLNS))
.push_attribute_opt("from", self.from.clone())
.push_attribute_opt("id", self.id.clone())
@@ -174,7 +171,7 @@ pub enum Show {
}
impl FromElement for Show {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("show")?;
element.check_namespace(XMLNS)?;
@@ -197,7 +194,7 @@ impl FromStr for Show {
}
impl IntoElement for Show {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("show", Some(XMLNS)).push_text(*self)
}
}
@@ -220,7 +217,7 @@ pub struct Status {
}
impl FromElement for Status {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("status")?;
element.check_namespace(XMLNS)?;
@@ -232,7 +229,7 @@ impl FromElement for Status {
}
impl IntoElement for Status {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("status", Some(XMLNS))
.push_attribute_opt_namespaced(XML_NS, "lang", self.lang.clone())
.push_text(self.status.clone())
@@ -263,7 +260,7 @@ impl ToString for String1024 {
pub struct Priority(pub i8);
impl FromElement for Priority {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("priority")?;
element.check_namespace(XMLNS)?;
@@ -272,7 +269,7 @@ impl FromElement for Priority {
}
impl IntoElement for Priority {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("priority", Some(XMLNS)).push_text(self.0)
}
}