forked from lavina/lavina
61 lines
1.6 KiB
Rust
61 lines
1.6 KiB
Rust
use quick_xml::events::{BytesStart, Event};
|
|
|
|
use crate::prelude::*;
|
|
use crate::util::xml::*;
|
|
|
|
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
|
|
))));
|
|
}
|
|
}
|