Add the service

This commit is contained in:
Rodolphe Bréard 2023-07-14 18:24:27 +02:00
parent 3e792358ed
commit 45e6ac733e
2 changed files with 41 additions and 5 deletions

View file

@ -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
}
}
}

31
src/service.rs Normal file
View file

@ -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|smtpin|txrcpt");
println!("register|ready");
// Input processing
loop {
buffer.clear();
stdin.read_line(&mut buffer)?;
}
}