rust/app-layer: macros to export de_state functions

These macros generate the extern "C" functions for transactions
structs that need provide functions for setting and getting
the de_state. The idea is to provide macros do avoid code
duplication and make it simpler to create an app-layer.

A trait would be the correct solution, but it doesn't look like
you can use traits to export extern "C" functions.
pull/3394/head
Jason Ish 8 years ago
parent da4912dfe7
commit 2ec3381600

@ -61,3 +61,39 @@ impl LoggerFlags {
}
}
/// Export a function to get the DetectEngineState on a struct.
#[macro_export]
macro_rules!export_tx_get_detect_state {
($name:ident, $type:ty) => (
#[no_mangle]
pub extern "C" fn $name(tx: *mut libc::c_void)
-> *mut core::DetectEngineState
{
let tx = cast_pointer!(tx, $type);
match tx.de_state {
Some(ds) => {
return ds;
},
None => {
return std::ptr::null_mut();
}
}
}
)
}
/// Export a function to set the DetectEngineState on a struct.
#[macro_export]
macro_rules!export_tx_set_detect_state {
($name:ident, $type:ty) => (
#[no_mangle]
pub extern "C" fn $name(tx: *mut libc::c_void,
de_state: &mut core::DetectEngineState) -> libc::c_int
{
let tx = cast_pointer!(tx, $type);
tx.de_state = Some(de_state);
0
}
)
}

@ -35,6 +35,7 @@ pub mod core;
pub mod conf;
pub mod json;
#[macro_use]
pub mod applayer;
pub mod filecontainer;
pub mod filetracker;

Loading…
Cancel
Save