From 060088be2968b34932f978a978edc17673ad3181 Mon Sep 17 00:00:00 2001 From: famfo Date: Tue, 23 Jan 2024 16:09:07 +0100 Subject: [PATCH] Implement function to get stream features --- tokio-xmpp/src/client/async_client.rs | 9 +++++++++ tokio-xmpp/src/client/simple_client.rs | 6 ++++++ tokio-xmpp/src/stream_features.rs | 1 + 3 files changed, 16 insertions(+) diff --git a/tokio-xmpp/src/client/async_client.rs b/tokio-xmpp/src/client/async_client.rs index 34171d6..4f85185 100644 --- a/tokio-xmpp/src/client/async_client.rs +++ b/tokio-xmpp/src/client/async_client.rs @@ -8,6 +8,7 @@ use xmpp_parsers::{ns, Element, Jid}; use super::connect::client_login; use crate::connect::{AsyncReadAndWrite, ServerConnector}; use crate::event::Event; +use crate::stream_features::StreamFeatures; use crate::xmpp_codec::Packet; use crate::xmpp_stream::{add_stanza_id, XMPPStream}; use crate::{Error, ProtocolError}; @@ -81,6 +82,14 @@ impl Client { .await } + /// Get the stream features (``) of the underlying stream + pub fn get_stream_features(&self) -> Option<&StreamFeatures> { + match self.state { + ClientState::Connected(ref stream) => Some(&stream.stream_features), + _ => None, + } + } + /// End connection by sending `` /// /// You may expect the server to respond with the same. This diff --git a/tokio-xmpp/src/client/simple_client.rs b/tokio-xmpp/src/client/simple_client.rs index 3f2b07c..19ab2f9 100644 --- a/tokio-xmpp/src/client/simple_client.rs +++ b/tokio-xmpp/src/client/simple_client.rs @@ -5,6 +5,7 @@ use tokio_stream::StreamExt; use xmpp_parsers::{ns, Element, Jid}; use crate::connect::ServerConnector; +use crate::stream_features::StreamFeatures; use crate::xmpp_codec::Packet; use crate::xmpp_stream::{add_stanza_id, XMPPStream}; use crate::Error; @@ -53,6 +54,11 @@ impl Client { .await } + /// Get the stream features (``) of the underlying stream + pub fn get_stream_features(&self) -> &StreamFeatures { + &self.stream.stream_features + } + /// End connection by sending `` /// /// You may expect the server to respond with the same. This diff --git a/tokio-xmpp/src/stream_features.rs b/tokio-xmpp/src/stream_features.rs index 6b97ec3..63263f3 100644 --- a/tokio-xmpp/src/stream_features.rs +++ b/tokio-xmpp/src/stream_features.rs @@ -8,6 +8,7 @@ use xmpp_parsers::{ns, Element}; /// /// TODO: should this rather go into xmpp-parsers, kept in a decoded /// struct? +#[derive(Debug)] pub struct StreamFeatures(pub Element); impl StreamFeatures {