tokio-xmpp: implicitly add bound_jid to IQs
This commit is contained in:
parent
cff9195d6e
commit
f7931e95b6
3 changed files with 23 additions and 1 deletions
|
|
@ -3,6 +3,8 @@ Version NEXT:
|
||||||
* Fixed:
|
* Fixed:
|
||||||
- Ignore missing "version" stream attribute for 0114 components.
|
- Ignore missing "version" stream attribute for 0114 components.
|
||||||
- Gate `AsRawFd` behind `ktls` feature to make Windows build work again.
|
- Gate `AsRawFd` behind `ktls` feature to make Windows build work again.
|
||||||
|
- Implicitly use the `Client`'s bound JID on empty `to` in tokio-xmpp's
|
||||||
|
`IqResponseTracker`.
|
||||||
|
|
||||||
Version 5.0.0:
|
Version 5.0.0:
|
||||||
2025-10-28 pep <pep@bouah.net>
|
2025-10-28 pep <pep@bouah.net>
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ use core::pin::Pin;
|
||||||
use core::task::{ready, Context, Poll};
|
use core::task::{ready, Context, Poll};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
use xmpp_parsers::jid::BareJid;
|
||||||
|
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
|
|
@ -254,6 +255,7 @@ impl IqResponseSink {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct IqResponseTracker {
|
pub struct IqResponseTracker {
|
||||||
map: Arc<Mutex<IqMap>>,
|
map: Arc<Mutex<IqMap>>,
|
||||||
|
account_jid: Arc<Mutex<Option<BareJid>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IqResponseTracker {
|
impl IqResponseTracker {
|
||||||
|
|
@ -261,9 +263,16 @@ impl IqResponseTracker {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
map: Arc::new(Mutex::new(IqMap::new())),
|
map: Arc::new(Mutex::new(IqMap::new())),
|
||||||
|
account_jid: Arc::new(Mutex::new(None)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the local JID the `IqResponseTracker` is handling IQs on behalf of.
|
||||||
|
pub fn set_account_jid(&self, jid: BareJid) {
|
||||||
|
let mut guard = self.account_jid.lock().unwrap();
|
||||||
|
*guard = Some(jid);
|
||||||
|
}
|
||||||
|
|
||||||
/// Attempt to handle an IQ stanza as IQ response.
|
/// Attempt to handle an IQ stanza as IQ response.
|
||||||
///
|
///
|
||||||
/// Returns the IQ stanza unharmed if it is not an IQ response matching
|
/// Returns the IQ stanza unharmed if it is not an IQ response matching
|
||||||
|
|
@ -305,9 +314,16 @@ impl IqResponseTracker {
|
||||||
pub fn allocate_iq_handle(
|
pub fn allocate_iq_handle(
|
||||||
&self,
|
&self,
|
||||||
from: Option<Jid>,
|
from: Option<Jid>,
|
||||||
to: Option<Jid>,
|
mut to: Option<Jid>,
|
||||||
req: IqRequest,
|
req: IqRequest,
|
||||||
) -> (Iq, IqResponseToken) {
|
) -> (Iq, IqResponseToken) {
|
||||||
|
if to.is_none() {
|
||||||
|
// Implicitly setting None to the JID the tracker is active for, which the server
|
||||||
|
// should do as well. This ensures that the IQ can be matched in the map again.
|
||||||
|
let account_jid = self.account_jid.lock().unwrap();
|
||||||
|
to = account_jid.clone().map(Jid::from);
|
||||||
|
}
|
||||||
|
|
||||||
let key = (to, make_id());
|
let key = (to, make_id());
|
||||||
let mut map = self.map.lock().unwrap();
|
let mut map = self.map.lock().unwrap();
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,10 @@ impl Stream for Client {
|
||||||
})) => {
|
})) => {
|
||||||
self.features = Some(features);
|
self.features = Some(features);
|
||||||
self.bound_jid = Some(bound_jid.clone());
|
self.bound_jid = Some(bound_jid.clone());
|
||||||
|
|
||||||
|
self.iq_response_tracker
|
||||||
|
.set_account_jid(bound_jid.to_bare());
|
||||||
|
|
||||||
Some(Event::Online {
|
Some(Event::Online {
|
||||||
bound_jid,
|
bound_jid,
|
||||||
resumed: false,
|
resumed: false,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue