2024-08-06 21:04:34 +02:00
//! Low-level [XMPP](https://xmpp.org/) decentralized instant messaging & social networking implementation with asynchronous I/O using [tokio](https://tokio.rs/).
//!
//! For an easier, batteries-included experience, try the [xmpp crate](https://docs.rs/xmpp).
//!
//! # Getting started
//!
//! In most cases, you want to start with a [`Client`], that will connect to a server over TCP/IP with StartTLS encryption. Then, you can build an event loop by calling the client's `next` method repeatedly. You can find a more complete example in the [examples/echo_bot.rs](https://gitlab.com/xmpp-rs/xmpp-rs/-/blob/main/tokio-xmpp/examples/echo_bot.rs) file in the repository.
//!
//! # Features
//!
//! This library is not feature-complete yet. Here's a quick overview of the feature set.
//!
//! Supported implementations:
//! - [x] Clients
//! - [x] Components
//! - [ ] Servers
//!
//! Supported transports:
//! - [x] Plaintext TCP (IPv4/IPv6)
//! - [x] StartTLS TCP (IPv4/IPv6 with [happy eyeballs](https://en.wikipedia.org/wiki/Happy_Eyeballs) support)
//! - [x] Custom connectors via the [`connect::ServerConnector`] trait
//! - [ ] Websockets
//! - [ ] BOSH
//!
2025-05-10 10:45:43 +02:00
//! # Cargo features
//!
//! ## TLS backends
//!
//! - `aws_lc_rs` (default) enables rustls with the `aws_lc_rs` backend.
//! - `ring` enables rustls with the `ring` backend`.
//! - `rustls-any-backend` enables rustls, but without enabling a backend. It
//! is the application's responsibility to ensure that a backend is enabled
//! and installed.
//! - `ktls` enables the use of ktls.
//! **Important:** Currently, connections will fail if the `tls` kernel
//! module is not available. There is no fallback to non-ktls connections!
//! - `native-tls` enables the system-native TLS library (commonly
//! libssl/OpenSSL).
//!
//! **Note:** It is not allowed to mix rustls-based TLS backends with
//! `tls-native`. Attempting to do so will result in a compilation error.
//!
//! **Note:** The `ktls` feature requires at least one `rustls` backend to be
//! enabled (`aws_lc_rs` or `ring`).
//!
//! **Note:** When enabling not exactly one rustls backend, it is the
//! application's responsibility to make sure that a default crypto provider is
//! installed in `rustls`. Otherwise, all TLS connections will fail.
//!
//! ## Certificate validation
//!
//! When using `native-tls`, the system's native certificate store is used.
//! Otherwise, you need to pick one of the following to ensure that TLS
//! connections will succeed:
//!
//! - `rustls-native-certs` (default): Uses [rustls-native-certs](https://crates.io/crates/rustls-native-certs).
//! - `webpki-roots`: Uses [webpki-roots](https://crates.io/crates/webpki-roots).
//!
//! ## Other features
//!
//! - `starttls` (default): Enables support for `<starttls/>`. Required as per
//! RFC 6120.
//! - `insecure-tcp`: Allow the use of insecure TCP connections to connect to
//! XMPP servers. Required for XMPP components, but disabled by default to
//! prevent accidental use.
//! - `serde`: Enable the `serde` feature in `xmpp-parsers`.
//! - `component`: Enable component support (implies `insecure-tcp`).
//!
2024-08-06 21:04:34 +02:00
//! # More information
//!
//! You can find more information on our website [xmpp.rs](https://xmpp.rs/) or by joining our chatroom [chat@xmpp.rs](xmpp:chat@xmpp.rs?join).
2018-08-02 19:58:19 +02:00
2021-09-02 03:21:25 +02:00
#![ deny(unsafe_code, missing_docs, bare_trait_objects) ]
2024-08-04 22:35:01 +02:00
#![ cfg_attr(docsrs, feature(doc_auto_cfg)) ]
2020-03-16 00:34:46 +01:00
2025-05-10 10:45:43 +02:00
macro_rules ! fail_native_with_any {
( $( $feature :literal ) , + ) = > {
$(
#[ cfg(all(
not ( xmpprs_doc_build ) ,
not ( doc ) ,
feature = " native-tls " ,
feature = $feature ,
) ) ]
compile_error! (
concat! (
" native-tls cannot be mixed with the " ,
$feature ,
" feature. Pick one or the other. "
)
) ;
) +
}
}
fail_native_with_any! ( " ring " , " aws_lc_rs " , " ktls " , " rustls-any-backend " ) ;
2023-10-24 18:24:04 +02:00
2023-12-30 22:08:37 -05:00
#[ cfg(all(
feature = " starttls " ,
2025-05-10 10:45:43 +02:00
not ( feature = " native-tls " ) ,
not ( any ( feature = " rustls-any-backend " ) )
2023-12-30 22:08:37 -05:00
) ) ]
compile_error! (
2025-05-10 10:45:43 +02:00
" When the starttls feature is enabled, either native-tls or any of the rustls (aws_lc_rs, ring, or rustls-any-backend) features must be enabled. "
2023-12-30 22:08:37 -05:00
) ;
2023-10-24 19:58:59 +02:00
2024-12-19 19:34:10 +01:00
extern crate alloc ;
2024-12-18 17:59:06 +01:00
pub use parsers ::{ jid , minidom } ;
pub use xmpp_parsers as parsers ;
2023-12-30 22:08:37 -05:00
2025-05-10 10:45:43 +02:00
#[ cfg(any(feature = " ring " , feature = " aws_lc_rs " , feature = " ktls " )) ]
2025-05-10 09:23:56 +02:00
pub use tokio_rustls ::rustls ;
2024-08-11 11:53:20 +02:00
mod client ;
2024-08-10 17:39:55 +02:00
#[ cfg(feature = " insecure-tcp " ) ]
2017-07-22 01:59:51 +01:00
mod component ;
2024-12-18 17:59:06 +01:00
pub mod connect ;
2024-08-04 17:32:12 +02:00
/// Detailed error types
pub mod error ;
2024-12-18 17:59:06 +01:00
mod event ;
pub mod stanzastream ;
pub mod xmlstream ;
2024-08-06 21:04:34 +02:00
#[ doc(inline) ]
2024-08-04 17:32:12 +02:00
/// Generic tokio_xmpp Error
pub use crate ::error ::Error ;
2025-01-26 11:10:44 +01:00
pub use client ::{ Client , IqFailure , IqRequest , IqResponse , IqResponseToken } ;
2024-12-18 17:59:06 +01:00
#[ cfg(feature = " insecure-tcp " ) ]
pub use component ::Component ;
pub use event ::{ Event , Stanza } ;
2023-08-17 16:17:13 +02:00
2024-12-18 17:59:06 +01:00
#[ cfg(test) ]
mod tests {
#[ test ]
fn reexports ( ) {
#[ allow(unused_imports) ]
use crate ::jid ;
#[ allow(unused_imports) ]
use crate ::minidom ;
#[ allow(unused_imports) ]
use crate ::parsers ;
}
}
2024-11-12 10:55:36 +01:00
// Re-export for debug purposes
pub use xso ::asxml ::PrintRawXml ;