From d848b6efe7811e4cb3128f478322472364e24b28 Mon Sep 17 00:00:00 2001 From: Link Mauve Date: Wed, 10 Jun 2026 14:44:23 +0200 Subject: [PATCH] tokio-xmpp: Make bound_jid a FullJid That way we have fewer checks to make in client code. --- tokio-xmpp/ChangeLog | 3 ++- tokio-xmpp/src/client/mod.rs | 9 ++++++--- tokio-xmpp/src/client/receiver.rs | 4 ++-- tokio-xmpp/src/client/stream.rs | 3 ++- tokio-xmpp/src/client/worker.rs | 9 +++++---- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tokio-xmpp/ChangeLog b/tokio-xmpp/ChangeLog index 4bef1523..ce5eab85 100644 --- a/tokio-xmpp/ChangeLog +++ b/tokio-xmpp/ChangeLog @@ -7,7 +7,8 @@ Version NEXT: child elements and attributes. - Add `xmpp_parsers::stream_features::StreamFeatures` to `tokio_xmpp::event::Online` (!631) - - `Component.jid` iw now a `BareJid` and not a raw `Jid` (!684) + - `Component.jid` is now a `BareJid` and not a raw `Jid` (!684) + - `Client.bound_jid` is now a `FullJid` and not a raw `Jid` (!687) * Added: - Expose `client_auth` method to allow manual stream setups for advanced use cases. diff --git a/tokio-xmpp/src/client/mod.rs b/tokio-xmpp/src/client/mod.rs index 8ba65967..72f9b34a 100644 --- a/tokio-xmpp/src/client/mod.rs +++ b/tokio-xmpp/src/client/mod.rs @@ -15,7 +15,10 @@ use std::io; use std::sync::Arc; use tokio::sync::{mpsc, oneshot, Mutex}; use tokio::task::JoinHandle; -use xmpp_parsers::{jid::Jid, stream_features::StreamFeatures}; +use xmpp_parsers::{ + jid::{FullJid, Jid}, + stream_features::StreamFeatures, +}; #[cfg(feature = "direct-tls")] use crate::connect::DirectTlsServerConnector; @@ -54,7 +57,7 @@ pub struct Client { // Client worker task worker: JoinHandle, // JID of the logged-in client - bound_jid: Option, + bound_jid: Option, // Stream features of the currently connected stream features: Option, // Response tracker for IQs @@ -64,7 +67,7 @@ pub struct Client { impl Client { /// Get the client's bound JID (the one reported by the XMPP /// server). - pub fn bound_jid(&self) -> Option<&Jid> { + pub fn bound_jid(&self) -> Option<&FullJid> { self.bound_jid.as_ref() } diff --git a/tokio-xmpp/src/client/receiver.rs b/tokio-xmpp/src/client/receiver.rs index ec78adb0..9495db49 100644 --- a/tokio-xmpp/src/client/receiver.rs +++ b/tokio-xmpp/src/client/receiver.rs @@ -11,7 +11,7 @@ use futures::StreamExt; use futures::{task::Poll, Stream}; use std::sync::Arc; use tokio::sync::Mutex; -use xmpp_parsers::{jid::Jid, stream_features::StreamFeatures}; +use xmpp_parsers::{jid::FullJid, stream_features::StreamFeatures}; /// Read half of a [`Client`](crate::Client). #[derive(Debug)] @@ -22,7 +22,7 @@ impl ClientReceiver { /// /// See the documentation of [`Client::bound_jid`](crate::Client::bound_jid) for more /// information. - pub async fn bound_jid(&self) -> Option { + pub async fn bound_jid(&self) -> Option { self.0.lock().await.bound_jid.clone() } diff --git a/tokio-xmpp/src/client/stream.rs b/tokio-xmpp/src/client/stream.rs index 4e1c4e32..a62343b2 100644 --- a/tokio-xmpp/src/client/stream.rs +++ b/tokio-xmpp/src/client/stream.rs @@ -36,7 +36,8 @@ impl Stream for Client { .. } = event { - self.bound_jid = Some(bound_jid.clone()); + // This unwrap() will never fail because the server MUST send us a full JID. + self.bound_jid = Some(bound_jid.try_as_full().unwrap().clone()); self.features = Some(features.clone()); } diff --git a/tokio-xmpp/src/client/worker.rs b/tokio-xmpp/src/client/worker.rs index c2652a23..ca35765e 100644 --- a/tokio-xmpp/src/client/worker.rs +++ b/tokio-xmpp/src/client/worker.rs @@ -12,7 +12,7 @@ use core::ops::ControlFlow; use futures::StreamExt; use tokio::sync::mpsc; use tokio::sync::oneshot; -use xmpp_parsers::jid::Jid; +use xmpp_parsers::jid::FullJid; use xmpp_parsers::stream_features::StreamFeatures; /// Worker to drive the [`crate::stanzastream`] of a client in the background and continue to @@ -25,7 +25,7 @@ pub struct ClientWorker { // Shutdown signal receiver from frontend shutdown_rx: oneshot::Receiver<()>, // JID of the logged-in client - bound_jid: Option, + bound_jid: Option, // Stream features of the currently connected stream features: Option, // Response tracker for IQs @@ -81,7 +81,8 @@ impl ClientWorker { bound_jid, features, }) => { - self.bound_jid = Some(bound_jid.clone()); + // This unwrap() will never fail, because the server always uses our own bound JID. + self.bound_jid = Some(bound_jid.try_as_full().unwrap().clone()); self.features = Some(features.clone()); self.iq_response_tracker .set_account_jid(bound_jid.to_bare()); @@ -93,7 +94,7 @@ impl ClientWorker { } } StanzaStreamEvent::Stream(StreamEvent::Resumed) => Event::Online { - bound_jid: self.bound_jid.as_ref().unwrap().clone(), + bound_jid: self.bound_jid.as_ref().unwrap().clone().into(), features: self.features.as_ref().unwrap().clone(), resumed: true, },