summaryrefslogtreecommitdiffstats
path: root/src/jabber.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2023-10-20 04:51:56 +0100
committerLibravatar cel 🌸 <cel@blos.sm>2023-10-20 04:51:56 +0100
commitba94ee66fafbabd63d6d1ed5edf435d4c46c6796 (patch)
treefe1bebc35914941b5c4fbd6f0286f4c9f8916154 /src/jabber.rs
parent2536fa4937f0283b4187142cc6cede8e1dbfafa8 (diff)
downloadluz-ba94ee66fafbabd63d6d1ed5edf435d4c46c6796.tar.gz
luz-ba94ee66fafbabd63d6d1ed5edf435d4c46c6796.tar.bz2
luz-ba94ee66fafbabd63d6d1ed5edf435d4c46c6796.zip
WIP: refactor to parse incoming stream as state machine
Diffstat (limited to 'src/jabber.rs')
-rw-r--r--src/jabber.rs18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/jabber.rs b/src/jabber.rs
index 1a7eddb..d48eb9c 100644
--- a/src/jabber.rs
+++ b/src/jabber.rs
@@ -3,7 +3,7 @@ use std::net::{IpAddr, SocketAddr};
use std::str::FromStr;
use std::sync::Arc;
-use quick_xml::{Reader, Writer};
+use quick_xml::{NsReader, Writer};
use rsasl::prelude::SASLConfig;
use tokio::io::BufReader;
use tokio::net::TcpStream;
@@ -22,7 +22,7 @@ pub struct Jabber<'j> {
}
impl<'j> Jabber<'j> {
- pub fn new(jid: JID, password: String) -> Result<Self> {
+ pub fn user(jid: JID, password: String) -> Result<Self> {
let server = jid.domainpart.clone();
let auth = SASLConfig::with_credentials(None, jid.localpart.clone().unwrap(), password)?;
println!("auth: {:?}", auth);
@@ -36,7 +36,7 @@ impl<'j> Jabber<'j> {
pub async fn login(&'j mut self) -> Result<JabberClient<'j>> {
let mut client = self.connect().await?.ensure_tls().await?;
- println!("negotiation");
+ client.start_stream().await?;
client.negotiate().await?;
Ok(client)
}
@@ -106,6 +106,7 @@ impl<'j> Jabber<'j> {
socket_addrs
}
+ /// establishes a connection to the server
pub async fn connect(&'j mut self) -> Result<JabberClientType> {
for (socket_addr, is_tls) in self.get_sockets().await {
println!("trying {}", socket_addr);
@@ -118,21 +119,18 @@ impl<'j> Jabber<'j> {
.await
{
let (read, write) = tokio::io::split(stream);
- let reader = Reader::from_reader(BufReader::new(read));
+ let reader = NsReader::from_reader(BufReader::new(read));
let writer = Writer::new(write);
- let mut client = client::encrypted::JabberClient::new(reader, writer, self);
- client.start_stream().await?;
+ let client = client::encrypted::JabberClient::new(reader, writer, self);
return Ok(JabberClientType::Encrypted(client));
}
}
false => {
if let Ok(stream) = TcpStream::connect(socket_addr).await {
let (read, write) = tokio::io::split(stream);
- let reader = Reader::from_reader(BufReader::new(read));
+ let reader = NsReader::from_reader(BufReader::new(read));
let writer = Writer::new(write);
- let mut client =
- client::unencrypted::JabberClient::new(reader, writer, self);
- client.start_stream().await?;
+ let client = client::unencrypted::JabberClient::new(reader, writer, self);
return Ok(JabberClientType::Unencrypted(client));
}
}