diff options
author | 2024-12-04 18:18:37 +0000 | |
---|---|---|
committer | 2024-12-04 18:18:37 +0000 | |
commit | 1b91ff690488b65b552c90bd5392b9a300c8c981 (patch) | |
tree | 9c290f69b26eba0393d7bbc05ba29c28ea74a26e /jabber/src | |
parent | 03764f8cedb3f0a55a61be0f0a59faaa6357a83a (diff) | |
download | luz-1b91ff690488b65b552c90bd5392b9a300c8c981.tar.gz luz-1b91ff690488b65b552c90bd5392b9a300c8c981.tar.bz2 luz-1b91ff690488b65b552c90bd5392b9a300c8c981.zip |
use cargo workspace
Diffstat (limited to '')
-rw-r--r-- | jabber/src/client.rs (renamed from src/client.rs) | 45 | ||||
-rw-r--r-- | jabber/src/connection.rs (renamed from src/connection.rs) | 0 | ||||
-rw-r--r-- | jabber/src/error.rs (renamed from src/error.rs) | 8 | ||||
-rw-r--r-- | jabber/src/jabber_stream.rs (renamed from src/jabber_stream.rs) | 19 | ||||
-rw-r--r-- | jabber/src/lib.rs (renamed from src/lib.rs) | 2 |
5 files changed, 21 insertions, 53 deletions
diff --git a/src/client.rs b/jabber/src/client.rs index e94008d..c8b0b73 100644 --- a/src/client.rs +++ b/jabber/src/client.rs @@ -1,16 +1,16 @@ use std::{pin::pin, sync::Arc, task::Poll}; use futures::{Sink, Stream, StreamExt}; +use jid::ParseError; use rsasl::config::SASLConfig; +use stanza::{ + client::Stanza, + sasl::Mechanisms, + stream::{Feature, Features}, +}; use crate::{ connection::{Tls, Unencrypted}, - jid::ParseError, - stanza::{ - client::Stanza, - sasl::Mechanisms, - stream::{Feature, Features}, - }, Connection, Error, JabberStream, Result, JID, }; @@ -113,7 +113,7 @@ impl ConnectionState { )) } Connecting::InsecureGotFeatures((features, jabber_stream)) => { - match features.negotiate()? { + match features.negotiate().ok_or(Error::Negotiation)? { Feature::StartTls(_start_tls) => { self = ConnectionState::Connecting(Connecting::StartTls(jabber_stream)) @@ -138,7 +138,7 @@ impl ConnectionState { )) } Connecting::GotFeatures((features, jabber_stream)) => { - match features.negotiate()? { + match features.negotiate().ok_or(Error::Negotiation)? { Feature::StartTls(_start_tls) => return Err(Error::AlreadyTls), Feature::Sasl(mechanisms) => { self = ConnectionState::Connecting(Connecting::Sasl( @@ -190,35 +190,6 @@ impl Connecting { } } -impl Features { - pub fn negotiate(self) -> Result<Feature> { - if let Some(Feature::StartTls(s)) = self - .features - .iter() - .find(|feature| matches!(feature, Feature::StartTls(_s))) - { - // TODO: avoid clone - return Ok(Feature::StartTls(s.clone())); - } else if let Some(Feature::Sasl(mechanisms)) = self - .features - .iter() - .find(|feature| matches!(feature, Feature::Sasl(_))) - { - // TODO: avoid clone - return Ok(Feature::Sasl(mechanisms.clone())); - } else if let Some(Feature::Bind) = self - .features - .into_iter() - .find(|feature| matches!(feature, Feature::Bind)) - { - Ok(Feature::Bind) - } else { - // TODO: better error - return Err(Error::Negotiation); - } - } -} - pub enum InsecureConnecting { Disconnected, ConnectionEstablished(Connection), diff --git a/src/connection.rs b/jabber/src/connection.rs index bc5a282..bc5a282 100644 --- a/src/connection.rs +++ b/jabber/src/connection.rs diff --git a/src/error.rs b/jabber/src/error.rs index 8875ebb..aad033c 100644 --- a/src/error.rs +++ b/jabber/src/error.rs @@ -1,10 +1,10 @@ use std::str::Utf8Error; +use jid::ParseError; use rsasl::mechname::MechanismNameError; - -use crate::stanza::client::error::Error as ClientError; -use crate::stanza::stream::Error as StreamError; -use crate::{jid::ParseError, stanza::sasl::Failure}; +use stanza::client::error::Error as ClientError; +use stanza::sasl::Failure; +use stanza::stream::Error as StreamError; #[derive(Debug)] pub enum Error { diff --git a/src/jabber_stream.rs b/jabber/src/jabber_stream.rs index 8ee45b5..dd0dcbf 100644 --- a/src/jabber_stream.rs +++ b/jabber/src/jabber_stream.rs @@ -2,26 +2,25 @@ use std::pin::pin; use std::str::{self, FromStr}; use std::sync::Arc; -use async_recursion::async_recursion; use futures::StreamExt; +use jid::JID; use peanuts::element::{FromContent, IntoElement}; use peanuts::{Reader, Writer}; use rsasl::prelude::{Mechname, SASLClient, SASLConfig}; +use stanza::bind::{Bind, BindType, FullJidType, ResourceType}; +use stanza::client::iq::{Iq, IqType, Query}; +use stanza::client::Stanza; +use stanza::sasl::{Auth, Challenge, Mechanisms, Response, ServerResponse}; +use stanza::starttls::{Proceed, StartTls}; +use stanza::stream::{Features, Stream}; +use stanza::XML_VERSION; use tokio::io::{AsyncRead, AsyncWrite, ReadHalf, WriteHalf}; use tokio_native_tls::native_tls::TlsConnector; use tracing::{debug, instrument}; use crate::connection::{Tls, Unencrypted}; use crate::error::Error; -use crate::stanza::bind::{Bind, BindType, FullJidType, ResourceType}; -use crate::stanza::client::iq::{Iq, IqType, Query}; -use crate::stanza::client::Stanza; -use crate::stanza::sasl::{Auth, Challenge, Mechanisms, Response, ServerResponse}; -use crate::stanza::starttls::{Proceed, StartTls}; -use crate::stanza::stream::{Feature, Features, Stream}; -use crate::stanza::XML_VERSION; -use crate::JID; -use crate::{Connection, Result}; +use crate::Result; // open stream (streams started) pub struct JabberStream<S> { diff --git a/src/lib.rs b/jabber/src/lib.rs index 43aa581..bcd63db 100644 --- a/src/lib.rs +++ b/jabber/src/lib.rs @@ -6,8 +6,6 @@ pub mod client; pub mod connection; pub mod error; pub mod jabber_stream; -pub mod jid; -pub mod stanza; pub use connection::Connection; use connection::Tls; |