diff options
author | cel 🌸 <cel@blos.sm> | 2023-10-20 04:51:56 +0100 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2023-10-20 04:51:56 +0100 |
commit | ba94ee66fafbabd63d6d1ed5edf435d4c46c6796 (patch) | |
tree | fe1bebc35914941b5c4fbd6f0286f4c9f8916154 /src/stanza/bind.rs | |
parent | 2536fa4937f0283b4187142cc6cede8e1dbfafa8 (diff) | |
download | luz-ba94ee66fafbabd63d6d1ed5edf435d4c46c6796.tar.gz luz-ba94ee66fafbabd63d6d1ed5edf435d4c46c6796.tar.bz2 luz-ba94ee66fafbabd63d6d1ed5edf435d4c46c6796.zip |
WIP: refactor to parse incoming stream as state machine
Diffstat (limited to 'src/stanza/bind.rs')
-rw-r--r-- | src/stanza/bind.rs | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/src/stanza/bind.rs b/src/stanza/bind.rs index 939a716..8b13789 100644 --- a/src/stanza/bind.rs +++ b/src/stanza/bind.rs @@ -1,48 +1 @@ -use super::{Element, ElementParseError}; -use crate::{JabberError, JID}; -const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-bind"; - -pub struct Bind { - pub resource: Option<String>, - pub jid: Option<JID>, -} - -impl From<Bind> for Element { - fn from(bind: Bind) -> Self { - let bind_element = Element::new("bind", None, XMLNS); - bind_element.push_namespace_declaration((None, XMLNS)); - if let Some(resource) = bind.resource { - let resource_element = Element::new("resource", None, XMLNS); - resource_element.push_child(resource); - bind_element.push_child(resource_element) - } - if let Some(jid) = bind.jid { - let jid_element = Element::new("jid", None, XMLNS); - jid_element.push_child(jid); - bind_element.push_child(jid_element) - } - bind_element - } -} - -impl TryFrom<Element> for Bind { - type Error = JabberError; - - fn try_from(element: Element) -> Result<Self, Self::Error> { - if element.namespace() == XMLNS && element.localname() == "bind" { - let (resource, jid); - let child: &Element = element.child()?; - if child.namespace() == XMLNS { - match child.localname() { - "resource" => Bind::new(Some( - child - .text_content()? - .first() - .ok_or(ElementParseError::NoContent)?, - )), - } - } - } - } -} |