unstringify Error type
This commit is contained in:
parent
2e0dd44352
commit
e9d30f16c3
12 changed files with 279 additions and 167 deletions
|
|
@ -1,13 +1,15 @@
|
|||
use std::mem::replace;
|
||||
use std::borrow::Cow;
|
||||
// use std::error::Error as StdError;
|
||||
// use std::{fmt, io};
|
||||
use futures::{Future, Async, Poll, Stream, sink, Sink};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use tokio_codec::Framed;
|
||||
use jid::Jid;
|
||||
use minidom::Element;
|
||||
|
||||
use xmpp_codec::{XMPPCodec, Packet, ParserError};
|
||||
use xmpp_codec::{XMPPCodec, Packet};
|
||||
use xmpp_stream::XMPPStream;
|
||||
use {Error, ProtocolError};
|
||||
|
||||
const NS_XMPP_STREAM: &str = "http://etherx.jabber.org/streams";
|
||||
|
||||
|
|
@ -43,7 +45,7 @@ impl<S: AsyncWrite> StreamStart<S> {
|
|||
|
||||
impl<S: AsyncRead + AsyncWrite> Future for StreamStart<S> {
|
||||
type Item = XMPPStream<S>;
|
||||
type Error = ParserError;
|
||||
type Error = Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
let old_state = replace(&mut self.state, StreamStartState::Invalid);
|
||||
|
|
@ -67,7 +69,7 @@ impl<S: AsyncRead + AsyncWrite> Future for StreamStart<S> {
|
|||
let stream_ns = match stream_attrs.get("xmlns") {
|
||||
Some(ns) => ns.clone(),
|
||||
None =>
|
||||
return Err(ParserError::Parse(Cow::from("Missing stream namespace"))),
|
||||
return Err(ProtocolError::NoStreamNamespace.into()),
|
||||
};
|
||||
if self.ns == "jabber:client" {
|
||||
retry = true;
|
||||
|
|
@ -77,7 +79,7 @@ impl<S: AsyncRead + AsyncWrite> Future for StreamStart<S> {
|
|||
let id = match stream_attrs.get("id") {
|
||||
Some(id) => id.clone(),
|
||||
None =>
|
||||
return Err(ParserError::Parse(Cow::from("No stream id"))),
|
||||
return Err(ProtocolError::NoStreamId.into()),
|
||||
};
|
||||
// FIXME: huge hack, shouldn’t be an element!
|
||||
let stream = XMPPStream::new(self.jid.clone(), stream, self.ns.clone(), Element::builder(id).build());
|
||||
|
|
@ -85,11 +87,11 @@ impl<S: AsyncRead + AsyncWrite> Future for StreamStart<S> {
|
|||
}
|
||||
},
|
||||
Ok(Async::Ready(_)) =>
|
||||
return Err(ParserError::Parse(Cow::from("Invalid XML event received"))),
|
||||
return Err(ProtocolError::InvalidToken.into()),
|
||||
Ok(Async::NotReady) =>
|
||||
(StreamStartState::RecvStart(stream), Ok(Async::NotReady)),
|
||||
Err(e) =>
|
||||
return Err(e),
|
||||
return Err(ProtocolError::from(e).into()),
|
||||
},
|
||||
StreamStartState::RecvFeatures(mut stream, stream_ns) =>
|
||||
match stream.poll() {
|
||||
|
|
@ -103,7 +105,7 @@ impl<S: AsyncRead + AsyncWrite> Future for StreamStart<S> {
|
|||
Ok(Async::Ready(_)) | Ok(Async::NotReady) =>
|
||||
(StreamStartState::RecvFeatures(stream, stream_ns), Ok(Async::NotReady)),
|
||||
Err(e) =>
|
||||
return Err(e),
|
||||
return Err(ProtocolError::from(e).into()),
|
||||
},
|
||||
StreamStartState::Invalid =>
|
||||
unreachable!(),
|
||||
|
|
@ -117,3 +119,59 @@ impl<S: AsyncRead + AsyncWrite> Future for StreamStart<S> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #[derive(Debug)]
|
||||
// pub enum StreamStartError {
|
||||
// MissingStreamNs,
|
||||
// MissingStreamId,
|
||||
// Unexpected,
|
||||
// Parser(ParserError),
|
||||
// IO(io::Error),
|
||||
// }
|
||||
|
||||
// impl From<io::Error> for StreamStartError {
|
||||
// fn from(e: io::Error) -> Self {
|
||||
// StreamStartError::IO(e)
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl From<ParserError> for StreamStartError {
|
||||
// fn from(e: ParserError) -> Self {
|
||||
// match e {
|
||||
// ParserError::IO(e) => StreamStartError::IO(e),
|
||||
// _ => StreamStartError::Parser(e)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl StdError for StreamStartError {
|
||||
// fn description(&self) -> &str {
|
||||
// match *self {
|
||||
// StreamStartError::MissingStreamNs => "Missing stream namespace",
|
||||
// StreamStartError::MissingStreamId => "Missing stream id",
|
||||
// StreamStartError::Unexpected => "Unexpected",
|
||||
// StreamStartError::Parser(ref pe) => pe.description(),
|
||||
// StreamStartError::IO(ref ie) => ie.description(),
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn cause(&self) -> Option<&StdError> {
|
||||
// match *self {
|
||||
// StreamStartError::Parser(ref pe) => pe.cause(),
|
||||
// StreamStartError::IO(ref ie) => ie.cause(),
|
||||
// _ => None,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl fmt::Display for StreamStartError {
|
||||
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// match *self {
|
||||
// StreamStartError::MissingStreamNs => write!(f, "Missing stream namespace"),
|
||||
// StreamStartError::MissingStreamId => write!(f, "Missing stream id"),
|
||||
// StreamStartError::Unexpected => write!(f, "Received unexpected data"),
|
||||
// StreamStartError::Parser(ref pe) => write!(f, "{}", pe),
|
||||
// StreamStartError::IO(ref ie) => write!(f, "{}", ie),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
Loading…
Reference in a new issue