rust: bindgen FileAppendData

Ticket: 7667
pull/13958/head
Philippe Antoine 10 months ago committed by Victor Julien
parent 811d28cc6b
commit 958344787f

@ -141,6 +141,7 @@ if HAVE_BINDGEN
--default-enum-style rust \
--allowlist-type 'AppProto.*' \
--allowlist-function 'AppProto.*' \
--allowlist-function 'FileAppendData' \
--allowlist-type 'SC.*' \
--allowlist-function 'SC.*' \
--allowlist-var 'SC.*' \

@ -102,7 +102,6 @@ exclude = [
"DetectEngineThreadCtx",
"GenericVar",
"Flow",
"StreamingBufferConfig",
"HttpRangeContainerBlock",
"FileContainer",
"JsonT",

@ -66,7 +66,7 @@ macro_rules!BIT_U64 {
//
// Function types for calls into C.
//
pub enum StreamingBufferConfig {}
pub use suricata_sys::sys::StreamingBufferConfig;
#[allow(non_snake_case)]
#[repr(C)]

@ -17,14 +17,12 @@
use super::mime;
use crate::core::StreamingBufferConfig;
use crate::filecontainer::FileContainer;
use crate::utils::base64;
use digest::Digest;
use digest::Update;
use md5::Md5;
use std::ffi::CStr;
use std::os::raw::c_uchar;
use suricata_sys::sys::SCBasicSearchNocaseIndex;
use suricata_sys::sys::{FileAppendData, FileContainer, SCBasicSearchNocaseIndex};
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Eq)]
@ -258,14 +256,6 @@ fn mime_smtp_process_headers(ctx: &mut MimeStateSMTP) -> (u32, bool) {
return (warnings, encap);
}
extern "C" {
// Defined in util-file.h
pub fn FileAppendData(
c: *mut FileContainer, sbcfg: *const StreamingBufferConfig, data: *const c_uchar,
data_len: u32,
) -> std::os::raw::c_int;
}
fn hex(i: u8) -> Option<u8> {
if i.is_ascii_digit() {
return Some(i - b'0');

@ -753,6 +753,12 @@ pub struct AppLayerParserState_ {
pub type AppLayerParserState = AppLayerParserState_;
#[doc = " \\brief Data structure to store app layer decoder events."]
pub type AppLayerDecoderEvents = AppLayerDecoderEvents_;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct File_ {
_unused: [u8; 0],
}
pub type File = File_;
extern "C" {
#[doc = " \\brief Given a protocol name, checks if the parser is enabled in\n the conf file.\n\n \\param alproto_name Name of the app layer protocol.\n\n \\retval 1 If enabled.\n \\retval 0 If disabled."]
pub fn SCAppLayerParserConfParserEnabled(
@ -866,6 +872,42 @@ extern "C" {
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct StreamingBufferConfig_ {
pub buf_size: u32,
#[doc = "< max concurrent memory regions. 0 means no limit."]
pub max_regions: u16,
#[doc = "< max gap size before a new region will be created."]
pub region_gap: u32,
pub Calloc: ::std::option::Option<
unsafe extern "C" fn(n: usize, size: usize) -> *mut ::std::os::raw::c_void,
>,
pub Realloc: ::std::option::Option<
unsafe extern "C" fn(
ptr: *mut ::std::os::raw::c_void,
orig_size: usize,
size: usize,
) -> *mut ::std::os::raw::c_void,
>,
pub Free:
::std::option::Option<unsafe extern "C" fn(ptr: *mut ::std::os::raw::c_void, size: usize)>,
}
pub type StreamingBufferConfig = StreamingBufferConfig_;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct FileContainer_ {
pub head: *mut File,
pub tail: *mut File,
}
pub type FileContainer = FileContainer_;
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(
arg1: *mut FileContainer, sbcfg: *const StreamingBufferConfig, data: *const u8,
data_len: u32,
) -> ::std::os::raw::c_int;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct GenericVar_ {
#[doc = "< variable type, uses detection sm_type"]
pub type_: u16,

@ -28,6 +28,7 @@
#include "stdint.h"
#include "stdbool.h"
#include "stddef.h"
#define WARN_UNUSED

@ -29,10 +29,32 @@
// uses some structrues from rust
uint16_t SCFileFlowFlagsToFlags(const uint16_t flow_file_flags, uint8_t direction);
#ifndef SURICATA_BINDGEN_H
#include "conf.h"
#include "util-streaming-buffer.h"
typedef struct File_ File;
typedef struct FileContainer_ {
File *head;
File *tail;
} FileContainer;
/**
* \brief Store a chunk of file data in the flow. The open "flowfile"
* will be used.
*
* \param ffc the container
* \param data data chunk
* \param data_len data chunk len
*
* \retval 0 ok
* \retval -1 error
*/
int FileAppendData(FileContainer *, const StreamingBufferConfig *sbcfg, const uint8_t *data,
uint32_t data_len);
#ifndef SURICATA_BINDGEN_H
#include "flow.h"
/* Hack: Pulling rust.h to get the SCSha256 causes all sorts of problems with
@ -116,11 +138,6 @@ typedef struct File_ {
uint32_t sid_max;
} File;
typedef struct FileContainer_ {
File *head;
File *tail;
} FileContainer;
FileContainer *FileContainerAlloc(void);
void FileContainerFree(FileContainer *, const StreamingBufferConfig *cfg);
@ -170,19 +187,6 @@ int FileCloseFileById(FileContainer *, const StreamingBufferConfig *sbcfg, uint3
int FileCloseFilePtr(File *ff, const StreamingBufferConfig *sbcfg, const uint8_t *data,
uint32_t data_len, uint16_t flags);
/**
* \brief Store a chunk of file data in the flow. The open "flowfile"
* will be used.
*
* \param ffc the container
* \param data data chunk
* \param data_len data chunk len
*
* \retval 0 ok
* \retval -1 error
*/
int FileAppendData(FileContainer *, const StreamingBufferConfig *sbcfg, const uint8_t *data,
uint32_t data_len);
int FileAppendDataById(FileContainer *, const StreamingBufferConfig *sbcfg, uint32_t track_id,
const uint8_t *data, uint32_t data_len);
int FileAppendGAPById(FileContainer *ffc, const StreamingBufferConfig *sbcfg, uint32_t track_id,

Loading…
Cancel
Save