output/plugin: API changes for threaded support

This commit extends the interface to better support file output plugins.
pull/6109/head
Jeff Lucovsky 4 years ago committed by Victor Julien
parent 0ed62e93ec
commit 05836a4452

@ -1194,7 +1194,7 @@ OutputInitResult OutputJsonInitCtx(ConfNode *conf)
ConfNode *plugin_conf = ConfNodeLookupChild(conf,
json_ctx->plugin->name);
void *plugin_data = NULL;
if (json_ctx->plugin->Open(plugin_conf, &plugin_data) < 0) {
if (json_ctx->plugin->Init(plugin_conf, false, &plugin_data) < 0) {
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
SCFree(output_ctx);

@ -1,4 +1,4 @@
/* Copyright (C) 2020 Open Information Security Foundation
/* Copyright (C) 2020-2021 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -45,12 +45,22 @@ typedef struct SCPlugin_ {
* Structure used to define a file type plugin.
*
* Currently only used by the Eve output type.
*
* name -- The plugin name. This name is used to identify the plugin: eve-log.filetype and in the
* plugins: section
*/
typedef struct SCPluginFileType_ {
char *name;
int (*Open)(ConfNode *conf, void **data);
int (*Write)(const char *buffer, int buffer_len, void *ctx);
void (*Close)(void *ctx);
/* Init Called on first access */
int (*Init)(ConfNode *conf, bool threaded, void **init_data);
/* Write - Called on each write to the object */
int (*Write)(const char *buffer, int buffer_len, void *init_data, void *thread_data);
/* Close - Called on final close */
void (*Deinit)(void *init_data);
/* ThreadInit - Called for each thread using file object*/
int (*ThreadInit)(void *init_data, int thread_id, void **thread_data);
/* ThreadDeinit - Called for each thread using file object */
int (*ThreadDeinit)(void *init_data, void *thread_data);
TAILQ_ENTRY(SCPluginFileType_) entries;
} SCPluginFileType;
@ -59,6 +69,8 @@ bool SCPluginRegisterFileType(SCPluginFileType *);
typedef struct SCCapturePlugin_ {
char *name;
void (*Init)(const char *args, int plugin_slot, int receive_slot, int decode_slot);
int (*ThreadInit)(void *ctx, int thread_id, void **thread_ctx);
int (*ThreadDeinit)(void *ctx, void *thread_ctx);
const char *(*GetDefaultMode)(void);
TAILQ_ENTRY(SCCapturePlugin_) entries;
} SCCapturePlugin;

@ -831,8 +831,8 @@ int LogFileFreeCtx(LogFileCtx *lf_ctx)
SCFree(lf_ctx->threads);
} else {
if (lf_ctx->type == LOGFILE_TYPE_PLUGIN) {
if (lf_ctx->plugin->Close != NULL) {
lf_ctx->plugin->Close(lf_ctx->plugin_data);
if (lf_ctx->plugin->Deinit != NULL) {
lf_ctx->plugin->Deinit(lf_ctx->plugin_data);
}
} else if (lf_ctx->fp != NULL) {
lf_ctx->Close(lf_ctx);
@ -889,7 +889,7 @@ int LogFileWrite(LogFileCtx *file_ctx, MemBuffer *buffer)
#endif
else if (file_ctx->type == LOGFILE_TYPE_PLUGIN) {
file_ctx->plugin->Write((const char *)MEMBUFFER_BUFFER(buffer),
MEMBUFFER_OFFSET(buffer), file_ctx->plugin_data);
MEMBUFFER_OFFSET(buffer), file_ctx->plugin_data, NULL);
}
return 0;

Loading…
Cancel
Save