tokio-xmpp: Ensure id is added only to stanza

The previous commit didn't fix a bug where @id would be added to
elements that didn't need it / where it was invalid (e.g., stream
management).

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

View file

@ -17,7 +17,7 @@ use crate::event::Event;
use crate::happy_eyeballs::{connect_to_host, connect_with_srv};
use crate::starttls::starttls;
use crate::xmpp_codec::Packet;
use crate::xmpp_stream::{self, make_id};
use crate::xmpp_stream::{self, add_stanza_id};
use crate::{Error, ProtocolError};
/// XMPP client connection and state
@ -161,11 +161,8 @@ impl Client {
/// Send stanza
pub async fn send_stanza(&mut self, stanza: Element) -> Result<(), Error> {
let mut el: Element = stanza;
if el.attr("id").is_none() {
el.set_attr("id", make_id());
}
self.send(Packet::Stanza(el)).await
self.send(Packet::Stanza(add_stanza_id(stanza, ns::JABBER_CLIENT)))
.await
}
/// End connection by sending `</stream:stream>`