add XMPPStream.send_stanza() convenience method

This commit is contained in:
Astro 2018-08-02 00:19:06 +02:00
parent 06b97ea228
commit 71e2b1c84f
4 changed files with 14 additions and 8 deletions

View file

@ -76,7 +76,7 @@ impl<S: AsyncWrite> ClientAuth<S> {
.append(content.to_base64(base64::STANDARD)) .append(content.to_base64(base64::STANDARD))
.build(); .build();
let send = stream.send(Packet::Stanza(nonza)); let send = stream.send_stanza(nonza);
self.state = ClientAuthState::WaitSend(send); self.state = ClientAuthState::WaitSend(send);
} }

View file

@ -32,10 +32,8 @@ impl<S: AsyncWrite> ClientBind<S> {
ClientBind::Unsupported(stream), ClientBind::Unsupported(stream),
Some(_) => { Some(_) => {
let resource = stream.jid.resource.clone(); let resource = stream.jid.resource.clone();
let iq = Element::from( let iq = Bind::new(resource);
Bind::new(resource) let send = stream.send_stanza(iq);
);
let send = stream.send(Packet::Stanza(iq));
ClientBind::WaitSend(send) ClientBind::WaitSend(send)
}, },
} }

View file

@ -34,8 +34,8 @@ impl<S: AsyncWrite> ComponentAuth<S> {
} }
fn send(&mut self, stream: XMPPStream<S>, handshake: Handshake) { fn send(&mut self, stream: XMPPStream<S>, handshake: Handshake) {
let nonza = Element::from(handshake); let nonza = handshake;
let send = stream.send(Packet::Stanza(nonza)); let send = stream.send_stanza(nonza);
self.state = ComponentAuthState::WaitSend(send); self.state = ComponentAuthState::WaitSend(send);
} }

View file

@ -1,10 +1,11 @@
use futures::{Poll, Stream, Sink, StartSend}; use futures::{Poll, Stream, Sink, StartSend};
use futures::sink::Send;
use tokio_io::{AsyncRead, AsyncWrite}; use tokio_io::{AsyncRead, AsyncWrite};
use tokio_codec::Framed; use tokio_codec::Framed;
use minidom::Element; use minidom::Element;
use jid::Jid; use jid::Jid;
use xmpp_codec::XMPPCodec; use xmpp_codec::{XMPPCodec, Packet};
use stream_start::StreamStart; use stream_start::StreamStart;
pub const NS_XMPP_STREAM: &str = "http://etherx.jabber.org/streams"; pub const NS_XMPP_STREAM: &str = "http://etherx.jabber.org/streams";
@ -38,6 +39,13 @@ impl<S: AsyncRead + AsyncWrite> XMPPStream<S> {
} }
} }
impl<S: AsyncWrite> XMPPStream<S> {
/// Convenience method
pub fn send_stanza<E: Into<Element>>(self, e: E) -> Send<Self> {
self.send(Packet::Stanza(e.into()))
}
}
/// Proxy to self.stream /// Proxy to self.stream
impl<S: AsyncWrite> Sink for XMPPStream<S> { impl<S: AsyncWrite> Sink for XMPPStream<S> {
type SinkItem = <Framed<S, XMPPCodec> as Sink>::SinkItem; type SinkItem = <Framed<S, XMPPCodec> as Sink>::SinkItem;