diff --git a/src/log-tcp-data.c b/src/log-tcp-data.c index c3dadd4416..b1ebfca397 100644 --- a/src/log-tcp-data.c +++ b/src/log-tcp-data.c @@ -61,18 +61,13 @@ static void LogTcpDataLogDeInitCtx(OutputCtx *); int LogTcpDataLogger(ThreadVars *tv, void *thread_data, const Flow *f, const uint8_t *data, uint32_t data_len, uint64_t tx_id, uint8_t flags); void TmModuleLogTcpDataLogRegister (void) { - tmm_modules[TMM_LOGTCPDATALOG].name = MODULE_NAME; - tmm_modules[TMM_LOGTCPDATALOG].ThreadInit = LogTcpDataLogThreadInit; - tmm_modules[TMM_LOGTCPDATALOG].ThreadExitPrintStats = LogTcpDataLogExitPrintStats; - tmm_modules[TMM_LOGTCPDATALOG].ThreadDeinit = LogTcpDataLogThreadDeinit; - tmm_modules[TMM_LOGTCPDATALOG].RegisterTests = NULL; - tmm_modules[TMM_LOGTCPDATALOG].cap_flags = 0; - tmm_modules[TMM_LOGTCPDATALOG].flags = TM_FLAG_LOGAPI_TM; - OutputRegisterStreamingModule(MODULE_NAME, "tcp-data", LogTcpDataLogInitCtx, - LogTcpDataLogger, STREAMING_TCP_DATA); - OutputRegisterStreamingModule(MODULE_NAME, "http-body-data", LogTcpDataLogInitCtx, - LogTcpDataLogger, STREAMING_HTTP_BODIES); + LogTcpDataLogger, STREAMING_TCP_DATA, LogTcpDataLogThreadInit, + LogTcpDataLogThreadDeinit, LogTcpDataLogExitPrintStats); + OutputRegisterStreamingModule(MODULE_NAME, "http-body-data", + LogTcpDataLogInitCtx, LogTcpDataLogger, STREAMING_HTTP_BODIES, + LogTcpDataLogThreadInit, LogTcpDataLogThreadDeinit, + LogTcpDataLogExitPrintStats); } typedef struct LogTcpDataFileCtx_ { diff --git a/src/output-streaming.c b/src/output-streaming.c index 2955066203..b72a38a44f 100644 --- a/src/output-streaming.c +++ b/src/output-streaming.c @@ -55,16 +55,23 @@ typedef struct OutputStreamingLogger_ { const char *name; TmmId module_id; enum OutputStreamingType type; + ThreadInitFunc ThreadInit; + ThreadDeinitFunc ThreadDeinit; + ThreadExitPrintStatsFunc ThreadExitPrintStats; } OutputStreamingLogger; static OutputStreamingLogger *list = NULL; int OutputRegisterStreamingLogger(const char *name, StreamingLogger LogFunc, - OutputCtx *output_ctx, enum OutputStreamingType type ) + OutputCtx *output_ctx, enum OutputStreamingType type, + ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats) { +#if 0 int module_id = TmModuleGetIdByName(name); if (module_id < 0) return -1; +#endif OutputStreamingLogger *op = SCMalloc(sizeof(*op)); if (op == NULL) @@ -74,8 +81,13 @@ int OutputRegisterStreamingLogger(const char *name, StreamingLogger LogFunc, op->LogFunc = LogFunc; op->output_ctx = output_ctx; op->name = name; +#if 0 op->module_id = (TmmId) module_id; +#endif op->type = type; + op->ThreadInit = ThreadInit; + op->ThreadDeinit = ThreadDeinit; + op->ThreadExitPrintStats = ThreadExitPrintStats; if (list == NULL) list = op; @@ -368,16 +380,9 @@ static TmEcode OutputStreamingLogThreadInit(ThreadVars *tv, void *initdata, void OutputStreamingLogger *logger = list; while (logger) { - TmModule *tm_module = TmModuleGetByName((char *)logger->name); - if (tm_module == NULL) { - SCLogError(SC_ERR_INVALID_ARGUMENT, - "TmModuleGetByName for %s failed", logger->name); - exit(EXIT_FAILURE); - } - - if (tm_module->ThreadInit) { + if (logger->ThreadInit) { void *retptr = NULL; - if (tm_module->ThreadInit(tv, (void *)logger->output_ctx, &retptr) == TM_ECODE_OK) { + if (logger->ThreadInit(tv, (void *)logger->output_ctx, &retptr) == TM_ECODE_OK) { OutputLoggerThreadStore *ts = SCMalloc(sizeof(*ts)); /* todo */ BUG_ON(ts == NULL); memset(ts, 0x00, sizeof(*ts)); @@ -412,15 +417,8 @@ static TmEcode OutputStreamingLogThreadDeinit(ThreadVars *tv, void *thread_data) OutputStreamingLogger *logger = list; while (logger && store) { - TmModule *tm_module = TmModuleGetByName((char *)logger->name); - if (tm_module == NULL) { - SCLogError(SC_ERR_INVALID_ARGUMENT, - "TmModuleGetByName for %s failed", logger->name); - exit(EXIT_FAILURE); - } - - if (tm_module->ThreadDeinit) { - tm_module->ThreadDeinit(tv, store->thread_data); + if (logger->ThreadDeinit) { + logger->ThreadDeinit(tv, store->thread_data); } logger = logger->next; @@ -436,15 +434,8 @@ static void OutputStreamingLogExitPrintStats(ThreadVars *tv, void *thread_data) OutputStreamingLogger *logger = list; while (logger && store) { - TmModule *tm_module = TmModuleGetByName((char *)logger->name); - if (tm_module == NULL) { - SCLogError(SC_ERR_INVALID_ARGUMENT, - "TmModuleGetByName for %s failed", logger->name); - exit(EXIT_FAILURE); - } - - if (tm_module->ThreadExitPrintStats) { - tm_module->ThreadExitPrintStats(tv, store->thread_data); + if (logger->ThreadExitPrintStats) { + logger->ThreadExitPrintStats(tv, store->thread_data); } logger = logger->next; diff --git a/src/output-streaming.h b/src/output-streaming.h index 8b30374228..9508903a8a 100644 --- a/src/output-streaming.h +++ b/src/output-streaming.h @@ -45,8 +45,10 @@ typedef int (*StreamingLogger)(ThreadVars *, void *thread_data, const Flow *f, const uint8_t *data, uint32_t data_len, uint64_t tx_id, uint8_t flags); -int OutputRegisterStreamingLogger(const char *name, StreamingLogger LogFunc, OutputCtx *, - enum OutputStreamingType); +int OutputRegisterStreamingLogger(const char *name, StreamingLogger LogFunc, + OutputCtx *, enum OutputStreamingType, ThreadInitFunc ThreadInit, + ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats); void TmModuleStreamingLoggerRegister (void); diff --git a/src/output.c b/src/output.c index 85840cb18e..351cd294ae 100644 --- a/src/output.c +++ b/src/output.c @@ -587,7 +587,9 @@ error: void OutputRegisterStreamingModule(const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *), StreamingLogger StreamingLogFunc, - enum OutputStreamingType stream_type) + enum OutputStreamingType stream_type, ThreadInitFunc ThreadInit, + ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats) { if (unlikely(StreamingLogFunc == NULL)) { goto error; @@ -603,6 +605,9 @@ OutputRegisterStreamingModule(const char *name, const char *conf_name, module->InitFunc = InitFunc; module->StreamingLogFunc = StreamingLogFunc; module->stream_type = stream_type; + module->ThreadInit = ThreadInit; + module->ThreadDeinit = ThreadDeinit; + module->ThreadExitPrintStats = ThreadExitPrintStats; TAILQ_INSERT_TAIL(&output_modules, module, entries); SCLogDebug("Streaming logger \"%s\" registered.", name); @@ -623,7 +628,9 @@ error: void OutputRegisterStreamingSubModule(const char *parent_name, const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), - StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type) + StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type, + ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats) { if (unlikely(StreamingLogFunc == NULL)) { goto error; @@ -640,6 +647,9 @@ OutputRegisterStreamingSubModule(const char *parent_name, const char *name, module->InitSubFunc = InitFunc; module->StreamingLogFunc = StreamingLogFunc; module->stream_type = stream_type; + module->ThreadInit = ThreadInit; + module->ThreadDeinit = ThreadDeinit; + module->ThreadExitPrintStats = ThreadExitPrintStats; TAILQ_INSERT_TAIL(&output_modules, module, entries); SCLogDebug("Streaming logger \"%s\" registered.", name); diff --git a/src/output.h b/src/output.h index 073f810cad..e34d34379d 100644 --- a/src/output.h +++ b/src/output.h @@ -153,10 +153,14 @@ void OutputRegisterFlowSubModule(const char *parent_name, const char *name, void OutputRegisterStreamingModule(const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *), StreamingLogger StreamingLogFunc, - enum OutputStreamingType stream_type); + enum OutputStreamingType stream_type, ThreadInitFunc ThreadInit, + ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats); void OutputRegisterStreamingSubModule(const char *parent_name, const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), - StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type); + StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type, + ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats); void OutputRegisterStatsModule(const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *), StatsLogger StatsLogFunc, diff --git a/src/runmodes.c b/src/runmodes.c index 903f9a99a3..3f043b9409 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -711,7 +711,8 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu } else if (module->StreamingLogFunc) { SCLogDebug("%s is a streaming logger", module->name); OutputRegisterStreamingLogger(module->name, module->StreamingLogFunc, - output_ctx, module->stream_type); + output_ctx, module->stream_type, module->ThreadInit, + module->ThreadDeinit, module->ThreadExitPrintStats); /* need one instance of the streaming logger module */ if (streaming_logger_module == NULL) { diff --git a/src/tm-modules.c b/src/tm-modules.c index 49d519e66f..cab1538384 100644 --- a/src/tm-modules.c +++ b/src/tm-modules.c @@ -214,7 +214,6 @@ const char * TmModuleTmmIdToString(TmmId id) CASE_CODE (TMM_ALERTDEBUGLOG); CASE_CODE (TMM_RESPONDREJECT); CASE_CODE (TMM_LOGTLSLOG); - CASE_CODE (TMM_LOGTCPDATALOG); CASE_CODE (TMM_PCAPLOG); CASE_CODE (TMM_DECODEIPFW); CASE_CODE (TMM_VERDICTIPFW); diff --git a/src/tm-threads-common.h b/src/tm-threads-common.h index dfebc45429..b528053b1e 100644 --- a/src/tm-threads-common.h +++ b/src/tm-threads-common.h @@ -44,7 +44,6 @@ typedef enum { TMM_ALERTDEBUGLOG, TMM_RESPONDREJECT, TMM_LOGTLSLOG, - TMM_LOGTCPDATALOG, TMM_OUTPUTJSON, TMM_PCAPLOG, TMM_DECODEIPFW,