From 9151461b109159cade9494b7c719e0e38fb01d18 Mon Sep 17 00:00:00 2001 From: xmppftw Date: Mon, 5 Aug 2024 15:41:27 +0200 Subject: [PATCH] TCP connector is now in connect module --- tokio-xmpp/examples/echo_component.rs | 2 +- tokio-xmpp/src/{connect.rs => connect/mod.rs} | 3 +++ tokio-xmpp/src/{tcp/mod.rs => connect/tcp.rs} | 15 ++++++----- tokio-xmpp/src/lib.rs | 2 -- tokio-xmpp/src/tcp/component.rs | 10 ------- tokio-xmpp/src/tcp/error.rs | 26 ------------------- 6 files changed, 13 insertions(+), 45 deletions(-) rename tokio-xmpp/src/{connect.rs => connect/mod.rs} (99%) rename tokio-xmpp/src/{tcp/mod.rs => connect/tcp.rs} (80%) delete mode 100644 tokio-xmpp/src/tcp/component.rs delete mode 100644 tokio-xmpp/src/tcp/error.rs diff --git a/tokio-xmpp/examples/echo_component.rs b/tokio-xmpp/examples/echo_component.rs index bfaf44be..40502c26 100644 --- a/tokio-xmpp/examples/echo_component.rs +++ b/tokio-xmpp/examples/echo_component.rs @@ -3,7 +3,7 @@ use minidom::Element; use std::env::args; use std::process::exit; use std::str::FromStr; -use tokio_xmpp::tcp::TcpComponent as Component; +use tokio_xmpp::connect::tcp::TcpComponent as Component; use xmpp_parsers::jid::Jid; use xmpp_parsers::message::{Body, Message, MessageType}; use xmpp_parsers::presence::{Presence, Show as PresenceShow, Type as PresenceType}; diff --git a/tokio-xmpp/src/connect.rs b/tokio-xmpp/src/connect/mod.rs similarity index 99% rename from tokio-xmpp/src/connect.rs rename to tokio-xmpp/src/connect/mod.rs index 532dcf19..939d0f2c 100644 --- a/tokio-xmpp/src/connect.rs +++ b/tokio-xmpp/src/connect/mod.rs @@ -17,6 +17,9 @@ use xmpp_parsers::jid::Jid; use crate::xmpp_stream::XMPPStream; use crate::Error; +#[cfg(feature="insecure-tcp")] +pub mod tcp; + /// trait returned wrapped in XMPPStream by ServerConnector pub trait AsyncReadAndWrite: AsyncRead + AsyncWrite + Unpin + Send {} impl AsyncReadAndWrite for T {} diff --git a/tokio-xmpp/src/tcp/mod.rs b/tokio-xmpp/src/connect/tcp.rs similarity index 80% rename from tokio-xmpp/src/tcp/mod.rs rename to tokio-xmpp/src/connect/tcp.rs index 508d7627..0ceedc3e 100644 --- a/tokio-xmpp/src/tcp/mod.rs +++ b/tokio-xmpp/src/connect/tcp.rs @@ -4,12 +4,7 @@ use std::sync::Arc; use tokio::net::TcpStream; -use crate::{connect::ServerConnector, xmpp_stream::XMPPStream, Component}; - -use crate::Error; - -mod component; -pub mod error; +use crate::{connect::ServerConnector, xmpp_stream::XMPPStream, Component, Error}; /// Component that connects over TCP pub type TcpComponent = Component; @@ -40,3 +35,11 @@ impl ServerConnector for TcpServerConnector { Ok(XMPPStream::start(stream, jid.clone(), ns.to_owned()).await?) } } + +impl Component { + /// Start a new XMPP component + pub async fn new(jid: &str, password: &str, server: String) -> Result { + Self::new_with_connector(jid, password, TcpServerConnector::new(server)).await + } +} + diff --git a/tokio-xmpp/src/lib.rs b/tokio-xmpp/src/lib.rs index 7b6ed92e..dd1d81f4 100644 --- a/tokio-xmpp/src/lib.rs +++ b/tokio-xmpp/src/lib.rs @@ -23,8 +23,6 @@ compile_error!( #[cfg(feature = "starttls")] pub mod starttls; mod stream_start; -#[cfg(feature = "insecure-tcp")] -pub mod tcp; mod xmpp_codec; pub use crate::xmpp_codec::{Packet, XmppCodec}; mod event; diff --git a/tokio-xmpp/src/tcp/component.rs b/tokio-xmpp/src/tcp/component.rs deleted file mode 100644 index 29a9e621..00000000 --- a/tokio-xmpp/src/tcp/component.rs +++ /dev/null @@ -1,10 +0,0 @@ -use crate::{Component, Error}; - -use super::TcpServerConnector; - -impl Component { - /// Start a new XMPP component - pub async fn new(jid: &str, password: &str, server: String) -> Result { - Self::new_with_connector(jid, password, TcpServerConnector::new(server)).await - } -} diff --git a/tokio-xmpp/src/tcp/error.rs b/tokio-xmpp/src/tcp/error.rs deleted file mode 100644 index f384e588..00000000 --- a/tokio-xmpp/src/tcp/error.rs +++ /dev/null @@ -1,26 +0,0 @@ -//! TCP ServerConnector Error - -use core::fmt; - -/// TCP ServerConnector Error -#[derive(Debug)] -pub enum Error { - /// tokio-xmpp error - TokioXMPP(crate::error::Error), -} - -impl std::error::Error for Error {} - -impl fmt::Display for Error { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - match self { - Error::TokioXMPP(e) => write!(fmt, "TokioXMPP error: {}", e), - } - } -} - -impl From for Error { - fn from(e: crate::error::Error) -> Self { - Error::TokioXMPP(e) - } -}