From c6bdf077b82b30f8228b56702bd3ee71d92b3910 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Sun, 1 Jun 2025 13:31:52 +0100 Subject: refactor: utilise new jid type safety --- stanza/src/bind.rs | 4 ++-- stanza/src/rfc_7395.rs | 10 +++++----- stanza/src/roster.rs | 4 ++-- stanza/src/stream.rs | 17 +++++++++++------ stanza/src/xep_0060/owner.rs | 4 ++-- 5 files changed, 22 insertions(+), 17 deletions(-) (limited to 'stanza') diff --git a/stanza/src/bind.rs b/stanza/src/bind.rs index 3ce2246..0f0f681 100644 --- a/stanza/src/bind.rs +++ b/stanza/src/bind.rs @@ -1,4 +1,4 @@ -use jid::JID; +use jid::FullJID; use peanuts::{Element, FromElement, IntoElement}; pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-bind"; @@ -54,7 +54,7 @@ impl IntoElement for BindType { // minLength 8 maxLength 3071 #[derive(Clone, Debug)] -pub struct FullJidType(pub JID); +pub struct FullJidType(pub FullJID); impl FromElement for FullJidType { fn from_element(mut element: peanuts::Element) -> peanuts::DeserializeResult { diff --git a/stanza/src/rfc_7395.rs b/stanza/src/rfc_7395.rs index 64d9f70..73e947d 100644 --- a/stanza/src/rfc_7395.rs +++ b/stanza/src/rfc_7395.rs @@ -1,12 +1,12 @@ -use jid::JID; +use jid::BareJID; use peanuts::{Element, ElementBuilder, FromElement, IntoElement}; pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-framing"; #[derive(Debug)] pub struct Open { - pub from: Option, - pub to: Option, + pub from: Option, + pub to: Option, pub id: Option, pub version: Option, pub lang: Option, @@ -46,8 +46,8 @@ impl IntoElement for Open { #[derive(Debug, Default)] pub struct Close { - pub from: Option, - pub to: Option, + pub from: Option, + pub to: Option, pub id: Option, pub version: Option, pub lang: Option, diff --git a/stanza/src/roster.rs b/stanza/src/roster.rs index 14f65ef..dcbf017 100644 --- a/stanza/src/roster.rs +++ b/stanza/src/roster.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use jid::JID; +use jid::BareJID; use peanuts::{DeserializeError, Element, FromElement, IntoElement}; pub const XMLNS: &str = "jabber:iq:roster"; @@ -38,7 +38,7 @@ pub struct Item { /// signals subscription sub-states (server only) pub ask: bool, /// uniquely identifies item - pub jid: JID, + pub jid: BareJID, /// handle that is determined by user, not contact pub name: Option, /// state of the presence subscription diff --git a/stanza/src/stream.rs b/stanza/src/stream.rs index 5be235a..e2f4f9b 100644 --- a/stanza/src/stream.rs +++ b/stanza/src/stream.rs @@ -1,6 +1,6 @@ use std::fmt::Display; -use jid::JID; +use jid::BareJID; use peanuts::{Element, ElementBuilder, FromElement, IntoElement}; use thiserror::Error; @@ -18,8 +18,8 @@ pub const XMLNS: &str = "http://etherx.jabber.org/streams"; // #[peanuts(xmlns = XMLNS)] #[derive(Debug)] pub struct Stream { - pub from: Option, - to: Option, + pub from: Option, + to: Option, id: Option, version: Option, // TODO: lang enum @@ -64,8 +64,8 @@ impl IntoElement for Stream { impl<'s> Stream { pub fn new( - from: Option, - to: Option, + from: Option, + to: Option, id: Option, version: Option, lang: Option, @@ -81,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, to: JID, id: Option, lang: String) -> Self { + pub fn new_client( + from: Option, + to: BareJID, + id: Option, + lang: String, + ) -> Self { Self { from, to: Some(to), diff --git a/stanza/src/xep_0060/owner.rs b/stanza/src/xep_0060/owner.rs index 0617712..4876bf5 100644 --- a/stanza/src/xep_0060/owner.rs +++ b/stanza/src/xep_0060/owner.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use jid::JID; +use jid::{BareJID, JID}; use peanuts::{DeserializeError, Element, FromElement, IntoElement}; use crate::xep_0004::X; @@ -85,7 +85,7 @@ impl IntoElement for Affiliations { #[derive(Clone, Debug)] pub struct Affiliation { affiliation: AffiliationType, - jid: JID, + jid: BareJID, } impl FromElement for Affiliation { -- cgit