Skip to content

Commit 330d8e8

Browse files
committed
output-eve: bindgen SCEveFileType callback types
1 parent 958b449 commit 330d8e8

2 files changed

Lines changed: 62 additions & 35 deletions

File tree

rust/sys/src/sys.rs

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -470,46 +470,57 @@ extern "C" {
470470
reg_data: EveJsonTxLoggerRegistrationData,
471471
) -> ::std::os::raw::c_int;
472472
}
473+
#[doc = " \\brief Function type for EVE file-type initialization."]
474+
pub type SCEveFileTypeInitFunc = ::std::option::Option<
475+
unsafe extern "C" fn(
476+
conf: *const SCConfNode,
477+
threaded: bool,
478+
init_data: *mut *mut ::std::os::raw::c_void,
479+
) -> ::std::os::raw::c_int,
480+
>;
481+
#[doc = " \\brief Function type for EVE file-type thread initialization."]
482+
pub type SCEveFileTypeThreadInitFunc = ::std::option::Option<
483+
unsafe extern "C" fn(
484+
init_data: *const ::std::os::raw::c_void,
485+
thread_id: ThreadId,
486+
thread_data: *mut *mut ::std::os::raw::c_void,
487+
) -> ::std::os::raw::c_int,
488+
>;
489+
#[doc = " \\brief Function type for EVE file-type writes."]
490+
pub type SCEveFileTypeWriteFunc = ::std::option::Option<
491+
unsafe extern "C" fn(
492+
buffer: *const ::std::os::raw::c_char,
493+
buffer_len: ::std::os::raw::c_int,
494+
init_data: *const ::std::os::raw::c_void,
495+
thread_data: *mut ::std::os::raw::c_void,
496+
) -> ::std::os::raw::c_int,
497+
>;
498+
#[doc = " \\brief Function type for EVE file-type thread deinitialization."]
499+
pub type SCEveFileTypeThreadDeinitFunc = ::std::option::Option<
500+
unsafe extern "C" fn(
501+
init_data: *const ::std::os::raw::c_void,
502+
thread_data: *mut ::std::os::raw::c_void,
503+
),
504+
>;
505+
#[doc = " \\brief Function type for EVE file-type deinitialization."]
506+
pub type SCEveFileTypeDeinitFunc =
507+
::std::option::Option<unsafe extern "C" fn(init_data: *mut ::std::os::raw::c_void)>;
473508
#[doc = " \\brief Structure used to define an EVE output file type.\n\n EVE filetypes implement an object with a file-like interface and\n are used to output EVE log records to files, syslog, or\n database. They can be built-in such as the syslog (see\n SyslogInitialize()) and nullsink (see NullLogInitialize()) outputs,\n registered by a library user or dynamically loaded as a plugin.\n\n The life cycle of an EVE filetype is:\n - Init: called once for each EVE instance using this filetype\n - ThreadInit: called once for each output thread\n - Write: called for each log record\n - ThreadDeinit: called once for each output thread on exit\n - Deinit: called once for each EVE instance using this filetype on exit\n\n Examples:\n - built-in syslog: \\ref src/output-eve-syslog.c\n - built-in nullsink: \\ref src/output-eve-null.c\n - example plugin: \\ref examples/plugins/c-json-filetype/filetype.c\n\n ### Multi-Threaded Note:\n\n The EVE logging system can be configured by the Suricata user to\n run in threaded or non-threaded modes. In the default non-threaded\n mode, ThreadInit will only be called once and the filetype does not\n need to be concerned with threads.\n\n However, in **threaded** mode, ThreadInit will be called multiple\n times and the filetype needs to be thread aware and thread-safe. If\n utilizing a unique resource such as a file for each thread then you\n may be naturally thread safe. However, if sharing a single file\n handle across all threads then your filetype will have to take care\n of locking, etc."]
474509
#[repr(C)]
475510
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
476511
pub struct SCEveFileType_ {
477512
#[doc = " \\brief The name of the output, used in the configuration.\n\n This name is used by the configuration file to specify the EVE\n filetype used.\n\n For example:\n\n \\code{.yaml}\n outputs:\n - eve-log:\n filetype: my-output-name\n \\endcode"]
478513
pub name: *const ::std::os::raw::c_char,
479514
#[doc = " \\brief Function to initialize this filetype.\n\n \\param conf The ConfNode of the `eve-log` configuration\n section this filetype is being initialized for\n\n \\param threaded Flag to specify if the EVE sub-systems is in\n threaded mode or not\n\n \\param init_data An output pointer for filetype specific data\n\n \\retval 0 on success, -1 on failure"]
480-
pub Init: ::std::option::Option<
481-
unsafe extern "C" fn(
482-
conf: *const SCConfNode,
483-
threaded: bool,
484-
init_data: *mut *mut ::std::os::raw::c_void,
485-
) -> ::std::os::raw::c_int,
486-
>,
515+
pub Init: SCEveFileTypeInitFunc,
487516
#[doc = " \\brief Initialize thread specific data.\n\n Initialize any thread specific data. For example, if\n implementing a file output you might open the files here, so\n you have one output file per thread.\n\n \\param init_data Data setup during Init\n\n \\param thread_id A unique ID to differentiate this thread from\n others. If EVE is not in threaded mode this will be called\n once with a ThreadId of 0. In threaded mode the ThreadId of\n 0 correlates to the main Suricata thread.\n\n \\param thread_data Output pointer for any data required by this\n thread.\n\n \\retval 0 on success, -1 on failure"]
488-
pub ThreadInit: ::std::option::Option<
489-
unsafe extern "C" fn(
490-
init_data: *const ::std::os::raw::c_void,
491-
thread_id: ThreadId,
492-
thread_data: *mut *mut ::std::os::raw::c_void,
493-
) -> ::std::os::raw::c_int,
494-
>,
517+
pub ThreadInit: SCEveFileTypeThreadInitFunc,
495518
#[doc = " \\brief Called for each EVE log record.\n\n The Write function is called for each log EVE log record. The\n provided buffer contains a fully formatted EVE record in JSON\n format.\n\n \\param buffer The fully formatted JSON EVE log record\n\n \\param buffer_len The length of the buffer\n\n \\param init_data The data setup in the call to Init\n\n \\param thread_data The data setup in the call to ThreadInit\n\n \\retval 0 on success, -1 on failure"]
496-
pub Write: ::std::option::Option<
497-
unsafe extern "C" fn(
498-
buffer: *const ::std::os::raw::c_char,
499-
buffer_len: ::std::os::raw::c_int,
500-
init_data: *const ::std::os::raw::c_void,
501-
thread_data: *mut ::std::os::raw::c_void,
502-
) -> ::std::os::raw::c_int,
503-
>,
519+
pub Write: SCEveFileTypeWriteFunc,
504520
#[doc = " \\brief Called to deinitialize each thread.\n\n This function will be called for each thread. It is where any\n resources allocated in ThreadInit should be released.\n\n \\param init_data The data setup in Init\n\n \\param thread_data The data setup in ThreadInit"]
505-
pub ThreadDeinit: ::std::option::Option<
506-
unsafe extern "C" fn(
507-
init_data: *const ::std::os::raw::c_void,
508-
thread_data: *mut ::std::os::raw::c_void,
509-
),
510-
>,
521+
pub ThreadDeinit: SCEveFileTypeThreadDeinitFunc,
511522
#[doc = " \\brief Final call to deinitialize this filetype.\n\n Called, usually on exit to deinitialize and free any resources\n allocated during Init.\n\n \\param init_data Data setup in the call to Init."]
512-
pub Deinit: ::std::option::Option<unsafe extern "C" fn(init_data: *mut ::std::os::raw::c_void)>,
523+
pub Deinit: SCEveFileTypeDeinitFunc,
513524
pub entries: SCEveFileType___bindgen_ty_1,
514525
}
515526
#[repr(C)]

src/output-eve-bindgen.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ typedef struct EveJsonTxLoggerRegistrationData {
5656

5757
int SCOutputEvePreRegisterLogger(EveJsonTxLoggerRegistrationData reg_data);
5858

59+
/** \brief Function type for EVE file-type initialization. */
60+
typedef int (*SCEveFileTypeInitFunc)(const SCConfNode *conf, const bool threaded, void **init_data);
61+
62+
/** \brief Function type for EVE file-type thread initialization. */
63+
typedef int (*SCEveFileTypeThreadInitFunc)(
64+
const void *init_data, const ThreadId thread_id, void **thread_data);
65+
66+
/** \brief Function type for EVE file-type writes. */
67+
typedef int (*SCEveFileTypeWriteFunc)(
68+
const char *buffer, const int buffer_len, const void *init_data, void *thread_data);
69+
70+
/** \brief Function type for EVE file-type thread deinitialization. */
71+
typedef void (*SCEveFileTypeThreadDeinitFunc)(const void *init_data, void *thread_data);
72+
73+
/** \brief Function type for EVE file-type deinitialization. */
74+
typedef void (*SCEveFileTypeDeinitFunc)(void *init_data);
75+
5976
/** \brief Structure used to define an EVE output file type.
6077
*
6178
* EVE filetypes implement an object with a file-like interface and
@@ -120,7 +137,7 @@ typedef struct SCEveFileType_ {
120137
*
121138
* \retval 0 on success, -1 on failure
122139
*/
123-
int (*Init)(const SCConfNode *conf, const bool threaded, void **init_data);
140+
SCEveFileTypeInitFunc Init;
124141

125142
/**
126143
* \brief Initialize thread specific data.
@@ -141,7 +158,7 @@ typedef struct SCEveFileType_ {
141158
*
142159
* \retval 0 on success, -1 on failure
143160
*/
144-
int (*ThreadInit)(const void *init_data, const ThreadId thread_id, void **thread_data);
161+
SCEveFileTypeThreadInitFunc ThreadInit;
145162

146163
/**
147164
* \brief Called for each EVE log record.
@@ -160,8 +177,7 @@ typedef struct SCEveFileType_ {
160177
*
161178
* \retval 0 on success, -1 on failure
162179
*/
163-
int (*Write)(
164-
const char *buffer, const int buffer_len, const void *init_data, void *thread_data);
180+
SCEveFileTypeWriteFunc Write;
165181

166182
/**
167183
* \brief Called to deinitialize each thread.
@@ -173,7 +189,7 @@ typedef struct SCEveFileType_ {
173189
*
174190
* \param thread_data The data setup in ThreadInit
175191
*/
176-
void (*ThreadDeinit)(const void *init_data, void *thread_data);
192+
SCEveFileTypeThreadDeinitFunc ThreadDeinit;
177193

178194
/**
179195
* \brief Final call to deinitialize this filetype.
@@ -183,7 +199,7 @@ typedef struct SCEveFileType_ {
183199
*
184200
* \param init_data Data setup in the call to Init.
185201
*/
186-
void (*Deinit)(void *init_data);
202+
SCEveFileTypeDeinitFunc Deinit;
187203

188204
/* Internal list management. */
189205
TAILQ_ENTRY(SCEveFileType_) entries;

0 commit comments

Comments
 (0)