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::*;
|
|
|
|
use anyhow::{anyhow as ffail, Result};
|
2023-03-12 21:50:28 +00:00
|
|
|
|
|
|
|
pub const XMLNS: &'static str = "jabber:iq:roster";
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq, Debug)]
|
|
|
|
pub struct RosterQuery;
|
|
|
|
|
|
|
|
pub struct QueryParser(QueryParserInner);
|
|
|
|
|
|
|
|
enum QueryParserInner {
|
|
|
|
Initial,
|
|
|
|
InQuery,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Parser for QueryParser {
|
|
|
|
type Output = Result<RosterQuery>;
|
|
|
|
|
|
|
|
fn consume<'a>(
|
|
|
|
self: Self,
|
|
|
|
namespace: quick_xml::name::ResolveResult,
|
|
|
|
event: &quick_xml::events::Event<'a>,
|
|
|
|
) -> Continuation<Self, Self::Output> {
|
|
|
|
match self.0 {
|
|
|
|
QueryParserInner::Initial => match event {
|
|
|
|
Event::Start(_) => Continuation::Continue(QueryParser(QueryParserInner::InQuery)),
|
|
|
|
Event::Empty(_) => Continuation::Final(Ok(RosterQuery)),
|
|
|
|
_ => Continuation::Final(Err(ffail!("Unexpected XML event: {event:?}"))),
|
|
|
|
},
|
|
|
|
QueryParserInner::InQuery => match event {
|
|
|
|
Event::End(_) => Continuation::Final(Ok(RosterQuery)),
|
|
|
|
_ => Continuation::Final(Err(ffail!("Unexpected XML event: {event:?}"))),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromXml for RosterQuery {
|
|
|
|
type P = QueryParser;
|
|
|
|
|
|
|
|
fn parse() -> Self::P {
|
|
|
|
QueryParser(QueryParserInner::Initial)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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>>) {
|
|
|
|
events.push(Event::Empty(BytesStart::new(format!(
|
|
|
|
r#"query xmlns="{}""#,
|
|
|
|
XMLNS
|
|
|
|
))));
|
|
|
|
}
|
|
|
|
}
|