aboutsummaryrefslogtreecommitdiffstats
path: root/stanza/src/xep_0084/metadata.rs
diff options
context:
space:
mode:
Diffstat (limited to 'stanza/src/xep_0084/metadata.rs')
-rw-r--r--stanza/src/xep_0084/metadata.rs106
1 files changed, 106 insertions, 0 deletions
diff --git a/stanza/src/xep_0084/metadata.rs b/stanza/src/xep_0084/metadata.rs
new file mode 100644
index 0000000..c6a3fb4
--- /dev/null
+++ b/stanza/src/xep_0084/metadata.rs
@@ -0,0 +1,106 @@
+use peanuts::{
+ element::{FromElement, IntoElement},
+ Element,
+};
+
+pub const XMLNS: &str = "urn:xmpp:avatar:metadata";
+
+#[derive(Debug, Clone)]
+pub struct Metadata {
+ pub info: Vec<Info>,
+ pub pointers: Vec<Pointer>,
+}
+
+impl FromElement for Metadata {
+ fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ element.check_name("metadata")?;
+ element.check_namespace(XMLNS)?;
+
+ let info = element.pop_children()?;
+ let pointers = element.pop_children()?;
+
+ Ok(Self { info, pointers })
+ }
+}
+
+impl IntoElement for Metadata {
+ fn builder(&self) -> peanuts::element::ElementBuilder {
+ Element::builder("metadata", Some(XMLNS))
+ .push_children(self.info.clone())
+ .push_children(self.pointers.clone())
+ }
+}
+
+#[derive(Debug, Clone)]
+pub struct Info {
+ pub bytes: u32,
+ pub height: Option<u16>,
+ pub id: String,
+ pub r#type: String,
+ pub url: Option<String>,
+ pub width: Option<u16>,
+}
+
+impl FromElement for Info {
+ fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ element.check_name("info")?;
+ element.check_namespace(XMLNS)?;
+
+ let bytes = element.attribute("bytes")?;
+ let height = element.attribute_opt("height")?;
+ let id = element.attribute("id")?;
+ let r#type = element.attribute("type")?;
+ let url = element.attribute_opt("url")?;
+ let width = element.attribute_opt("width")?;
+
+ Ok(Self {
+ bytes,
+ height,
+ id,
+ r#type,
+ url,
+ width,
+ })
+ }
+}
+
+impl IntoElement for Info {
+ fn builder(&self) -> peanuts::element::ElementBuilder {
+ Element::builder("info", Some(XMLNS))
+ .push_attribute("bytes", self.bytes)
+ .push_attribute_opt("height", self.height)
+ .push_attribute("id", self.id.clone())
+ .push_attribute("type", self.r#type.clone())
+ .push_attribute_opt("url", self.url.clone())
+ .push_attribute_opt("width", self.width)
+ }
+}
+
+#[derive(Debug, Clone)]
+pub struct Pointer(pub PointerInner);
+
+impl FromElement for Pointer {
+ fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ element.check_name("pointer")?;
+ element.check_namespace(XMLNS)?;
+
+ Ok(Self(PointerInner::Unsupported(element.pop_child_one()?)))
+ }
+}
+
+impl IntoElement for Pointer {
+ fn builder(&self) -> peanuts::element::ElementBuilder {
+ let _builder = Element::builder("pointer", Some(XMLNS));
+
+ match &self.0 {
+ PointerInner::Unsupported(_element) => {
+ panic!("cannot serialize unsupported PointerInner")
+ }
+ }
+ }
+}
+
+#[derive(Debug, Clone)]
+pub enum PointerInner {
+ Unsupported(Element),
+}