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.rs73
1 files changed, 72 insertions, 1 deletions
diff --git a/src/stanza/stream.rs b/src/stanza/stream.rs
index ac4badc..4516682 100644
--- a/src/stanza/stream.rs
+++ b/src/stanza/stream.rs
@@ -6,12 +6,15 @@ use peanuts::{element::Name, Element};
use crate::{Error, JID};
+use super::starttls::StartTls;
+
pub const XMLNS: &str = "http://etherx.jabber.org/streams";
pub const XMLNS_CLIENT: &str = "jabber:client";
// MUST be qualified by stream namespace
// #[derive(XmlSerialize, XmlDeserialize)]
// #[peanuts(xmlns = XMLNS)]
+#[derive(Debug)]
pub struct Stream {
pub from: Option<JID>,
to: Option<JID>,
@@ -93,7 +96,7 @@ impl IntoElement for Stream {
attributes.insert(
Name {
namespace: None,
- local_name: "version".to_string(),
+ local_name: "id".to_string(),
},
id.clone(),
);
@@ -158,3 +161,71 @@ impl<'s> Stream {
}
}
}
+
+#[derive(Debug)]
+pub struct Features {
+ features: Vec<Feature>,
+}
+
+impl IntoElement for Features {
+ fn into_element(&self) -> Element {
+ 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_declarations: HashSet::new(),
+ attributes: HashMap::new(),
+ content,
+ }
+ }
+}
+
+impl FromElement for Features {
+ fn from_element(element: Element) -> peanuts::Result<Self> {
+ let Name {
+ namespace,
+ local_name,
+ } = element.name;
+ if namespace.as_deref() == Some(XMLNS) && &local_name == "features" {
+ let mut features = Vec::new();
+ for feature in element.content {
+ match feature {
+ Content::Element(element) => {
+ if let Ok(start_tls) = FromElement::from_element(element) {
+ features.push(Feature::StartTls(start_tls))
+ } else {
+ features.push(Feature::Unknown)
+ }
+ }
+ c => return Err(peanuts::Error::UnexpectedContent(c.clone())),
+ }
+ }
+ return Ok(Self { features });
+ } else {
+ return Err(peanuts::Error::IncorrectName(Name {
+ namespace,
+ local_name,
+ }));
+ }
+ }
+}
+
+#[derive(Debug)]
+pub enum Feature {
+ StartTls(StartTls),
+ Sasl,
+ Bind,
+ Unknown,
+}