From 82fe5e24dec7f5c86c43b341b4bc752d2b59695d Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sat, 12 Jan 2019 10:42:37 +0100 Subject: [PATCH] Add the report registration --- opensmtpd/src/entry.rs | 23 +++++++++++++++++++++++ opensmtpd/src/event_handlers.rs | 2 +- opensmtpd/src/lib.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/opensmtpd/src/entry.rs b/opensmtpd/src/entry.rs index 6bc10cb..55d3f49 100644 --- a/opensmtpd/src/entry.rs +++ b/opensmtpd/src/entry.rs @@ -48,6 +48,29 @@ impl FromStr for Event { } } +impl ToString for Event { + fn to_string(&self) -> String { + let s = match self { + Event::LinkConnect => "link-connect", + Event::LinkDisconnect => "link-disconnect", + Event::LinkIdentify => "link-identify", + Event::LinkTls => "link-tls", + Event::TxBegin => "tx-begin", + Event::TxMail => "tx-mail", + Event::TxRcpt => "tx-rcpt", + Event::TxEnvelope => "tx-envelope", + Event::TxData => "tx-data", + Event::TxCommit => "tx-commit", + Event::TxRollback => "tx-rollback", + Event::ProtocolClient => "protocol-client", + Event::ProtocolServer => "protocol-server", + Event::Timeout => "timeout", + Event::FilterResponse => "filter-response", + }; + String::from(s) + } +} + #[derive(Debug)] pub struct TimeVal { pub sec: i64, diff --git a/opensmtpd/src/event_handlers.rs b/opensmtpd/src/event_handlers.rs index 3543d84..2402e75 100644 --- a/opensmtpd/src/event_handlers.rs +++ b/opensmtpd/src/event_handlers.rs @@ -17,7 +17,7 @@ pub enum Callback { #[derive(Clone)] pub struct EventHandler { - event: MatchEvent, + pub(crate) event: MatchEvent, callback: Callback, } diff --git a/opensmtpd/src/lib.rs b/opensmtpd/src/lib.rs index c50f4f0..0c1d5de 100644 --- a/opensmtpd/src/lib.rs +++ b/opensmtpd/src/lib.rs @@ -75,6 +75,31 @@ pub struct SmtpIn { } impl SmtpIn { + fn register_events(&self) { + let mut evts = Vec::new(); + for eh in self.event_handlers.iter() { + match eh.event { + MatchEvent::Evt(ref v) => { + for e in v.iter() { + evts.push(e); + } + }, + MatchEvent::All => { + println!("register|report|smtp-in|*"); + evts.clear(); + break ; + }, + } + } + evts.dedup(); + for e in evts.iter() { + println!("register|report|smtp-in|{}", e.to_string()); + } + // TODO: register filters + // println!("register|filter|smtp-in|{}", "name"); + println!("register|ready"); + } + /// Read a line from the standard input. /// Since EOF should not append, it is considered as an error. fn read(&self) -> Result { @@ -144,6 +169,7 @@ impl SmtpIn { /// Run the infinite loop that will read and process input from stdin. pub fn run(&mut self) { + self.register_events(); loop { let line = match self.read() { Ok(l) => l,