Remove the Response from the events callback
Events, also known as reports, do not generate responses. Responses must therefore be limited to filters, which are not implemented yet.
This commit is contained in:
parent
82fe5e24de
commit
dd7f4d1a86
2 changed files with 26 additions and 15 deletions
|
@ -1,17 +1,15 @@
|
|||
use env_logger::{Builder, Env};
|
||||
use log::{debug, info};
|
||||
use opensmtpd::{event, handlers, Entry, NoContext, Response, SmtpIn};
|
||||
use opensmtpd::{event, handlers, Entry, NoContext, SmtpIn};
|
||||
|
||||
#[event(Any)]
|
||||
fn on_event(_context: &mut NoContext, entry: &Entry) -> Response {
|
||||
fn on_event(_context: &mut NoContext, entry: &Entry) {
|
||||
debug!("Event received: {:?}", entry);
|
||||
Response::None
|
||||
}
|
||||
|
||||
#[event(LinkConnect)]
|
||||
fn on_connect(_context: &mut NoContext, entry: &Entry) -> Response {
|
||||
fn on_connect(_context: &mut NoContext, entry: &Entry) {
|
||||
info!("New client on session {:x}.", entry.session_id);
|
||||
Response::None
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::entry::{Entry, Event};
|
||||
use crate::Response;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
@ -10,9 +9,9 @@ pub enum MatchEvent {
|
|||
|
||||
#[derive(Clone)]
|
||||
pub enum Callback<T> {
|
||||
NoCtx(fn(&Entry) -> Response),
|
||||
Ctx(fn(&T, &Entry) -> Response),
|
||||
CtxMut(fn(&mut T, &Entry) -> Response),
|
||||
NoCtx(fn(&Entry)),
|
||||
Ctx(fn(&T, &Entry)),
|
||||
CtxMut(fn(&mut T, &Entry)),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -52,14 +51,11 @@ impl<T: Clone + Default> EventHandler<T> {
|
|||
}
|
||||
|
||||
pub fn call(&self, entry: &Entry, context: &mut T) {
|
||||
let ret = match self.callback {
|
||||
match self.callback {
|
||||
Callback::NoCtx(f) => f(entry),
|
||||
Callback::Ctx(f) => f(context, entry),
|
||||
Callback::CtxMut(f) => f(context, entry),
|
||||
};
|
||||
match ret {
|
||||
Response::None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,10 +64,27 @@ mod test {
|
|||
use crate::*;
|
||||
|
||||
#[test]
|
||||
fn test_eventhandler_build() {
|
||||
fn test_eventhandler_build_noctx() {
|
||||
// TODO: Remove the ::<NoContext>
|
||||
EventHandler::new(
|
||||
"Any",
|
||||
|_context: &mut NoContext, _entry: &Entry| -> Response { Response::None },
|
||||
Callback::NoCtx::<NoContext>(|_entry: &Entry| {}),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eventhandler_build_ctx() {
|
||||
EventHandler::new(
|
||||
"Any",
|
||||
Callback::Ctx(|_context: &NoContext, _entry: &Entry| {}),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eventhandler_build_ctxmut() {
|
||||
EventHandler::new(
|
||||
"Any",
|
||||
Callback::CtxMut(|_context: &mut NoContext, _entry: &Entry| {}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue