Use procedural macros to define events
The construction of an EventHandler object should not be directly done by the client. Instead, it is easier to use procedural macro to automatize the process, hence exposing a nice and simple interface. Such use of procedural macros requires to crate an additional crate.
This commit is contained in:
parent
ccda4b1517
commit
789455668c
17 changed files with 1190 additions and 76 deletions
22
opensmtpd/examples/dummy.rs
Normal file
22
opensmtpd/examples/dummy.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use env_logger::{Builder, Env};
|
||||
use log::{debug, info};
|
||||
use opensmtpd::{event, handlers, Entry, EventHandler, SmtpIn};
|
||||
|
||||
#[event(Any)]
|
||||
fn on_event(entry: &Entry) -> bool {
|
||||
debug!("Event received: {:?}", entry);
|
||||
true
|
||||
}
|
||||
|
||||
#[event(LinkConnect)]
|
||||
fn on_connect(entry: &Entry) -> bool {
|
||||
info!("New client on session {:x}.", entry.session_id);
|
||||
true
|
||||
}
|
||||
|
||||
fn main() {
|
||||
Builder::from_env(Env::default().default_filter_or("debug")).init();
|
||||
SmtpIn::new()
|
||||
.event_handlers(handlers!(on_event, on_connect))
|
||||
.run();
|
||||
}
|
10
opensmtpd/examples/samples/dual_session.txt
Normal file
10
opensmtpd/examples/samples/dual_session.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
report|1|1546681202.276920|smtp-in|link-connect|dbd829906c50e764|localhost|pass|127.0.0.1:34818|127.0.0.1:25
|
||||
report|1|1546681202.277715|smtp-in|filter-response|dbd829906c50e764|connected|proceed
|
||||
report|1|1546681202.276920|smtp-in|link-connect|4b0148c60f798628|localhost|pass|127.0.0.1:34818|127.0.0.1:25
|
||||
report|1|1546681202.277715|smtp-in|filter-response|4b0148c60f798628|connected|proceed
|
||||
report|1|1546681202.277761|smtp-in|protocol-server|dbd829906c50e764|220 laptop.home ESMTP OpenSMTPD
|
||||
report|1|1546681232.283049|smtp-in|timeout|dbd829906c50e764
|
||||
report|1|1546681202.277761|smtp-in|protocol-server|4b0148c60f798628|220 laptop.home ESMTP OpenSMTPD
|
||||
report|1|1546681232.283049|smtp-in|timeout|4b0148c60f798628
|
||||
report|1|1546681232.283083|smtp-in|link-disconnect|dbd829906c50e764
|
||||
report|1|1546681232.283083|smtp-in|link-disconnect|4b0148c60f798628
|
5
opensmtpd/examples/samples/single_session.txt
Normal file
5
opensmtpd/examples/samples/single_session.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
report|1|1546681202.276920|smtp-in|link-connect|dbd829906c50e764|localhost|pass|127.0.0.1:34818|127.0.0.1:25
|
||||
report|1|1546681202.277715|smtp-in|filter-response|dbd829906c50e764|connected|proceed
|
||||
report|1|1546681202.277761|smtp-in|protocol-server|dbd829906c50e764|220 laptop.home ESMTP OpenSMTPD
|
||||
report|1|1546681232.283049|smtp-in|timeout|dbd829906c50e764
|
||||
report|1|1546681232.283083|smtp-in|link-disconnect|dbd829906c50e764
|
Reference in a new issue