forked from lavina/lavina
1
0
Fork 0

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?;
}
proto::IqClientBody::Unknown(_) => {
_ => {
let mut events = vec![];
let req = Iq {
from: None,

View File

@ -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()
}

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_ITEM: &'static str = "http://jabber.org/protocol/disco#item";
#[derive(PartialEq, Eq, Debug)]
pub struct InfoQuery {
pub node: Option<String>,
pub identity: Vec<Identity>,
@ -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<String>,
@ -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<Item>,
}
@ -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<String>,
@ -286,4 +301,4 @@ impl FromXmlTag for Item {
const NAME: &'static str = "item";
const NS: &'static str = XMLNS_ITEM;
}
}