From c20fadf99d2293b1229655cc85275236a00dbb60 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Thu, 17 Jan 2019 20:05:31 +0100 Subject: [PATCH] Alias event as report This alias is made so people with OpenSMTPD filters knowledge will directly understand that events are reports. --- opensmtpd-derive/src/lib.rs | 5 +++++ opensmtpd/examples/session_event_counter.rs | 8 ++++---- opensmtpd/src/lib.rs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/opensmtpd-derive/src/lib.rs b/opensmtpd-derive/src/lib.rs index 4aadd15..adfee9e 100644 --- a/opensmtpd-derive/src/lib.rs +++ b/opensmtpd-derive/src/lib.rs @@ -64,3 +64,8 @@ pub fn event(attr: TokenStream, input: TokenStream) -> TokenStream { }; output.into() } + +#[proc_macro_attribute] +pub fn report(attr: TokenStream, input: TokenStream) -> TokenStream { + event(attr, input) +} diff --git a/opensmtpd/examples/session_event_counter.rs b/opensmtpd/examples/session_event_counter.rs index c899da8..f75359e 100644 --- a/opensmtpd/examples/session_event_counter.rs +++ b/opensmtpd/examples/session_event_counter.rs @@ -1,18 +1,18 @@ use log::{info, Level}; -use opensmtpd::{event, handlers, Entry, SmtpIn, SmtpdLogger}; +use opensmtpd::{handlers, report, Entry, SmtpIn, SmtpdLogger}; #[derive(Clone, Default)] struct MyContext { nb: usize, } -#[event(Any)] -fn on_event(ctx: &mut MyContext, entry: &Entry) { +#[report(Any)] +fn on_report(ctx: &mut MyContext, entry: &Entry) { ctx.nb += 1; info!("Event received: {}, {}", entry.session_id, ctx.nb); } fn main() { let _ = SmtpdLogger::new().set_level(Level::Debug).init(); - SmtpIn::new().event_handlers(handlers!(on_event)).run(); + SmtpIn::new().event_handlers(handlers!(on_report)).run(); } diff --git a/opensmtpd/src/lib.rs b/opensmtpd/src/lib.rs index 00c227a..6324599 100644 --- a/opensmtpd/src/lib.rs +++ b/opensmtpd/src/lib.rs @@ -14,7 +14,7 @@ pub use crate::entry::{Entry, Event}; pub use crate::errors::Error; pub use crate::event_handlers::{Callback, EventHandler, MatchEvent}; pub use crate::logger::SmtpdLogger; -pub use opensmtpd_derive::event; +pub use opensmtpd_derive::{event, report}; #[macro_export] macro_rules! handlers {