Add a Response object
This object will abstract the filter response. For now, it only allow not to respond. This will change in a future version.
This commit is contained in:
parent
21efb88331
commit
4ed4609272
3 changed files with 16 additions and 9 deletions
|
@ -1,17 +1,17 @@
|
|||
use env_logger::{Builder, Env};
|
||||
use log::{debug, info};
|
||||
use opensmtpd::{event, handlers, Entry, SmtpIn};
|
||||
use opensmtpd::{event, handlers, Entry, Response, SmtpIn};
|
||||
|
||||
#[event(Any)]
|
||||
fn on_event(entry: &Entry) -> bool {
|
||||
fn on_event(entry: &Entry) -> Response {
|
||||
debug!("Event received: {:?}", entry);
|
||||
true
|
||||
Response::None
|
||||
}
|
||||
|
||||
#[event(LinkConnect)]
|
||||
fn on_connect(entry: &Entry) -> bool {
|
||||
fn on_connect(entry: &Entry) -> Response {
|
||||
info!("New client on session {:x}.", entry.session_id);
|
||||
true
|
||||
Response::None
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::entry::{Entry, Event};
|
||||
use crate::Response;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum MatchEvent {
|
||||
|
@ -9,7 +10,7 @@ pub enum MatchEvent {
|
|||
#[derive(Clone)]
|
||||
pub struct EventHandler {
|
||||
event: MatchEvent,
|
||||
callback: (fn(&Entry) -> bool),
|
||||
callback: (fn(&Entry) -> Response),
|
||||
}
|
||||
|
||||
impl EventHandler {
|
||||
|
@ -31,7 +32,7 @@ impl EventHandler {
|
|||
MatchEvent::Evt(events)
|
||||
}
|
||||
|
||||
pub fn new(event_str: String, callback: (fn(&Entry) -> bool)) -> Self {
|
||||
pub fn new(event_str: String, callback: (fn(&Entry) -> Response)) -> Self {
|
||||
EventHandler {
|
||||
event: EventHandler::get_events_from_string(&event_str),
|
||||
callback,
|
||||
|
@ -45,7 +46,9 @@ impl EventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn call(&self, entry: &Entry) -> bool {
|
||||
(self.callback)(entry)
|
||||
pub fn call(&self, entry: &Entry) {
|
||||
match (self.callback)(entry) {
|
||||
Response::None => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,10 @@ macro_rules! handlers {
|
|||
};
|
||||
}
|
||||
|
||||
pub enum Response {
|
||||
None,
|
||||
}
|
||||
|
||||
struct SessionHandler {
|
||||
entry_rx: mpsc::Receiver<Entry>,
|
||||
event_handlers: Vec<EventHandler>,
|
||||
|
|
Reference in a new issue