From f3bdd599425424de8dbff5e4e89b7bcdef205c85 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Thu, 3 Apr 2025 06:15:55 +0100 Subject: feat(stanza): xep-0390: entity capabilities 2.0 --- stanza/Cargo.toml | 1 + stanza/src/lib.rs | 2 ++ stanza/src/xep_0390.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 stanza/src/xep_0390.rs (limited to 'stanza') diff --git a/stanza/Cargo.toml b/stanza/Cargo.toml index c492f1b..1863aa5 100644 --- a/stanza/Cargo.toml +++ b/stanza/Cargo.toml @@ -20,3 +20,4 @@ xep_0172 = [] xep_0199 = [] xep_0203 = ["dep:chrono"] xep_0300 = [] +xep_0390 = ["xep_0300"] diff --git a/stanza/src/lib.rs b/stanza/src/lib.rs index bc8d59a..ced847e 100644 --- a/stanza/src/lib.rs +++ b/stanza/src/lib.rs @@ -27,5 +27,7 @@ pub mod xep_0199; pub mod xep_0203; #[cfg(feature = "xep_0300")] pub mod xep_0300; +#[cfg(feature = "xep_0390")] +pub mod xep_0390; pub static XML_VERSION: VersionInfo = VersionInfo::One; diff --git a/stanza/src/xep_0390.rs b/stanza/src/xep_0390.rs new file mode 100644 index 0000000..a05a659 --- /dev/null +++ b/stanza/src/xep_0390.rs @@ -0,0 +1,26 @@ +use crate::xep_0300::Hash; +use peanuts::{ + element::{FromElement, IntoElement}, + Element, +}; + +pub const XMLNS: &str = "urn:xmpp:caps"; + +// TODO: have a vec which guarantees at least one item +#[derive(Debug, Clone)] +pub struct C(Vec); + +impl FromElement for C { + fn from_element(mut element: Element) -> peanuts::element::DeserializeResult { + element.check_name("c")?; + element.check_namespace(XMLNS)?; + + Ok(Self(element.pop_children()?)) + } +} + +impl IntoElement for C { + fn builder(&self) -> peanuts::element::ElementBuilder { + Element::builder("c", Some(XMLNS)).push_children(self.0.clone()) + } +} -- cgit