Skip to content

Commit 5531150

Browse files
committed
rust/ffi: rust wrapper around eve filetype registration
1 parent 330d8e8 commit 5531150

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

rust/ffi/src/eve.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* Copyright (C) 2026 Open Information Security Foundation
2+
*
3+
* You can copy, redistribute or modify this Program under the terms of
4+
* the GNU General Public License version 2 as published by the Free
5+
* Software Foundation.
6+
*
7+
* This program is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
* GNU General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License
13+
* version 2 along with this program; if not, write to the Free Software
14+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15+
* 02110-1301, USA.
16+
*/
17+
18+
use std::ffi::CString;
19+
20+
use suricata_sys::sys::{
21+
SCEveFileType, SCEveFileTypeDeinitFunc, SCEveFileTypeInitFunc, SCEveFileTypeThreadDeinitFunc,
22+
SCEveFileTypeThreadInitFunc, SCEveFileTypeWriteFunc, SCRegisterEveFileType,
23+
};
24+
25+
pub struct EveFileType {
26+
pub name: &'static str,
27+
pub init: SCEveFileTypeInitFunc,
28+
pub deinit: SCEveFileTypeDeinitFunc,
29+
pub write: SCEveFileTypeWriteFunc,
30+
pub thread_init: SCEveFileTypeThreadInitFunc,
31+
pub thread_deinit: SCEveFileTypeThreadDeinitFunc,
32+
}
33+
34+
impl EveFileType {
35+
pub fn register(ft: Self) -> Result<(), &'static str> {
36+
let name = CString::new(ft.name).map_err(|_| "invalid name")?;
37+
if ft.init.is_none() {
38+
return Err("None not allowed for init");
39+
}
40+
if ft.deinit.is_none() {
41+
return Err("None not allowed for deinit");
42+
}
43+
if ft.write.is_none() {
44+
return Err("None now allowed for write");
45+
}
46+
if ft.thread_init.is_none() {
47+
return Err("None now allowed for thread_init");
48+
}
49+
if ft.thread_deinit.is_none() {
50+
return Err("None not allowed for thread_deinit");
51+
}
52+
let mut cft = Box::new(SCEveFileType {
53+
name: name.as_ptr(),
54+
Init: ft.init,
55+
ThreadInit: ft.thread_init,
56+
Write: ft.write,
57+
ThreadDeinit: ft.thread_deinit,
58+
Deinit: ft.deinit,
59+
entries: Default::default(),
60+
});
61+
if unsafe { SCRegisterEveFileType(&mut *cft) } {
62+
std::mem::forget(cft);
63+
std::mem::forget(name);
64+
Ok(())
65+
} else {
66+
Err("Failed to register EveFileType")
67+
}
68+
}
69+
}

rust/ffi/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
*/
1717

1818
pub mod debug;
19+
pub mod eve;
1920
pub mod plugin;

0 commit comments

Comments
 (0)