tokio-xmpp: @id wasn't correctly added to every stanza

This commit moves the code adding @id to AsyncClient and SimpleClient,
instead of on the lower level send_stanza helper, which seemed to only
be used internally.

Support is also added for Component.

This removes the addition of @id on elements like <auth/> or <bind/>,
which probably weren't required anyway?

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-06-04 19:01:45 +02:00
commit bc73af1e5e
No known key found for this signature in database
GPG key ID: DEDA74AEECA9D0F2
4 changed files with 20 additions and 11 deletions

View file

@ -12,6 +12,7 @@ use super::happy_eyeballs::connect_to_host;
use super::xmpp_codec::Packet;
use super::xmpp_stream;
use super::Error;
use crate::xmpp_stream::make_id;
mod auth;
@ -53,7 +54,11 @@ impl Component {
/// Send stanza
pub async fn send_stanza(&mut self, stanza: Element) -> Result<(), Error> {
self.send(stanza).await
let mut el: Element = stanza;
if el.attr("id").is_none() {
el.set_attr("id", make_id());
}
self.send(el).await
}
/// End connection