Add the filter proc macro
This commit is contained in:
parent
2dff22062c
commit
789a41b51e
1 changed files with 16 additions and 6 deletions
|
@ -26,8 +26,8 @@ macro_rules! parse_item {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[proc_macro_attribute]
|
fn get_tokenstream(attr: TokenStream, input: TokenStream, type_str: &str) -> TokenStream {
|
||||||
pub fn report(attr: TokenStream, input: TokenStream) -> TokenStream {
|
let kind = parse_item!(type_str, TypePath);
|
||||||
let attr = parse_macro_input!(attr as OpenSmtpdAttributes);
|
let attr = parse_macro_input!(attr as OpenSmtpdAttributes);
|
||||||
let version = parse_item!(&attr.get_version(), TypePath);
|
let version = parse_item!(&attr.get_version(), TypePath);
|
||||||
let subsystem = parse_item!(&attr.get_subsystem(), TypePath);
|
let subsystem = parse_item!(&attr.get_subsystem(), TypePath);
|
||||||
|
@ -40,20 +40,30 @@ pub fn report(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
fn #fn_name() -> opensmtpd::Handler {
|
fn #fn_name() -> opensmtpd::Handler {
|
||||||
opensmtpd::Handler::new(
|
opensmtpd::Handler::new(
|
||||||
#version,
|
#version,
|
||||||
opensmtpd::entry::Kind::Report,
|
#kind,
|
||||||
#subsystem,
|
#subsystem,
|
||||||
&#events,
|
&#events,
|
||||||
|_output: &mut dyn opensmtpd::output::FilterOutput, entry: &opensmtpd::entry::Entry,| {
|
|_output: &mut dyn opensmtpd::output::FilterOutput, _entry: &opensmtpd::entry::Entry,| {
|
||||||
// TODO: look at `item.sig.output` and adapt the calling scheme.
|
// TODO: look at `item.sig.output` and adapt the calling scheme.
|
||||||
// example: if no return, add `Ok(())`.
|
// example: if no return, add `Ok(())`.
|
||||||
// https://docs.rs/syn/1.0.5/syn/struct.Signature.html
|
// https://docs.rs/syn/1.0.5/syn/struct.Signature.html
|
||||||
let inner_fn = |#fn_params| -> Result<(), String> {
|
let inner_fn = |#fn_params| -> Result<(), String> {
|
||||||
#fn_body
|
#fn_body
|
||||||
};
|
};
|
||||||
inner_fn(entry)
|
inner_fn(_entry)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
output.into()
|
output.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[proc_macro_attribute]
|
||||||
|
pub fn report(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
|
get_tokenstream(attr, input, "opensmtpd::entry::Kind::Report")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[proc_macro_attribute]
|
||||||
|
pub fn filter(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
|
get_tokenstream(attr, input, "opensmtpd::entry::Kind::Filter")
|
||||||
|
}
|
||||||
|
|
Reference in a new issue