From 9b18e40d8ba5f891e077daa039632f81d5fd2f86 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Thu, 3 Apr 2025 09:45:41 +0100 Subject: feat(stanza): xep-0128: service discovery extensions --- stanza/Cargo.toml | 1 + stanza/src/xep_0030/info.rs | 18 +++++++++++++++++- stanza/src/xep_0300.rs | 10 +++++----- stanza/src/xep_0390.rs | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/stanza/Cargo.toml b/stanza/Cargo.toml index 1863aa5..3ffa59f 100644 --- a/stanza/Cargo.toml +++ b/stanza/Cargo.toml @@ -15,6 +15,7 @@ xep_0004 = [] xep_0030 = [] xep_0059 = [] xep_0060 = ["xep_0004", "dep:chrono"] +xep_0128 = ["xep_0004"] xep_0131 = [] xep_0172 = [] xep_0199 = [] diff --git a/stanza/src/xep_0030/info.rs b/stanza/src/xep_0030/info.rs index 94cbabb..539934f 100644 --- a/stanza/src/xep_0030/info.rs +++ b/stanza/src/xep_0030/info.rs @@ -1,8 +1,10 @@ use peanuts::{ element::{FromElement, IntoElement}, - DeserializeError, Element, + DeserializeError, Element, XML_NS, }; +#[cfg(feature = "xep_0128")] +use crate::xep_0004::X; #[cfg(feature = "xep_0059")] use crate::xep_0059::Set; @@ -13,6 +15,8 @@ pub struct Query { pub node: Option, pub features: Vec, pub identities: Vec, + #[cfg(feature = "xep_0128")] + pub extensions: Vec, #[cfg(feature = "xep_0059")] pub set: Option, } @@ -30,12 +34,17 @@ impl FromElement for Query { #[cfg(feature = "xep_0059")] let set = element.child_opt()?; + #[cfg(feature = "xep_0128")] + let extensions = element.children()?; + Ok(Self { node, features, identities, #[cfg(feature = "xep_0059")] set, + #[cfg(feature = "xep_0128")] + extensions, }) } } @@ -50,6 +59,9 @@ impl IntoElement for Query { #[cfg(feature = "xep_0059")] let builder = builder.push_child_opt(self.set.clone()); + #[cfg(feature = "xep_0128")] + let builder = builder.push_children(self.extensions.clone()); + builder } } @@ -62,6 +74,7 @@ pub struct Identity { pub name: Option, /// non empty string pub r#type: String, + pub lang: Option, } impl FromElement for Identity { @@ -84,10 +97,13 @@ impl FromElement for Identity { return Err(DeserializeError::AttributeEmptyString("type".to_string())); } + let lang = element.attribute_opt_namespaced("lang", XML_NS)?; + Ok(Self { category, name, r#type, + lang, }) } } diff --git a/stanza/src/xep_0300.rs b/stanza/src/xep_0300.rs index 9efad46..71a2c36 100644 --- a/stanza/src/xep_0300.rs +++ b/stanza/src/xep_0300.rs @@ -1,16 +1,16 @@ -use std::str::FromStr; +use std::{convert::Infallible, str::FromStr}; use peanuts::{ element::{FromElement, IntoElement}, - DeserializeError, Element, + Element, }; pub const XMLNS: &str = "urn:xmpp:hashes:2"; #[derive(Debug, Clone)] pub struct Hash { - algo: Algo, - hash: String, + pub algo: Algo, + pub hash: String, } impl FromElement for Hash { @@ -82,7 +82,7 @@ pub enum Algo { } impl FromStr for Algo { - type Err = DeserializeError; + type Err = Infallible; fn from_str(s: &str) -> Result { match s { diff --git a/stanza/src/xep_0390.rs b/stanza/src/xep_0390.rs index a05a659..bcd331d 100644 --- a/stanza/src/xep_0390.rs +++ b/stanza/src/xep_0390.rs @@ -8,7 +8,7 @@ pub const XMLNS: &str = "urn:xmpp:caps"; // TODO: have a vec which guarantees at least one item #[derive(Debug, Clone)] -pub struct C(Vec); +pub struct C(pub Vec); impl FromElement for C { fn from_element(mut element: Element) -> peanuts::element::DeserializeResult { -- cgit