JIDs now have typed and stringy methods for node/domain/resource access
Jid now has typed with_resource and stringy with_resource_str Jid now has is_full, is_bare
This commit is contained in:
parent
199b3ae7ae
commit
4266368a98
8 changed files with 177 additions and 39 deletions
|
|
@ -109,13 +109,13 @@ impl Client {
|
|||
jid: Jid,
|
||||
password: String,
|
||||
) -> Result<XMPPStream, Error> {
|
||||
let username = jid.node().unwrap();
|
||||
let username = jid.node_str().unwrap();
|
||||
let password = password;
|
||||
|
||||
// TCP connection
|
||||
let tcp_stream = match server {
|
||||
ServerConfig::UseSrv => {
|
||||
connect_with_srv(jid.domain(), "_xmpp-client._tcp", 5222).await?
|
||||
connect_with_srv(jid.domain_str(), "_xmpp-client._tcp", 5222).await?
|
||||
}
|
||||
ServerConfig::Manual { host, port } => connect_to_host(host.as_str(), port).await?,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub async fn bind<S: AsyncRead + AsyncWrite + Unpin>(
|
|||
if stream.stream_features.can_bind() {
|
||||
let resource = stream
|
||||
.jid
|
||||
.resource()
|
||||
.resource_str()
|
||||
.and_then(|resource| Some(resource.to_owned()));
|
||||
let iq = Iq::from_set(BIND_REQ_ID, BindQuery::new(resource));
|
||||
stream.send_stanza(iq).await?;
|
||||
|
|
|
|||
|
|
@ -50,9 +50,9 @@ impl Client {
|
|||
}
|
||||
|
||||
async fn connect(jid: Jid, password: String) -> Result<XMPPStream, Error> {
|
||||
let username = jid.node().unwrap();
|
||||
let username = jid.node_str().unwrap();
|
||||
let password = password;
|
||||
let domain = idna::domain_to_ascii(&jid.clone().domain()).map_err(|_| Error::Idna)?;
|
||||
let domain = idna::domain_to_ascii(&jid.clone().domain_str()).map_err(|_| Error::Idna)?;
|
||||
|
||||
// TCP connection
|
||||
let tcp_stream = connect_with_srv(&domain, "_xmpp-client._tcp", 5222).await?;
|
||||
|
|
|
|||
|
|
@ -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.domain().to_owned();
|
||||
let domain = xmpp_stream.jid.domain_str().to_owned();
|
||||
let stream = xmpp_stream.into_inner();
|
||||
let tls_stream = TlsConnector::from(NativeTlsConnector::builder().build().unwrap())
|
||||
.connect(&domain, stream)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ pub async fn start<S: AsyncRead + AsyncWrite + Unpin>(
|
|||
ns: String,
|
||||
) -> Result<XMPPStream<S>, Error> {
|
||||
let attrs = [
|
||||
("to".to_owned(), jid.domain().to_owned()),
|
||||
("to".to_owned(), jid.domain_str().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