add disco iqs to all iqs

This commit is contained in:
Nikita Vilunov 2023-03-27 23:52:31 +02:00
parent 63704d6010
commit 4ce97f8e13
3 changed files with 28 additions and 8 deletions

View File

@ -333,7 +333,7 @@ async fn socket_final(
} }
xml_writer.get_mut().flush().await?; xml_writer.get_mut().flush().await?;
} }
proto::IqClientBody::Unknown(_) => { _ => {
let mut events = vec![]; let mut events = vec![];
let req = Iq { let req = Iq {
from: None, from: None,

View File

@ -4,6 +4,7 @@ use quick_xml::name::{Namespace, ResolveResult};
use crate::protos::xmpp::bind::BindRequest; use crate::protos::xmpp::bind::BindRequest;
use crate::protos::xmpp::client::{Iq, Message, Presence}; 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::roster::RosterQuery;
use crate::protos::xmpp::session::Session; use crate::protos::xmpp::session::Session;
use crate::util::xml::*; use crate::util::xml::*;
@ -15,6 +16,8 @@ pub enum IqClientBody {
Bind(BindRequest), Bind(BindRequest),
Session(Session), Session(Session),
Roster(RosterQuery), Roster(RosterQuery),
DiscoInfo(InfoQuery),
DiscoItem(ItemQuery),
Unknown(Ignore), Unknown(Ignore),
} }
@ -33,6 +36,8 @@ impl FromXml for IqClientBody {
BindRequest, BindRequest,
Session, Session,
RosterQuery, RosterQuery,
InfoQuery,
ItemQuery,
{ {
delegate_parsing!(Ignore, namespace, event).into() delegate_parsing!(Ignore, namespace, event).into()
} }

View File

@ -9,7 +9,7 @@ use super::bind::Jid;
pub const XMLNS_INFO: &'static str = "http://jabber.org/protocol/disco#info"; pub const XMLNS_INFO: &'static str = "http://jabber.org/protocol/disco#info";
pub const XMLNS_ITEM: &'static str = "http://jabber.org/protocol/disco#item"; pub const XMLNS_ITEM: &'static str = "http://jabber.org/protocol/disco#item";
#[derive(PartialEq, Eq, Debug)]
pub struct InfoQuery { pub struct InfoQuery {
pub node: Option<String>, pub node: Option<String>,
pub identity: Vec<Identity>, pub identity: Vec<Identity>,
@ -40,7 +40,11 @@ impl FromXml for InfoQuery {
} }
} }
if end { if end {
return Ok(InfoQuery { node, identity, feature }) return Ok(InfoQuery {
node,
identity,
feature,
});
} }
loop { loop {
let (namespace, event) = yield; let (namespace, event) = yield;
@ -60,7 +64,11 @@ impl FromXml for InfoQuery {
return Err(ffail!("Unexpected XML event: {event:?}")); 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; const NS: &'static str = XMLNS_INFO;
} }
#[derive(PartialEq, Eq, Debug)]
pub struct Identity { pub struct Identity {
category: String, category: String,
name: Option<String>, name: Option<String>,
@ -114,7 +123,11 @@ impl FromXml for Identity {
let Some(r#type) = r#type else { let Some(r#type) = r#type else {
return Err(ffail!("No type provided")); return Err(ffail!("No type provided"));
}; };
let item = Identity { category, name, r#type }; let item = Identity {
category,
name,
r#type,
};
if end { if end {
return Ok(item); return Ok(item);
} }
@ -134,6 +147,7 @@ impl FromXmlTag for Identity {
const NS: &'static str = XMLNS_INFO; const NS: &'static str = XMLNS_INFO;
} }
#[derive(PartialEq, Eq, Debug)]
pub struct Feature { pub struct Feature {
pub var: String, pub var: String,
} }
@ -182,6 +196,7 @@ impl FromXmlTag for Feature {
const NS: &'static str = XMLNS_INFO; const NS: &'static str = XMLNS_INFO;
} }
#[derive(PartialEq, Eq, Debug)]
pub struct ItemQuery { pub struct ItemQuery {
pub item: Vec<Item>, pub item: Vec<Item>,
} }
@ -198,7 +213,7 @@ impl FromXml for ItemQuery {
_ => return Err(ffail!("Unexpected XML event: {event:?}")), _ => return Err(ffail!("Unexpected XML event: {event:?}")),
}; };
if end { if end {
return Ok(ItemQuery { item }) return Ok(ItemQuery { item });
} }
loop { loop {
let (namespace, event) = yield; let (namespace, event) = yield;
@ -226,7 +241,7 @@ impl FromXmlTag for ItemQuery {
const NS: &'static str = XMLNS_ITEM; const NS: &'static str = XMLNS_ITEM;
} }
#[derive(Debug)] #[derive(PartialEq, Eq, Debug)]
pub struct Item { pub struct Item {
pub jid: super::bind::Jid, pub jid: super::bind::Jid,
pub name: Option<String>, pub name: Option<String>,