aboutsummaryrefslogtreecommitdiffstats
path: root/stanza/src/xep_0131.rs
diff options
context:
space:
mode:
Diffstat (limited to 'stanza/src/xep_0131.rs')
-rw-r--r--stanza/src/xep_0131.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/stanza/src/xep_0131.rs b/stanza/src/xep_0131.rs
new file mode 100644
index 0000000..27fc962
--- /dev/null
+++ b/stanza/src/xep_0131.rs
@@ -0,0 +1,56 @@
+use peanuts::{
+ element::{FromElement, IntoElement},
+ Element,
+};
+
+pub const XMLNS: &str = "http://jabber.org/protocol/disco#info";
+
+#[derive(Clone, Debug)]
+pub struct Headers(pub Vec<Header>);
+
+impl FromElement for Headers {
+ fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ element.check_name("headers")?;
+ element.check_namespace(XMLNS)?;
+
+ Ok(Self(element.pop_children()?))
+ }
+}
+
+impl IntoElement for Headers {
+ fn builder(&self) -> peanuts::element::ElementBuilder {
+ Element::builder("headers", Some(XMLNS)).push_children(self.0.clone())
+ }
+}
+
+#[derive(Clone, Debug)]
+pub struct Header {
+ name: String,
+ header: String,
+}
+
+impl FromElement for Header {
+ fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> {
+ element.check_name("header")?;
+ element.check_namespace(XMLNS)?;
+
+ let name = element.attribute("name")?;
+
+ let header = element.pop_value_opt()?.unwrap_or_default();
+
+ Ok(Self { name, header })
+ }
+}
+
+impl IntoElement for Header {
+ fn builder(&self) -> peanuts::element::ElementBuilder {
+ let builder =
+ Element::builder("header", Some(XMLNS)).push_attribute("name", self.name.clone());
+
+ if self.header.is_empty() {
+ builder
+ } else {
+ builder.push_text(self.header.clone())
+ }
+ }
+}