aboutsummaryrefslogtreecommitdiffstats
path: root/stanza
diff options
context:
space:
mode:
Diffstat (limited to 'stanza')
-rw-r--r--stanza/Cargo.toml11
-rw-r--r--stanza/src/bind.rs25
-rw-r--r--stanza/src/client/error.rs7
-rw-r--r--stanza/src/client/iq.rs26
-rw-r--r--stanza/src/client/message.rs33
-rw-r--r--stanza/src/client/mod.rs12
-rw-r--r--stanza/src/client/presence.rs21
-rw-r--r--stanza/src/lib.rs6
-rw-r--r--stanza/src/rfc_7395.rs90
-rw-r--r--stanza/src/roster.rs21
-rw-r--r--stanza/src/sasl.rs29
-rw-r--r--stanza/src/stanza_error.rs13
-rw-r--r--stanza/src/starttls.rs19
-rw-r--r--stanza/src/stream.rs26
-rw-r--r--stanza/src/stream_error.rs13
-rw-r--r--stanza/src/xep_0004.rs45
-rw-r--r--stanza/src/xep_0030/info.rs17
-rw-r--r--stanza/src/xep_0030/items.rs13
-rw-r--r--stanza/src/xep_0059.rs37
-rw-r--r--stanza/src/xep_0060/errors.rs9
-rw-r--r--stanza/src/xep_0060/event.rs61
-rw-r--r--stanza/src/xep_0060/owner.rs53
-rw-r--r--stanza/src/xep_0060/pubsub.rs81
-rw-r--r--stanza/src/xep_0084/data.rs9
-rw-r--r--stanza/src/xep_0084/metadata.rs17
-rw-r--r--stanza/src/xep_0115.rs9
-rw-r--r--stanza/src/xep_0131.rs13
-rw-r--r--stanza/src/xep_0156.rs230
-rw-r--r--stanza/src/xep_0172.rs9
-rw-r--r--stanza/src/xep_0199.rs9
-rw-r--r--stanza/src/xep_0203.rs9
-rw-r--r--stanza/src/xep_0297.rs69
-rw-r--r--stanza/src/xep_0300.rs13
-rw-r--r--stanza/src/xep_0390.rs9
34 files changed, 704 insertions, 360 deletions
diff --git a/stanza/Cargo.toml b/stanza/Cargo.toml
index 69fabc2..ec68499 100644
--- a/stanza/Cargo.toml
+++ b/stanza/Cargo.toml
@@ -4,13 +4,14 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-peanuts = { version = "0.1.0", path = "../../peanuts" }
-jid = { version = "0.1.0", path = "../jid" }
-thiserror = "2.0.11"
-chrono = { version = "0.4.40", optional = true }
+peanuts = { workspace = true }
+jid = { workspace = true }
+thiserror = { workspace = true }
+chrono = { workspace = true, optional = true }
[features]
rfc_6121 = []
+rfc_7395 = []
xep_0004 = []
xep_0030 = []
xep_0059 = []
@@ -19,8 +20,10 @@ xep_0084 = []
xep_0115 = []
xep_0128 = ["xep_0004"]
xep_0131 = []
+xep_0156 = ["dep:chrono"]
xep_0172 = []
xep_0199 = []
xep_0203 = ["dep:chrono"]
+xep_0297 = ["xep_0203"]
xep_0300 = []
xep_0390 = ["xep_0300"]
diff --git a/stanza/src/bind.rs b/stanza/src/bind.rs
index f72c510..0f0f681 100644
--- a/stanza/src/bind.rs
+++ b/stanza/src/bind.rs
@@ -1,8 +1,5 @@
-use jid::JID;
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use jid::FullJID;
+use peanuts::{Element, FromElement, IntoElement};
pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-bind";
@@ -12,7 +9,7 @@ pub struct Bind {
}
impl FromElement for Bind {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("bind")?;
element.check_namespace(XMLNS)?;
@@ -23,7 +20,7 @@ impl FromElement for Bind {
}
impl IntoElement for Bind {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("bind", Some(XMLNS)).push_child_opt(self.r#type.clone())
}
}
@@ -35,7 +32,7 @@ pub enum BindType {
}
impl FromElement for BindType {
- fn from_element(element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
match element.identify() {
(Some(XMLNS), "resource") => {
Ok(BindType::Resource(ResourceType::from_element(element)?))
@@ -47,7 +44,7 @@ impl FromElement for BindType {
}
impl IntoElement for BindType {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
match self {
BindType::Resource(resource_type) => resource_type.builder(),
BindType::Jid(full_jid_type) => full_jid_type.builder(),
@@ -57,10 +54,10 @@ impl IntoElement for BindType {
// minLength 8 maxLength 3071
#[derive(Clone, Debug)]
-pub struct FullJidType(pub JID);
+pub struct FullJidType(pub FullJID);
impl FromElement for FullJidType {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("jid")?;
element.check_namespace(XMLNS)?;
@@ -71,7 +68,7 @@ impl FromElement for FullJidType {
}
impl IntoElement for FullJidType {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("jid", Some(XMLNS)).push_text(self.0.clone())
}
}
@@ -81,7 +78,7 @@ impl IntoElement for FullJidType {
pub struct ResourceType(pub String);
impl FromElement for ResourceType {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("resource")?;
element.check_namespace(XMLNS)?;
@@ -92,7 +89,7 @@ impl FromElement for ResourceType {
}
impl IntoElement for ResourceType {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("resource", Some(XMLNS)).push_text(self.0.clone())
}
}
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..478530a 100644
--- a/stanza/src/client/iq.rs
+++ b/stanza/src/client/iq.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};
use crate::{
bind::{self, Bind},
@@ -18,7 +15,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,6 +47,8 @@ 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")]
@@ -55,7 +57,7 @@ pub enum Query {
}
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 +76,17 @@ 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)?,
+ )),
_ => 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 +101,14 @@ 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(),
}
}
}
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 +133,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 78258ca..13ee6f1 100644
--- a/stanza/src/client/message.rs
+++ b/stanza/src/client/message.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_0060")]
use crate::xep_0060::event::Event;
@@ -14,6 +11,8 @@ use crate::xep_0131::Headers;
use crate::xep_0172::Nick;
#[cfg(feature = "xep_0203")]
use crate::xep_0203::Delay;
+#[cfg(feature = "xep_0297")]
+use crate::xep_0297::Forwarded;
use super::XMLNS;
@@ -37,10 +36,12 @@ pub struct Message {
pub nick: Option<Nick>,
#[cfg(feature = "xep_0060")]
pub event: Option<Event>,
+ #[cfg(feature = "xep_0297")]
+ pub forwarded: Option<Forwarded>,
}
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)?;
@@ -66,6 +67,9 @@ impl FromElement for Message {
#[cfg(feature = "xep_0060")]
let event = element.child_opt()?;
+ #[cfg(feature = "xep_0297")]
+ let forwarded = element.child_opt()?;
+
Ok(Message {
from,
id,
@@ -83,12 +87,14 @@ impl FromElement for Message {
nick,
#[cfg(feature = "xep_0060")]
event,
+ #[cfg(feature = "xep_0297")]
+ forwarded,
})
}
}
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())
@@ -117,6 +123,9 @@ impl IntoElement for Message {
#[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());
+
builder
}
}
@@ -166,7 +175,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)?;
@@ -178,7 +187,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())
@@ -192,7 +201,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)?;
@@ -204,7 +213,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())
@@ -218,7 +227,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)?;
@@ -230,7 +239,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)
}
}
diff --git a/stanza/src/lib.rs b/stanza/src/lib.rs
index 569b891..8f9b788 100644
--- a/stanza/src/lib.rs
+++ b/stanza/src/lib.rs
@@ -2,6 +2,8 @@ use peanuts::declaration::VersionInfo;
pub mod bind;
pub mod client;
+#[cfg(feature = "rfc_7395")]
+pub mod rfc_7395;
#[cfg(feature = "rfc_6121")]
pub mod roster;
pub mod sasl;
@@ -23,12 +25,16 @@ pub mod xep_0084;
pub mod xep_0115;
#[cfg(feature = "xep_0131")]
pub mod xep_0131;
+#[cfg(feature = "xep_0156")]
+pub mod xep_0156;
#[cfg(feature = "xep_0172")]
pub mod xep_0172;
#[cfg(feature = "xep_0199")]
pub mod xep_0199;
#[cfg(feature = "xep_0203")]
pub mod xep_0203;
+#[cfg(feature = "xep_0297")]
+pub mod xep_0297;
#[cfg(feature = "xep_0300")]
pub mod xep_0300;
#[cfg(feature = "xep_0390")]
diff --git a/stanza/src/rfc_7395.rs b/stanza/src/rfc_7395.rs
new file mode 100644
index 0000000..73e947d
--- /dev/null
+++ b/stanza/src/rfc_7395.rs
@@ -0,0 +1,90 @@
+use jid::BareJID;
+use peanuts::{Element, ElementBuilder, FromElement, IntoElement};
+
+pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-framing";
+
+#[derive(Debug)]
+pub struct Open {
+ pub from: Option<BareJID>,
+ pub to: Option<BareJID>,
+ pub id: Option<String>,
+ pub version: Option<String>,
+ pub lang: Option<String>,
+}
+
+impl FromElement for Open {
+ fn from_element(mut element: Element) -> std::result::Result<Self, peanuts::DeserializeError> {
+ element.check_name("open")?;
+ element.check_namespace(XMLNS)?;
+
+ let from = element.attribute_opt("from")?;
+ let to = element.attribute_opt("to")?;
+ let id = element.attribute_opt("id")?;
+ let version = element.attribute_opt("version")?;
+ let lang = element.attribute_opt_namespaced("lang", peanuts::XML_NS)?;
+
+ Ok(Open {
+ from,
+ to,
+ id,
+ version,
+ lang,
+ })
+ }
+}
+
+impl IntoElement for Open {
+ fn builder(&self) -> ElementBuilder {
+ Element::builder("open", Some(XMLNS.to_string()))
+ .push_attribute_opt("to", self.to.clone())
+ .push_attribute_opt("from", self.from.clone())
+ .push_attribute_opt("id", self.id.clone())
+ .push_attribute_opt("version", self.version.clone())
+ .push_attribute_opt_namespaced(peanuts::XML_NS, "lang", self.lang.clone())
+ }
+}
+
+#[derive(Debug, Default)]
+pub struct Close {
+ pub from: Option<BareJID>,
+ pub to: Option<BareJID>,
+ pub id: Option<String>,
+ pub version: Option<String>,
+ pub lang: Option<String>,
+ pub see_other_uri: Option<String>,
+}
+
+impl FromElement for Close {
+ fn from_element(mut element: Element) -> std::result::Result<Self, peanuts::DeserializeError> {
+ element.check_name("close")?;
+ element.check_namespace(XMLNS)?;
+
+ let from = element.attribute_opt("from")?;
+ let to = element.attribute_opt("to")?;
+ let id = element.attribute_opt("id")?;
+ let version = element.attribute_opt("version")?;
+ let lang = element.attribute_opt_namespaced("lang", peanuts::XML_NS)?;
+ let see_other_uri = element.attribute_opt("see-other-uri")?;
+
+ Ok(Close {
+ from,
+ to,
+ id,
+ version,
+ lang,
+ see_other_uri,
+ })
+ }
+}
+
+impl IntoElement for Close {
+ fn builder(&self) -> ElementBuilder {
+ Element::builder("close", Some(XMLNS.to_string()))
+ .push_attribute_opt("to", self.to.clone())
+ .push_attribute_opt("from", self.from.clone())
+ .push_attribute_opt("id", self.id.clone())
+ .push_attribute_opt("version", self.version.clone())
+ .push_attribute_opt_namespaced(peanuts::XML_NS, "lang", self.lang.clone())
+ .push_attribute_opt("see-other-uri", self.see_other_uri.clone())
+ }
+}
diff --git a/stanza/src/roster.rs b/stanza/src/roster.rs
index 0181193..dcbf017 100644
--- a/stanza/src/roster.rs
+++ b/stanza/src/roster.rs
@@ -1,10 +1,7 @@
use std::str::FromStr;
-use jid::JID;
-use peanuts::{
- element::{FromElement, IntoElement},
- DeserializeError, Element,
-};
+use jid::BareJID;
+use peanuts::{DeserializeError, Element, FromElement, IntoElement};
pub const XMLNS: &str = "jabber:iq:roster";
@@ -15,7 +12,7 @@ pub struct Query {
}
impl FromElement for Query {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("query")?;
element.check_namespace(XMLNS)?;
@@ -27,7 +24,7 @@ impl FromElement for Query {
}
impl IntoElement for Query {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("query", Some(XMLNS))
.push_attribute_opt("ver", self.ver.clone())
.push_children(self.items.clone())
@@ -41,7 +38,7 @@ pub struct Item {
/// signals subscription sub-states (server only)
pub ask: bool,
/// uniquely identifies item
- pub jid: JID,
+ pub jid: BareJID,
/// handle that is determined by user, not contact
pub name: Option<String>,
/// state of the presence subscription
@@ -50,7 +47,7 @@ pub struct Item {
}
impl FromElement for Item {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("item")?;
element.check_namespace(XMLNS)?;
@@ -83,7 +80,7 @@ impl FromElement for Item {
}
impl IntoElement for Item {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("item", Some(XMLNS))
.push_attribute_opt("approved", self.approved)
.push_attribute_opt(
@@ -143,7 +140,7 @@ impl ToString for Subscription {
pub struct Group(pub Option<String>);
impl FromElement for Group {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("group")?;
element.check_namespace(XMLNS)?;
@@ -154,7 +151,7 @@ impl FromElement for Group {
}
impl IntoElement for Group {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("group", Some(XMLNS)).push_text_opt(self.0.clone())
}
}
diff --git a/stanza/src/sasl.rs b/stanza/src/sasl.rs
index 598a91b..58aab84 100644
--- a/stanza/src/sasl.rs
+++ b/stanza/src/sasl.rs
@@ -1,9 +1,6 @@
use std::{fmt::Display, ops::Deref};
-use peanuts::{
- element::{FromElement, IntoElement},
- DeserializeError, Element,
-};
+use peanuts::{DeserializeError, Element, FromElement, IntoElement};
use thiserror::Error;
pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-sasl";
@@ -14,7 +11,7 @@ pub struct Mechanisms {
}
impl FromElement for Mechanisms {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("mechanisms")?;
element.check_namespace(XMLNS)?;
let mechanisms: Vec<Mechanism> = element.pop_children()?;
@@ -27,7 +24,7 @@ impl FromElement for Mechanisms {
}
impl IntoElement for Mechanisms {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("mechanisms", Some(XMLNS)).push_children(
self.mechanisms
.iter()
@@ -40,7 +37,7 @@ impl IntoElement for Mechanisms {
pub struct Mechanism(String);
impl FromElement for Mechanism {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("mechanism")?;
element.check_namespace(XMLNS)?;
@@ -51,7 +48,7 @@ impl FromElement for Mechanism {
}
impl IntoElement for Mechanism {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("mechanism", Some(XMLNS)).push_text(self.0.clone())
}
}
@@ -71,7 +68,7 @@ pub struct Auth {
}
impl IntoElement for Auth {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("auth", Some(XMLNS))
.push_attribute("mechanism", self.mechanism.clone())
.push_text(self.sasl_data.clone())
@@ -90,7 +87,7 @@ impl Deref for Challenge {
}
impl FromElement for Challenge {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("challenge")?;
element.check_namespace(XMLNS)?;
@@ -112,7 +109,7 @@ impl Deref for Success {
}
impl FromElement for Success {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("success")?;
element.check_namespace(XMLNS)?;
@@ -130,7 +127,7 @@ pub enum ServerResponse {
}
impl FromElement for ServerResponse {
- fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
match element.identify() {
(Some(XMLNS), "challenge") => {
Ok(ServerResponse::Challenge(Challenge::from_element(element)?))
@@ -164,7 +161,7 @@ impl Deref for Response {
}
impl IntoElement for Response {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("response", Some(XMLNS)).push_text(self.0.clone())
}
}
@@ -212,7 +209,7 @@ impl Display for Failure {
}
impl FromElement for Failure {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("failure")?;
element.check_namespace(XMLNS)?;
@@ -250,7 +247,7 @@ pub enum FailureType {
}
impl FromElement for FailureType {
- fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
match element.identify() {
(Some(XMLNS), "aborted") => Ok(FailureType::Aborted),
(Some(XMLNS), "account-disabled") => Ok(FailureType::AccountDisabled),
@@ -276,7 +273,7 @@ pub struct Text {
}
impl FromElement for Text {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("text")?;
element.check_namespace(XMLNS)?;
diff --git a/stanza/src/stanza_error.rs b/stanza/src/stanza_error.rs
index 664a168..8fb862f 100644
--- a/stanza/src/stanza_error.rs
+++ b/stanza/src/stanza_error.rs
@@ -1,9 +1,6 @@
// https://datatracker.ietf.org/doc/html/rfc6120#appendix-A.8
-use peanuts::{
- element::{FromElement, IntoElement},
- Element, XML_NS,
-};
+use peanuts::{Element, FromElement, IntoElement, XML_NS};
use thiserror::Error;
#[cfg(feature = "xep_0060")]
@@ -64,7 +61,7 @@ pub enum 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> {
let error;
match element.identify() {
(Some(XMLNS), "bad-request") => error = Error::BadRequest,
@@ -101,7 +98,7 @@ impl FromElement for Error {
}
impl IntoElement for Error {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
match self {
Error::BadRequest => Element::builder("bad-request", Some(XMLNS)),
Error::Conflict => Element::builder("conflict", Some(XMLNS)),
@@ -142,7 +139,7 @@ pub struct Text {
}
impl FromElement for Text {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("text")?;
element.check_name(XMLNS)?;
@@ -154,7 +151,7 @@ impl FromElement for Text {
}
impl IntoElement for Text {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("text", Some(XMLNS))
.push_attribute_opt_namespaced(XML_NS, "lang", self.lang.clone())
.push_text_opt(self.text.clone())
diff --git a/stanza/src/starttls.rs b/stanza/src/starttls.rs
index b0e0f0f..730c044 100644
--- a/stanza/src/starttls.rs
+++ b/stanza/src/starttls.rs
@@ -1,7 +1,4 @@
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use peanuts::{Element, FromElement, IntoElement};
pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-tls";
@@ -11,7 +8,7 @@ pub struct StartTls {
}
impl IntoElement for StartTls {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let mut builder = Element::builder("starttls", Some(XMLNS));
if self.required {
@@ -42,7 +39,7 @@ impl FromElement for StartTls {
pub struct Required;
impl FromElement for Required {
- fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("required")?;
element.check_namespace(XMLNS)?;
@@ -51,7 +48,7 @@ impl FromElement for Required {
}
impl IntoElement for Required {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("required", Some(XMLNS))
}
}
@@ -60,13 +57,13 @@ impl IntoElement for Required {
pub struct Proceed;
impl IntoElement for Proceed {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("proceed", Some(XMLNS))
}
}
impl FromElement for Proceed {
- fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("proceed")?;
element.check_namespace(XMLNS)?;
@@ -77,13 +74,13 @@ impl FromElement for Proceed {
pub struct Failure;
impl IntoElement for Failure {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("failure", Some(XMLNS))
}
}
impl FromElement for Failure {
- fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("failure")?;
element.check_namespace(XMLNS)?;
diff --git a/stanza/src/stream.rs b/stanza/src/stream.rs
index 732a826..e2f4f9b 100644
--- a/stanza/src/stream.rs
+++ b/stanza/src/stream.rs
@@ -1,8 +1,7 @@
use std::fmt::Display;
-use jid::JID;
-use peanuts::element::{ElementBuilder, FromElement, IntoElement};
-use peanuts::Element;
+use jid::BareJID;
+use peanuts::{Element, ElementBuilder, FromElement, IntoElement};
use thiserror::Error;
use crate::bind;
@@ -19,8 +18,8 @@ pub const XMLNS: &str = "http://etherx.jabber.org/streams";
// #[peanuts(xmlns = XMLNS)]
#[derive(Debug)]
pub struct Stream {
- pub from: Option<JID>,
- to: Option<JID>,
+ pub from: Option<BareJID>,
+ to: Option<BareJID>,
id: Option<String>,
version: Option<String>,
// TODO: lang enum
@@ -59,14 +58,14 @@ impl IntoElement for Stream {
.push_attribute_opt("from", self.from.clone())
.push_attribute_opt("id", self.id.clone())
.push_attribute_opt("version", self.version.clone())
- .push_attribute_opt_namespaced(peanuts::XML_NS, "to", self.lang.clone())
+ .push_attribute_opt_namespaced(peanuts::XML_NS, "lang", self.lang.clone())
}
}
impl<'s> Stream {
pub fn new(
- from: Option<JID>,
- to: Option<JID>,
+ from: Option<BareJID>,
+ to: Option<BareJID>,
id: Option<String>,
version: Option<String>,
lang: Option<String>,
@@ -82,7 +81,12 @@ impl<'s> Stream {
/// For initial stream headers, the initiating entity SHOULD include the 'xml:lang' attribute.
/// For privacy, it is better to not set `from` when sending a client stanza over an unencrypted connection.
- pub fn new_client(from: Option<JID>, to: JID, id: Option<String>, lang: String) -> Self {
+ pub fn new_client(
+ from: Option<BareJID>,
+ to: BareJID,
+ id: Option<String>,
+ lang: String,
+ ) -> Self {
Self {
from,
to: Some(to),
@@ -165,7 +169,7 @@ impl IntoElement for Feature {
}
impl FromElement for Feature {
- fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
match element.identify() {
(Some(starttls::XMLNS), "starttls") => {
Ok(Feature::StartTls(StartTls::from_element(element)?))
@@ -198,7 +202,7 @@ impl Display for Error {
}
impl FromElement for Error {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("error")?;
element.check_namespace(XMLNS)?;
diff --git a/stanza/src/stream_error.rs b/stanza/src/stream_error.rs
index 03d48eb..19ad1ae 100644
--- a/stanza/src/stream_error.rs
+++ b/stanza/src/stream_error.rs
@@ -1,7 +1,4 @@
-use peanuts::{
- element::{FromElement, IntoElement},
- DeserializeError, Element, XML_NS,
-};
+use peanuts::{DeserializeError, Element, FromElement, IntoElement, XML_NS};
use thiserror::Error;
pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-streams";
@@ -61,7 +58,7 @@ pub enum 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> {
let error;
match element.identify() {
(Some(XMLNS), "bad-format") => error = Error::BadFormat,
@@ -99,7 +96,7 @@ impl FromElement for Error {
}
impl IntoElement for Error {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
match self {
Error::BadFormat => Element::builder("bad-format", Some(XMLNS)),
Error::BadNamespacePrefix => Element::builder("bad-namespace-prefix", Some(XMLNS)),
@@ -143,7 +140,7 @@ pub struct Text {
}
impl FromElement for Text {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("text")?;
element.check_name(XMLNS)?;
@@ -155,7 +152,7 @@ impl FromElement for Text {
}
impl IntoElement for Text {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("text", Some(XMLNS))
.push_attribute_opt_namespaced(XML_NS, "lang", self.lang.clone())
.push_text_opt(self.text.clone())
diff --git a/stanza/src/xep_0004.rs b/stanza/src/xep_0004.rs
index f929517..f6ff7a0 100644
--- a/stanza/src/xep_0004.rs
+++ b/stanza/src/xep_0004.rs
@@ -1,9 +1,6 @@
use std::str::FromStr;
-use peanuts::{
- element::{FromElement, IntoElement},
- DeserializeError, Element,
-};
+use peanuts::{DeserializeError, Element, FromElement, IntoElement};
pub const XMLNS: &str = "jabber:x:data";
@@ -18,7 +15,7 @@ pub struct X {
}
impl FromElement for X {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("x")?;
element.check_namespace(XMLNS)?;
@@ -42,7 +39,7 @@ impl FromElement for X {
}
impl IntoElement for X {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("x", Some(XMLNS))
.push_attribute("type", self.r#type.clone())
.push_children(self.instructions.clone())
@@ -91,7 +88,7 @@ impl ToString for XType {
pub struct Instructions(pub String);
impl FromElement for Instructions {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("instructions")?;
element.check_namespace(XMLNS)?;
@@ -100,7 +97,7 @@ impl FromElement for Instructions {
}
impl IntoElement for Instructions {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("instructions", Some(XMLNS)).push_text(self.0.clone())
}
}
@@ -109,7 +106,7 @@ impl IntoElement for Instructions {
pub struct Title(pub String);
impl FromElement for Title {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("instructions")?;
element.check_namespace(XMLNS)?;
@@ -118,7 +115,7 @@ impl FromElement for Title {
}
impl IntoElement for Title {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("title", Some(XMLNS)).push_text(self.0.clone())
}
}
@@ -135,7 +132,7 @@ pub struct Field {
}
impl FromElement for Field {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("field")?;
element.check_namespace(XMLNS)?;
@@ -166,7 +163,7 @@ impl FromElement for Field {
}
impl IntoElement for Field {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let mut builder = Element::builder("field", Some(XMLNS))
.push_attribute_opt("label", self.label.clone())
.push_attribute_opt("type", self.r#type.clone())
@@ -239,7 +236,7 @@ impl ToString for FieldType {
pub struct Desc(pub String);
impl FromElement for Desc {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("desc")?;
element.check_namespace(XMLNS)?;
@@ -248,7 +245,7 @@ impl FromElement for Desc {
}
impl IntoElement for Desc {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("desc", Some(XMLNS)).push_text(self.0.clone())
}
}
@@ -257,7 +254,7 @@ impl IntoElement for Desc {
pub struct Required;
impl FromElement for Required {
- fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("required")?;
element.check_namespace(XMLNS)?;
@@ -266,7 +263,7 @@ impl FromElement for Required {
}
impl IntoElement for Required {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("required", Some(XMLNS))
}
}
@@ -278,7 +275,7 @@ pub struct XOption {
}
impl FromElement for XOption {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("option")?;
element.check_namespace(XMLNS)?;
@@ -291,7 +288,7 @@ impl FromElement for XOption {
}
impl IntoElement for XOption {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("option", Some(XMLNS))
.push_attribute_opt("label", self.label.clone())
.push_child(self.value.clone())
@@ -302,7 +299,7 @@ impl IntoElement for XOption {
pub struct Value(pub String);
impl FromElement for Value {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("value")?;
element.check_namespace(XMLNS)?;
@@ -311,7 +308,7 @@ impl FromElement for Value {
}
impl IntoElement for Value {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("value", Some(XMLNS)).push_text(self.0.clone())
}
}
@@ -323,7 +320,7 @@ pub struct Reported {
}
impl FromElement for Reported {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("reported")?;
element.check_namespace(XMLNS)?;
@@ -334,7 +331,7 @@ impl FromElement for Reported {
}
impl IntoElement for Reported {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("reported", Some(XMLNS)).push_children(self.fields.clone())
}
}
@@ -345,7 +342,7 @@ pub struct Item {
}
impl FromElement for Item {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("item")?;
element.check_namespace(XMLNS)?;
@@ -356,7 +353,7 @@ impl FromElement for Item {
}
impl IntoElement for Item {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("item", Some(XMLNS)).push_children(self.fields.clone())
}
}
diff --git a/stanza/src/xep_0030/info.rs b/stanza/src/xep_0030/info.rs
index 539934f..0344ccb 100644
--- a/stanza/src/xep_0030/info.rs
+++ b/stanza/src/xep_0030/info.rs
@@ -1,7 +1,4 @@
-use peanuts::{
- element::{FromElement, IntoElement},
- DeserializeError, Element, XML_NS,
-};
+use peanuts::{DeserializeError, Element, FromElement, IntoElement, XML_NS};
#[cfg(feature = "xep_0128")]
use crate::xep_0004::X;
@@ -22,7 +19,7 @@ pub struct Query {
}
impl FromElement for Query {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("query")?;
element.check_namespace(XMLNS)?;
@@ -50,7 +47,7 @@ impl FromElement for Query {
}
impl IntoElement for Query {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder = Element::builder("query", Some(XMLNS))
.push_attribute_opt("node", self.node.clone())
.push_children(self.features.clone())
@@ -78,7 +75,7 @@ pub struct Identity {
}
impl FromElement for Identity {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("identity")?;
element.check_namespace(XMLNS)?;
@@ -109,7 +106,7 @@ impl FromElement for Identity {
}
impl IntoElement for Identity {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("identity", Some(XMLNS))
.push_attribute("category", self.category.clone())
.push_attribute_opt("name", self.name.clone())
@@ -124,7 +121,7 @@ pub struct Feature {
}
impl FromElement for Feature {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("feature")?;
element.check_namespace(XMLNS)?;
@@ -135,7 +132,7 @@ impl FromElement for Feature {
}
impl IntoElement for Feature {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("feature", Some(XMLNS)).push_attribute("var", self.var.clone())
}
}
diff --git a/stanza/src/xep_0030/items.rs b/stanza/src/xep_0030/items.rs
index 471f3e1..7707eac 100644
--- a/stanza/src/xep_0030/items.rs
+++ b/stanza/src/xep_0030/items.rs
@@ -1,8 +1,5 @@
use jid::JID;
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use peanuts::{Element, FromElement, IntoElement};
#[cfg(feature = "xep_0059")]
use crate::xep_0059::Set;
@@ -18,7 +15,7 @@ pub struct Query {
}
impl FromElement for Query {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("query")?;
element.check_namespace(XMLNS)?;
@@ -39,7 +36,7 @@ impl FromElement for Query {
}
impl IntoElement for Query {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder = Element::builder("query", Some(XMLNS))
.push_attribute_opt("node", self.node.clone())
.push_children(self.items.clone());
@@ -59,7 +56,7 @@ pub struct Item {
}
impl FromElement for Item {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("item")?;
element.check_namespace(XMLNS)?;
@@ -72,7 +69,7 @@ impl FromElement for Item {
}
impl IntoElement for Item {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("item", Some(XMLNS))
.push_attribute("jid", self.jid.clone())
.push_attribute_opt("name", self.name.clone())
diff --git a/stanza/src/xep_0059.rs b/stanza/src/xep_0059.rs
index 01dbc6c..6490ad1 100644
--- a/stanza/src/xep_0059.rs
+++ b/stanza/src/xep_0059.rs
@@ -1,7 +1,4 @@
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use peanuts::{Element, FromElement, IntoElement};
pub const XMLNS: &str = "http://jabber.org/protocol/rsm";
@@ -17,7 +14,7 @@ pub struct Set {
}
impl FromElement for Set {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("set")?;
element.check_namespace(XMLNS)?;
@@ -42,7 +39,7 @@ impl FromElement for Set {
}
impl IntoElement for Set {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("set", Some(XMLNS))
.push_child_opt(self.after.clone())
.push_child_opt(self.before.clone())
@@ -58,7 +55,7 @@ impl IntoElement for Set {
pub struct After(pub String);
impl FromElement for After {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("after")?;
element.check_namespace(XMLNS)?;
@@ -67,7 +64,7 @@ impl FromElement for After {
}
impl IntoElement for After {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
// TODO: better way for push_text to work, empty string should be empty element no matter what
let builder = Element::builder("after", Some(XMLNS));
@@ -83,7 +80,7 @@ impl IntoElement for After {
pub struct Before(pub String);
impl FromElement for Before {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("before")?;
element.check_namespace(XMLNS)?;
@@ -92,7 +89,7 @@ impl FromElement for Before {
}
impl IntoElement for Before {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
// TODO: better way for push_text to work, empty string should be empty element no matter what
let builder = Element::builder("before", Some(XMLNS));
@@ -108,7 +105,7 @@ impl IntoElement for Before {
pub struct Count(pub i32);
impl FromElement for Count {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("count")?;
element.check_namespace(XMLNS)?;
@@ -117,7 +114,7 @@ impl FromElement for Count {
}
impl IntoElement for Count {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("count", Some(XMLNS)).push_text(self.0)
}
}
@@ -126,7 +123,7 @@ impl IntoElement for Count {
pub struct Index(pub i32);
impl FromElement for Index {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("index")?;
element.check_namespace(XMLNS)?;
@@ -135,7 +132,7 @@ impl FromElement for Index {
}
impl IntoElement for Index {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("index", Some(XMLNS)).push_text(self.0)
}
}
@@ -144,7 +141,7 @@ impl IntoElement for Index {
pub struct Last(pub String);
impl FromElement for Last {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("last")?;
element.check_namespace(XMLNS)?;
@@ -153,7 +150,7 @@ impl FromElement for Last {
}
impl IntoElement for Last {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
// TODO: better way for push_text to work, empty string should be empty element no matter what
let builder = Element::builder("last", Some(XMLNS));
@@ -169,7 +166,7 @@ impl IntoElement for Last {
pub struct Max(pub i32);
impl FromElement for Max {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("max")?;
element.check_namespace(XMLNS)?;
@@ -178,7 +175,7 @@ impl FromElement for Max {
}
impl IntoElement for Max {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("max", Some(XMLNS)).push_text(self.0)
}
}
@@ -190,7 +187,7 @@ pub struct First {
}
impl FromElement for First {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("first")?;
element.check_namespace(XMLNS)?;
@@ -203,7 +200,7 @@ impl FromElement for First {
}
impl IntoElement for First {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder =
Element::builder("first", Some(XMLNS)).push_attribute_opt("index", self.index);
diff --git a/stanza/src/xep_0060/errors.rs b/stanza/src/xep_0060/errors.rs
index e6817ac..6c6c530 100644
--- a/stanza/src/xep_0060/errors.rs
+++ b/stanza/src/xep_0060/errors.rs
@@ -1,9 +1,6 @@
use std::{fmt::Display, str::FromStr};
-use peanuts::{
- element::{FromElement, IntoElement},
- DeserializeError, Element,
-};
+use peanuts::{DeserializeError, Element, FromElement, IntoElement};
use thiserror::Error;
use crate::{client::error::ErrorType, stanza_error::Error as StanzaError};
@@ -121,7 +118,7 @@ impl Error {
}
impl FromElement for Error {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
match element.identify() {
(Some(XMLNS), "closed-node") => Ok(Self::ClosedNode),
(Some(XMLNS), "configuration-required") => Ok(Self::ConfigurationRequired),
@@ -154,7 +151,7 @@ impl FromElement for Error {
}
impl IntoElement for Error {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
match self {
Error::ClosedNode => Element::builder("closed-node", Some(XMLNS)),
Error::ConfigurationRequired => Element::builder("configuration-required", Some(XMLNS)),
diff --git a/stanza/src/xep_0060/event.rs b/stanza/src/xep_0060/event.rs
index 1be011d..3cb124b 100644
--- a/stanza/src/xep_0060/event.rs
+++ b/stanza/src/xep_0060/event.rs
@@ -2,10 +2,7 @@ use std::str::FromStr;
use chrono::{DateTime, Utc};
use jid::JID;
-use peanuts::{
- element::{FromElement, IntoElement},
- DeserializeError, Element,
-};
+use peanuts::{DeserializeError, Element, FromElement, IntoElement};
use crate::xep_0004::X;
#[cfg(feature = "xep_0084")]
@@ -26,7 +23,7 @@ pub enum Event {
}
impl FromElement for Event {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("event")?;
element.check_namespace(XMLNS)?;
@@ -49,7 +46,7 @@ impl FromElement for Event {
}
impl IntoElement for Event {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder = Element::builder("event", Some(XMLNS));
match self {
@@ -70,7 +67,7 @@ pub struct Collection {
}
impl FromElement for Collection {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("node")?;
element.check_namespace(XMLNS)?;
@@ -82,7 +79,7 @@ impl FromElement for Collection {
}
impl IntoElement for Collection {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("collection", Some(XMLNS))
.push_attribute_opt("node", self.node.clone())
.push_child(self.r#type.clone())
@@ -96,7 +93,7 @@ pub enum CollectionType {
}
impl FromElement for CollectionType {
- fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
match element.identify() {
(Some(XMLNS), "associate") => {
Ok(CollectionType::Associate(Associate::from_element(element)?))
@@ -110,7 +107,7 @@ impl FromElement for CollectionType {
}
impl IntoElement for CollectionType {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
match self {
CollectionType::Associate(associate) => associate.builder(),
CollectionType::Disassociate(disassociate) => disassociate.builder(),
@@ -124,7 +121,7 @@ pub struct Associate {
}
impl FromElement for Associate {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("associate")?;
element.check_namespace(XMLNS)?;
@@ -135,7 +132,7 @@ impl FromElement for Associate {
}
impl IntoElement for Associate {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("associate", Some(XMLNS)).push_attribute("node", self.node.clone())
}
}
@@ -146,7 +143,7 @@ pub struct Disassociate {
}
impl FromElement for Disassociate {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("disassociate")?;
element.check_namespace(XMLNS)?;
@@ -157,7 +154,7 @@ impl FromElement for Disassociate {
}
impl IntoElement for Disassociate {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("disassociate", Some(XMLNS)).push_attribute("node", self.node.clone())
}
}
@@ -169,7 +166,7 @@ pub struct Configuration {
}
impl FromElement for Configuration {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("configuration")?;
element.check_namespace(XMLNS)?;
@@ -185,7 +182,7 @@ impl FromElement for Configuration {
}
impl IntoElement for Configuration {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("configuration", Some(XMLNS))
.push_attribute_opt("node", self.node.clone())
.push_child_opt(self.configuration.clone())
@@ -199,7 +196,7 @@ pub struct Delete {
}
impl FromElement for Delete {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("delete")?;
element.check_namespace(XMLNS)?;
@@ -212,7 +209,7 @@ impl FromElement for Delete {
}
impl IntoElement for Delete {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("delete", Some(XMLNS))
.push_attribute("node", self.node.clone())
.push_child_opt(self.redirect.clone())
@@ -226,7 +223,7 @@ pub struct Items {
}
impl FromElement for Items {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("items")?;
element.check_namespace(XMLNS)?;
@@ -243,7 +240,7 @@ impl FromElement for Items {
}
impl IntoElement for Items {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder =
Element::builder("items", Some(XMLNS)).push_attribute("node", self.node.clone());
@@ -268,7 +265,7 @@ pub struct Item {
}
impl FromElement for Item {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("item")?;
element.check_namespace(XMLNS)?;
@@ -286,7 +283,7 @@ impl FromElement for Item {
}
impl IntoElement for Item {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("item", Some(XMLNS))
.push_attribute_opt("id", self.id.clone())
.push_attribute_opt("publisher", self.publisher.clone())
@@ -306,7 +303,7 @@ pub enum Content {
}
impl FromElement for Content {
- fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
match element.identify() {
#[cfg(feature = "xep_0172")]
(Some(xep_0172::XMLNS), "nick") => Ok(Content::Nick(Nick::from_element(element)?)),
@@ -324,7 +321,7 @@ impl FromElement for Content {
}
impl IntoElement for Content {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
match self {
#[cfg(feature = "xep_0172")]
Content::Nick(nick) => nick.builder(),
@@ -343,7 +340,7 @@ pub struct Purge {
}
impl FromElement for Purge {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("purge")?;
element.check_namespace(XMLNS)?;
@@ -354,7 +351,7 @@ impl FromElement for Purge {
}
impl IntoElement for Purge {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("purge", Some(XMLNS)).push_attribute("node", self.node.clone())
}
}
@@ -365,7 +362,7 @@ pub struct Redirect {
}
impl FromElement for Redirect {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("redirect")?;
element.check_namespace(XMLNS)?;
@@ -376,7 +373,7 @@ impl FromElement for Redirect {
}
impl IntoElement for Redirect {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("redirect", Some(XMLNS)).push_attribute("uri", self.uri.clone())
}
}
@@ -387,7 +384,7 @@ pub struct Retract {
}
impl FromElement for Retract {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("retract")?;
element.check_namespace(XMLNS)?;
@@ -398,7 +395,7 @@ impl FromElement for Retract {
}
impl IntoElement for Retract {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("retract", Some(XMLNS)).push_attribute("id", self.id.clone())
}
}
@@ -413,7 +410,7 @@ pub struct Subscription {
}
impl FromElement for Subscription {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("subscription")?;
element.check_namespace(XMLNS)?;
@@ -434,7 +431,7 @@ impl FromElement for Subscription {
}
impl IntoElement for Subscription {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("subscription", Some(XMLNS))
.push_attribute_opt("expiry", self.expiry)
.push_attribute("jid", self.jid.clone())
diff --git a/stanza/src/xep_0060/owner.rs b/stanza/src/xep_0060/owner.rs
index 1fedc60..4876bf5 100644
--- a/stanza/src/xep_0060/owner.rs
+++ b/stanza/src/xep_0060/owner.rs
@@ -1,10 +1,7 @@
use std::str::FromStr;
-use jid::JID;
-use peanuts::{
- element::{FromElement, IntoElement},
- DeserializeError, Element,
-};
+use jid::{BareJID, JID};
+use peanuts::{DeserializeError, Element, FromElement, IntoElement};
use crate::xep_0004::X;
@@ -21,7 +18,7 @@ pub enum Pubsub {
}
impl FromElement for Pubsub {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("pubsub")?;
element.check_namespace(XMLNS)?;
@@ -44,7 +41,7 @@ impl FromElement for Pubsub {
}
impl IntoElement for Pubsub {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder = Element::builder("pubsub", Some(XMLNS));
match self {
@@ -65,7 +62,7 @@ pub struct Affiliations {
}
impl FromElement for Affiliations {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("affiliations")?;
element.check_namespace(XMLNS)?;
@@ -78,7 +75,7 @@ impl FromElement for Affiliations {
}
impl IntoElement for Affiliations {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("affiliations", Some(XMLNS))
.push_attribute("node", self.node.clone())
.push_children(self.affiliations.clone())
@@ -88,11 +85,11 @@ impl IntoElement for Affiliations {
#[derive(Clone, Debug)]
pub struct Affiliation {
affiliation: AffiliationType,
- jid: JID,
+ jid: BareJID,
}
impl FromElement for Affiliation {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("affiliation")?;
element.check_namespace(XMLNS)?;
@@ -104,7 +101,7 @@ impl FromElement for Affiliation {
}
impl IntoElement for Affiliation {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("affiliation", Some(XMLNS))
.push_attribute("affiliation", self.affiliation.clone())
.push_attribute("jid", self.jid.clone())
@@ -158,7 +155,7 @@ pub struct Configure {
}
impl FromElement for Configure {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("configure")?;
element.check_namespace(XMLNS)?;
@@ -171,7 +168,7 @@ impl FromElement for Configure {
}
impl IntoElement for Configure {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("configure", Some(XMLNS))
.push_attribute_opt("node", self.node.clone())
.push_child_opt(self.configure.clone())
@@ -182,7 +179,7 @@ impl IntoElement for Configure {
pub struct Default(Option<X>);
impl FromElement for Default {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("default")?;
element.check_namespace(XMLNS)?;
@@ -191,19 +188,19 @@ impl FromElement for Default {
}
impl IntoElement for Default {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("default", Some(XMLNS)).push_child_opt(self.0.clone())
}
}
#[derive(Clone, Debug)]
pub struct Delete {
- node: String,
- redirect: Option<Redirect>,
+ pub node: String,
+ pub redirect: Option<Redirect>,
}
impl FromElement for Delete {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("delete")?;
element.check_namespace(XMLNS)?;
@@ -216,7 +213,7 @@ impl FromElement for Delete {
}
impl IntoElement for Delete {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("delete", Some(XMLNS))
.push_attribute("node", self.node.clone())
.push_child_opt(self.redirect.clone())
@@ -229,7 +226,7 @@ pub struct Purge {
}
impl FromElement for Purge {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("purge")?;
element.check_namespace(XMLNS)?;
@@ -240,7 +237,7 @@ impl FromElement for Purge {
}
impl IntoElement for Purge {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("purge", Some(XMLNS)).push_attribute("node", self.node.clone())
}
}
@@ -251,7 +248,7 @@ pub struct Redirect {
}
impl FromElement for Redirect {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("redirect")?;
element.check_namespace(XMLNS)?;
@@ -262,7 +259,7 @@ impl FromElement for Redirect {
}
impl IntoElement for Redirect {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("redirect", Some(XMLNS)).push_attribute("uri", self.uri.clone())
}
}
@@ -274,7 +271,7 @@ pub struct Subscriptions {
}
impl FromElement for Subscriptions {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("subscriptions")?;
element.check_namespace(XMLNS)?;
@@ -290,7 +287,7 @@ impl FromElement for Subscriptions {
}
impl IntoElement for Subscriptions {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("subscriptions", Some(XMLNS))
.push_attribute("node", self.node.clone())
.push_children(self.subscriptions.clone())
@@ -304,7 +301,7 @@ pub struct Subscription {
}
impl FromElement for Subscription {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("subscription")?;
element.check_namespace(XMLNS)?;
@@ -316,7 +313,7 @@ impl FromElement for Subscription {
}
impl IntoElement for Subscription {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("subscription", Some(XMLNS))
.push_attribute("subscription", self.subscription.clone())
.push_attribute("jid", self.jid.clone())
diff --git a/stanza/src/xep_0060/pubsub.rs b/stanza/src/xep_0060/pubsub.rs
index 0f698dc..0416b78 100644
--- a/stanza/src/xep_0060/pubsub.rs
+++ b/stanza/src/xep_0060/pubsub.rs
@@ -1,10 +1,7 @@
use std::str::FromStr;
use jid::JID;
-use peanuts::{
- element::{FromElement, IntoElement},
- DeserializeError, Element,
-};
+use peanuts::{DeserializeError, Element, FromElement, IntoElement};
use crate::xep_0004::X;
#[cfg(feature = "xep_0084")]
@@ -30,7 +27,7 @@ pub enum Pubsub {
}
impl FromElement for Pubsub {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("pubsub")?;
element.check_namespace(XMLNS)?;
@@ -81,7 +78,7 @@ impl FromElement for Pubsub {
}
impl IntoElement for Pubsub {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let element = Element::builder("pubsub", Some(XMLNS));
match self {
@@ -113,7 +110,7 @@ pub struct Affiliations {
}
impl FromElement for Affiliations {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("affiliations")?;
element.check_namespace(XMLNS)?;
@@ -126,7 +123,7 @@ impl FromElement for Affiliations {
}
impl IntoElement for Affiliations {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("affilations", Some(XMLNS))
.push_attribute_opt("node", self.node.clone())
.push_children(self.affiliations.clone())
@@ -141,7 +138,7 @@ pub struct Affiliation {
}
impl FromElement for Affiliation {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("affiliation")?;
element.check_namespace(XMLNS)?;
@@ -153,7 +150,7 @@ impl FromElement for Affiliation {
}
impl IntoElement for Affiliation {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("affiliation", Some(XMLNS))
.push_attribute("affiliation", self.affiliation.clone())
.push_attribute("node", self.node.clone())
@@ -204,7 +201,7 @@ impl ToString for AffiliationType {
pub struct Configure(Option<X>);
impl FromElement for Configure {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("configure")?;
element.check_namespace(XMLNS)?;
@@ -213,7 +210,7 @@ impl FromElement for Configure {
}
impl IntoElement for Configure {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("configure", Some(XMLNS)).push_child_opt(self.0.clone())
}
}
@@ -224,7 +221,7 @@ pub struct Create {
}
impl FromElement for Create {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("create")?;
element.check_namespace(XMLNS)?;
@@ -235,7 +232,7 @@ impl FromElement for Create {
}
impl IntoElement for Create {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("create", Some(XMLNS)).push_attribute_opt("node", self.node.clone())
}
}
@@ -249,7 +246,7 @@ pub struct Default {
}
impl FromElement for Default {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("default")?;
element.check_namespace(XMLNS)?;
@@ -267,7 +264,7 @@ impl FromElement for Default {
}
impl IntoElement for Default {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("default", Some(XMLNS))
.push_attribute_opt("node", self.node.clone())
.push_attribute_opt("type", self.r#type.clone())
@@ -312,7 +309,7 @@ pub struct Items {
}
impl FromElement for Items {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("items")?;
element.check_namespace(XMLNS)?;
@@ -332,7 +329,7 @@ impl FromElement for Items {
}
impl IntoElement for Items {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("items", Some(XMLNS))
.push_attribute_opt("max_items", self.max_items)
.push_attribute("node", self.node.clone())
@@ -349,7 +346,7 @@ pub struct Item {
}
impl FromElement for Item {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("item")?;
element.check_namespace(XMLNS)?;
@@ -367,7 +364,7 @@ impl FromElement for Item {
}
impl IntoElement for Item {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("item", Some(XMLNS))
.push_attribute_opt("id", self.id.clone())
.push_attribute_opt("publisher", self.publisher.clone())
@@ -387,7 +384,7 @@ pub enum Content {
}
impl FromElement for Content {
- fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
match element.identify() {
#[cfg(feature = "xep_0172")]
(Some(xep_0172::XMLNS), "nick") => Ok(Content::Nick(Nick::from_element(element)?)),
@@ -405,7 +402,7 @@ impl FromElement for Content {
}
impl IntoElement for Content {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
match self {
#[cfg(feature = "xep_0172")]
Content::Nick(nick) => nick.builder(),
@@ -427,7 +424,7 @@ pub struct Options {
}
impl FromElement for Options {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("options")?;
element.check_namespace(XMLNS)?;
@@ -447,7 +444,7 @@ impl FromElement for Options {
}
impl IntoElement for Options {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("options", Some(XMLNS))
.push_attribute("jid", self.jid.clone())
.push_attribute_opt("node", self.node.clone())
@@ -463,7 +460,7 @@ pub struct Publish {
}
impl FromElement for Publish {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("publish")?;
element.check_namespace(XMLNS)?;
@@ -476,7 +473,7 @@ impl FromElement for Publish {
}
impl IntoElement for Publish {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("publish", Some(XMLNS))
.push_attribute("node", self.node.clone())
.push_children(self.items.clone())
@@ -487,7 +484,7 @@ impl IntoElement for Publish {
pub struct PublishOptions(pub Option<X>);
impl FromElement for PublishOptions {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("publish-options")?;
element.check_namespace(XMLNS)?;
@@ -496,7 +493,7 @@ impl FromElement for PublishOptions {
}
impl IntoElement for PublishOptions {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("publish-options", Some(XMLNS)).push_child_opt(self.0.clone())
}
}
@@ -510,7 +507,7 @@ pub struct Retract {
}
impl FromElement for Retract {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("retract")?;
element.check_namespace(XMLNS)?;
@@ -528,7 +525,7 @@ impl FromElement for Retract {
}
impl IntoElement for Retract {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("retract", Some(XMLNS))
.push_attribute("node", self.node.clone())
.push_attribute_opt("notify", self.notify)
@@ -543,7 +540,7 @@ pub struct SubscribeOptions {
}
impl FromElement for SubscribeOptions {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("subscribe-options")?;
element.check_namespace(XMLNS)?;
@@ -559,7 +556,7 @@ impl FromElement for SubscribeOptions {
}
impl IntoElement for SubscribeOptions {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder = Element::builder("subscribe-options", Some(XMLNS));
if self.required {
@@ -573,7 +570,7 @@ impl IntoElement for SubscribeOptions {
pub struct Required;
impl FromElement for Required {
- fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("required")?;
element.check_namespace(XMLNS)?;
@@ -582,7 +579,7 @@ impl FromElement for Required {
}
impl IntoElement for Required {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("required", Some(XMLNS))
}
}
@@ -594,7 +591,7 @@ pub struct Subscribe {
}
impl FromElement for Subscribe {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("subscribe")?;
element.check_namespace(XMLNS)?;
@@ -606,7 +603,7 @@ impl FromElement for Subscribe {
}
impl IntoElement for Subscribe {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("subscribe", Some(XMLNS))
.push_attribute("jid", self.jid.clone())
.push_attribute_opt("node", self.node.clone())
@@ -620,7 +617,7 @@ pub struct Subscriptions {
}
impl FromElement for Subscriptions {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("subscriptions")?;
element.check_namespace(XMLNS)?;
@@ -636,7 +633,7 @@ impl FromElement for Subscriptions {
}
impl IntoElement for Subscriptions {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("subscriptions", Some(XMLNS))
.push_attribute_opt("node", self.node.clone())
.push_children(self.subscriptions.clone())
@@ -653,7 +650,7 @@ pub struct Subscription {
}
impl FromElement for Subscription {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("subscription")?;
element.check_namespace(XMLNS)?;
@@ -675,7 +672,7 @@ impl FromElement for Subscription {
}
impl IntoElement for Subscription {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("subscription", Some(XMLNS))
.push_attribute("jid", self.jid.clone())
.push_attribute_opt("node", self.node.clone())
@@ -727,7 +724,7 @@ pub struct Unsubscribe {
}
impl FromElement for Unsubscribe {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("unsubscribe")?;
element.check_namespace(XMLNS)?;
@@ -740,7 +737,7 @@ impl FromElement for Unsubscribe {
}
impl IntoElement for Unsubscribe {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("unsubscribe", Some(XMLNS))
.push_attribute("jid", self.jid.clone())
.push_attribute_opt("node", self.node.clone())
diff --git a/stanza/src/xep_0084/data.rs b/stanza/src/xep_0084/data.rs
index 2a37df4..4b3223f 100644
--- a/stanza/src/xep_0084/data.rs
+++ b/stanza/src/xep_0084/data.rs
@@ -1,7 +1,4 @@
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use peanuts::{Element, FromElement, IntoElement};
pub const XMLNS: &str = "urn:xmpp:avatar:data";
@@ -9,7 +6,7 @@ pub const XMLNS: &str = "urn:xmpp:avatar:data";
pub struct Data(pub String);
impl FromElement for Data {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("data")?;
element.check_namespace(XMLNS)?;
@@ -18,7 +15,7 @@ impl FromElement for Data {
}
impl IntoElement for Data {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder = Element::builder("data", Some(XMLNS));
if self.0.is_empty() {
diff --git a/stanza/src/xep_0084/metadata.rs b/stanza/src/xep_0084/metadata.rs
index c6a3fb4..e4edb2f 100644
--- a/stanza/src/xep_0084/metadata.rs
+++ b/stanza/src/xep_0084/metadata.rs
@@ -1,7 +1,4 @@
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use peanuts::{Element, FromElement, IntoElement};
pub const XMLNS: &str = "urn:xmpp:avatar:metadata";
@@ -12,7 +9,7 @@ pub struct Metadata {
}
impl FromElement for Metadata {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("metadata")?;
element.check_namespace(XMLNS)?;
@@ -24,7 +21,7 @@ impl FromElement for Metadata {
}
impl IntoElement for Metadata {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("metadata", Some(XMLNS))
.push_children(self.info.clone())
.push_children(self.pointers.clone())
@@ -42,7 +39,7 @@ pub struct Info {
}
impl FromElement for Info {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("info")?;
element.check_namespace(XMLNS)?;
@@ -65,7 +62,7 @@ impl FromElement for Info {
}
impl IntoElement for Info {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("info", Some(XMLNS))
.push_attribute("bytes", self.bytes)
.push_attribute_opt("height", self.height)
@@ -80,7 +77,7 @@ impl IntoElement for Info {
pub struct Pointer(pub PointerInner);
impl FromElement for Pointer {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("pointer")?;
element.check_namespace(XMLNS)?;
@@ -89,7 +86,7 @@ impl FromElement for Pointer {
}
impl IntoElement for Pointer {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let _builder = Element::builder("pointer", Some(XMLNS));
match &self.0 {
diff --git a/stanza/src/xep_0115.rs b/stanza/src/xep_0115.rs
index 1c2ef69..1c9cd6f 100644
--- a/stanza/src/xep_0115.rs
+++ b/stanza/src/xep_0115.rs
@@ -1,7 +1,4 @@
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use peanuts::{Element, FromElement, IntoElement};
pub const XMLNS: &str = "http://jabber.org/protocol/caps";
@@ -14,7 +11,7 @@ pub struct C {
}
impl FromElement for C {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("c")?;
element.check_namespace(XMLNS)?;
@@ -33,7 +30,7 @@ impl FromElement for C {
}
impl IntoElement for C {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("c", Some(XMLNS))
.push_attribute_opt("ext", self.ext.clone())
.push_attribute("hash", self.hash.clone())
diff --git a/stanza/src/xep_0131.rs b/stanza/src/xep_0131.rs
index 27fc962..68e6e96 100644
--- a/stanza/src/xep_0131.rs
+++ b/stanza/src/xep_0131.rs
@@ -1,7 +1,4 @@
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use peanuts::{Element, FromElement, IntoElement};
pub const XMLNS: &str = "http://jabber.org/protocol/disco#info";
@@ -9,7 +6,7 @@ pub const XMLNS: &str = "http://jabber.org/protocol/disco#info";
pub struct Headers(pub Vec<Header>);
impl FromElement for Headers {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("headers")?;
element.check_namespace(XMLNS)?;
@@ -18,7 +15,7 @@ impl FromElement for Headers {
}
impl IntoElement for Headers {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("headers", Some(XMLNS)).push_children(self.0.clone())
}
}
@@ -30,7 +27,7 @@ pub struct Header {
}
impl FromElement for Header {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("header")?;
element.check_namespace(XMLNS)?;
@@ -43,7 +40,7 @@ impl FromElement for Header {
}
impl IntoElement for Header {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder =
Element::builder("header", Some(XMLNS)).push_attribute("name", self.name.clone());
diff --git a/stanza/src/xep_0156.rs b/stanza/src/xep_0156.rs
new file mode 100644
index 0000000..bf6eac5
--- /dev/null
+++ b/stanza/src/xep_0156.rs
@@ -0,0 +1,230 @@
+use chrono::{DateTime, Utc};
+use peanuts::{Element, FromElement, IntoElement, XML_NS};
+
+pub const XMLNS: &str = "http://docs.oasis-open.org/ns/xri/xrd-1.0";
+pub const SIGNATURE_XMLNS: &str = "http://www.w3.org/2000/09/xmldsig#";
+
+#[derive(Debug, Clone)]
+pub struct XRD {
+ pub id: Option<String>,
+ pub expires: Option<Expires>,
+ pub subject: Option<Subject>,
+ pub aliases: Vec<Alias>,
+ pub properties: Vec<Property>,
+ pub links: Vec<Link>,
+ pub signature: Vec<Signature>,
+}
+
+impl FromElement for XRD {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
+ element.check_name("XRD")?;
+ element.check_namespace(XMLNS)?;
+
+ let id = element.attribute_opt_namespaced("id", XML_NS)?;
+
+ let expires = element.child_opt()?;
+ let subject = element.child_opt()?;
+ let aliases = element.children()?;
+ let properties = element.children()?;
+ let links = element.children()?;
+ let signature = element.children()?;
+
+ Ok(Self {
+ id,
+ expires,
+ subject,
+ aliases,
+ properties,
+ links,
+ signature,
+ })
+ }
+}
+
+impl IntoElement for XRD {
+ fn builder(&self) -> peanuts::ElementBuilder {
+ Element::builder("XRD", Some(XMLNS))
+ .push_attribute_opt_namespaced(XML_NS, "id", self.id.clone())
+ .push_child_opt(self.expires.clone())
+ .push_child_opt(self.subject.clone())
+ .push_children(self.aliases.clone())
+ .push_children(self.properties.clone())
+ .push_children(self.links.clone())
+ .push_children(self.signature.clone())
+ }
+}
+
+#[derive(Debug, Clone)]
+pub struct Expires(pub DateTime<Utc>);
+
+impl FromElement for Expires {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
+ element.check_name("Expires")?;
+ element.check_namespace(XMLNS)?;
+
+ Ok(Self(element.pop_value()?))
+ }
+}
+
+impl IntoElement for Expires {
+ fn builder(&self) -> peanuts::ElementBuilder {
+ Element::builder("Expires", Some(XMLNS))
+ .push_text(self.0.format("%C%y-%m-%dT%H:%M:%S%.3f%:z"))
+ }
+}
+
+// anyURI
+#[derive(Debug, Clone)]
+pub struct Subject(pub String);
+
+impl FromElement for Subject {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
+ element.check_name("Subject")?;
+ element.check_namespace(XMLNS)?;
+
+ Ok(Self(element.pop_value()?))
+ }
+}
+
+impl IntoElement for Subject {
+ fn builder(&self) -> peanuts::ElementBuilder {
+ Element::builder("Subject", Some(XMLNS)).push_text(self.0.clone())
+ }
+}
+
+// anyURI
+#[derive(Debug, Clone)]
+pub struct Alias(pub String);
+
+impl FromElement for Alias {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
+ element.check_name("Alias")?;
+ element.check_namespace(XMLNS)?;
+
+ Ok(Self(element.pop_value()?))
+ }
+}
+
+impl IntoElement for Alias {
+ fn builder(&self) -> peanuts::ElementBuilder {
+ Element::builder("Alias", Some(XMLNS)).push_text(self.0.clone())
+ }
+}
+
+#[derive(Debug, Clone)]
+pub struct Property {
+ pub r#type: String,
+ pub property: Option<String>,
+}
+
+impl FromElement for Property {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
+ element.check_name("Property")?;
+ element.check_name(XMLNS)?;
+
+ let r#type = element.attribute("type")?;
+
+ let property = element.pop_value_opt()?;
+
+ Ok(Self { r#type, property })
+ }
+}
+
+impl IntoElement for Property {
+ fn builder(&self) -> peanuts::ElementBuilder {
+ Element::builder("Property", Some(XMLNS))
+ .push_attribute("type", self.r#type.clone())
+ .push_text_opt(self.property.clone())
+ }
+}
+
+#[derive(Debug, Clone)]
+pub struct Link {
+ pub rel: Option<String>,
+ pub r#type: Option<String>,
+ pub href: Option<String>,
+ pub template: Option<String>,
+ pub titles: Vec<Title>,
+ pub properties: Vec<Property>,
+}
+
+impl FromElement for Link {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
+ element.check_name("Link")?;
+ element.check_namespace(XMLNS)?;
+
+ let rel = element.attribute_opt("rel")?;
+ let r#type = element.attribute_opt("type")?;
+ let href = element.attribute_opt("href")?;
+ let template = element.attribute_opt("template")?;
+
+ let titles = element.children()?;
+ let properties = element.children()?;
+
+ Ok(Self {
+ rel,
+ r#type,
+ href,
+ template,
+ titles,
+ properties,
+ })
+ }
+}
+
+impl IntoElement for Link {
+ fn builder(&self) -> peanuts::ElementBuilder {
+ Element::builder("Link", Some(XMLNS))
+ .push_attribute_opt("rel", self.rel.clone())
+ .push_attribute_opt("type", self.r#type.clone())
+ .push_attribute_opt("href", self.href.clone())
+ .push_attribute_opt("template", self.template.clone())
+ .push_children(self.titles.clone())
+ .push_children(self.properties.clone())
+ }
+}
+
+#[derive(Debug, Clone)]
+pub struct Title {
+ pub lang: Option<String>,
+ pub title: String,
+}
+
+impl FromElement for Title {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
+ element.check_name("Title")?;
+ element.check_namespace(XMLNS)?;
+
+ let lang = element.attribute_opt_namespaced("lang", XML_NS)?;
+
+ let title = element.pop_value_opt()?.unwrap_or_default();
+
+ Ok(Self { lang, title })
+ }
+}
+
+impl IntoElement for Title {
+ fn builder(&self) -> peanuts::ElementBuilder {
+ Element::builder("Title", Some(XMLNS))
+ .push_attribute_opt_namespaced(XML_NS, "lang", self.lang.clone())
+ .push_text(self.title.clone())
+ }
+}
+
+#[derive(Debug, Clone, Copy)]
+pub struct Signature;
+
+impl FromElement for Signature {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
+ element.check_name("Signature")?;
+ element.check_namespace(SIGNATURE_XMLNS)?;
+
+ Ok(Self)
+ }
+}
+
+impl IntoElement for Signature {
+ fn builder(&self) -> peanuts::ElementBuilder {
+ Element::builder("Signature", Some(SIGNATURE_XMLNS))
+ }
+}
diff --git a/stanza/src/xep_0172.rs b/stanza/src/xep_0172.rs
index 1c24200..54846b8 100644
--- a/stanza/src/xep_0172.rs
+++ b/stanza/src/xep_0172.rs
@@ -1,7 +1,4 @@
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use peanuts::{Element, FromElement, IntoElement};
pub const XMLNS: &str = "http://jabber.org/protocol/nick";
@@ -9,7 +6,7 @@ pub const XMLNS: &str = "http://jabber.org/protocol/nick";
pub struct Nick(pub String);
impl FromElement for Nick {
- fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("nick")?;
element.check_namespace(XMLNS)?;
@@ -18,7 +15,7 @@ impl FromElement for Nick {
}
impl IntoElement for Nick {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder = Element::builder("nick", Some(XMLNS));
if self.0.is_empty() {
diff --git a/stanza/src/xep_0199.rs b/stanza/src/xep_0199.rs
index 9605721..2ab3a86 100644
--- a/stanza/src/xep_0199.rs
+++ b/stanza/src/xep_0199.rs
@@ -1,7 +1,4 @@
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use peanuts::{Element, FromElement, IntoElement};
pub const XMLNS: &str = "urn:xmpp:ping";
@@ -9,7 +6,7 @@ pub const XMLNS: &str = "urn:xmpp:ping";
pub struct Ping;
impl FromElement for Ping {
- fn from_element(element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(element: peanuts::Element) -> peanuts::DeserializeResult<Self> {
element.check_name("ping")?;
element.check_namespace(XMLNS)?;
@@ -20,7 +17,7 @@ impl FromElement for Ping {
}
impl IntoElement for Ping {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("ping", Some(XMLNS))
}
}
diff --git a/stanza/src/xep_0203.rs b/stanza/src/xep_0203.rs
index b8f9239..41ff196 100644
--- a/stanza/src/xep_0203.rs
+++ b/stanza/src/xep_0203.rs
@@ -1,9 +1,6 @@
use chrono::{DateTime, Utc};
use jid::JID;
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use peanuts::{Element, FromElement, IntoElement};
pub const XMLNS: &str = "urn:xmpp:delay";
@@ -14,7 +11,7 @@ pub struct Delay {
}
impl FromElement for Delay {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("delay")?;
element.check_namespace(XMLNS)?;
@@ -26,7 +23,7 @@ impl FromElement for Delay {
}
impl IntoElement for Delay {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("delay", Some(XMLNS))
.push_attribute_opt("from", self.from.clone())
.push_attribute("stamp", self.stamp.format("%C%y-%m-%dT%H:%M:%S%.3f%:z"))
diff --git a/stanza/src/xep_0297.rs b/stanza/src/xep_0297.rs
new file mode 100644
index 0000000..4dc8a26
--- /dev/null
+++ b/stanza/src/xep_0297.rs
@@ -0,0 +1,69 @@
+use peanuts::{Element, FromElement, IntoElement};
+
+use crate::{
+ client::{self, iq::Iq, message::Message, presence::Presence},
+ xep_0203::Delay,
+};
+
+pub const XMLNS: &str = "urn:xmpp:forward:0";
+
+#[derive(Clone, Debug)]
+pub struct Forwarded {
+ delay: Option<Delay>,
+ stanza: Option<Box<Stanza>>,
+}
+
+impl FromElement for Forwarded {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
+ element.check_name("forwarded")?;
+ element.check_namespace(XMLNS)?;
+
+ let delay = element.pop_child_opt()?;
+ let stanza = element.pop_child_opt()?;
+ let stanza = stanza.map(|stanza| Box::new(stanza));
+
+ Ok(Self { delay, stanza })
+ }
+}
+
+impl IntoElement for Forwarded {
+ fn builder(&self) -> peanuts::ElementBuilder {
+ Element::builder("forwarded", Some(XMLNS))
+ .push_child_opt(self.delay.clone())
+ .push_child_opt(self.stanza.clone().map(|stanza| *stanza))
+ }
+}
+
+#[derive(Clone, Debug)]
+pub enum Stanza {
+ Message(Message),
+ Presence(Presence),
+ Iq(Iq),
+ // TODO: raw elements are received with reads.
+ // Raw(Element),
+}
+
+impl FromElement for Stanza {
+ fn from_element(element: Element) -> peanuts::DeserializeResult<Self> {
+ match element.identify() {
+ (Some(client::XMLNS), "message") => {
+ Ok(Stanza::Message(Message::from_element(element)?))
+ }
+ (Some(client::XMLNS), "presence") => {
+ Ok(Stanza::Presence(Presence::from_element(element)?))
+ }
+ (Some(client::XMLNS), "iq") => Ok(Stanza::Iq(Iq::from_element(element)?)),
+ _ => Err(peanuts::DeserializeError::UnexpectedElement(element)),
+ }
+ }
+}
+
+impl IntoElement for Stanza {
+ fn builder(&self) -> peanuts::ElementBuilder {
+ match self {
+ Stanza::Message(message) => message.builder(),
+ Stanza::Presence(presence) => presence.builder(),
+ Stanza::Iq(iq) => iq.builder(),
+ }
+ }
+}
diff --git a/stanza/src/xep_0300.rs b/stanza/src/xep_0300.rs
index 71a2c36..f522f1c 100644
--- a/stanza/src/xep_0300.rs
+++ b/stanza/src/xep_0300.rs
@@ -1,9 +1,6 @@
use std::{convert::Infallible, str::FromStr};
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use peanuts::{Element, FromElement, IntoElement};
pub const XMLNS: &str = "urn:xmpp:hashes:2";
@@ -14,7 +11,7 @@ pub struct Hash {
}
impl FromElement for Hash {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("hash")?;
element.check_namespace(XMLNS)?;
@@ -27,7 +24,7 @@ impl FromElement for Hash {
}
impl IntoElement for Hash {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
let builder =
Element::builder("hash", Some(XMLNS)).push_attribute("algo", self.algo.clone());
@@ -46,7 +43,7 @@ pub struct HashUsed {
}
impl FromElement for HashUsed {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("hash-used")?;
element.check_namespace(XMLNS)?;
@@ -57,7 +54,7 @@ impl FromElement for HashUsed {
}
impl IntoElement for HashUsed {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("hash-used", Some(XMLNS)).push_attribute("algo", self.algo.clone())
}
}
diff --git a/stanza/src/xep_0390.rs b/stanza/src/xep_0390.rs
index bcd331d..1a079c2 100644
--- a/stanza/src/xep_0390.rs
+++ b/stanza/src/xep_0390.rs
@@ -1,8 +1,5 @@
use crate::xep_0300::Hash;
-use peanuts::{
- element::{FromElement, IntoElement},
- Element,
-};
+use peanuts::{Element, FromElement, IntoElement};
pub const XMLNS: &str = "urn:xmpp:caps";
@@ -11,7 +8,7 @@ pub const XMLNS: &str = "urn:xmpp:caps";
pub struct C(pub Vec<Hash>);
impl FromElement for C {
- fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
element.check_name("c")?;
element.check_namespace(XMLNS)?;
@@ -20,7 +17,7 @@ impl FromElement for C {
}
impl IntoElement for C {
- fn builder(&self) -> peanuts::element::ElementBuilder {
+ fn builder(&self) -> peanuts::ElementBuilder {
Element::builder("c", Some(XMLNS)).push_children(self.0.clone())
}
}