xmpp: new 'escape-hatch' feature

Maxime “pep” Buquet created

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>

Change summary

xmpp/Cargo.toml   | 1 +
xmpp/ChangeLog    | 3 +++
xmpp/src/agent.rs | 9 +++++++++
3 files changed, 13 insertions(+)

Detailed changes

xmpp/Cargo.toml 🔗

@@ -35,6 +35,7 @@ default = ["avatars", "starttls-rust"]
 starttls-native = ["tokio-xmpp/starttls", "tokio-xmpp/tls-native", "reqwest/native-tls"]
 starttls-rust = ["tokio-xmpp/starttls", "tokio-xmpp/tls-rust", "reqwest/rustls-tls"]
 avatars = []
+escape-hatch = []
 syntax-highlighting = [ "tokio-xmpp/syntax-highlighting" ]
 # Enable serde support in jid crate
 serde = [ "tokio-xmpp/serde" ]

xmpp/ChangeLog 🔗

@@ -24,6 +24,9 @@ XXXX-YY-ZZ [ RELEASER <admin@localhost> ]
       - Agent::new helper method.
       - Handle SIGINT, SIGTERM and SIGKILL in hello_bot example to avoid leaving
         hibernating resources around.
+      - New 'escape-hatch' feature: Allow sending tokio_xmpp::Stanza directly
+        instead of having to go through xmpp-rs' API when it's lacking. This
+        is meant to stay behind a feature.
     * Fixes:
       - Use tokio::sync::RwLock not std::sync::RwLock (!432)
       - Agent::wait_for_events now return Vec<Event> and sets inner tokio_xmpp Client

xmpp/src/agent.rs 🔗

@@ -7,6 +7,8 @@
 use alloc::sync::Arc;
 use std::collections::HashMap;
 use std::path::{Path, PathBuf};
+#[cfg(feature = "escape-hatch")]
+use tokio::io;
 use tokio::sync::RwLock;
 
 use crate::{
@@ -17,6 +19,8 @@ use crate::{
     upload, Error, Event, RoomNick,
 };
 use tokio_xmpp::Client as TokioXmppClient;
+#[cfg(feature = "escape-hatch")]
+use tokio_xmpp::{stanzastream::StanzaToken, Stanza};
 
 pub struct Agent {
     pub(crate) client: TokioXmppClient,
@@ -58,6 +62,11 @@ impl Agent {
         self.client.send_end().await
     }
 
+    #[cfg(feature = "escape-hatch")]
+    pub async fn send_stanza<S: Into<Stanza>>(&mut self, st: S) -> Result<StanzaToken, io::Error> {
+        self.client.send_stanza(st.into()).await
+    }
+
     pub async fn join_room<'a>(&mut self, settings: muc::room::JoinRoomSettings<'a>) {
         muc::room::join_room(self, settings).await
     }