Implement function to get stream features

This commit is contained in:
famfo 2024-01-23 16:09:07 +01:00
parent 45c19690a8
commit 060088be29
3 changed files with 16 additions and 0 deletions

View file

@ -8,6 +8,7 @@ use xmpp_parsers::{ns, Element, Jid};
use super::connect::client_login; use super::connect::client_login;
use crate::connect::{AsyncReadAndWrite, ServerConnector}; use crate::connect::{AsyncReadAndWrite, ServerConnector};
use crate::event::Event; use crate::event::Event;
use crate::stream_features::StreamFeatures;
use crate::xmpp_codec::Packet; use crate::xmpp_codec::Packet;
use crate::xmpp_stream::{add_stanza_id, XMPPStream}; use crate::xmpp_stream::{add_stanza_id, XMPPStream};
use crate::{Error, ProtocolError}; use crate::{Error, ProtocolError};
@ -81,6 +82,14 @@ impl<C: ServerConnector> Client<C> {
.await .await
} }
/// Get the stream features (`<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 `</stream:stream>` /// End connection by sending `</stream:stream>`
/// ///
/// You may expect the server to respond with the same. This /// You may expect the server to respond with the same. This

View file

@ -5,6 +5,7 @@ use tokio_stream::StreamExt;
use xmpp_parsers::{ns, Element, Jid}; use xmpp_parsers::{ns, Element, Jid};
use crate::connect::ServerConnector; use crate::connect::ServerConnector;
use crate::stream_features::StreamFeatures;
use crate::xmpp_codec::Packet; use crate::xmpp_codec::Packet;
use crate::xmpp_stream::{add_stanza_id, XMPPStream}; use crate::xmpp_stream::{add_stanza_id, XMPPStream};
use crate::Error; use crate::Error;
@ -53,6 +54,11 @@ impl<C: ServerConnector> Client<C> {
.await .await
} }
/// Get the stream features (`<stream:features/>`) of the underlying stream
pub fn get_stream_features(&self) -> &StreamFeatures {
&self.stream.stream_features
}
/// End connection by sending `</stream:stream>` /// End connection by sending `</stream:stream>`
/// ///
/// You may expect the server to respond with the same. This /// You may expect the server to respond with the same. This

View file

@ -8,6 +8,7 @@ use xmpp_parsers::{ns, Element};
/// ///
/// TODO: should this rather go into xmpp-parsers, kept in a decoded /// TODO: should this rather go into xmpp-parsers, kept in a decoded
/// struct? /// struct?
#[derive(Debug)]
pub struct StreamFeatures(pub Element); pub struct StreamFeatures(pub Element);
impl StreamFeatures { impl StreamFeatures {