aboutsummaryrefslogtreecommitdiffstats
path: root/stanza/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 /stanza/src
parent03764f8cedb3f0a55a61be0f0a59faaa6357a83a (diff)
downloadluz-1b91ff690488b65b552c90bd5392b9a300c8c981.tar.gz
luz-1b91ff690488b65b552c90bd5392b9a300c8c981.tar.bz2
luz-1b91ff690488b65b552c90bd5392b9a300c8c981.zip
use cargo workspace
Diffstat (limited to '')
-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
12 files changed, 40 insertions, 37 deletions
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