diff options
Diffstat (limited to 'stanza/src/stream.rs')
-rw-r--r-- | stanza/src/stream.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/stanza/src/stream.rs b/stanza/src/stream.rs index 732a826..e2f4f9b 100644 --- a/stanza/src/stream.rs +++ b/stanza/src/stream.rs @@ -1,8 +1,7 @@ use std::fmt::Display; -use jid::JID; -use peanuts::element::{ElementBuilder, FromElement, IntoElement}; -use peanuts::Element; +use jid::BareJID; +use peanuts::{Element, ElementBuilder, FromElement, IntoElement}; use thiserror::Error; use crate::bind; @@ -19,8 +18,8 @@ pub const XMLNS: &str = "http://etherx.jabber.org/streams"; // #[peanuts(xmlns = XMLNS)] #[derive(Debug)] pub struct Stream { - pub from: Option<JID>, - to: Option<JID>, + pub from: Option<BareJID>, + to: Option<BareJID>, id: Option<String>, version: Option<String>, // TODO: lang enum @@ -59,14 +58,14 @@ impl IntoElement for Stream { .push_attribute_opt("from", self.from.clone()) .push_attribute_opt("id", self.id.clone()) .push_attribute_opt("version", self.version.clone()) - .push_attribute_opt_namespaced(peanuts::XML_NS, "to", self.lang.clone()) + .push_attribute_opt_namespaced(peanuts::XML_NS, "lang", self.lang.clone()) } } impl<'s> Stream { pub fn new( - from: Option<JID>, - to: Option<JID>, + from: Option<BareJID>, + to: Option<BareJID>, id: Option<String>, version: Option<String>, lang: Option<String>, @@ -82,7 +81,12 @@ impl<'s> Stream { /// For initial stream headers, the initiating entity SHOULD include the 'xml:lang' attribute. /// For privacy, it is better to not set `from` when sending a client stanza over an unencrypted connection. - pub fn new_client(from: Option<JID>, to: JID, id: Option<String>, lang: String) -> Self { + pub fn new_client( + from: Option<BareJID>, + to: BareJID, + id: Option<String>, + lang: String, + ) -> Self { Self { from, to: Some(to), @@ -165,7 +169,7 @@ impl IntoElement for Feature { } impl FromElement for Feature { - fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(element: Element) -> peanuts::DeserializeResult<Self> { match element.identify() { (Some(starttls::XMLNS), "starttls") => { Ok(Feature::StartTls(StartTls::from_element(element)?)) @@ -198,7 +202,7 @@ impl Display for Error { } impl FromElement for Error { - fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { + fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> { element.check_name("error")?; element.check_namespace(XMLNS)?; |