From 04a47e18e4c23f1478658a98bd4d2afe3e06471d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Sun, 19 Mar 2023 17:13:49 +0100 Subject: [PATCH] Implement the initial handshake --- src/handshake.rs | 23 +++++++++++++++++++++++ src/main.rs | 5 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/handshake.rs diff --git a/src/handshake.rs b/src/handshake.rs new file mode 100644 index 0000000..c293387 --- /dev/null +++ b/src/handshake.rs @@ -0,0 +1,23 @@ +pub const CONFIG_END: &str = "config|ready"; +pub const CONFIG_TAG: &str = "config|"; + +pub fn read_config() { + let mut buffer = String::new(); + let stdin = std::io::stdin(); + loop { + buffer.clear(); + stdin.read_line(&mut buffer).unwrap(); + let entry = buffer.trim_end(); + if entry == CONFIG_END { + return; + } + if !entry.starts_with(CONFIG_TAG) { + eprintln!("invalid config line: {entry}"); + } + } +} + +pub fn register_filter() { + println!("register|filter|smtp-in|data-line"); + println!("register|ready"); +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..b0e76f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +mod handshake; + fn main() { - println!("Hello, world!"); + handshake::read_config(); + handshake::register_filter(); }