diff options
author | cel 🌸 <cel@blos.sm> | 2023-08-02 00:56:38 +0100 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2023-08-02 00:56:38 +0100 |
commit | cd7bb95c0a31d187bfe25bad15043f0b33b111cf (patch) | |
tree | c5be0c651198abf736f8867a36906f9345f3a0ac /src/client/encrypted.rs | |
parent | 322b2a3b46348ec1c5acbc538de93310c9030b96 (diff) | |
download | luz-cd7bb95c0a31d187bfe25bad15043f0b33b111cf.tar.gz luz-cd7bb95c0a31d187bfe25bad15043f0b33b111cf.tar.bz2 luz-cd7bb95c0a31d187bfe25bad15043f0b33b111cf.zip |
implement resource binding
Diffstat (limited to 'src/client/encrypted.rs')
-rw-r--r-- | src/client/encrypted.rs | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/src/client/encrypted.rs b/src/client/encrypted.rs index e8b7271..86aba13 100644 --- a/src/client/encrypted.rs +++ b/src/client/encrypted.rs @@ -11,19 +11,22 @@ use tokio::net::TcpStream; use tokio_native_tls::TlsStream; use crate::stanza::{ - sasl::{Auth, Response}, - stream::{Stream, StreamFeature}, -}; -use crate::stanza::{ + bind::Bind, + iq::IQ, sasl::{Challenge, Success}, Element, }; +use crate::stanza::{ + sasl::{Auth, Response}, + stream::{Stream, StreamFeature}, +}; use crate::Jabber; +use crate::JabberError; use crate::Result; pub struct JabberClient<'j> { - reader: Reader<BufReader<ReadHalf<TlsStream<TcpStream>>>>, - writer: Writer<WriteHalf<TlsStream<TcpStream>>>, + pub reader: Reader<BufReader<ReadHalf<TlsStream<TcpStream>>>>, + pub writer: Writer<WriteHalf<TlsStream<TcpStream>>>, jabber: &'j mut Jabber<'j>, } @@ -64,15 +67,19 @@ impl<'j> JabberClient<'j> { pub async fn negotiate(&mut self) -> Result<()> { loop { - println!("loop"); + println!("negotiate loop"); let features = self.get_features().await?; println!("features: {:?}", features); + match &features[0] { StreamFeature::Sasl(sasl) => { println!("sasl?"); self.sasl(&sasl).await?; } - StreamFeature::Bind => todo!(), + StreamFeature::Bind => { + self.bind().await?; + return Ok(()); + } x => println!("{:?}", x), } } @@ -165,4 +172,36 @@ impl<'j> JabberClient<'j> { self.start_stream().await?; Ok(()) } + + pub async fn bind(&mut self) -> Result<()> { + match &self.jabber.jid.resourcepart { + Some(resource) => { + println!("setting resource"); + let bind = Bind { + resource: Some(resource.clone()), + jid: None, + }; + let result: Bind = IQ::set(self, None, None, bind).await?.try_into()?; + if let Some(jid) = result.jid { + println!("{}", jid); + self.jabber.jid = jid; + return Ok(()); + } + } + None => { + println!("not setting resource"); + let bind = Bind { + resource: None, + jid: None, + }; + let result: Bind = IQ::set(self, None, None, bind).await?.try_into()?; + if let Some(jid) = result.jid { + println!("{}", jid); + self.jabber.jid = jid; + return Ok(()); + } + } + } + Err(JabberError::BindError) + } } |