2023-03-12 21:50:28 +00:00
|
|
|
use quick_xml::events::{BytesStart, Event};
|
|
|
|
|
2023-09-30 15:43:46 +00:00
|
|
|
use crate::xml::*;
|
2024-04-16 15:44:34 +00:00
|
|
|
use anyhow::{anyhow, Result};
|
|
|
|
use quick_xml::name::ResolveResult;
|
2023-03-12 21:50:28 +00:00
|
|
|
|
|
|
|
pub const XMLNS: &'static str = "jabber:iq:roster";
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq, Debug)]
|
|
|
|
pub struct RosterQuery;
|
|
|
|
|
|
|
|
impl FromXml for RosterQuery {
|
2024-04-16 15:44:34 +00:00
|
|
|
type P = impl Parser<Output = Result<Self>>;
|
2023-03-12 21:50:28 +00:00
|
|
|
|
|
|
|
fn parse() -> Self::P {
|
2024-04-16 15:44:34 +00:00
|
|
|
|(mut namespace, mut event): (ResolveResult<'static>, &'static Event<'static>)| -> Result<Self> {
|
|
|
|
match event {
|
|
|
|
Event::Start(_) => (),
|
|
|
|
Event::Empty(_) => return Ok(RosterQuery),
|
|
|
|
_ => return Err(anyhow!("Unexpected XML event: {event:?}")),
|
|
|
|
}
|
|
|
|
(namespace, event) = yield;
|
|
|
|
match event {
|
|
|
|
Event::End(_) => return Ok(RosterQuery),
|
|
|
|
_ => return Err(anyhow!("Unexpected XML event: {event:?}")),
|
|
|
|
}
|
|
|
|
}
|
2023-03-12 21:50:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromXmlTag for RosterQuery {
|
|
|
|
const NAME: &'static str = "query";
|
|
|
|
const NS: &'static str = XMLNS;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToXml for RosterQuery {
|
|
|
|
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
2024-03-20 18:59:15 +00:00
|
|
|
events.push(Event::Empty(BytesStart::new(format!(r#"query xmlns="{}""#, XMLNS))));
|
2023-03-12 21:50:28 +00:00
|
|
|
}
|
|
|
|
}
|