Add a context object the callbacks

Many filters requires to keep a state within a session. Although it not
currently possible to do so, the callback now accept a mutable object of
type NoContext. This is the first step, the next one will be to accept
any type that implements both Clone and Default.
An other step will be to allow the user to define different callback
parameters depending on his/her needs.
This commit is contained in:
Rodolphe Breard 2019-01-12 00:17:59 +01:00
parent ea710408d4
commit 11f3712138
5 changed files with 76 additions and 42 deletions

View file

@ -1,15 +1,15 @@
use env_logger::{Builder, Env};
use log::{debug, info};
use opensmtpd::{event, handlers, Entry, Response, SmtpIn};
use opensmtpd::{event, handlers, Entry, NoContext, Response, SmtpIn};
#[event(Any)]
fn on_event(entry: &Entry) -> Response {
fn on_event(_context: &mut NoContext, entry: &Entry) -> Response {
debug!("Event received: {:?}", entry);
Response::None
}
#[event(LinkConnect)]
fn on_connect(entry: &Entry) -> Response {
fn on_connect(_context: &mut NoContext, entry: &Entry) -> Response {
info!("New client on session {:x}.", entry.session_id);
Response::None
}