Add the report registration

This commit is contained in:
Rodolphe Breard 2019-01-12 10:42:37 +01:00
parent 11f3712138
commit 82fe5e24de
3 changed files with 50 additions and 1 deletions

View file

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

View file

@ -17,7 +17,7 @@ pub enum Callback<T> {
#[derive(Clone)]
pub struct EventHandler<T> {
event: MatchEvent,
pub(crate) event: MatchEvent,
callback: Callback<T>,
}

View file

@ -75,6 +75,31 @@ pub struct SmtpIn<T> {
}
impl<T: Clone + Default + 'static> SmtpIn<T> {
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<String, Error> {
@ -144,6 +169,7 @@ impl<T: Clone + Default + 'static> SmtpIn<T> {
/// 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,