From 4ce97f8e13e5e30d78f3e1ef4e2326d24f8465fb Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Mon, 27 Mar 2023 23:52:31 +0200 Subject: [PATCH] add disco iqs to all iqs --- src/projections/xmpp/mod.rs | 2 +- src/projections/xmpp/proto.rs | 5 +++++ src/protos/xmpp/disco.rs | 29 ++++++++++++++++++++++------- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/projections/xmpp/mod.rs b/src/projections/xmpp/mod.rs index 4ac60ed..a39ead6 100644 --- a/src/projections/xmpp/mod.rs +++ b/src/projections/xmpp/mod.rs @@ -333,7 +333,7 @@ async fn socket_final( } xml_writer.get_mut().flush().await?; } - proto::IqClientBody::Unknown(_) => { + _ => { let mut events = vec![]; let req = Iq { from: None, diff --git a/src/projections/xmpp/proto.rs b/src/projections/xmpp/proto.rs index 6b500bd..c3a4c79 100644 --- a/src/projections/xmpp/proto.rs +++ b/src/projections/xmpp/proto.rs @@ -4,6 +4,7 @@ use quick_xml::name::{Namespace, ResolveResult}; use crate::protos::xmpp::bind::BindRequest; use crate::protos::xmpp::client::{Iq, Message, Presence}; +use crate::protos::xmpp::disco::{InfoQuery, ItemQuery}; use crate::protos::xmpp::roster::RosterQuery; use crate::protos::xmpp::session::Session; use crate::util::xml::*; @@ -15,6 +16,8 @@ pub enum IqClientBody { Bind(BindRequest), Session(Session), Roster(RosterQuery), + DiscoInfo(InfoQuery), + DiscoItem(ItemQuery), Unknown(Ignore), } @@ -33,6 +36,8 @@ impl FromXml for IqClientBody { BindRequest, Session, RosterQuery, + InfoQuery, + ItemQuery, { delegate_parsing!(Ignore, namespace, event).into() } diff --git a/src/protos/xmpp/disco.rs b/src/protos/xmpp/disco.rs index bd9ead2..04fb8d6 100644 --- a/src/protos/xmpp/disco.rs +++ b/src/protos/xmpp/disco.rs @@ -9,7 +9,7 @@ use super::bind::Jid; pub const XMLNS_INFO: &'static str = "http://jabber.org/protocol/disco#info"; pub const XMLNS_ITEM: &'static str = "http://jabber.org/protocol/disco#item"; - +#[derive(PartialEq, Eq, Debug)] pub struct InfoQuery { pub node: Option, pub identity: Vec, @@ -40,7 +40,11 @@ impl FromXml for InfoQuery { } } if end { - return Ok(InfoQuery { node, identity, feature }) + return Ok(InfoQuery { + node, + identity, + feature, + }); } loop { let (namespace, event) = yield; @@ -60,7 +64,11 @@ impl FromXml for InfoQuery { return Err(ffail!("Unexpected XML event: {event:?}")); } } - return Ok(InfoQuery { node, identity, feature }) + return Ok(InfoQuery { + node, + identity, + feature, + }); } } } @@ -71,6 +79,7 @@ impl FromXmlTag for InfoQuery { const NS: &'static str = XMLNS_INFO; } +#[derive(PartialEq, Eq, Debug)] pub struct Identity { category: String, name: Option, @@ -114,7 +123,11 @@ impl FromXml for Identity { let Some(r#type) = r#type else { return Err(ffail!("No type provided")); }; - let item = Identity { category, name, r#type }; + let item = Identity { + category, + name, + r#type, + }; if end { return Ok(item); } @@ -134,6 +147,7 @@ impl FromXmlTag for Identity { const NS: &'static str = XMLNS_INFO; } +#[derive(PartialEq, Eq, Debug)] pub struct Feature { pub var: String, } @@ -182,6 +196,7 @@ impl FromXmlTag for Feature { const NS: &'static str = XMLNS_INFO; } +#[derive(PartialEq, Eq, Debug)] pub struct ItemQuery { pub item: Vec, } @@ -198,7 +213,7 @@ impl FromXml for ItemQuery { _ => return Err(ffail!("Unexpected XML event: {event:?}")), }; if end { - return Ok(ItemQuery { item }) + return Ok(ItemQuery { item }); } loop { let (namespace, event) = yield; @@ -226,7 +241,7 @@ impl FromXmlTag for ItemQuery { const NS: &'static str = XMLNS_ITEM; } -#[derive(Debug)] +#[derive(PartialEq, Eq, Debug)] pub struct Item { pub jid: super::bind::Jid, pub name: Option, @@ -286,4 +301,4 @@ impl FromXmlTag for Item { const NAME: &'static str = "item"; const NS: &'static str = XMLNS_ITEM; -} \ No newline at end of file +}