Alias event as report

This alias is made so people with OpenSMTPD filters knowledge will
directly understand that events are reports.
This commit is contained in:
Rodolphe Breard 2019-01-17 20:05:31 +01:00
parent ae8b64941e
commit c20fadf99d
3 changed files with 10 additions and 5 deletions

View file

@ -64,3 +64,8 @@ pub fn event(attr: TokenStream, input: TokenStream) -> TokenStream {
}; };
output.into() output.into()
} }
#[proc_macro_attribute]
pub fn report(attr: TokenStream, input: TokenStream) -> TokenStream {
event(attr, input)
}

View file

@ -1,18 +1,18 @@
use log::{info, Level}; use log::{info, Level};
use opensmtpd::{event, handlers, Entry, SmtpIn, SmtpdLogger}; use opensmtpd::{handlers, report, Entry, SmtpIn, SmtpdLogger};
#[derive(Clone, Default)] #[derive(Clone, Default)]
struct MyContext { struct MyContext {
nb: usize, nb: usize,
} }
#[event(Any)] #[report(Any)]
fn on_event(ctx: &mut MyContext, entry: &Entry) { fn on_report(ctx: &mut MyContext, entry: &Entry) {
ctx.nb += 1; ctx.nb += 1;
info!("Event received: {}, {}", entry.session_id, ctx.nb); info!("Event received: {}, {}", entry.session_id, ctx.nb);
} }
fn main() { fn main() {
let _ = SmtpdLogger::new().set_level(Level::Debug).init(); let _ = SmtpdLogger::new().set_level(Level::Debug).init();
SmtpIn::new().event_handlers(handlers!(on_event)).run(); SmtpIn::new().event_handlers(handlers!(on_report)).run();
} }

View file

@ -14,7 +14,7 @@ pub use crate::entry::{Entry, Event};
pub use crate::errors::Error; pub use crate::errors::Error;
pub use crate::event_handlers::{Callback, EventHandler, MatchEvent}; pub use crate::event_handlers::{Callback, EventHandler, MatchEvent};
pub use crate::logger::SmtpdLogger; pub use crate::logger::SmtpdLogger;
pub use opensmtpd_derive::event; pub use opensmtpd_derive::{event, report};
#[macro_export] #[macro_export]
macro_rules! handlers { macro_rules! handlers {