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
|
|
@ -14,11 +14,24 @@ use crate::stream_start;
|
|||
use crate::xmpp_codec::{Packet, XMPPCodec};
|
||||
use crate::Error;
|
||||
|
||||
pub(crate) fn make_id() -> String {
|
||||
fn make_id() -> String {
|
||||
let id: u64 = thread_rng().gen();
|
||||
format!("{}", id)
|
||||
}
|
||||
|
||||
pub(crate) fn add_stanza_id(mut stanza: Element, default_ns: &str) -> Element {
|
||||
if stanza.is("iq", default_ns)
|
||||
|| stanza.is("message", default_ns)
|
||||
|| stanza.is("presence", default_ns)
|
||||
{
|
||||
if stanza.attr("id").is_none() {
|
||||
stanza.set_attr("id", make_id());
|
||||
}
|
||||
}
|
||||
|
||||
stanza
|
||||
}
|
||||
|
||||
/// Wraps a binary stream (tokio's `AsyncRead + AsyncWrite`) to decode
|
||||
/// and encode XMPP packets.
|
||||
///
|
||||
|
|
|
|||
Loading…
Reference in a new issue