aboutsummaryrefslogtreecommitdiffstats
path: root/stanza/src/rfc_7395.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-04-13 15:02:41 +0100
committerLibravatar cel 🌸 <cel@bunny.garden>2025-04-13 15:02:41 +0100
commit8261d1bfe46b532fd926afb46702a5443552f2a8 (patch)
tree8f523e0ef3ff4575ef264c97dd824c95ce3440cf /stanza/src/rfc_7395.rs
parent986350b3fb786c1530a3fef199b6d51c536b1188 (diff)
downloadluz-8261d1bfe46b532fd926afb46702a5443552f2a8.tar.gz
luz-8261d1bfe46b532fd926afb46702a5443552f2a8.tar.bz2
luz-8261d1bfe46b532fd926afb46702a5443552f2a8.zip
feat(stanza): rfc 7395
Diffstat (limited to 'stanza/src/rfc_7395.rs')
-rw-r--r--stanza/src/rfc_7395.rs93
1 files changed, 93 insertions, 0 deletions
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())
+ }
+}