aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2024-12-04 18:18:37 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2024-12-04 18:18:37 +0000
commit1b91ff690488b65b552c90bd5392b9a300c8c981 (patch)
tree9c290f69b26eba0393d7bbc05ba29c28ea74a26e /src
parent03764f8cedb3f0a55a61be0f0a59faaa6357a83a (diff)
downloadluz-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
-rw-r--r--jid/src/lib.rs (renamed from src/jid.rs)9
-rw-r--r--stanza/src/bind.rs (renamed from src/stanza/bind.rs)3
-rw-r--r--stanza/src/client/error.rs (renamed from src/stanza/client/error.rs)4
-rw-r--r--stanza/src/client/iq.rs (renamed from src/stanza/client/iq.rs)8
-rw-r--r--stanza/src/client/message.rs (renamed from src/stanza/client/message.rs)3
-rw-r--r--stanza/src/client/mod.rs (renamed from src/stanza/client/mod.rs)0
-rw-r--r--stanza/src/client/presence.rs (renamed from src/stanza/client/presence.rs)3
-rw-r--r--stanza/src/lib.rs (renamed from src/stanza/mod.rs)0
-rw-r--r--stanza/src/sasl.rs (renamed from src/stanza/sasl.rs)6
-rw-r--r--stanza/src/stanza_error.rs (renamed from src/stanza/stanza_error.rs)0
-rw-r--r--stanza/src/starttls.rs (renamed from src/stanza/starttls.rs)0
-rw-r--r--stanza/src/stream.rs (renamed from src/stanza/stream.rs)50
-rw-r--r--stanza/src/stream_error.rs (renamed from src/stanza/stream_error.rs)0
18 files changed, 61 insertions, 99 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;
diff --git a/src/jid.rs b/jid/src/lib.rs
index 233227a..ff1d82b 100644
--- a/src/jid.rs
+++ b/jid/src/lib.rs
@@ -19,15 +19,6 @@ pub enum ParseError {
Malformed(String),
}
-impl From<ParseError> for peanuts::Error {
- fn from(e: ParseError) -> Self {
- match e {
- ParseError::Empty => peanuts::Error::DeserializeError("".to_string()),
- ParseError::Malformed(e) => peanuts::Error::DeserializeError(e),
- }
- }
-}
-
impl JID {
pub fn new(
localpart: Option<String>,
diff --git a/src/stanza/bind.rs b/stanza/src/bind.rs
index 0e67a83..155fd1b 100644
--- a/src/stanza/bind.rs
+++ b/stanza/src/bind.rs
@@ -1,10 +1,9 @@
+use jid::JID;
use peanuts::{
element::{FromElement, IntoElement},
Element,
};
-use crate::JID;
-
pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-bind";
#[derive(Clone)]
diff --git a/src/stanza/client/error.rs b/stanza/src/client/error.rs
index 545b9a7..689953a 100644
--- a/src/stanza/client/error.rs
+++ b/stanza/src/client/error.rs
@@ -3,8 +3,8 @@ use std::str::FromStr;
use peanuts::element::{FromElement, IntoElement};
use peanuts::{DeserializeError, Element};
-use crate::stanza::stanza_error::Error as StanzaError;
-use crate::stanza::stanza_error::Text;
+use crate::stanza_error::Error as StanzaError;
+use crate::stanza_error::Text;
use super::XMLNS;
diff --git a/src/stanza/client/iq.rs b/stanza/src/client/iq.rs
index b23f8b7..388979e 100644
--- a/src/stanza/client/iq.rs
+++ b/stanza/src/client/iq.rs
@@ -1,16 +1,14 @@
use std::str::FromStr;
+use jid::JID;
use peanuts::{
element::{FromElement, IntoElement},
DeserializeError, Element, XML_NS,
};
use crate::{
- stanza::{
- bind::{self, Bind},
- client::error::Error,
- },
- JID,
+ bind::{self, Bind},
+ client::error::Error,
};
use super::XMLNS;
diff --git a/src/stanza/client/message.rs b/stanza/src/client/message.rs
index 626d781..b9d995f 100644
--- a/src/stanza/client/message.rs
+++ b/stanza/src/client/message.rs
@@ -1,12 +1,11 @@
use std::str::FromStr;
+use jid::JID;
use peanuts::{
element::{FromElement, IntoElement},
DeserializeError, Element, XML_NS,
};
-use crate::JID;
-
use super::XMLNS;
pub struct Message {
diff --git a/src/stanza/client/mod.rs b/stanza/src/client/mod.rs
index 2b063d6..2b063d6 100644
--- a/src/stanza/client/mod.rs
+++ b/stanza/src/client/mod.rs
diff --git a/src/stanza/client/presence.rs b/stanza/src/client/presence.rs
index bcb04d4..dd14bff 100644
--- a/src/stanza/client/presence.rs
+++ b/stanza/src/client/presence.rs
@@ -1,12 +1,11 @@
use std::str::FromStr;
+use jid::JID;
use peanuts::{
element::{FromElement, IntoElement},
DeserializeError, Element, XML_NS,
};
-use crate::JID;
-
use super::{error::Error, XMLNS};
pub struct Presence {
diff --git a/src/stanza/mod.rs b/stanza/src/lib.rs
index 32716d3..32716d3 100644
--- a/src/stanza/mod.rs
+++ b/stanza/src/lib.rs
diff --git a/src/stanza/sasl.rs b/stanza/src/sasl.rs
index ec6f63c..0a3f06f 100644
--- a/src/stanza/sasl.rs
+++ b/stanza/src/sasl.rs
@@ -4,7 +4,6 @@ use peanuts::{
element::{FromElement, IntoElement},
DeserializeError, Element,
};
-use tracing::debug;
pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-sasl";
@@ -17,15 +16,11 @@ impl FromElement for Mechanisms {
fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
element.check_name("mechanisms")?;
element.check_namespace(XMLNS)?;
- debug!("getting mechanisms");
let mechanisms: Vec<Mechanism> = element.pop_children()?;
- debug!("gottting mechanisms");
let mechanisms = mechanisms
.into_iter()
.map(|Mechanism(mechanism)| mechanism)
.collect();
- debug!("gottting mechanisms");
-
Ok(Mechanisms { mechanisms })
}
}
@@ -135,7 +130,6 @@ pub enum ServerResponse {
impl FromElement for ServerResponse {
fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
- debug!("identification: {:?}", element.identify());
match element.identify() {
(Some(XMLNS), "challenge") => {
Ok(ServerResponse::Challenge(Challenge::from_element(element)?))
diff --git a/src/stanza/stanza_error.rs b/stanza/src/stanza_error.rs
index 99c1f15..99c1f15 100644
--- a/src/stanza/stanza_error.rs
+++ b/stanza/src/stanza_error.rs
diff --git a/src/stanza/starttls.rs b/stanza/src/starttls.rs
index fb66711..fb66711 100644
--- a/src/stanza/starttls.rs
+++ b/stanza/src/starttls.rs
diff --git a/src/stanza/stream.rs b/stanza/src/stream.rs
index 84d62d9..89b03d8 100644
--- a/src/stanza/stream.rs
+++ b/stanza/src/stream.rs
@@ -1,12 +1,10 @@
use std::collections::{HashMap, HashSet};
+use jid::JID;
use peanuts::element::{Content, ElementBuilder, FromElement, IntoElement, NamespaceDeclaration};
-use peanuts::XML_NS;
use peanuts::{element::Name, Element};
-use tracing::debug;
-use crate::stanza::bind;
-use crate::JID;
+use crate::bind;
use super::sasl::{self, Mechanisms};
use super::starttls::{self, StartTls};
@@ -99,6 +97,34 @@ pub struct Features {
pub features: Vec<Feature>,
}
+impl Features {
+ pub fn negotiate(self) -> Option<Feature> {
+ if let Some(Feature::StartTls(s)) = self
+ .features
+ .iter()
+ .find(|feature| matches!(feature, Feature::StartTls(_s)))
+ {
+ // TODO: avoid clone
+ return Some(Feature::StartTls(s.clone()));
+ } else if let Some(Feature::Sasl(mechanisms)) = self
+ .features
+ .iter()
+ .find(|feature| matches!(feature, Feature::Sasl(_)))
+ {
+ // TODO: avoid clone
+ return Some(Feature::Sasl(mechanisms.clone()));
+ } else if let Some(Feature::Bind) = self
+ .features
+ .into_iter()
+ .find(|feature| matches!(feature, Feature::Bind))
+ {
+ Some(Feature::Bind)
+ } else {
+ return None;
+ }
+ }
+}
+
impl IntoElement for Features {
fn builder(&self) -> ElementBuilder {
Element::builder("features", Some(XMLNS)).push_children(self.features.clone())
@@ -112,9 +138,7 @@ impl FromElement for Features {
element.check_namespace(XMLNS)?;
element.check_name("features")?;
- debug!("got features stanza");
let features = element.children()?;
- debug!("got features period");
Ok(Features { features })
}
@@ -141,25 +165,15 @@ impl IntoElement for Feature {
impl FromElement for Feature {
fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
- let identity = element.identify();
- debug!("identity: {:?}", identity);
match element.identify() {
(Some(starttls::XMLNS), "starttls") => {
- debug!("identified starttls");
Ok(Feature::StartTls(StartTls::from_element(element)?))
}
(Some(sasl::XMLNS), "mechanisms") => {
- debug!("identified mechanisms");
Ok(Feature::Sasl(Mechanisms::from_element(element)?))
}
- (Some(bind::XMLNS), "bind") => {
- debug!("identified bind");
- Ok(Feature::Bind)
- }
- _ => {
- debug!("identified unknown feature");
- Ok(Feature::Unknown)
- }
+ (Some(bind::XMLNS), "bind") => Ok(Feature::Bind),
+ _ => Ok(Feature::Unknown),
}
}
}
diff --git a/src/stanza/stream_error.rs b/stanza/src/stream_error.rs
index 5ae04a6..5ae04a6 100644
--- a/src/stanza/stream_error.rs
+++ b/stanza/src/stream_error.rs