rust: define TxDetectFlag struct and binding macros

Define a TxDetectFlag type and macros to generating C
bindings for getting and settings the tx detect
flags.
pull/4405/head
Jason Ish 6 years ago
parent cde49ec246
commit 8a232be77e

@ -16,6 +16,7 @@
*/
use std;
use core::{STREAM_TOSERVER};
#[repr(C)]
pub struct AppLayerGetTxIterTuple {
@ -96,3 +97,49 @@ macro_rules!export_tx_set_detect_state {
}
)
}
#[derive(Debug,Default)]
pub struct TxDetectFlags {
ts: u64,
tc: u64,
}
impl TxDetectFlags {
pub fn set(&mut self, direction: u8, flags: u64) {
if direction & STREAM_TOSERVER != 0 {
self.ts = flags;
} else {
self.tc = flags;
}
}
pub fn get(&self, direction: u8) -> u64 {
if (direction & STREAM_TOSERVER) != 0 {
self.ts
} else {
self.tc
}
}
}
#[macro_export]
macro_rules!export_tx_detect_flags_set {
($name:ident, $type:ty) => {
#[no_mangle]
pub unsafe extern "C" fn $name(tx: *mut std::os::raw::c_void, direction: u8, flags: u64) {
let tx = &mut *(tx as *mut $type);
tx.detect_flags.set(direction, flags);
}
}
}
#[macro_export]
macro_rules!export_tx_detect_flags_get {
($name:ident, $type:ty) => {
#[no_mangle]
pub unsafe extern "C" fn $name(tx: *mut std::os::raw::c_void, direction: u8) -> u64 {
let tx = &mut *(tx as *mut $type);
return tx.detect_flags.get(direction);
}
}
}

Loading…
Cancel
Save