tokio_xmpp/connect/
mod.rs

1//! `ServerConnector` provides streams for XMPP clients
2
3use sasl::common::ChannelBinding;
4use tokio::io::{AsyncBufRead, AsyncWrite};
5use xmpp_parsers::jid::Jid;
6
7use crate::xmlstream::{PendingFeaturesRecv, Timeouts};
8use crate::Error;
9
10#[cfg(feature = "starttls")]
11pub mod starttls;
12#[cfg(feature = "starttls")]
13pub use starttls::StartTlsServerConnector;
14
15#[cfg(feature = "direct-tls")]
16pub mod direct_tls;
17#[cfg(feature = "direct-tls")]
18pub use direct_tls::DirectTlsServerConnector;
19
20#[cfg(feature = "insecure-tcp")]
21pub mod tcp;
22#[cfg(feature = "insecure-tcp")]
23pub use tcp::TcpServerConnector;
24
25#[cfg(any(feature = "direct-tls", feature = "starttls"))]
26pub mod tls_common;
27
28mod dns;
29pub use dns::DnsConfig;
30
31/// trait returned wrapped in XmppStream by ServerConnector
32pub trait AsyncReadAndWrite: AsyncBufRead + AsyncWrite + Unpin + Send {}
33impl<T: AsyncBufRead + AsyncWrite + Unpin + Send> AsyncReadAndWrite for T {}
34
35/// Trait that must be extended by the implementation of ServerConnector
36pub trait ServerConnectorError: core::error::Error + Sync + Send {}
37
38/// Trait called to connect to an XMPP server, perhaps called multiple times
39pub trait ServerConnector: Clone + core::fmt::Debug + Send + Unpin + 'static {
40    /// The type of Stream this ServerConnector produces
41    type Stream: AsyncReadAndWrite;
42    /// This must return the connection ready to login, ie if starttls is involved, after TLS has been started, and then after the <stream headers are exchanged
43    fn connect(
44        &self,
45        jid: &Jid,
46        ns: &'static str,
47        timeouts: Timeouts,
48    ) -> impl core::future::Future<
49        Output = Result<(PendingFeaturesRecv<Self::Stream>, ChannelBinding), Error>,
50    > + Send;
51}