2018-12-18 18:04:31 +00:00
|
|
|
use native_tls::Error as TlsError;
|
2018-09-06 15:46:06 +00:00
|
|
|
use std::borrow::Cow;
|
2018-12-18 18:04:31 +00:00
|
|
|
use std::error::Error as StdError;
|
2018-09-06 15:46:06 +00:00
|
|
|
use std::fmt;
|
2018-12-18 18:04:31 +00:00
|
|
|
use std::io::Error as IoError;
|
|
|
|
use std::str::Utf8Error;
|
2018-09-06 16:20:05 +00:00
|
|
|
use trust_dns_proto::error::ProtoError;
|
2018-12-18 18:04:31 +00:00
|
|
|
use trust_dns_resolver::error::ResolveError;
|
2018-09-06 16:20:05 +00:00
|
|
|
|
2019-01-16 13:35:38 +00:00
|
|
|
use xmpp_parsers::Error as ParsersError;
|
2018-09-06 15:46:06 +00:00
|
|
|
use xmpp_parsers::sasl::DefinedCondition as SaslDefinedCondition;
|
|
|
|
|
2018-09-07 23:42:23 +00:00
|
|
|
/// Top-level error type
|
2018-09-06 15:46:06 +00:00
|
|
|
#[derive(Debug, Error)]
|
|
|
|
pub enum Error {
|
2018-09-07 23:42:23 +00:00
|
|
|
/// I/O error
|
2018-09-06 15:46:06 +00:00
|
|
|
Io(IoError),
|
2018-09-07 23:42:23 +00:00
|
|
|
/// Error resolving DNS and establishing a connection
|
2018-09-06 15:46:06 +00:00
|
|
|
Connection(ConnecterError),
|
|
|
|
/// DNS label conversion error, no details available from module
|
|
|
|
/// `idna`
|
|
|
|
Idna,
|
2018-09-07 23:42:23 +00:00
|
|
|
/// Protocol-level error
|
2018-09-06 15:46:06 +00:00
|
|
|
Protocol(ProtocolError),
|
2018-09-07 23:42:23 +00:00
|
|
|
/// Authentication error
|
2018-09-06 15:46:06 +00:00
|
|
|
Auth(AuthError),
|
2018-09-07 23:42:23 +00:00
|
|
|
/// TLS error
|
2018-09-06 15:46:06 +00:00
|
|
|
Tls(TlsError),
|
2018-12-20 19:39:01 +00:00
|
|
|
/// Connection closed
|
|
|
|
Disconnected,
|
2018-09-06 15:46:06 +00:00
|
|
|
/// Shoud never happen
|
|
|
|
InvalidState,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Causes for stream parsing errors
|
|
|
|
#[derive(Debug, Error)]
|
|
|
|
pub enum ParserError {
|
|
|
|
/// Encoding error
|
|
|
|
Utf8(Utf8Error),
|
|
|
|
/// XML parse error
|
|
|
|
Parse(ParseError),
|
|
|
|
/// Illegal `</>`
|
|
|
|
ShortTag,
|
|
|
|
/// Required by `impl Decoder`
|
|
|
|
IO(IoError),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ParserError> for Error {
|
|
|
|
fn from(e: ParserError) -> Self {
|
|
|
|
ProtocolError::Parser(e).into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// XML parse error wrapper type
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ParseError(pub Cow<'static, str>);
|
|
|
|
|
|
|
|
impl StdError for ParseError {
|
|
|
|
fn description(&self) -> &str {
|
|
|
|
self.0.as_ref()
|
|
|
|
}
|
|
|
|
fn cause(&self) -> Option<&StdError> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for ParseError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-07 23:42:23 +00:00
|
|
|
/// XMPP protocol-level error
|
2018-09-06 15:46:06 +00:00
|
|
|
#[derive(Debug, Error)]
|
|
|
|
pub enum ProtocolError {
|
2018-09-07 23:42:23 +00:00
|
|
|
/// XML parser error
|
2018-09-06 15:46:06 +00:00
|
|
|
Parser(ParserError),
|
2018-09-07 23:42:23 +00:00
|
|
|
/// Error with expected stanza schema
|
2018-09-06 15:46:06 +00:00
|
|
|
#[error(non_std)]
|
|
|
|
Parsers(ParsersError),
|
2018-09-07 23:42:23 +00:00
|
|
|
/// No TLS available
|
2018-09-06 15:46:06 +00:00
|
|
|
NoTls,
|
2018-09-07 23:42:23 +00:00
|
|
|
/// Invalid response to resource binding
|
2018-09-06 15:46:06 +00:00
|
|
|
InvalidBindResponse,
|
2018-09-07 23:42:23 +00:00
|
|
|
/// No xmlns attribute in <stream:stream>
|
2018-09-06 15:46:06 +00:00
|
|
|
NoStreamNamespace,
|
2018-09-07 23:42:23 +00:00
|
|
|
/// No id attribute in <stream:stream>
|
2018-09-06 15:46:06 +00:00
|
|
|
NoStreamId,
|
2018-09-07 23:42:23 +00:00
|
|
|
/// Encountered an unexpected XML token
|
2018-09-06 15:46:06 +00:00
|
|
|
InvalidToken,
|
2019-01-26 20:07:15 +00:00
|
|
|
/// Unexpected <stream:stream> (shouldn't occur)
|
|
|
|
InvalidStreamStart,
|
2018-09-06 15:46:06 +00:00
|
|
|
}
|
|
|
|
|
2018-09-07 23:42:23 +00:00
|
|
|
/// Authentication error
|
2018-09-06 15:46:06 +00:00
|
|
|
#[derive(Debug, Error)]
|
|
|
|
pub enum AuthError {
|
2018-09-07 23:42:23 +00:00
|
|
|
/// No matching SASL mechanism available
|
2018-09-06 15:46:06 +00:00
|
|
|
NoMechanism,
|
2018-09-07 23:42:23 +00:00
|
|
|
/// Local SASL implementation error
|
2018-09-06 15:46:06 +00:00
|
|
|
#[error(no_from, non_std, msg_embedded)]
|
|
|
|
Sasl(String),
|
2018-09-07 23:42:23 +00:00
|
|
|
/// Failure from server
|
2018-09-06 15:46:06 +00:00
|
|
|
#[error(non_std)]
|
|
|
|
Fail(SaslDefinedCondition),
|
2018-09-07 23:42:23 +00:00
|
|
|
/// Component authentication failure
|
2018-09-06 15:46:06 +00:00
|
|
|
#[error(no_from)]
|
|
|
|
ComponentFail,
|
|
|
|
}
|
|
|
|
|
2018-09-07 23:42:23 +00:00
|
|
|
/// Error establishing connection
|
2019-01-17 00:24:26 +00:00
|
|
|
#[derive(Debug)]
|
2018-09-06 15:46:06 +00:00
|
|
|
pub enum ConnecterError {
|
2018-09-07 23:42:23 +00:00
|
|
|
/// All attempts failed, no error available
|
2018-09-06 15:46:06 +00:00
|
|
|
AllFailed,
|
2018-09-07 23:42:23 +00:00
|
|
|
/// DNS protocol error
|
2018-09-06 16:20:05 +00:00
|
|
|
Dns(ProtoError),
|
|
|
|
/// DNS resolution error
|
|
|
|
Resolve(ResolveError),
|
|
|
|
}
|
2019-01-17 00:24:26 +00:00
|
|
|
|
|
|
|
impl std::error::Error for ConnecterError {}
|
|
|
|
|
|
|
|
impl std::fmt::Display for ConnecterError {
|
|
|
|
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
|
|
|
write!(fmt, "{:?}", self)
|
|
|
|
}
|
|
|
|
}
|