forked from lavina/lavina
1
0
Fork 0

feat(xmpp): improve disco responses

This commit is contained in:
Nikita Vilunov 2023-04-05 22:37:33 +02:00
parent f71d098420
commit 2b54260f0b
2 changed files with 25 additions and 10 deletions

View File

@ -25,7 +25,7 @@ use crate::prelude::*;
use crate::protos::xmpp; use crate::protos::xmpp;
use crate::protos::xmpp::bind::{BindResponse, Jid, Name, Resource, Server}; use crate::protos::xmpp::bind::{BindResponse, Jid, Name, Resource, Server};
use crate::protos::xmpp::client::{Iq, Presence}; use crate::protos::xmpp::client::{Iq, Presence};
use crate::protos::xmpp::disco::{Feature, InfoQuery, Item, ItemQuery}; use crate::protos::xmpp::disco::*;
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::protos::xmpp::stream::*; use crate::protos::xmpp::stream::*;
@ -314,7 +314,7 @@ fn handle_packet(output: &mut Vec<Event<'static>>, packet: ClientPacket) -> bool
}; };
response.serialize(output); response.serialize(output);
false false
}, }
proto::ClientPacket::StreamEnd => { proto::ClientPacket::StreamEnd => {
ServerStreamEnd.serialize(output); ServerStreamEnd.serialize(output);
true true
@ -394,9 +394,16 @@ fn handle_iq(output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>) {
} }
fn disco_info(to: Option<&str>, req: &InfoQuery) -> InfoQuery { fn disco_info(to: Option<&str>, req: &InfoQuery) -> InfoQuery {
let feature = match to { let identity;
let feature;
match to {
Some("localhost") => { Some("localhost") => {
vec![ identity = vec![Identity {
category: "server".into(),
name: None,
r#type: "im".into(),
}];
feature = vec![
Feature::new("http://jabber.org/protocol/disco#info"), Feature::new("http://jabber.org/protocol/disco#info"),
Feature::new("http://jabber.org/protocol/disco#items"), Feature::new("http://jabber.org/protocol/disco#items"),
Feature::new("iq"), Feature::new("iq"),
@ -404,17 +411,25 @@ fn disco_info(to: Option<&str>, req: &InfoQuery) -> InfoQuery {
] ]
} }
Some("rooms.localhost") => { Some("rooms.localhost") => {
vec![ identity = vec![Identity {
category: "conference".into(),
name: Some("Chat rooms".into()),
r#type: "text".into(),
}];
feature = vec![
Feature::new("http://jabber.org/protocol/disco#info"), Feature::new("http://jabber.org/protocol/disco#info"),
Feature::new("http://jabber.org/protocol/disco#items"), Feature::new("http://jabber.org/protocol/disco#items"),
Feature::new("http://jabber.org/protocol/muc"), Feature::new("http://jabber.org/protocol/muc"),
] ]
} }
_ => vec![], _ => {
identity = vec![];
feature = vec![];
}
}; };
InfoQuery { InfoQuery {
node: None, node: None,
identity: vec![], identity,
feature, feature,
} }
} }

View File

@ -132,9 +132,9 @@ impl ToXml for InfoQuery {
#[derive(PartialEq, Eq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub struct Identity { pub struct Identity {
category: String, pub category: String,
name: Option<String>, pub name: Option<String>,
r#type: String, pub r#type: String,
} }
impl FromXml for Identity { impl FromXml for Identity {