tokio_xmpp: Replace std stuff with alloc/core stuff
This commit is contained in:
parent
668cc05445
commit
1ce2f894aa
12 changed files with 27 additions and 28 deletions
|
|
@ -10,10 +10,10 @@
|
||||||
//! as good as it can, transparently reconnecting on interruptions of the TCP
|
//! as good as it can, transparently reconnecting on interruptions of the TCP
|
||||||
//! stream.
|
//! stream.
|
||||||
|
|
||||||
|
use core::str::FromStr;
|
||||||
|
use core::time::Duration;
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::str::FromStr;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
|
use alloc::borrow::Cow;
|
||||||
|
use core::str::FromStr;
|
||||||
use futures::{SinkExt, StreamExt};
|
use futures::{SinkExt, StreamExt};
|
||||||
use sasl::client::mechanisms::{Anonymous, Plain, Scram};
|
use sasl::client::mechanisms::{Anonymous, Plain, Scram};
|
||||||
use sasl::client::Mechanism;
|
use sasl::client::Mechanism;
|
||||||
use sasl::common::scram::{Sha1, Sha256};
|
use sasl::common::scram::{Sha1, Sha256};
|
||||||
use sasl::common::Credentials;
|
use sasl::common::Credentials;
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::str::FromStr;
|
|
||||||
use tokio::io::{AsyncBufRead, AsyncWrite};
|
use tokio::io::{AsyncBufRead, AsyncWrite};
|
||||||
use xmpp_parsers::{
|
use xmpp_parsers::{
|
||||||
jid::Jid,
|
jid::Jid,
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,8 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
use core::{pin::Pin, task::Context};
|
||||||
use futures::{ready, task::Poll, Stream};
|
use futures::{ready, task::Poll, Stream};
|
||||||
use std::pin::Pin;
|
|
||||||
use std::task::Context;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
client::Client,
|
client::Client,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use core::{fmt, net::SocketAddr};
|
||||||
#[cfg(feature = "dns")]
|
#[cfg(feature = "dns")]
|
||||||
use futures::{future::select_ok, FutureExt};
|
use futures::{future::select_ok, FutureExt};
|
||||||
#[cfg(feature = "dns")]
|
#[cfg(feature = "dns")]
|
||||||
|
|
@ -6,7 +7,6 @@ use hickory_resolver::{
|
||||||
};
|
};
|
||||||
#[cfg(feature = "dns")]
|
#[cfg(feature = "dns")]
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use std::net::SocketAddr;
|
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
@ -43,8 +43,8 @@ pub enum DnsConfig {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for DnsConfig {
|
impl fmt::Display for DnsConfig {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(feature = "dns")]
|
#[cfg(feature = "dns")]
|
||||||
Self::UseSrv { host, .. } => write!(f, "{}", host),
|
Self::UseSrv { host, .. } => write!(f, "{}", host),
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ pub trait AsyncReadAndWrite: AsyncBufRead + AsyncWrite + Unpin + Send {}
|
||||||
impl<T: AsyncBufRead + AsyncWrite + Unpin + Send> AsyncReadAndWrite for T {}
|
impl<T: AsyncBufRead + AsyncWrite + Unpin + Send> AsyncReadAndWrite for T {}
|
||||||
|
|
||||||
/// Trait that must be extended by the implementation of ServerConnector
|
/// Trait that must be extended by the implementation of ServerConnector
|
||||||
pub trait ServerConnectorError: std::error::Error + Sync + Send {}
|
pub trait ServerConnectorError: core::error::Error + Sync + Send {}
|
||||||
|
|
||||||
/// Trait called to connect to an XMPP server, perhaps called multiple times
|
/// Trait called to connect to an XMPP server, perhaps called multiple times
|
||||||
pub trait ServerConnector: Clone + core::fmt::Debug + Send + Unpin + 'static {
|
pub trait ServerConnector: Clone + core::fmt::Debug + Send + Unpin + 'static {
|
||||||
|
|
@ -37,7 +37,7 @@ pub trait ServerConnector: Clone + core::fmt::Debug + Send + Unpin + 'static {
|
||||||
jid: &Jid,
|
jid: &Jid,
|
||||||
ns: &'static str,
|
ns: &'static str,
|
||||||
timeouts: Timeouts,
|
timeouts: Timeouts,
|
||||||
) -> impl std::future::Future<
|
) -> impl core::future::Future<
|
||||||
Output = Result<(PendingFeaturesRecv<Self::Stream>, ChannelBinding), Error>,
|
Output = Result<(PendingFeaturesRecv<Self::Stream>, ChannelBinding), Error>,
|
||||||
> + Send;
|
> + Send;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
//! `starttls::ServerConfig` provides a `ServerConnector` for starttls connections
|
//! `starttls::ServerConfig` provides a `ServerConnector` for starttls connections
|
||||||
|
|
||||||
|
use alloc::borrow::Cow;
|
||||||
|
use core::{error::Error as StdError, fmt};
|
||||||
#[cfg(feature = "tls-native")]
|
#[cfg(feature = "tls-native")]
|
||||||
use native_tls::Error as TlsError;
|
use native_tls::Error as TlsError;
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::error::Error as StdError;
|
|
||||||
use std::fmt;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::os::fd::AsRawFd;
|
use std::os::fd::AsRawFd;
|
||||||
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
||||||
|
|
@ -16,7 +15,7 @@ use futures::{sink::SinkExt, stream::StreamExt};
|
||||||
|
|
||||||
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
||||||
use {
|
use {
|
||||||
std::sync::Arc,
|
alloc::sync::Arc,
|
||||||
tokio_rustls::{
|
tokio_rustls::{
|
||||||
rustls::pki_types::ServerName,
|
rustls::pki_types::ServerName,
|
||||||
rustls::{ClientConfig, RootCertStore},
|
rustls::{ClientConfig, RootCertStore},
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
//! `starttls::ServerConfig` provides a `ServerConnector` for starttls connections
|
//! `starttls::ServerConfig` provides a `ServerConnector` for starttls connections
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use alloc::borrow::Cow;
|
||||||
|
|
||||||
use tokio::{io::BufStream, net::TcpStream};
|
use tokio::{io::BufStream, net::TcpStream};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
|
use core::{error::Error as StdError, fmt, net::AddrParseError, str::Utf8Error};
|
||||||
#[cfg(feature = "dns")]
|
#[cfg(feature = "dns")]
|
||||||
use hickory_resolver::{
|
use hickory_resolver::{
|
||||||
error::ResolveError as DnsResolveError, proto::error::ProtoError as DnsProtoError,
|
error::ResolveError as DnsResolveError, proto::error::ProtoError as DnsProtoError,
|
||||||
};
|
};
|
||||||
use sasl::client::MechanismError as SaslMechanismError;
|
use sasl::client::MechanismError as SaslMechanismError;
|
||||||
use std::error::Error as StdError;
|
|
||||||
use std::fmt;
|
|
||||||
use std::io::Error as IoError;
|
use std::io::Error as IoError;
|
||||||
use std::net::AddrParseError;
|
|
||||||
use std::str::Utf8Error;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
connect::ServerConnectorError, jid, minidom,
|
connect::ServerConnectorError, jid, minidom,
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ compile_error!(
|
||||||
"when starttls feature enabled one of tls-native and tls-rust features must be enabled."
|
"when starttls feature enabled one of tls-native and tls-rust features must be enabled."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
pub use parsers::{jid, minidom};
|
pub use parsers::{jid, minidom};
|
||||||
pub use xmpp_parsers as parsers;
|
pub use xmpp_parsers as parsers;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
use core::future::Future;
|
use alloc::borrow::Cow;
|
||||||
use core::pin::Pin;
|
use core::{
|
||||||
use core::task::{Context, Poll};
|
future::Future,
|
||||||
use core::time::Duration;
|
pin::Pin,
|
||||||
use std::borrow::Cow;
|
task::{Context, Poll},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use futures::{ready, Sink, SinkExt, Stream, StreamExt};
|
use futures::{ready, Sink, SinkExt, Stream, StreamExt};
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ struct LogXsoBuf<'x>(&'x [u8]);
|
||||||
impl<'x> fmt::Display for LogXsoBuf<'x> {
|
impl<'x> fmt::Display for LogXsoBuf<'x> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
// We always generate UTF-8, so this should be good... I think.
|
// We always generate UTF-8, so this should be good... I think.
|
||||||
let text = std::str::from_utf8(&self.0).unwrap();
|
let text = core::str::from_utf8(&self.0).unwrap();
|
||||||
#[cfg(feature = "syntax-highlighting")]
|
#[cfg(feature = "syntax-highlighting")]
|
||||||
let text = highlight_xml(text);
|
let text = highlight_xml(text);
|
||||||
f.write_str(&text)
|
f.write_str(&text)
|
||||||
|
|
@ -195,7 +195,7 @@ impl fmt::Display for ReadError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::error::Error for ReadError {
|
impl core::error::Error for ReadError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
|
||||||
match self {
|
match self {
|
||||||
ReadError::HardError(e) => Some(e),
|
ReadError::HardError(e) => Some(e),
|
||||||
ReadError::ParseError(e) => Some(e),
|
ReadError::ParseError(e) => Some(e),
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
use std::time::Duration;
|
use core::time::Duration;
|
||||||
|
|
||||||
use futures::{SinkExt, StreamExt};
|
use futures::{SinkExt, StreamExt};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue