From 45e6ac733e86c68651f3b5c10636186a79f392d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Fri, 14 Jul 2023 18:24:27 +0200 Subject: [PATCH] Add the service --- src/main.rs | 15 ++++++++++----- src/service.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 src/service.rs diff --git a/src/main.rs b/src/main.rs index 40b70d5..0583169 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,19 @@ -use clap::Parser; +use std::process::ExitCode; mod address; mod config; +mod service; const COMMENT_CHAR: char = '#'; const DEFAULT_SEPARATOR: char = '+'; const KEY_SEPARATOR: char = ':'; -fn main() { - let cfg = config::Config::parse(); - println!("{cfg:?}"); - println!("{:?}", cfg.addresses()); +fn main() -> ExitCode { + match service::start_service() { + Ok(_) => ExitCode::SUCCESS, + Err(e) => { + eprintln!("{e}"); + ExitCode::FAILURE + } + } } diff --git a/src/service.rs b/src/service.rs new file mode 100644 index 0000000..b120416 --- /dev/null +++ b/src/service.rs @@ -0,0 +1,31 @@ +use crate::address::CodedAddress; +use crate::config::Config; +use anyhow::Result; +use clap::Parser; +use std::io; + +pub const BUFF_SIZE: usize = 4096; +pub const CONFIG_END: &str = "config|ready\n"; + +pub fn start_service() -> Result<()> { + let cfg = Config::parse(); + let mut buffer = String::with_capacity(BUFF_SIZE); + let stdin = io::stdin(); + + // Handshake + loop { + buffer.clear(); + stdin.read_line(&mut buffer)?; + if buffer == CONFIG_END { + break; + } + } + println!("register|report|smtp‐in|tx‐rcpt"); + println!("register|ready"); + + // Input processing + loop { + buffer.clear(); + stdin.read_line(&mut buffer)?; + } +}