rust: move AppLayerGetFileState definition to C

and bindgen it to rust.

Will make easier the bindgen of RustParser structure which uses
a callback which uses AppLayerGetFileState
pull/14758/head
Philippe Antoine 9 months ago committed by Victor Julien
parent fc23e54c6d
commit 76efb8af4d

@ -146,6 +146,7 @@ if HAVE_BINDGEN
--allowlist-function 'File.*' \
--allowlist-type 'SC.*' \
--allowlist-type 'AppLayerEventType' \
--allowlist-type 'AppLayerGetFileState' \
--allowlist-type 'AppLayerGetTxIterState' \
--allowlist-function 'SC.*' \
--allowlist-var 'SC.*' \

@ -76,7 +76,6 @@ include = [
"StreamSlice",
"AppLayerResult",
"AppLayerStateData",
"AppLayerGetFileState",
"AppLayerGetTxIterTuple",
"RdpState",
"SIPState",

@ -20,11 +20,9 @@
use std;
use crate::core::{self,AppLayerEventType, STREAM_TOSERVER};
use crate::direction::Direction;
use crate::filecontainer::FileContainer;
use crate::flow::Flow;
use std::os::raw::{c_void,c_char,c_int};
use std::ffi::CStr;
use crate::core::StreamingBufferConfig;
// Make the AppLayerEvent derive macro available to users importing
// AppLayerEvent from this module.
@ -33,6 +31,7 @@ use suricata_sys::sys::{
AppLayerDecoderEvents, AppLayerGetTxIterState, AppLayerParserState, AppProto,
DetectEngineState, GenericVar,
};
pub use suricata_sys::sys::AppLayerGetFileState;
#[cfg(not(test))]
use suricata_sys::sys::{
SCAppLayerDecoderEventsFreeEvents, SCAppLayerDecoderEventsSetEventRaw, SCDetectEngineStateFree,
@ -478,16 +477,12 @@ macro_rules! build_slice {
($buf:ident, $len:expr) => ( std::slice::from_raw_parts($buf, $len) );
}
/// helper for the GetTxFilesFn. Not meant to be embedded as the config
/// pointer is passed around in the API.
#[allow(non_snake_case)]
#[repr(C)]
pub struct AppLayerGetFileState {
pub fc: *mut FileContainer,
pub cfg: *const StreamingBufferConfig,
pub trait AppLayerGetFileStateRust {
fn err() -> Self;
}
impl AppLayerGetFileState {
pub fn err() -> AppLayerGetFileState {
impl AppLayerGetFileStateRust for AppLayerGetFileState {
fn err() -> AppLayerGetFileState {
AppLayerGetFileState { fc: std::ptr::null_mut(), cfg: std::ptr::null() }
}
}

@ -16,6 +16,7 @@
*/
use std;
use crate::applayer::AppLayerGetFileStateRust;
use crate::core::*;
use crate::direction::Direction;
use crate::filetracker::*;

@ -1145,6 +1145,22 @@ impl Default for FileContainer_ {
}
}
pub type FileContainer = FileContainer_;
#[doc = " helper for the GetTxFilesFn. Not meant to be embedded as the config\n pointer is passed around in the API."]
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct AppLayerGetFileState {
pub fc: *mut FileContainer,
pub cfg: *const StreamingBufferConfig,
}
impl Default for AppLayerGetFileState {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " \\brief Store a chunk of file data in the flow. The open \"flowfile\"\n will be used.\n\n \\param ffc the container\n \\param data data chunk\n \\param data_len data chunk len\n\n \\retval 0 ok\n \\retval -1 error"]
pub fn FileAppendData(

@ -39,6 +39,13 @@ typedef struct FileContainer_ {
File *tail;
} FileContainer;
/// helper for the GetTxFilesFn. Not meant to be embedded as the config
/// pointer is passed around in the API.
typedef struct AppLayerGetFileState {
FileContainer *fc;
const StreamingBufferConfig *cfg;
} AppLayerGetFileState;
/**
* \brief Store a chunk of file data in the flow. The open "flowfile"
* will be used.

Loading…
Cancel
Save