aboutsummaryrefslogtreecommitdiffstats
path: root/src/stanza/stream.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/stanza/stream.rs')
-rw-r--r--src/stanza/stream.rs42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/stanza/stream.rs b/src/stanza/stream.rs
index 40f6ba0..fecace5 100644
--- a/src/stanza/stream.rs
+++ b/src/stanza/stream.rs
@@ -3,9 +3,11 @@ use std::collections::{HashMap, HashSet};
use peanuts::element::{Content, ElementBuilder, FromElement, IntoElement, NamespaceDeclaration};
use peanuts::XML_NS;
use peanuts::{element::Name, Element};
+use tracing::debug;
use crate::{Error, JID};
+use super::sasl::{self, Mechanisms};
use super::starttls::{self, StartTls};
pub const XMLNS: &str = "http://etherx.jabber.org/streams";
@@ -92,32 +94,12 @@ impl<'s> Stream {
#[derive(Debug)]
pub struct Features {
- features: Vec<Feature>,
+ pub features: Vec<Feature>,
}
impl IntoElement for Features {
fn builder(&self) -> ElementBuilder {
Element::builder("features", Some(XMLNS)).push_children(self.features.clone())
- // let mut content = Vec::new();
- // for feature in &self.features {
- // match feature {
- // Feature::StartTls(start_tls) => {
- // content.push(Content::Element(start_tls.into_element()))
- // }
- // Feature::Sasl => {}
- // Feature::Bind => {}
- // Feature::Unknown => {}
- // }
- // }
- // Element {
- // name: Name {
- // namespace: Some(XMLNS.to_string()),
- // local_name: "features".to_string(),
- // },
- // namespace_declaration_overrides: HashSet::new(),
- // attributes: HashMap::new(),
- // content,
- // }
}
}
@@ -128,7 +110,9 @@ 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 })
}
@@ -137,7 +121,7 @@ impl FromElement for Features {
#[derive(Debug, Clone)]
pub enum Feature {
StartTls(StartTls),
- Sasl,
+ Sasl(Mechanisms),
Bind,
Unknown,
}
@@ -146,7 +130,7 @@ impl IntoElement for Feature {
fn builder(&self) -> ElementBuilder {
match self {
Feature::StartTls(start_tls) => start_tls.builder(),
- Feature::Sasl => todo!(),
+ Feature::Sasl(mechanisms) => mechanisms.builder(),
Feature::Bind => todo!(),
Feature::Unknown => todo!(),
}
@@ -155,11 +139,21 @@ 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)?))
}
- _ => Ok(Feature::Unknown),
+ (Some(sasl::XMLNS), "mechanisms") => {
+ debug!("identified mechanisms");
+ Ok(Feature::Sasl(Mechanisms::from_element(element)?))
+ }
+ _ => {
+ debug!("identified unknown feature");
+ Ok(Feature::Unknown)
+ }
}
}
}