Refactor the library
Threads are a bad idea because for now the filter API is not guaranteed to be state-less. The interface is now synchronous, which should be enough for most filters. The refactoring brought other changes, the most important being the concept of modular input sources and output destination and the complete rewrite of the procedural macro.
This commit is contained in:
parent
988f028c23
commit
45639f18c0
18 changed files with 486 additions and 400 deletions
|
@ -1,19 +0,0 @@
|
|||
use log::{debug, info, Level};
|
||||
use opensmtpd::{event, handlers, Entry, SmtpIn, SmtpdLogger};
|
||||
|
||||
#[event(Any)]
|
||||
fn on_event(entry: &Entry) {
|
||||
debug!("Event received: {:?}", entry);
|
||||
}
|
||||
|
||||
#[event(LinkConnect)]
|
||||
fn on_connect(entry: &Entry) {
|
||||
info!("New client on session {:x}.", entry.get_session_id());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = SmtpdLogger::new().set_level(Level::Debug).init();
|
||||
SmtpIn::new()
|
||||
.event_handlers(handlers!(on_event, on_connect))
|
||||
.run();
|
||||
}
|
18
opensmtpd/examples/echo.rs
Normal file
18
opensmtpd/examples/echo.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use opensmtpd::entry::Entry;
|
||||
use opensmtpd::{report, simple_filter};
|
||||
|
||||
#[report(v1, smtp_in, match(all))]
|
||||
fn echo_handler(entry: &Entry) -> Result<(), String> {
|
||||
log::info!("TEST ENTRY: {:?}", entry);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[report(v1, smtp_in, match(link_disconnect))]
|
||||
fn test(entry: &Entry) {
|
||||
log::info!("HAZ LINK DISCONNECT: {:?}", entry);
|
||||
Ok(()) // TODO: REMOVE ME!
|
||||
}
|
||||
|
||||
fn main() {
|
||||
simple_filter!(echo_handler, test);
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
use log::{info, Level};
|
||||
use opensmtpd::{handlers, report, Entry, SmtpIn, SmtpdLogger};
|
||||
use opensmtpd::{report, simple_filter};
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct MyContext {
|
||||
|
@ -13,6 +12,5 @@ fn on_report(ctx: &mut MyContext, entry: &Entry) {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let _ = SmtpdLogger::new().set_level(Level::Debug).init();
|
||||
SmtpIn::new().event_handlers(handlers!(on_report)).run();
|
||||
simple_filter!(vec![on_report]);
|
||||
}
|
||||
|
|
Reference in a new issue