pass_it_on/
lib.rs

1#![warn(missing_docs)]
2//! # Pass-It-On
3//! A library that provides simple notification client and server that receives messages and passes them on to endpoints
4//!
5//!
6//! ## Client Example
7//! To use the client to pass messages to the server you will need to pass a valid [`ClientConfiguration`]
8//! and a channel receiver to the start client function.  It will monitor that channel for incoming
9//! [`Notification`][crate::notifications::Notification] values and send them in the expected format to server.
10//!
11//! ```
12//! # use pass_it_on::notifications::{Key, Notification};
13//! # use pass_it_on::{ClientConfigFileParser, start_client, Error};
14//! # use tokio::sync::mpsc;
15//! #
16//! # const CLIENT_TOML_CONFIG: &str = r#"
17//! #    [client]
18//! #    key = "UVXu7wtbXHWNgAr6rWyPnaZbZK9aYin8"
19//! #
20//! #    [[client.interface]]
21//! #    type = "http"
22//! #    port = 8080
23//! #
24//! # "#;
25//!
26//! # #[tokio::main]
27//! async fn main() -> Result<(), Error> {
28//!     const NOTIFICATION_NAME: &str = "test1";
29//!     let config = ClientConfiguration::from_toml(CLIENT_TOML_CONFIG)?;
30//!     let (interface_tx, interface_rx) = mpsc::channel(100);
31//!
32//!     let messages = vec![
33//!         Message::new("A message to be sent").to_client_ready_message(NOTIFICATION_NAME),
34//!         Message::new("Another message").to_client_ready_message(NOTIFICATION_NAME),
35//!     ];
36//!
37//!     for message in messages {
38//!         if let Err(send_error) = interface_tx.send(message).await {
39//!             println!("Send Error: {}", send_error);
40//!         }
41//!     }
42//!
43//!     start_client(config, interface_rx, None).await?;
44//!
45//!     Ok(())
46//! }
47//! ```
48//!
49//! ## Feature Flags
50//!
51//! | Feature                 | Description                                                                                                            |
52//! |-------------------------|------------------------------------------------------------------------------------------------------------------------|
53//! | client                  | Enables the client but not any particular interface.                                                                   |
54//! | discord                 | Enables the discord webhook endpoint.                                                                                  |
55//! | email                   | Enables the email endpoint.                                                                                            |
56//! | endpoints               | Enables the Endpoint and EndpointConfig traits.                                                                        |
57//! | file                    | Enables the regular file endpoint.                                                                                     |
58//! | http                    | Enables the HTTP interface client and server.                                                                          |
59//! | http-client             | Enables the HTTP interface for just client.                                                                            |
60//! | http-server             | Enables the HTTP interface for just server.                                                                            |
61//! | interfaces              | Enables the Interface and InterfaceConfig traits.                                                                      |
62//! | matrix                  | Enables the matrix endpoint.                                                                                           |
63//! | parse-cfg               | Enables parsing of client or server configurations from TOML when those features are also enabled.                     |
64//! | pipe                    | Enables the named pipe interface client and server. **(Unix only)**                                                    |
65//! | pipe-client             | Enables the named pipe interface client. **(Unix only)**                                                               |
66//! | pipe-server             | Enables the named pipe interface server. **(Unix only)**                                                               |
67//! | server                  | Enables the server but not any particular interface or endpoint.                                                       |
68//! | server-bin-full         | Enables the building of the provided `pass-it-on-server` binary with all available interfaces and endpoints            |
69//! | server-bin-minimal      | Enables the building of the provided `pass-it-on-server` binary while not requiring any specific interface or endpoint |
70//! | rustls-tls-native-roots | Enables rustls-tls-native-roots for reqwest.                                                                           |
71
72#[cfg(feature = "client")]
73mod client;
74#[cfg(any(feature = "server", feature = "client"))]
75mod configuration;
76#[cfg(feature = "endpoints")]
77pub mod endpoints;
78mod error;
79#[cfg(feature = "interfaces")]
80pub mod interfaces;
81pub mod notifications;
82#[cfg(feature = "server")]
83mod server;
84#[cfg(any(feature = "server", feature = "client"))]
85pub(crate) mod shutdown;
86
87#[cfg(feature = "client")]
88pub use self::client::{start_client, start_client_arc};
89#[cfg(all(feature = "client", feature = "parse-cfg"))]
90pub use self::configuration::client_configuration_file::ClientConfigFile;
91#[cfg(all(feature = "server", feature = "parse-cfg"))]
92pub use self::configuration::server_configuration_file::ServerConfigFile;
93#[cfg(feature = "client")]
94pub use self::configuration::ClientConfiguration;
95#[cfg(feature = "server")]
96pub use self::configuration::ServerConfiguration;
97pub use self::error::Error;
98#[cfg(feature = "server")]
99pub use self::server::start_server;
100#[cfg(all(feature = "server", feature = "matrix"))]
101pub use self::server::verify_matrix_devices;
102
103#[allow(dead_code)]
104const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");
105#[allow(dead_code)]
106const CHANNEL_BUFFER: usize = 200;
107const KEY_CONTEXT: &str = "pass-it-on 2024-02-18 client-server shared-key";