cleanup and typos
This commit is contained in:
parent
bf4dbc5ba7
commit
e4dff0429c
@ -3,7 +3,7 @@ name = "sieverman"
|
||||
version = "0.1.0"
|
||||
authors = ["Franz Dietrich<dietrich@teilgedanken.de>"]
|
||||
edition = "2021"
|
||||
license = "MIT OR Apache-2.0"
|
||||
licenses = ["MIT", "Apache-2.0"]
|
||||
description = "Connect to a Managesieve-Server"
|
||||
documentation = "https://docs.rs/bitflags"
|
||||
readme = "README.md"
|
||||
|
@ -13,8 +13,7 @@ pub(crate) async fn run(
|
||||
info!("connecting…");
|
||||
let future_info = info.connect();
|
||||
info!("waiting for the connection to be established");
|
||||
let mut connected = future_info.await.context("Something went wrong")?;
|
||||
|
||||
let connected = future_info.await.context("Something went wrong")?;
|
||||
info!("Fully read the introduction:");
|
||||
to_frontend_tx
|
||||
.send(BackToFront::ServerConnected(
|
||||
|
@ -17,9 +17,7 @@ pub(crate) fn get_app(
|
||||
let app = Application::builder()
|
||||
.application_id("de.teilgedanken.sieverman")
|
||||
.build();
|
||||
|
||||
app.connect_activate(move |app| build_ui(app, from_backend_rx.clone()));
|
||||
|
||||
app
|
||||
}
|
||||
|
||||
@ -35,23 +33,23 @@ fn build_ui(
|
||||
.object::<libadwaita::ApplicationWindow>("window")
|
||||
.unwrap();
|
||||
|
||||
let prefrences_group = builder
|
||||
let preferences_group = builder
|
||||
.object::<libadwaita::PreferencesGroup>("server_settings")
|
||||
.unwrap();
|
||||
main_window.set_application(Some(app));
|
||||
|
||||
let future = {
|
||||
let mut data_event_receiver = from_backend_rx.take().expect("data_event_reciver");
|
||||
let mut data_event_receiver = from_backend_rx.take().expect("data_event_receiver");
|
||||
async move {
|
||||
while let Some(event) = data_event_receiver.recv().await {
|
||||
match event {
|
||||
BackToFront::ServerConnected(caps) => {
|
||||
prefrences_group.add(&row_in_settings("Greeting", &caps.implementation));
|
||||
prefrences_group
|
||||
preferences_group.add(&row_in_settings("Greeting", &caps.implementation));
|
||||
preferences_group
|
||||
.add(&row_in_settings("Authentication", &caps.sasl.join(",")));
|
||||
prefrences_group
|
||||
preferences_group
|
||||
.add(&row_in_settings("Starttls", &caps.starttls.to_string()));
|
||||
prefrences_group.add(&row_in_settings("Version", &caps.version));
|
||||
preferences_group.add(&row_in_settings("Version", &caps.version));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ fn main() -> glib::ExitCode {
|
||||
gtk::init().expect("Failed to initialize GTK");
|
||||
libadwaita::init().expect("Adwaita initialization failed");
|
||||
|
||||
let (to_frontent_tx, from_backend_rx) = tokio::sync::mpsc::channel(5);
|
||||
let (to_frontend_tx, from_backend_rx) = tokio::sync::mpsc::channel(5);
|
||||
let _handle = thread::spawn(move || {
|
||||
info!("Running Backend");
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
@ -27,12 +27,14 @@ fn main() -> glib::ExitCode {
|
||||
.enable_time()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(backend::run::run(to_frontent_tx))
|
||||
.block_on(backend::run::run(to_frontend_tx))
|
||||
.expect("Failed to run or interrupted");
|
||||
});
|
||||
|
||||
let app = gui::main_window::get_app(Rc::new(RefCell::new(Some(from_backend_rx))));
|
||||
|
||||
gtk::Window::set_default_icon_name("scanner");
|
||||
|
||||
let res = app.run();
|
||||
trace!("End");
|
||||
|
||||
|
11
src/lib.rs
11
src/lib.rs
@ -15,8 +15,6 @@ use tokio_rustls::{
|
||||
};
|
||||
use tracing::{error, info, trace};
|
||||
|
||||
pub mod parser;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ConnectionInfo {
|
||||
domain: String,
|
||||
@ -39,7 +37,6 @@ impl ConnectionInfo {
|
||||
.with_root_certificates(root_store)
|
||||
.with_no_client_auth();
|
||||
|
||||
// Allow using SSLKEYLOGFILE.
|
||||
config.key_log = Arc::new(KeyLogFile::new());
|
||||
trace!("Creating connector");
|
||||
let connector = TlsConnector::from(Arc::new(config));
|
||||
@ -147,16 +144,16 @@ impl ConnectionConnected {
|
||||
.await
|
||||
.context("Failed to write LISTSCRIPTS command")?;
|
||||
|
||||
let scriptslist = loop {
|
||||
let scripts_list = loop {
|
||||
let mut buf = buffer.lock().await;
|
||||
trace!("reading new input:\n{}", buf);
|
||||
match managesieve::response_listscripts(&buf.to_string()) {
|
||||
Ok((rest, scriptslist, resp)) => match resp.tag {
|
||||
Ok((rest, scripts_list, resp)) => match resp.tag {
|
||||
managesieve::OkNoBye::Ok => {
|
||||
buf.clear();
|
||||
buf.push_str(rest);
|
||||
info!("Read the introduction");
|
||||
break scriptslist;
|
||||
break scripts_list;
|
||||
}
|
||||
managesieve::OkNoBye::No | managesieve::OkNoBye::Bye => {
|
||||
trace!("Connection closed!");
|
||||
@ -168,7 +165,7 @@ impl ConnectionConnected {
|
||||
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||
};
|
||||
Ok((
|
||||
scriptslist,
|
||||
scripts_list,
|
||||
Self {
|
||||
writer,
|
||||
buffer,
|
||||
|
54
src/old2.rs
54
src/old2.rs
@ -1,54 +0,0 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::net::TcpStream;
|
||||
|
||||
async fn connect(addr: &str) -> Result<TlsStream<TcpStream>, Box<dyn std::error::Error>> {
|
||||
let mut root_cert_store = RootCertStore::empty();
|
||||
|
||||
for cert in rustls_native_certs::load_native_certs().expect("could not load platform certs") {
|
||||
root_cert_store.add(cert)
|
||||
}
|
||||
let roots = webpki_roots::TLS_SERVER_ROOTS.iter().map(|ta| {
|
||||
OwnedTrustAnchor::from_subject_spki_name_constraints(
|
||||
ta.subject,
|
||||
ta.subject_public_key_info,
|
||||
ta.name_constraints,
|
||||
)
|
||||
});
|
||||
root_cert_store.add_trust_anchors(roots);
|
||||
let config = ClientConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_root_certificates(root_cert_store)
|
||||
.with_no_client_auth();
|
||||
let connector = TlsConnector::from(Arc::new(config));
|
||||
let dnsname = ServerName::try_from("www.rust-lang.org").unwrap();
|
||||
|
||||
let stream = TcpStream::connect(&addr).await?;
|
||||
let mut stream = connector.connect(dnsname, stream).await?;
|
||||
|
||||
Ok(tls_stream)
|
||||
}
|
||||
|
||||
async fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let tls_stream = connect("127.0.0.1:8080").await?;
|
||||
|
||||
// Send a request to the server
|
||||
let request = b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n";
|
||||
tls_stream.write_all(request)?;
|
||||
|
||||
// Read the response from the server
|
||||
let mut buf = [0; 1024];
|
||||
let n = tls_stream.read(&mut buf)?;
|
||||
println!("{}", String::from_utf8_lossy(&buf[..n]));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tokio::runtime::Builder::new()
|
||||
.threaded_scheduler()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(run());
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
mod server_config;
|
||||
mod utils;
|
||||
|
||||
pub use server_config::parse_server_config;
|
@ -1,84 +0,0 @@
|
||||
use nom::{
|
||||
branch::alt,
|
||||
bytes::complete::is_not,
|
||||
bytes::complete::tag,
|
||||
character::{
|
||||
self,
|
||||
complete::{alpha1, multispace1},
|
||||
},
|
||||
multi::many_m_n,
|
||||
sequence::preceded,
|
||||
IResult,
|
||||
};
|
||||
use tracing::trace;
|
||||
|
||||
use crate::{parser::utils::key_value, Methods, ServerSettings};
|
||||
|
||||
fn parse_version(input: &str) -> IResult<&str, Vec<i32>> {
|
||||
many_m_n(
|
||||
1,
|
||||
5,
|
||||
alt((
|
||||
character::complete::i32,
|
||||
preceded(character::complete::char('.'), character::complete::i32),
|
||||
)),
|
||||
)(input)
|
||||
}
|
||||
|
||||
fn parse_methods(input: &str) -> IResult<&str, Vec<Methods>> {
|
||||
let (rem, res) = many_m_n(1, 10, alt((alpha1, preceded(multispace1, alpha1))))(input)?;
|
||||
let methods = res
|
||||
.into_iter()
|
||||
.map(|m| match m {
|
||||
"PLAIN" => Methods::Plain,
|
||||
"OAUTHBEARER" => Methods::OAuthbearer,
|
||||
any => todo!("That method is not yet implemented: {}", any),
|
||||
})
|
||||
.collect();
|
||||
Ok((rem, methods))
|
||||
}
|
||||
|
||||
fn parse_extensions(input: &str) -> IResult<&str, Vec<String>> {
|
||||
let space_then_word = preceded(tag(" "), is_not(" "));
|
||||
let word = is_not(" ");
|
||||
let (rem, res) = many_m_n(1, 200, alt((word, space_then_word)))(input)?;
|
||||
let extensions = res.into_iter().map(|m| m.to_string()).collect();
|
||||
Ok((rem, extensions))
|
||||
}
|
||||
|
||||
pub fn parse_server_config(input: &str) -> IResult<&str, ServerSettings> {
|
||||
let (remain, (_key, implementation)) = key_value(input)?;
|
||||
trace!("Implementation:# {}", implementation);
|
||||
let (remain, (_key, version)) = key_value(remain)?;
|
||||
trace!("{}", version);
|
||||
let (_, version) = parse_version(version)?;
|
||||
trace!("Version:# {:?}", version);
|
||||
let (remain, (_key, sasl)) = key_value(remain)?;
|
||||
trace!("{}", sasl);
|
||||
let (_, sasl) = parse_methods(sasl)?;
|
||||
trace!("SASL:# {:?}", sasl);
|
||||
let (remain, (_key, capabilities)) = key_value(remain)?;
|
||||
trace!("{}", capabilities);
|
||||
let (_, capabilities) = parse_extensions(capabilities)?;
|
||||
trace!("Extensions:# {:?}", &capabilities);
|
||||
let (remain, (_key, notify)) = key_value(remain)?;
|
||||
trace!("{}", notify);
|
||||
let (_, notify) = parse_extensions(remain)?;
|
||||
trace!("Notify:# {:?}", ¬ify);
|
||||
let (remain, (_key, max_redirects)) = key_value(remain)?;
|
||||
trace!("{}", max_redirects);
|
||||
let (_, max_redirects) = character::complete::u32(max_redirects)?;
|
||||
trace!("Max Redirects:# {}", max_redirects);
|
||||
|
||||
IResult::Ok((
|
||||
remain,
|
||||
ServerSettings {
|
||||
implementation: implementation.to_string(),
|
||||
version,
|
||||
sasl,
|
||||
capabilities,
|
||||
notify,
|
||||
max_redirects,
|
||||
},
|
||||
))
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
use nom::{
|
||||
bytes::complete::is_not,
|
||||
bytes::complete::tag,
|
||||
character::complete::{multispace0, multispace1},
|
||||
sequence::{delimited, preceded, separated_pair},
|
||||
IResult,
|
||||
};
|
||||
|
||||
pub(crate) fn quoted(input: &str) -> IResult<&str, &str> {
|
||||
preceded(multispace0, delimited(tag("\""), is_not("\n\""), tag("\"")))(input)
|
||||
}
|
||||
|
||||
pub(crate) fn key_value(input: &str) -> IResult<&str, (&str, &str)> {
|
||||
// note that this is really creating a function, the parser for abc
|
||||
// vvvvv
|
||||
// which is then called here, returning an IResult<&str, &str>
|
||||
// vvvvv
|
||||
preceded(multispace0, separated_pair(quoted, multispace1, quoted))(input)
|
||||
}
|
Loading…
Reference in New Issue
Block a user