diff --git a/rust/Makefile.am b/rust/Makefile.am index a687c37017..d547d8e3e4 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -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.*' \ diff --git a/rust/cbindgen.toml b/rust/cbindgen.toml index 3a661747db..4122670374 100644 --- a/rust/cbindgen.toml +++ b/rust/cbindgen.toml @@ -76,7 +76,6 @@ include = [ "StreamSlice", "AppLayerResult", "AppLayerStateData", - "AppLayerGetFileState", "AppLayerGetTxIterTuple", "RdpState", "SIPState", diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 44495d1083..ac69659a64 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -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() } } } diff --git a/rust/src/smb/files.rs b/rust/src/smb/files.rs index 48dd089f78..0352eb7f0f 100644 --- a/rust/src/smb/files.rs +++ b/rust/src/smb/files.rs @@ -16,6 +16,7 @@ */ use std; +use crate::applayer::AppLayerGetFileStateRust; use crate::core::*; use crate::direction::Direction; use crate::filetracker::*; diff --git a/rust/sys/src/sys.rs b/rust/sys/src/sys.rs index 94f8ce3338..e179f0e1cc 100644 --- a/rust/sys/src/sys.rs +++ b/rust/sys/src/sys.rs @@ -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::::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( diff --git a/src/util-file.h b/src/util-file.h index fd0bea0a9d..47ae3dd3eb 100644 --- a/src/util-file.h +++ b/src/util-file.h @@ -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.