diff options
author | 2024-12-22 18:58:28 +0000 | |
---|---|---|
committer | 2024-12-22 18:58:28 +0000 | |
commit | 6385e43e8ca467e53c6a705a932016c5af75c3a2 (patch) | |
tree | f63fb7bd9a349f24b093ba4dd037c6ce7789f5ee /stanza | |
parent | 595d165479b8b12e456f39205d8433b822b07487 (diff) | |
download | luz-6385e43e8ca467e53c6a705a932016c5af75c3a2.tar.gz luz-6385e43e8ca467e53c6a705a932016c5af75c3a2.tar.bz2 luz-6385e43e8ca467e53c6a705a932016c5af75c3a2.zip |
implement sink and stream with tokio::spawn
Diffstat (limited to 'stanza')
-rw-r--r-- | stanza/src/bind.rs | 8 | ||||
-rw-r--r-- | stanza/src/client/iq.rs | 9 | ||||
-rw-r--r-- | stanza/src/client/message.rs | 9 | ||||
-rw-r--r-- | stanza/src/client/mod.rs | 1 | ||||
-rw-r--r-- | stanza/src/client/presence.rs | 11 | ||||
-rw-r--r-- | stanza/src/lib.rs | 1 | ||||
-rw-r--r-- | stanza/src/xep_0199.rs | 26 |
7 files changed, 50 insertions, 15 deletions
diff --git a/stanza/src/bind.rs b/stanza/src/bind.rs index 155fd1b..63644b1 100644 --- a/stanza/src/bind.rs +++ b/stanza/src/bind.rs @@ -6,7 +6,7 @@ use peanuts::{ pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-bind"; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Bind { pub r#type: Option<BindType>, } @@ -28,7 +28,7 @@ impl IntoElement for Bind { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum BindType { Resource(ResourceType), Jid(FullJidType), @@ -56,7 +56,7 @@ impl IntoElement for BindType { } // minLength 8 maxLength 3071 -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct FullJidType(pub JID); impl FromElement for FullJidType { @@ -77,7 +77,7 @@ impl IntoElement for FullJidType { } // minLength 1 maxLength 1023 -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ResourceType(pub String); impl FromElement for ResourceType { diff --git a/stanza/src/client/iq.rs b/stanza/src/client/iq.rs index 388979e..6ee80ea 100644 --- a/stanza/src/client/iq.rs +++ b/stanza/src/client/iq.rs @@ -9,10 +9,12 @@ use peanuts::{ use crate::{ bind::{self, Bind}, client::error::Error, + xep_0199::{self, Ping}, }; use super::XMLNS; +#[derive(Debug)] pub struct Iq { pub from: Option<JID>, pub id: String, @@ -25,9 +27,10 @@ pub struct Iq { pub errors: Vec<Error>, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum Query { Bind(Bind), + Ping(Ping), Unsupported, } @@ -35,6 +38,7 @@ impl FromElement for Query { fn from_element(element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> { match element.identify() { (Some(bind::XMLNS), "bind") => Ok(Query::Bind(Bind::from_element(element)?)), + (Some(xep_0199::XMLNS), "ping") => Ok(Query::Ping(Ping::from_element(element)?)), _ => Ok(Query::Unsupported), } } @@ -44,6 +48,7 @@ impl IntoElement for Query { fn builder(&self) -> peanuts::element::ElementBuilder { match self { Query::Bind(bind) => bind.builder(), + Query::Ping(ping) => ping.builder(), // TODO: consider what to do if attempt to serialize unsupported Query::Unsupported => todo!(), } @@ -88,7 +93,7 @@ impl IntoElement for Iq { } } -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum IqType { Error, Get, diff --git a/stanza/src/client/message.rs b/stanza/src/client/message.rs index b9d995f..2337d7b 100644 --- a/stanza/src/client/message.rs +++ b/stanza/src/client/message.rs @@ -8,6 +8,7 @@ use peanuts::{ use super::XMLNS; +#[derive(Debug)] pub struct Message { from: Option<JID>, id: Option<String>, @@ -69,7 +70,7 @@ impl IntoElement for Message { } } -#[derive(Default, PartialEq, Eq, Copy, Clone)] +#[derive(Default, PartialEq, Eq, Copy, Clone, Debug)] pub enum MessageType { Chat, Error, @@ -106,7 +107,7 @@ impl ToString for MessageType { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Body { lang: Option<String>, body: Option<String>, @@ -132,7 +133,7 @@ impl IntoElement for Body { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Subject { lang: Option<String>, subject: Option<String>, @@ -158,7 +159,7 @@ impl IntoElement for Subject { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Thread { parent: Option<String>, thread: Option<String>, diff --git a/stanza/src/client/mod.rs b/stanza/src/client/mod.rs index 2b063d6..e9c336e 100644 --- a/stanza/src/client/mod.rs +++ b/stanza/src/client/mod.rs @@ -15,6 +15,7 @@ pub mod presence; pub const XMLNS: &str = "jabber:client"; +#[derive(Debug)] pub enum Stanza { Message(Message), Presence(Presence), diff --git a/stanza/src/client/presence.rs b/stanza/src/client/presence.rs index dd14bff..5354966 100644 --- a/stanza/src/client/presence.rs +++ b/stanza/src/client/presence.rs @@ -8,6 +8,7 @@ use peanuts::{ use super::{error::Error, XMLNS}; +#[derive(Debug)] pub struct Presence { from: Option<JID>, id: Option<String>, @@ -70,7 +71,7 @@ impl IntoElement for Presence { pub enum Other {} -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub enum PresenceType { Error, Probe, @@ -112,7 +113,7 @@ impl ToString for PresenceType { } } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub enum Show { Away, Chat, @@ -160,7 +161,7 @@ impl ToString for Show { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Status { lang: Option<String>, status: String1024, @@ -188,7 +189,7 @@ impl IntoElement for Status { // TODO: enforce? /// minLength 1 maxLength 1024 -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct String1024(pub String); impl FromStr for String1024 { @@ -206,7 +207,7 @@ impl ToString for String1024 { } // xs:byte -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub struct Priority(pub i8); impl FromElement for Priority { diff --git a/stanza/src/lib.rs b/stanza/src/lib.rs index 32716d3..f3b0dca 100644 --- a/stanza/src/lib.rs +++ b/stanza/src/lib.rs @@ -7,5 +7,6 @@ pub mod stanza_error; pub mod starttls; pub mod stream; pub mod stream_error; +pub mod xep_0199; pub static XML_VERSION: VersionInfo = VersionInfo::One; diff --git a/stanza/src/xep_0199.rs b/stanza/src/xep_0199.rs new file mode 100644 index 0000000..9605721 --- /dev/null +++ b/stanza/src/xep_0199.rs @@ -0,0 +1,26 @@ +use peanuts::{ + element::{FromElement, IntoElement}, + Element, +}; + +pub const XMLNS: &str = "urn:xmpp:ping"; + +#[derive(Clone, Copy, Debug)] +pub struct Ping; + +impl FromElement for Ping { + fn from_element(element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> { + element.check_name("ping")?; + element.check_namespace(XMLNS)?; + + element.no_more_content()?; + + Ok(Ping) + } +} + +impl IntoElement for Ping { + fn builder(&self) -> peanuts::element::ElementBuilder { + Element::builder("ping", Some(XMLNS)) + } +} |