From 2b54260f0bb999a7c59c8a215a38ac51f62d24d9 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Wed, 5 Apr 2023 22:37:33 +0200 Subject: [PATCH] feat(xmpp): improve disco responses --- src/projections/xmpp/mod.rs | 29 ++++++++++++++++++++++------- src/protos/xmpp/disco.rs | 6 +++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/projections/xmpp/mod.rs b/src/projections/xmpp/mod.rs index 57c1222..6d4f1ce 100644 --- a/src/projections/xmpp/mod.rs +++ b/src/projections/xmpp/mod.rs @@ -25,7 +25,7 @@ use crate::prelude::*; use crate::protos::xmpp; use crate::protos::xmpp::bind::{BindResponse, Jid, Name, Resource, Server}; 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::session::Session; use crate::protos::xmpp::stream::*; @@ -314,7 +314,7 @@ fn handle_packet(output: &mut Vec>, packet: ClientPacket) -> bool }; response.serialize(output); false - }, + } proto::ClientPacket::StreamEnd => { ServerStreamEnd.serialize(output); true @@ -394,9 +394,16 @@ fn handle_iq(output: &mut Vec>, iq: Iq) { } fn disco_info(to: Option<&str>, req: &InfoQuery) -> InfoQuery { - let feature = match to { + let identity; + let feature; + match to { 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#items"), Feature::new("iq"), @@ -404,17 +411,25 @@ fn disco_info(to: Option<&str>, req: &InfoQuery) -> InfoQuery { ] } 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#items"), Feature::new("http://jabber.org/protocol/muc"), ] } - _ => vec![], + _ => { + identity = vec![]; + feature = vec![]; + } }; InfoQuery { node: None, - identity: vec![], + identity, feature, } } diff --git a/src/protos/xmpp/disco.rs b/src/protos/xmpp/disco.rs index c4cd07f..f49585d 100644 --- a/src/protos/xmpp/disco.rs +++ b/src/protos/xmpp/disco.rs @@ -132,9 +132,9 @@ impl ToXml for InfoQuery { #[derive(PartialEq, Eq, Debug)] pub struct Identity { - category: String, - name: Option, - r#type: String, + pub category: String, + pub name: Option, + pub r#type: String, } impl FromXml for Identity {