use std::collections::HashMap; use futures::*; use tokio_io::{AsyncRead, AsyncWrite}; use tokio_io::codec::Framed; use xml; use jid::Jid; use xmpp_codec::*; use stream_start::*; pub const NS_XMPP_STREAM: &str = "http://etherx.jabber.org/streams"; pub struct XMPPStream { pub jid: Jid, pub stream: Framed, pub stream_attrs: HashMap, pub stream_features: xml::Element, } impl XMPPStream { pub fn new(jid: Jid, stream: Framed, stream_attrs: HashMap, stream_features: xml::Element) -> Self { XMPPStream { jid, stream, stream_attrs, stream_features } } pub fn from_stream(stream: S, jid: Jid) -> StreamStart { let xmpp_stream = AsyncRead::framed(stream, XMPPCodec::new()); StreamStart::from_stream(xmpp_stream, jid) } pub fn into_inner(self) -> S { self.stream.into_inner() } pub fn restart(self) -> StreamStart { Self::from_stream(self.stream.into_inner(), self.jid) } } /// Proxy to self.stream impl Sink for XMPPStream { type SinkItem = as Sink>::SinkItem; type SinkError = as Sink>::SinkError; fn start_send(&mut self, item: Self::SinkItem) -> StartSend { self.stream.start_send(item) } fn poll_complete(&mut self) -> Poll<(), Self::SinkError> { self.stream.poll_complete() } } /// Proxy to self.stream impl Stream for XMPPStream { type Item = as Stream>::Item; type Error = as Stream>::Error; fn poll(&mut self) -> Poll, Self::Error> { self.stream.poll() } }