Have output plugs use an OutputCtx which is a little more generic than LogFileCtx. The OutputCtx provides a place for module private data to avoi overriding the LogFileCtx.

remotes/origin/master-1.0.x
Jason Ish 16 years ago committed by Victor Julien
parent 99d5dc3d2a
commit 40f9653c06

@ -198,7 +198,7 @@ TmEcode AlertDebugLogThreadInit(ThreadVars *t, void *initdata, void **data)
return TM_ECODE_FAILED;
}
/** Use the Ouptut Context (file pointer and mutex) */
aft->file_ctx=(LogFileCtx *) initdata;
aft->file_ctx = ((OutputCtx *)initdata)->data;
*data = (void *)aft;
return TM_ECODE_OK;
@ -232,7 +232,7 @@ void AlertDebugLogExitPrintStats(ThreadVars *tv, void *data) {
* \param ConfNode containing configuration for this logger.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
LogFileCtx *AlertDebugLogInitCtx(ConfNode *conf)
OutputCtx *AlertDebugLogInitCtx(ConfNode *conf)
{
int ret=0;
LogFileCtx* file_ctx=LogFileNewCtx();
@ -253,7 +253,15 @@ LogFileCtx *AlertDebugLogInitCtx(ConfNode *conf)
if(ret < 0)
return NULL;
return file_ctx;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocate OutputCtx for AlertDebugLog");
exit(EXIT_FAILURE);
}
output_ctx->data = file_ctx;
return output_ctx;
}
/** \brief Read the config set the file pointer, open the file

@ -6,7 +6,7 @@
void TmModuleAlertDebugLogRegister (void);
void TmModuleAlertDebugLogIPv4Register (void);
void TmModuleAlertDebugLogIPv6Register (void);
LogFileCtx *AlertDebugLogInitCtx(ConfNode *);
OutputCtx *AlertDebugLogInitCtx(ConfNode *);
#endif /* __ALERT_DEBUGLOG_H__ */

@ -47,8 +47,9 @@ TmEcode AlertFastLogIPv6(ThreadVars *, Packet *, void *, PacketQueue *);
TmEcode AlertFastLogThreadInit(ThreadVars *, void *, void **);
TmEcode AlertFastLogThreadDeinit(ThreadVars *, void *);
void AlertFastLogExitPrintStats(ThreadVars *, void *);
int AlertFastLogOpenFileCtx(LogFileCtx *, const char *);
static int AlertFastLogOpenFileCtx(LogFileCtx *, const char *);
void AlertFastLogRegisterTests(void);
static void AlertFastLogDeInitCtx(OutputCtx *);
void TmModuleAlertFastLogRegister (void) {
tmm_modules[TMM_ALERTFASTLOG].name = MODULE_NAME;
@ -183,7 +184,8 @@ TmEcode AlertFastLogThreadInit(ThreadVars *t, void *initdata, void **data)
return TM_ECODE_FAILED;
}
/** Use the Ouptut Context (file pointer and mutex) */
aft->file_ctx = (LogFileCtx*) initdata;
aft->file_ctx = ((OutputCtx *)initdata)->data;
*data = (void *)aft;
return TM_ECODE_OK;
}
@ -216,7 +218,7 @@ void AlertFastLogExitPrintStats(ThreadVars *tv, void *data) {
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
LogFileCtx *AlertFastLogInitCtx(ConfNode *conf)
OutputCtx *AlertFastLogInitCtx(ConfNode *conf)
{
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
@ -232,9 +234,25 @@ LogFileCtx *AlertFastLogInitCtx(ConfNode *conf)
return NULL;
}
SCLogInfo("Fast log output registered, filename: %s", filename);
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocated memory for OutputCtx");
exit(EXIT_FAILURE);
}
output_ctx->data = logfile_ctx;
output_ctx->DeInit = AlertFastLogDeInitCtx;
SCLogInfo("Fast log output initialized, filename: %s", filename);
return logfile_ctx;
return output_ctx;
}
static void AlertFastLogDeInitCtx(OutputCtx *output_ctx)
{
LogFileCtx *logfile_ctx = (LogFileCtx *)output_ctx->data;
LogFileFreeCtx(logfile_ctx);
free(output_ctx);
}
/** \brief Read the config set the file pointer, open the file
@ -242,7 +260,7 @@ LogFileCtx *AlertFastLogInitCtx(ConfNode *conf)
* \param filename name of log file
* \return -1 if failure, 0 if succesful
* */
int AlertFastLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename)
static int AlertFastLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename)
{
char log_path[PATH_MAX], *log_dir;
if (ConfGet("default-log-dir", &log_dir) != 1)

@ -7,7 +7,7 @@
void TmModuleAlertFastLogRegister (void);
void TmModuleAlertFastLogIPv4Register (void);
void TmModuleAlertFastLogIPv6Register (void);
LogFileCtx *AlertFastLogInitCtx(ConfNode *);
OutputCtx *AlertFastLogInitCtx(ConfNode *);
#endif /* __ALERT_FASTLOG_H__ */

@ -52,6 +52,7 @@ TmEcode AlertUnifiedAlertThreadInit(ThreadVars *, void *, void **);
TmEcode AlertUnifiedAlertThreadDeinit(ThreadVars *, void *);
int AlertUnifiedAlertOpenFileCtx(LogFileCtx *, const char *);
void AlertUnifiedAlertRegisterTests (void);
static void AlertUnifiedAlertDeInitCtx(OutputCtx *);
void TmModuleAlertUnifiedAlertRegister (void) {
tmm_modules[TMM_ALERTUNIFIEDALERT].name = MODULE_NAME;
@ -250,7 +251,7 @@ TmEcode AlertUnifiedAlertThreadInit(ThreadVars *t, void *initdata, void **data)
return TM_ECODE_FAILED;
}
/** Use the Ouptut Context (file pointer and mutex) */
aun->file_ctx = (LogFileCtx*) initdata;
aun->file_ctx = ((OutputCtx *)initdata)->data;
*data = (void *)aun;
return TM_ECODE_OK;
@ -282,7 +283,7 @@ error:
* \param conf The ConfNode for this output.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
LogFileCtx *AlertUnifiedAlertInitCtx(ConfNode *conf)
OutputCtx *AlertUnifiedAlertInitCtx(ConfNode *conf)
{
int ret = 0;
LogFileCtx *file_ctx = LogFileNewCtx();
@ -325,10 +326,25 @@ LogFileCtx *AlertUnifiedAlertInitCtx(ConfNode *conf)
if (ret < 0)
return NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Failed to allocate memory for OutputCtx.");
exit(EXIT_FAILURE);
}
output_ctx->data = file_ctx;
output_ctx->DeInit = AlertUnifiedAlertDeInitCtx;
SCLogInfo("Unified-alert initialized: filename %s, limit %"PRIu32" MB",
filename, limit);
return file_ctx;
return output_ctx;
}
static void AlertUnifiedAlertDeInitCtx(OutputCtx *output_ctx)
{
LogFileCtx *logfile_ctx = (LogFileCtx *)output_ctx->data;
LogFileFreeCtx(logfile_ctx);
free(output_ctx);
}
/** \brief Read the config set the file pointer, open the file
@ -394,10 +410,14 @@ static int AlertUnifiedAlertTestRotate01(void)
int ret = 0;
int r = 0;
ThreadVars tv;
OutputCtx *oc;
LogFileCtx *lf;
void *data = NULL;
lf = AlertUnifiedAlertInitCtx(NULL);
oc = AlertUnifiedAlertInitCtx(NULL);
if (oc == NULL)
return 0;
lf = (LogFileCtx *)oc->data;
if (lf == NULL)
return 0;
char *filename = SCStrdup(lf->filename);
@ -407,7 +427,7 @@ static int AlertUnifiedAlertTestRotate01(void)
if (lf == NULL)
return 0;
ret = AlertUnifiedAlertThreadInit(&tv, lf, &data);
ret = AlertUnifiedAlertThreadInit(&tv, oc, &data);
if (ret == TM_ECODE_FAILED) {
LogFileFreeCtx(lf);
return 0;
@ -426,7 +446,7 @@ static int AlertUnifiedAlertTestRotate01(void)
error:
AlertUnifiedAlertThreadDeinit(&tv, data);
if (lf != NULL) LogFileFreeCtx(lf);
if (oc != NULL) AlertUnifiedAlertDeInitCtx(oc);
return r;
}
#endif /* UNITTESTS */

@ -4,7 +4,7 @@
#define __ALERT_UNIFIED_ALERT_H__
void TmModuleAlertUnifiedAlertRegister (void);
LogFileCtx *AlertUnifiedAlertInitCtx(ConfNode *);
OutputCtx *AlertUnifiedAlertInitCtx(ConfNode *);
#endif /* __ALERT_UNIFIED_ALERT_H__ */

@ -54,6 +54,7 @@ TmEcode AlertUnifiedLogThreadInit(ThreadVars *, void *, void **);
TmEcode AlertUnifiedLogThreadDeinit(ThreadVars *, void *);
int AlertUnifiedLogOpenFileCtx(LogFileCtx *, const char *);
void AlertUnifiedLogRegisterTests(void);
static void AlertUnifiedLogDeInitCtx(OutputCtx *);
void TmModuleAlertUnifiedLogRegister (void) {
tmm_modules[TMM_ALERTUNIFIEDLOG].name = MODULE_NAME;
@ -266,7 +267,7 @@ TmEcode AlertUnifiedLogThreadInit(ThreadVars *t, void *initdata, void **data)
return TM_ECODE_FAILED;
}
/** Use the Ouptut Context (file pointer and mutex) */
aun->file_ctx = (LogFileCtx*) initdata;
aun->file_ctx = ((OutputCtx *)initdata)->data;
/** Write Unified header */
int ret = AlertUnifiedLogWriteFileHeader(aun->file_ctx);
@ -311,7 +312,7 @@ error:
* \param ConfNode pointer to the configuration node for this logger.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
LogFileCtx *AlertUnifiedLogInitCtx(ConfNode *conf)
OutputCtx *AlertUnifiedLogInitCtx(ConfNode *conf)
{
int ret = 0;
LogFileCtx* file_ctx=LogFileNewCtx();
@ -355,10 +356,26 @@ LogFileCtx *AlertUnifiedLogInitCtx(ConfNode *conf)
if (ret < 0)
return NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocate OutputCtx for AlertUnifiedLog");
exit(EXIT_FAILURE);
}
output_ctx->data = file_ctx;
output_ctx->DeInit = AlertUnifiedLogDeInitCtx;
SCLogInfo("Unified-log initialized: filename %s, limit %"PRIu32" MB",
filename, limit);
return file_ctx;
return output_ctx;
}
static void AlertUnifiedLogDeInitCtx(OutputCtx *output_ctx)
{
LogFileCtx *logfile_ctx = (LogFileCtx *)output_ctx->data;
LogFileFreeCtx(logfile_ctx);
free(output_ctx);
}
/** \brief Read the config set the file pointer, open the file
@ -422,10 +439,14 @@ static int AlertUnifiedLogTestRotate01(void)
int ret = 0;
int r = 0;
ThreadVars tv;
OutputCtx *oc;
LogFileCtx *lf;
void *data = NULL;
lf = AlertUnifiedLogInitCtx(NULL);
oc = AlertUnifiedLogInitCtx(NULL);
if (oc == NULL)
return 0;
lf = (LogFileCtx *)oc->data;
if (lf == NULL)
return 0;
char *filename = SCStrdup(lf->filename);
@ -435,7 +456,7 @@ static int AlertUnifiedLogTestRotate01(void)
if (lf == NULL)
return 0;
ret = AlertUnifiedLogThreadInit(&tv, lf, &data);
ret = AlertUnifiedLogThreadInit(&tv, oc, &data);
if (ret == TM_ECODE_FAILED) {
LogFileFreeCtx(lf);
return 0;
@ -454,7 +475,7 @@ static int AlertUnifiedLogTestRotate01(void)
error:
AlertUnifiedLogThreadDeinit(&tv, data);
if (lf != NULL) LogFileFreeCtx(lf);
if (oc != NULL) AlertUnifiedLogDeInitCtx(oc);
return r;
}
#endif /* UNITTESTS */

@ -4,7 +4,7 @@
#define __ALERT_UNIFIED_LOG_H__
void TmModuleAlertUnifiedLogRegister (void);
LogFileCtx *AlertUnifiedLogInitCtx(ConfNode *);
OutputCtx *AlertUnifiedLogInitCtx(ConfNode *);
#endif /* __ALERT_UNIFIED_LOG_H__ */

@ -47,6 +47,7 @@ int Unified2IPv6TypeAlert(ThreadVars *, Packet *, void *, PacketQueue *);
int Unified2PacketTypeAlert(ThreadVars *, Packet *, void *);
void Unified2RegisterTests();
int Unified2AlertOpenFileCtx(LogFileCtx *, const char *);
static void Unified2AlertDeInitCtx(OutputCtx *);
/**
* Unified2 thread vars
@ -532,7 +533,7 @@ TmEcode Unified2AlertThreadInit(ThreadVars *t, void *initdata, void **data)
return TM_ECODE_FAILED;
}
/** Use the Ouptut Context (file pointer and mutex) */
aun->file_ctx = (LogFileCtx*) initdata;
aun->file_ctx = ((OutputCtx *)initdata)->data;
*data = (void *)aun;
return TM_ECODE_OK;
@ -573,7 +574,7 @@ error:
* \param conf The configuration node for this output.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
LogFileCtx *Unified2AlertInitCtx(ConfNode *conf)
OutputCtx *Unified2AlertInitCtx(ConfNode *conf)
{
int ret=0;
LogFileCtx* file_ctx=LogFileNewCtx();
@ -617,10 +618,26 @@ LogFileCtx *Unified2AlertInitCtx(ConfNode *conf)
if (ret < 0)
return NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocate OutputCtx for Unified2Alert");
exit(EXIT_FAILURE);
}
output_ctx->data = file_ctx;
output_ctx->DeInit = Unified2AlertDeInitCtx;
SCLogInfo("Unified2-alert initialized: filename %s, limit %"PRIu32" MB",
filename, limit);
return file_ctx;
return output_ctx;
}
static void Unified2AlertDeInitCtx(OutputCtx *output_ctx)
{
LogFileCtx *logfile_ctx = (LogFileCtx *)output_ctx->data;
LogFileFreeCtx(logfile_ctx);
free(output_ctx);
}
/** \brief Read the config set the file pointer, open the file
@ -680,6 +697,7 @@ static int Unified2Test01 (void) {
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
OutputCtx *oc;
LogFileCtx *lf;
uint8_t raw_ipv4_tcp[] = {
@ -713,10 +731,13 @@ static int Unified2Test01 (void) {
FlowShutdown();
lf=Unified2AlertInitCtx(NULL);
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL)
return 0;
lf = (LogFileCtx *)oc->data;
if(lf == NULL)
return 0;
ret = Unified2AlertThreadInit(&tv, lf, &data);
ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == TM_ECODE_FAILED)
return 0;
ret = Unified2Alert(&tv, &p, data, &pq);
@ -726,8 +747,8 @@ static int Unified2Test01 (void) {
if(ret == -1)
return 0;
if(LogFileFreeCtx(lf)==0)
return 0;
Unified2AlertDeInitCtx(oc);
return 1;
}
@ -743,6 +764,7 @@ static int Unified2Test02 (void) {
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
OutputCtx *oc;
LogFileCtx *lf;
uint8_t raw_ipv6_tcp[] = {
@ -778,10 +800,13 @@ static int Unified2Test02 (void) {
FlowShutdown();
lf=Unified2AlertInitCtx(NULL);
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL)
return 0;
lf = (LogFileCtx *)oc->data;
if(lf == NULL)
return 0;
ret = Unified2AlertThreadInit(&tv, lf, &data);
ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == -1)
return 0;
ret = Unified2Alert(&tv, &p, data, &pq);
@ -791,8 +816,7 @@ static int Unified2Test02 (void) {
if(ret == -1)
return 0;
if(LogFileFreeCtx(lf)==0)
return 0;
Unified2AlertDeInitCtx(oc);
return 1;
}
@ -810,6 +834,7 @@ static int Unified2Test03 (void) {
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
OutputCtx *oc;
LogFileCtx *lf;
uint8_t raw_gre[] = {
@ -850,10 +875,13 @@ static int Unified2Test03 (void) {
FlowShutdown();
lf=Unified2AlertInitCtx(NULL);
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL)
return 0;
lf = (LogFileCtx *)oc->data;
if(lf == NULL)
return 0;
ret = Unified2AlertThreadInit(&tv, lf, &data);
ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == -1)
return 0;
ret = Unified2Alert(&tv, &p, data, &pq);
@ -863,8 +891,7 @@ static int Unified2Test03 (void) {
if(ret == -1)
return 0;
if(LogFileFreeCtx(lf)==0)
return 0;
Unified2AlertDeInitCtx(oc);
Packet *pkt = PacketDequeue(&pq);
while (pkt != NULL) {
@ -887,6 +914,7 @@ static int Unified2Test04 (void) {
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
OutputCtx *oc;
LogFileCtx *lf;
uint8_t raw_ppp[] = {
@ -916,10 +944,13 @@ static int Unified2Test04 (void) {
FlowShutdown();
lf=Unified2AlertInitCtx(NULL);
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL)
return 0;
lf = (LogFileCtx *)oc->data;
if(lf == NULL)
return 0;
ret = Unified2AlertThreadInit(&tv, lf, &data);
ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == -1)
return 0;
ret = Unified2Alert(&tv, &p, data, &pq);
@ -929,8 +960,7 @@ static int Unified2Test04 (void) {
if(ret == -1)
return 0;
if(LogFileFreeCtx(lf)==0)
return 0;
Unified2AlertDeInitCtx(oc);
return 1;
}
@ -947,6 +977,7 @@ static int Unified2Test05 (void) {
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
OutputCtx *oc;
LogFileCtx *lf;
uint8_t raw_ipv4_tcp[] = {
@ -982,10 +1013,13 @@ static int Unified2Test05 (void) {
p.action = ACTION_DROP;
lf=Unified2AlertInitCtx(NULL);
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL)
return 0;
lf = (LogFileCtx *)oc->data;
if(lf == NULL)
return 0;
ret = Unified2AlertThreadInit(&tv, lf, &data);
ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == -1)
return 0;
ret = Unified2Alert(&tv, &p, data, &pq);
@ -995,8 +1029,7 @@ static int Unified2Test05 (void) {
if(ret == TM_ECODE_FAILED)
return 0;
if(LogFileFreeCtx(lf)==0)
return 0;
Unified2AlertDeInitCtx(oc);
return 1;
}
@ -1012,10 +1045,14 @@ static int Unified2TestRotate01(void)
int ret = 0;
int r = 0;
ThreadVars tv;
OutputCtx *oc;
LogFileCtx *lf;
void *data = NULL;
lf = Unified2AlertInitCtx(NULL);
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL)
return 0;
lf = (LogFileCtx *)oc->data;
if (lf == NULL)
return 0;
char *filename = SCStrdup(lf->filename);
@ -1025,7 +1062,7 @@ static int Unified2TestRotate01(void)
if (lf == NULL)
return 0;
ret = Unified2AlertThreadInit(&tv, lf, &data);
ret = Unified2AlertThreadInit(&tv, oc, &data);
if (ret == TM_ECODE_FAILED) {
LogFileFreeCtx(lf);
return 0;
@ -1047,8 +1084,8 @@ static int Unified2TestRotate01(void)
error:
Unified2AlertThreadDeinit(&tv, data);
if (lf != NULL) LogFileFreeCtx(lf);
if (filename != NULL) SCFree(filename);
if (oc != NULL) Unified2AlertDeInitCtx(oc);
if (filename != NULL) free(filename);
return r;
}
#endif

@ -22,7 +22,7 @@
#define UNIFIED2_IDS_EVENT_IPV6_MPLS_TYPE 100
void TmModuleUnified2AlertRegister (void);
LogFileCtx *Unified2AlertInitCtx(ConfNode *);
OutputCtx *Unified2AlertInitCtx(ConfNode *);
#endif /* __ALERT_UNIFIED2_ALERT_H__ */

@ -37,6 +37,7 @@ TmEcode LogHttpLogThreadInit(ThreadVars *, void *, void **);
TmEcode LogHttpLogThreadDeinit(ThreadVars *, void *);
void LogHttpLogExitPrintStats(ThreadVars *, void *);
int LogHttpLogOpenFileCtx(LogFileCtx* , const char *);
static void LogHttpLogDeInitCtx(OutputCtx *);
void TmModuleLogHttpLogRegister (void) {
tmm_modules[TMM_LOGHTTPLOG].name = MODULE_NAME;
@ -339,7 +340,7 @@ TmEcode LogHttpLogThreadInit(ThreadVars *t, void *initdata, void **data)
return TM_ECODE_FAILED;
}
/** Use the Ouptut Context (file pointer and mutex) */
aft->file_ctx=(LogFileCtx*) initdata;
aft->file_ctx= ((OutputCtx *)initdata)->data;
*data = (void *)aft;
return TM_ECODE_OK;
@ -372,7 +373,7 @@ void LogHttpLogExitPrintStats(ThreadVars *tv, void *data) {
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
LogFileCtx *LogHttpLogInitCtx(ConfNode *conf)
OutputCtx *LogHttpLogInitCtx(ConfNode *conf)
{
int ret=0;
LogFileCtx* file_ctx=LogFileNewCtx();
@ -394,7 +395,23 @@ LogFileCtx *LogHttpLogInitCtx(ConfNode *conf)
if(ret < 0)
return NULL;
return file_ctx;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (output_ctx == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocate OutputCtx for LogHttpLog");
exit(EXIT_FAILURE);
}
output_ctx->data = file_ctx;
output_ctx->DeInit = LogHttpLogDeInitCtx;
return output_ctx;
}
static void LogHttpLogDeInitCtx(OutputCtx *output_ctx)
{
LogFileCtx *logfile_ctx = (LogFileCtx *)output_ctx->data;
LogFileFreeCtx(logfile_ctx);
free(output_ctx);
}
/** \brief Read the config set the file pointer, open the file

@ -6,7 +6,7 @@
void TmModuleLogHttpLogRegister (void);
void TmModuleLogHttpLogIPv4Register (void);
void TmModuleLogHttpLogIPv6Register (void);
LogFileCtx *LogHttpLogInitCtx(ConfNode *);
OutputCtx *LogHttpLogInitCtx(ConfNode *);
#endif /* __LOG_HTTPLOG_H__ */

@ -25,7 +25,8 @@ static TAILQ_HEAD(, OutputModule_) output_modules =
* \retval Returns 0 on success, -1 on failure.
*/
void
OutputRegisterModule(char *name, char *conf_name, LogFileCtx *(*InitFunc)(ConfNode *))
OutputRegisterModule(char *name, char *conf_name,
OutputCtx *(*InitFunc)(ConfNode *))
{
OutputModule *module = SCCalloc(1, sizeof(*module));
if (module == NULL) {

@ -13,12 +13,12 @@
typedef struct OutputModule_ {
char *name;
char *conf_name;
LogFileCtx *(*InitFunc)(ConfNode *);
OutputCtx *(*InitFunc)(ConfNode *);
TAILQ_ENTRY(OutputModule_) entries;
} OutputModule;
void OutputRegisterModule(char *, char *, LogFileCtx *(*)(ConfNode *));
void OutputRegisterModule(char *, char *, OutputCtx *(*)(ConfNode *));
OutputModule *OutputGetModuleByConfName(char *name);
void OutputDeregisterAll(void);

@ -32,7 +32,7 @@
*/
typedef struct RunModeOutput_ {
TmModule *tm_module;
LogFileCtx *logfile_ctx;
OutputCtx *output_ctx;
TAILQ_ENTRY(RunModeOutput_) entries;
} RunModeOutput;
@ -49,8 +49,8 @@ void RunModeShutDown(void)
while ((output = TAILQ_FIRST(&RunModeOutputs))) {
SCLogDebug("Shutting down output %s.", output->tm_module->name);
TAILQ_REMOVE(&RunModeOutputs, output, entries);
if (output->logfile_ctx != NULL)
LogFileFreeCtx(output->logfile_ctx);
if (output->output_ctx != NULL && output->output_ctx->DeInit != NULL)
output->output_ctx->DeInit(output->output_ctx);
SCFree(output);
}
}
@ -89,11 +89,14 @@ void RunModeInitializeOutputs(void)
enabled = ConfNodeLookupChildValue(output_config, "enabled");
if (enabled != NULL && strcasecmp(enabled, "yes") == 0) {
LogFileCtx *logfile_ctx = module->InitFunc(output_config);
if (logfile_ctx == NULL) {
/* In most cases the init function will have logged the
* error. Maybe we should exit on init errors? */
continue;
OutputCtx *output_ctx = NULL;
if (module->InitFunc != NULL) {
output_ctx = module->InitFunc(output_config);
if (output_ctx == NULL) {
/* In most cases the init function will have logged the
* error. Maybe we should exit on init errors? */
continue;
}
}
tm_module = TmModuleGetByName(module->name);
if (tm_module == NULL) {
@ -108,7 +111,7 @@ void RunModeInitializeOutputs(void)
exit(EXIT_FAILURE);
}
runmode_output->tm_module = tm_module;
runmode_output->logfile_ctx = logfile_ctx;
runmode_output->output_ctx = output_ctx;
TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries);
}
}
@ -124,7 +127,7 @@ static void SetupOutputs(ThreadVars *tv)
{
RunModeOutput *output;
TAILQ_FOREACH(output, &RunModeOutputs, entries) {
TmVarSlotSetFuncAppend(tv, output->tm_module, output->logfile_ctx);
TmVarSlotSetFuncAppend(tv, output->tm_module, output->output_ctx);
}
}

@ -87,6 +87,18 @@ typedef struct LogFileCtx_ {
#define LOGFILE_HEADER_WRITTEN 0x01
#define LOGFILE_ALERTS_PRINTED 0x02
/**
* Structure that output modules use to maintain private data.
*/
typedef struct OutputCtx_ {
/** Pointer to data private to the output. */
void *data;
/** Pointer to a cleanup function. */
void (*DeInit)(struct OutputCtx_ *);
} OutputCtx;
LogFileCtx *LogFileNewCtx();
int LogFileFreeCtx(LogFileCtx *);

Loading…
Cancel
Save