tokio_xmpp: properly process <stream:error/> while waiting for features
Before this, a stream error would not be readable by user code, as the `recv_features()` function would not even attempt to parse it. This change allows application code to react to stream errors which are received before stream features are received. skip-changelog, because there's no release with the xmlstream module yet.
This commit is contained in:
parent
af7e47a791
commit
e438813fb2
6 changed files with 157 additions and 17 deletions
|
|
@ -6,9 +6,11 @@ use hickory_resolver::{
|
|||
use sasl::client::MechanismError as SaslMechanismError;
|
||||
use std::io;
|
||||
|
||||
use xmpp_parsers::stream_error::ReceivedStreamError;
|
||||
|
||||
use crate::{
|
||||
connect::ServerConnectorError, jid, minidom,
|
||||
parsers::sasl::DefinedCondition as SaslDefinedCondition,
|
||||
parsers::sasl::DefinedCondition as SaslDefinedCondition, xmlstream::RecvFeaturesError,
|
||||
};
|
||||
|
||||
/// Top-level error type
|
||||
|
|
@ -44,6 +46,8 @@ pub enum Error {
|
|||
Idna,
|
||||
/// Invalid IP/Port address
|
||||
Addr(AddrParseError),
|
||||
/// Received a stream error
|
||||
StreamError(ReceivedStreamError),
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
|
|
@ -65,6 +69,7 @@ impl fmt::Display for Error {
|
|||
#[cfg(feature = "dns")]
|
||||
Error::Idna => write!(fmt, "IDNA error"),
|
||||
Error::Addr(e) => write!(fmt, "Wrong network address: {e}"),
|
||||
Error::StreamError(e) => write!(fmt, "{e}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -140,6 +145,15 @@ impl From<AddrParseError> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<RecvFeaturesError> for Error {
|
||||
fn from(e: RecvFeaturesError) -> Self {
|
||||
match e {
|
||||
RecvFeaturesError::Io(e) => e.into(),
|
||||
RecvFeaturesError::StreamError(e) => Self::StreamError(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// XMPP protocol-level error
|
||||
#[derive(Debug)]
|
||||
pub enum ProtocolError {
|
||||
|
|
|
|||
Loading…
Reference in a new issue