X-Git-Url: https://git.r.bdr.sh/rbdr/olden-mail/blobdiff_plain/494920f168bccf5e4dd0b38d9d19c0f5e25c127c..573aaf2a8ccdb6c8c917b2d88a39c9c8103f64ef:/src/proxy.rs?ds=inline diff --git a/src/proxy.rs b/src/proxy.rs index 8348325..2798df3 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -42,6 +42,7 @@ use std::thread::{sleep, spawn, JoinHandle}; use std::time::Duration; use crate::configuration::Proxy; +use crate::middleware::MIDDLEWARE; /// A proxy server that listens for plaintext connections and forwards them /// via TLS. @@ -119,7 +120,7 @@ fn run_proxy(configuration: &Arc, running: &Arc) { Ok((stream, addr)) => { info!("New {} connection from {}", configuration.protocol, addr); - let configuration_clone = Arc::clone(&configuration); + let configuration_clone = Arc::clone(configuration); let handle = spawn(move || { handle_client(stream, &configuration_clone); }); @@ -213,7 +214,6 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc) { let mut buffer = [0u8; 8192]; let mut client_reader = client_stream; loop { - debug!(">"); let bytes_read = match client_reader.read(&mut buffer) { Ok(0) => break, Ok(n) => n, @@ -227,7 +227,13 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc) { } }; - let debug_str = String::from_utf8_lossy(&buffer[..bytes_read]) + let mut command = buffer[..bytes_read].to_vec(); + + for middleware in MIDDLEWARE { + command = middleware(&command); + } + + let debug_str = String::from_utf8_lossy(&command) .replace('\n', "\\n") .replace('\r', "\\r") .replace('\t', "\\t"); @@ -260,7 +266,6 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc) { let mut buffer = [0u8; 8192]; let mut client_writer = client_stream_clone; loop { - debug!("<"); // Lock the TLS stream and read from the server let bytes_read = match tls_stream_clone.lock() { Ok(mut tls_guard) => match tls_guard.read(&mut buffer) {