summaryrefslogtreecommitdiffstats
path: root/src/jabber.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2023-07-04 21:27:15 +0100
committerLibravatar cel 🌸 <cel@blos.sm>2023-07-04 21:27:15 +0100
commit143a0365d0822e6786cdac3530a725bbf450f38f (patch)
tree8b540aa73c1365ddc658e502ed93847dbb522064 /src/jabber.rs
parentc0a7116eef13ea75340fe7d75da97dfbd04fac20 (diff)
downloadluz-143a0365d0822e6786cdac3530a725bbf450f38f.tar.gz
luz-143a0365d0822e6786cdac3530a725bbf450f38f.tar.bz2
luz-143a0365d0822e6786cdac3530a725bbf450f38f.zip
horrible
Diffstat (limited to '')
-rw-r--r--src/jabber.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/jabber.rs b/src/jabber.rs
index a1f6272..a1b2a2f 100644
--- a/src/jabber.rs
+++ b/src/jabber.rs
@@ -1,33 +1,44 @@
use std::marker::PhantomData;
use std::net::{IpAddr, SocketAddr};
use std::str::FromStr;
+use std::sync::Arc;
use quick_xml::{Reader, Writer};
+use rsasl::prelude::SASLConfig;
use tokio::io::BufReader;
use tokio::net::TcpStream;
use tokio_native_tls::native_tls::TlsConnector;
-use crate::client;
use crate::client::JabberClientType;
use crate::jid::JID;
+use crate::{client, JabberClient};
use crate::{JabberError, Result};
pub struct Jabber<'j> {
pub jid: JID,
- pub password: String,
+ pub auth: Arc<SASLConfig>,
pub server: String,
_marker: PhantomData<&'j ()>,
}
impl<'j> Jabber<'j> {
- pub fn new(jid: JID, password: String) -> Self {
+ pub fn new(jid: JID, password: String) -> Result<Self> {
let server = jid.domainpart.clone();
- Self {
+ let auth = SASLConfig::with_credentials(None, jid.as_bare().to_string(), password)?;
+ println!("auth: {:?}", auth);
+ Ok(Self {
jid,
- password,
+ auth,
server,
_marker: PhantomData,
- }
+ })
+ }
+
+ pub async fn login(&'j mut self) -> Result<JabberClient<'j>> {
+ let mut client = self.connect().await?.ensure_tls().await?;
+ println!("negotiation");
+ client.negotiate().await?;
+ Ok(client)
}
async fn get_sockets(&self) -> Vec<(SocketAddr, bool)> {
@@ -106,9 +117,8 @@ impl<'j> Jabber<'j> {
.connect(&self.server, socket)
.await
{
- let (read, write) = tokio::io::split(stream);
+ let (read, writer) = tokio::io::split(stream);
let reader = Reader::from_reader(BufReader::new(read));
- let writer = Writer::new(write);
return Ok(JabberClientType::Encrypted(
client::encrypted::JabberClient::new(reader, writer, self),
));
@@ -126,6 +136,6 @@ impl<'j> Jabber<'j> {
}
}
}
- Err(JabberError::ConnectionError)
+ Err(JabberError::Connection)
}
}