tokio-xmpp: Update to the new jid crate
This helps a bit thanks to fewer clones, but otherwise there are very few changes.
This commit is contained in:
parent
c7887efbc7
commit
3c9df12606
5 changed files with 10 additions and 12 deletions
|
@ -109,13 +109,13 @@ impl Client {
|
|||
jid: Jid,
|
||||
password: String,
|
||||
) -> Result<XMPPStream, Error> {
|
||||
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?,
|
||||
};
|
||||
|
|
|
@ -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<S: AsyncRead + AsyncWrite + Unpin>(
|
|||
mut stream: XMPPStream<S>,
|
||||
) -> Result<XMPPStream<S>, 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?;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ impl Client {
|
|||
}
|
||||
|
||||
async fn connect(jid: Jid, password: String) -> Result<XMPPStream, Error> {
|
||||
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)?;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ use crate::{Error, ProtocolError};
|
|||
async fn get_tls_stream<S: AsyncRead + AsyncWrite + Unpin>(
|
||||
xmpp_stream: XMPPStream<S>,
|
||||
) -> Result<TlsStream<S>, 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<S: AsyncRead + AsyncWrite + Unpin>(
|
|||
async fn get_tls_stream<S: AsyncRead + AsyncWrite + Unpin>(
|
||||
xmpp_stream: XMPPStream<S>,
|
||||
) -> Result<TlsStream<S>, 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();
|
||||
|
|
|
@ -16,7 +16,7 @@ pub async fn start<S: AsyncRead + AsyncWrite + Unpin>(
|
|||
ns: String,
|
||||
) -> Result<XMPPStream<S>, 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()),
|
||||
|
|
Loading…
Reference in a new issue