diff options
| author | 2025-04-13 15:02:41 +0100 | |
|---|---|---|
| committer | 2025-04-13 15:02:41 +0100 | |
| commit | 8261d1bfe46b532fd926afb46702a5443552f2a8 (patch) | |
| tree | 8f523e0ef3ff4575ef264c97dd824c95ce3440cf /stanza | |
| parent | 986350b3fb786c1530a3fef199b6d51c536b1188 (diff) | |
| download | luz-8261d1bfe46b532fd926afb46702a5443552f2a8.tar.gz luz-8261d1bfe46b532fd926afb46702a5443552f2a8.tar.bz2 luz-8261d1bfe46b532fd926afb46702a5443552f2a8.zip  | |
feat(stanza): rfc 7395
Diffstat (limited to '')
| -rw-r--r-- | stanza/Cargo.toml | 1 | ||||
| -rw-r--r-- | stanza/src/lib.rs | 2 | ||||
| -rw-r--r-- | stanza/src/rfc_7395.rs | 93 | ||||
| -rw-r--r-- | stanza/src/stream.rs | 2 | 
4 files changed, 97 insertions, 1 deletions
diff --git a/stanza/Cargo.toml b/stanza/Cargo.toml index e4eb302..2832ed6 100644 --- a/stanza/Cargo.toml +++ b/stanza/Cargo.toml @@ -11,6 +11,7 @@ chrono = { version = "0.4.40", optional = true }  [features]  rfc_6121 = [] +rfc_7395 = []  xep_0004 = []  xep_0030 = []  xep_0059 = [] diff --git a/stanza/src/lib.rs b/stanza/src/lib.rs index 569b891..5e30cd0 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; diff --git a/stanza/src/rfc_7395.rs b/stanza/src/rfc_7395.rs new file mode 100644 index 0000000..23b9e5d --- /dev/null +++ b/stanza/src/rfc_7395.rs @@ -0,0 +1,93 @@ +use jid::JID; +use peanuts::{ +    element::{ElementBuilder, FromElement, IntoElement}, +    Element, +}; + +pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-framing"; + +#[derive(Debug)] +pub struct Open { +    pub from: Option<JID>, +    pub to: Option<JID>, +    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<JID>, +    pub to: Option<JID>, +    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/stream.rs b/stanza/src/stream.rs index 732a826..eb07999 100644 --- a/stanza/src/stream.rs +++ b/stanza/src/stream.rs @@ -59,7 +59,7 @@ 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())      }  }  | 
