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:
parent
ae8b64941e
commit
c20fadf99d
3 changed files with 10 additions and 5 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Reference in a new issue