diff options
Diffstat (limited to 'stanza/src/xep_0030/items.rs')
-rw-r--r-- | stanza/src/xep_0030/items.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/stanza/src/xep_0030/items.rs b/stanza/src/xep_0030/items.rs new file mode 100644 index 0000000..78fe332 --- /dev/null +++ b/stanza/src/xep_0030/items.rs @@ -0,0 +1,63 @@ +use jid::JID; +use peanuts::{ + element::{FromElement, IntoElement}, + Element, +}; + +pub const XMLNS: &str = "http://jabber.org/protocol/disco#items"; + +#[derive(Debug, Clone)] +pub struct Query { + node: Option<String>, + items: Vec<Item>, +} + +impl FromElement for Query { + fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + element.check_name("query")?; + element.check_namespace(XMLNS)?; + + let node = element.attribute_opt("node")?; + + let items = element.pop_children()?; + + Ok(Self { node, items }) + } +} + +impl IntoElement for Query { + fn builder(&self) -> peanuts::element::ElementBuilder { + Element::builder("query", Some(XMLNS)) + .push_attribute_opt("node", self.node.clone()) + .push_children(self.items.clone()) + } +} + +#[derive(Debug, Clone)] +pub struct Item { + jid: JID, + name: Option<String>, + node: Option<String>, +} + +impl FromElement for Item { + fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + element.check_name("item")?; + element.check_namespace(XMLNS)?; + + let jid = element.attribute("jid")?; + let name = element.attribute_opt("name")?; + let node = element.attribute_opt("node")?; + + Ok(Self { jid, name, node }) + } +} + +impl IntoElement for Item { + fn builder(&self) -> peanuts::element::ElementBuilder { + Element::builder("item", Some(XMLNS)) + .push_attribute("jid", self.jid.clone()) + .push_attribute_opt("name", self.name.clone()) + .push_attribute_opt("node", self.node.clone()) + } +} |