From 0532f12d4a9b51b113251467a4f756bb1d02af36 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 20 Jun 2023 14:35:28 +0200 Subject: [PATCH] tokio-xmpp: Update to the new jid crate This helps a bit thanks to fewer clones, but otherwise there are very few changes. --- tokio-xmpp/src/client/async_client.rs | 4 ++-- tokio-xmpp/src/client/bind.rs | 10 ++++------ tokio-xmpp/src/client/simple_client.rs | 2 +- tokio-xmpp/src/starttls.rs | 4 ++-- tokio-xmpp/src/stream_start.rs | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tokio-xmpp/src/client/async_client.rs b/tokio-xmpp/src/client/async_client.rs index 8afd73e..ff057df 100644 --- a/tokio-xmpp/src/client/async_client.rs +++ b/tokio-xmpp/src/client/async_client.rs @@ -109,13 +109,13 @@ impl Client { jid: Jid, password: String, ) -> Result { - let username = jid.clone().node().unwrap(); + let username = jid.node().unwrap(); let password = password; // TCP connection let tcp_stream = match server { ServerConfig::UseSrv => { - connect_with_srv(&jid.clone().domain(), "_xmpp-client._tcp", 5222).await? + connect_with_srv(jid.domain(), "_xmpp-client._tcp", 5222).await? } ServerConfig::Manual { host, port } => connect_to_host(host.as_str(), port).await?, }; diff --git a/tokio-xmpp/src/client/bind.rs b/tokio-xmpp/src/client/bind.rs index 386b4b4..8d6cb3f 100644 --- a/tokio-xmpp/src/client/bind.rs +++ b/tokio-xmpp/src/client/bind.rs @@ -4,7 +4,6 @@ use std::marker::Unpin; use tokio::io::{AsyncRead, AsyncWrite}; use xmpp_parsers::bind::{BindQuery, BindResponse}; use xmpp_parsers::iq::{Iq, IqType}; -use xmpp_parsers::Jid; use crate::xmpp_codec::Packet; use crate::xmpp_stream::XMPPStream; @@ -16,11 +15,10 @@ pub async fn bind( mut stream: XMPPStream, ) -> Result, Error> { if stream.stream_features.can_bind() { - let resource = if let Jid::Full(jid) = stream.jid.clone() { - Some(jid.resource) - } else { - None - }; + let resource = stream + .jid + .resource() + .and_then(|resource| Some(resource.to_owned())); let iq = Iq::from_set(BIND_REQ_ID, BindQuery::new(resource)); stream.send_stanza(iq).await?; diff --git a/tokio-xmpp/src/client/simple_client.rs b/tokio-xmpp/src/client/simple_client.rs index e9116aa..10c1b3b 100644 --- a/tokio-xmpp/src/client/simple_client.rs +++ b/tokio-xmpp/src/client/simple_client.rs @@ -50,7 +50,7 @@ impl Client { } async fn connect(jid: Jid, password: String) -> Result { - let username = jid.clone().node().unwrap(); + let username = jid.node().unwrap(); let password = password; let domain = idna::domain_to_ascii(&jid.clone().domain()).map_err(|_| Error::Idna)?; diff --git a/tokio-xmpp/src/starttls.rs b/tokio-xmpp/src/starttls.rs index 8b20934..4d5af3a 100644 --- a/tokio-xmpp/src/starttls.rs +++ b/tokio-xmpp/src/starttls.rs @@ -29,7 +29,7 @@ use crate::{Error, ProtocolError}; async fn get_tls_stream( xmpp_stream: XMPPStream, ) -> Result, Error> { - let domain = &xmpp_stream.jid.clone().domain(); + let domain = xmpp_stream.jid.domain().to_owned(); let stream = xmpp_stream.into_inner(); let tls_stream = TlsConnector::from(NativeTlsConnector::builder().build().unwrap()) .connect(&domain, stream) @@ -41,7 +41,7 @@ async fn get_tls_stream( async fn get_tls_stream( xmpp_stream: XMPPStream, ) -> Result, Error> { - let domain = &xmpp_stream.jid.clone().domain(); + let domain = xmpp_stream.jid.domain().to_owned(); let domain = ServerName::try_from(domain.as_str())?; let stream = xmpp_stream.into_inner(); let mut root_store = RootCertStore::empty(); diff --git a/tokio-xmpp/src/stream_start.rs b/tokio-xmpp/src/stream_start.rs index c80345c..563d7c2 100644 --- a/tokio-xmpp/src/stream_start.rs +++ b/tokio-xmpp/src/stream_start.rs @@ -16,7 +16,7 @@ pub async fn start( ns: String, ) -> Result, Error> { let attrs = [ - ("to".to_owned(), jid.clone().domain()), + ("to".to_owned(), jid.domain().to_owned()), ("version".to_owned(), "1.0".to_owned()), ("xmlns".to_owned(), ns.clone()), ("xmlns:stream".to_owned(), ns::STREAM.to_owned()),