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:
parent
bc73af1e5e
commit
ae67949e7a
4 changed files with 25 additions and 19 deletions
|
|
@ -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>`
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use super::bind::bind;
|
|||
use crate::happy_eyeballs::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};
|
||||
|
||||
/// A simple XMPP client connection
|
||||
|
|
@ -98,11 +98,11 @@ impl Client {
|
|||
where
|
||||
E: Into<Element>,
|
||||
{
|
||||
let mut el: Element = stanza.into();
|
||||
if el.attr("id").is_none() {
|
||||
el.set_attr("id", make_id());
|
||||
}
|
||||
self.send(Packet::Stanza(el.into())).await
|
||||
self.send(Packet::Stanza(add_stanza_id(
|
||||
stanza.into(),
|
||||
ns::JABBER_CLIENT,
|
||||
)))
|
||||
.await
|
||||
}
|
||||
|
||||
/// End connection by sending `</stream:stream>`
|
||||
|
|
|
|||
Loading…
Reference in a new issue