From 71e2b1c84fef31b8c33ccaaeba2426df8b26aae4 Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 2 Aug 2018 00:19:06 +0200 Subject: [PATCH] add XMPPStream.send_stanza() convenience method --- src/client/auth.rs | 2 +- src/client/bind.rs | 6 ++---- src/component/auth.rs | 4 ++-- src/xmpp_stream.rs | 10 +++++++++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/client/auth.rs b/src/client/auth.rs index ef828b3..36f6605 100644 --- a/src/client/auth.rs +++ b/src/client/auth.rs @@ -76,7 +76,7 @@ impl ClientAuth { .append(content.to_base64(base64::STANDARD)) .build(); - let send = stream.send(Packet::Stanza(nonza)); + let send = stream.send_stanza(nonza); self.state = ClientAuthState::WaitSend(send); } diff --git a/src/client/bind.rs b/src/client/bind.rs index d258f7b..348fc30 100644 --- a/src/client/bind.rs +++ b/src/client/bind.rs @@ -32,10 +32,8 @@ impl ClientBind { ClientBind::Unsupported(stream), Some(_) => { let resource = stream.jid.resource.clone(); - let iq = Element::from( - Bind::new(resource) - ); - let send = stream.send(Packet::Stanza(iq)); + let iq = Bind::new(resource); + let send = stream.send_stanza(iq); ClientBind::WaitSend(send) }, } diff --git a/src/component/auth.rs b/src/component/auth.rs index 2149da8..d53cc67 100644 --- a/src/component/auth.rs +++ b/src/component/auth.rs @@ -34,8 +34,8 @@ impl ComponentAuth { } fn send(&mut self, stream: XMPPStream, handshake: Handshake) { - let nonza = Element::from(handshake); - let send = stream.send(Packet::Stanza(nonza)); + let nonza = handshake; + let send = stream.send_stanza(nonza); self.state = ComponentAuthState::WaitSend(send); } diff --git a/src/xmpp_stream.rs b/src/xmpp_stream.rs index 29f7d2e..e5ba9fc 100644 --- a/src/xmpp_stream.rs +++ b/src/xmpp_stream.rs @@ -1,10 +1,11 @@ use futures::{Poll, Stream, Sink, StartSend}; +use futures::sink::Send; use tokio_io::{AsyncRead, AsyncWrite}; use tokio_codec::Framed; use minidom::Element; use jid::Jid; -use xmpp_codec::XMPPCodec; +use xmpp_codec::{XMPPCodec, Packet}; use stream_start::StreamStart; pub const NS_XMPP_STREAM: &str = "http://etherx.jabber.org/streams"; @@ -38,6 +39,13 @@ impl XMPPStream { } } +impl XMPPStream { + /// Convenience method + pub fn send_stanza>(self, e: E) -> Send { + self.send(Packet::Stanza(e.into())) + } +} + /// Proxy to self.stream impl Sink for XMPPStream { type SinkItem = as Sink>::SinkItem;