blob: 7af2bbfd07a0dddf9c88f61658129a8ec0fceb69 (
plain) (
tree)
|
|
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 {
pub node: Option<String>,
pub 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 {
pub jid: JID,
pub name: Option<String>,
pub 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())
}
}
|