output: introduce init return type

The new OutputInitResult is a struct return type that allows
logger init functions to return a NULL context without
raising error.

Instead of returning NULL to signal error, the "ok" field will
be set to false. If ok, but the ctx is NULL, then silently
move on to the next logger.

Use case: multiple versions of a specific logger, and one
implementation decides the configuration is not for that
implemenation. It can return NULL, ok.
pull/3175/head
Jason Ish 8 years ago
parent 50a762bfd1
commit 00e6cd4ced

@ -430,8 +430,9 @@ static void AlertDebugLogDeInitCtx(OutputCtx *output_ctx)
*
* \return output_ctx if succesful, NULL otherwise
*/
static OutputCtx *AlertDebugLogInitCtx(ConfNode *conf)
static OutputInitResult AlertDebugLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = NULL;
file_ctx = LogFileNewCtx();
@ -453,14 +454,16 @@ static OutputCtx *AlertDebugLogInitCtx(ConfNode *conf)
output_ctx->DeInit = AlertDebugLogDeInitCtx;
SCLogDebug("Alert debug log output initialized");
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
error:
if (file_ctx != NULL) {
LogFileFreeCtx(file_ctx);
}
return NULL;
return result;
}
static int AlertDebugLogCondition(ThreadVars *tv, const Packet *p)

@ -220,26 +220,29 @@ TmEcode AlertFastLogThreadDeinit(ThreadVars *t, void *data)
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
OutputCtx *AlertFastLogInitCtx(ConfNode *conf)
OutputInitResult AlertFastLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
SCLogDebug("AlertFastLogInitCtx2: Could not create new LogFileCtx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(logfile_ctx);
return NULL;
return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL))
return NULL;
return result;
output_ctx->data = logfile_ctx;
output_ctx->DeInit = AlertFastLogDeInitCtx;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
static void AlertFastLogDeInitCtx(OutputCtx *output_ctx)

@ -27,7 +27,7 @@
void AlertFastLogRegister(void);
void TmModuleAlertFastLogIPv4Register(void);
void TmModuleAlertFastLogIPv6Register(void);
OutputCtx *AlertFastLogInitCtx(ConfNode *);
OutputInitResult AlertFastLogInitCtx(ConfNode *);
#endif /* __ALERT_FASTLOG_H__ */

@ -778,7 +778,7 @@ static void AlertPreludeDeinitCtx(OutputCtx *output_ctx)
*
* \return A newly allocated AlertPreludeCtx structure, or NULL
*/
static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
static OutputInitResult AlertPreludeInitCtx(ConfNode *conf)
{
int ret;
prelude_client_t *client;
@ -786,6 +786,7 @@ static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
const char *prelude_profile_name;
const char *log_packet_content;
const char *log_packet_header;
OutputInitResult result = { NULL, false };
OutputCtx *output_ctx;
SCEnter();
@ -793,7 +794,7 @@ static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
ret = prelude_init(0, NULL);
if (unlikely(ret < 0)) {
prelude_perror(ret, "unable to initialize the prelude library");
SCReturnPtr(NULL, "AlertPreludeCtx");
SCReturnCT(result, "OutputInitResult");
}
prelude_profile_name = ConfNodeLookupChildValue(conf, "profile");
@ -807,35 +808,35 @@ static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
if ( unlikely(ret < 0 || client == NULL )) {
prelude_perror(ret, "Unable to create a prelude client object");
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
SCReturnPtr(NULL, "AlertPreludeCtx");
SCReturnCT(result, "OutputInitResult");
}
ret = prelude_client_set_flags(client, prelude_client_get_flags(client) | PRELUDE_CLIENT_FLAGS_ASYNC_TIMER|PRELUDE_CLIENT_FLAGS_ASYNC_SEND);
if (unlikely(ret < 0)) {
SCLogDebug("Unable to set asynchronous send and timer.");
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
SCReturnPtr(NULL, "AlertPreludeCtx");
SCReturnCT(result, "OutputInitResult");
}
ret = SetupAnalyzer(prelude_client_get_analyzer(client));
if (ret < 0) {
SCLogDebug("Unable to setup prelude client analyzer.");
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
SCReturnPtr(NULL, "AlertPreludeCtx");
SCReturnCT(result, "OutputInitResult");
}
ret = prelude_client_start(client);
if (unlikely(ret < 0)) {
prelude_perror(ret, "Unable to start prelude client");
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
SCReturnPtr(NULL, "AlertPreludeCtx");
SCReturnCT(result, "OutputInitResult");
}
ctx = SCMalloc(sizeof(AlertPreludeCtx));
if (unlikely(ctx == NULL)) {
prelude_perror(ret, "Unable to allocate memory");
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
SCReturnPtr(NULL, "AlertPreludeCtx");
SCReturnCT(result, "OutputInitResult");
}
ctx->client = client;
@ -851,13 +852,15 @@ static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
SCFree(ctx);
prelude_perror(ret, "Unable to allocate memory");
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
SCReturnPtr(NULL, "AlertPreludeCtx");
SCReturnCT(result, "OutputInitResult");
}
output_ctx->data = ctx;
output_ctx->DeInit = AlertPreludeDeinitCtx;
SCReturnPtr((void*)output_ctx, "OutputCtx");
result.ctx = output_ctx;
result.ok = true;
SCReturnCT(result, "OutputInitResult");
}
static int AlertPreludeCondition(ThreadVars *tv, const Packet *p)

@ -88,8 +88,9 @@ static void AlertSyslogDeInitCtx(OutputCtx *output_ctx)
* \param conf The configuration node for this output.
* \return A OutputCtx pointer on success, NULL on failure.
*/
static OutputCtx *AlertSyslogInitCtx(ConfNode *conf)
static OutputInitResult AlertSyslogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
const char *facility_s = ConfNodeLookupChildValue(conf, "facility");
if (facility_s == NULL) {
facility_s = DEFAULT_ALERT_SYSLOG_FACILITY_STR;
@ -98,7 +99,7 @@ static OutputCtx *AlertSyslogInitCtx(ConfNode *conf)
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
SCLogDebug("AlertSyslogInitCtx: Could not create new LogFileCtx");
return NULL;
return result;
}
int facility = SCMapEnumNameToValue(facility_s, SCSyslogGetFacilityMap());
@ -126,7 +127,7 @@ static OutputCtx *AlertSyslogInitCtx(ConfNode *conf)
OutputCtx *output_ctx = SCMalloc(sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCLogDebug("AlertSyslogInitCtx: Could not create new OutputCtx");
return NULL;
return result;
}
memset(output_ctx, 0x00, sizeof(OutputCtx));
@ -135,7 +136,9 @@ static OutputCtx *AlertSyslogInitCtx(ConfNode *conf)
SCLogInfo("Syslog output initialized");
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
/**

@ -38,6 +38,8 @@
#include "threadvars.h"
#include "tm-threads.h"
#include "output.h"
#include "util-unittest.h"
#include "alert-unified2-alert.h"
#include "decode-ipv4.h"
@ -58,7 +60,6 @@
#include "app-layer.h"
#include "app-layer-htp-xff.h"
#include "output.h"
#include "util-privs.h"
#include "stream.h"
@ -1218,8 +1219,9 @@ error:
* \param conf The configuration node for this output.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
OutputCtx *Unified2AlertInitCtx(ConfNode *conf)
OutputInitResult Unified2AlertInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
int ret = 0;
LogFileCtx* file_ctx = NULL;
OutputCtx* output_ctx = NULL;
@ -1341,7 +1343,9 @@ OutputCtx *Unified2AlertInitCtx(ConfNode *conf)
SC_ATOMIC_INIT(unified2_event_id);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
error:
if (xff_cfg != NULL) {
@ -1351,7 +1355,7 @@ error:
SCFree(output_ctx);
}
return NULL;
return result;
}
static void Unified2AlertDeInitCtx(OutputCtx *output_ctx)
@ -1444,7 +1448,7 @@ static int Unified2Test01(void)
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
OutputCtx *oc;
OutputInitResult oc;
LogFileCtx *lf;
Unified2AlertFileCtx *uaf = NULL;
Signature s;
@ -1483,17 +1487,17 @@ static int Unified2Test01(void)
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL) {
if (oc.ctx == NULL) {
goto end;
}
uaf = oc->data;
uaf = oc.ctx->data;
if (uaf == NULL)
return 0;
lf = uaf->file_ctx;
if(lf == NULL) {
goto end;
}
ret = Unified2AlertThreadInit(&tv, oc, &data);
ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
if(ret == TM_ECODE_FAILED) {
goto end;
}
@ -1506,7 +1510,7 @@ static int Unified2Test01(void)
goto end;
}
Unified2AlertDeInitCtx(oc);
Unified2AlertDeInitCtx(oc.ctx);
PACKET_RECYCLE(p);
SCFree(p);
@ -1533,7 +1537,7 @@ static int Unified2Test02(void)
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
OutputCtx *oc;
OutputInitResult oc;
LogFileCtx *lf;
Unified2AlertFileCtx *uaf = NULL;
Signature s;
@ -1573,17 +1577,17 @@ static int Unified2Test02(void)
DecodeEthernet(&tv, &dtv, p, raw_ipv6_tcp, sizeof(raw_ipv6_tcp), &pq);
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL) {
if (oc.ctx == NULL) {
goto end;
}
uaf = oc->data;
uaf = oc.ctx->data;
if (uaf == NULL)
return 0;
lf = uaf->file_ctx;
if(lf == NULL) {
goto end;
}
ret = Unified2AlertThreadInit(&tv, oc, &data);
ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
if(ret == -1) {
goto end;
}
@ -1596,7 +1600,7 @@ static int Unified2Test02(void)
goto end;
}
Unified2AlertDeInitCtx(oc);
Unified2AlertDeInitCtx(oc.ctx);
PACKET_RECYCLE(p);
SCFree(p);
@ -1624,7 +1628,7 @@ static int Unified2Test03(void)
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
OutputCtx *oc;
OutputInitResult oc;
LogFileCtx *lf;
Unified2AlertFileCtx *uaf = NULL;
Signature s;
@ -1670,17 +1674,17 @@ static int Unified2Test03(void)
DecodeEthernet(&tv, &dtv, p, raw_gre, sizeof(raw_gre), &pq);
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL) {
if (oc.ctx == NULL) {
goto end;
}
uaf = oc->data;
uaf = oc.ctx->data;
if (uaf == NULL)
return 0;
lf = uaf->file_ctx;
if(lf == NULL) {
goto end;
}
ret = Unified2AlertThreadInit(&tv, oc, &data);
ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
if(ret == -1) {
goto end;
}
@ -1693,7 +1697,7 @@ static int Unified2Test03(void)
goto end;
}
Unified2AlertDeInitCtx(oc);
Unified2AlertDeInitCtx(oc.ctx);
pkt = PacketDequeue(&pq);
while (pkt != NULL) {
@ -1733,7 +1737,7 @@ static int Unified2Test04(void)
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
OutputCtx *oc;
OutputInitResult oc;
LogFileCtx *lf;
Unified2AlertFileCtx *uaf = NULL;
Signature s;
@ -1767,17 +1771,17 @@ static int Unified2Test04(void)
DecodePPP(&tv, &dtv, p, raw_ppp, sizeof(raw_ppp), &pq);
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL) {
if (oc.ctx == NULL) {
goto end;
}
uaf = oc->data;
uaf = oc.ctx->data;
if (uaf == NULL)
return 0;
lf = uaf->file_ctx;
if(lf == NULL) {
goto end;
}
ret = Unified2AlertThreadInit(&tv, oc, &data);
ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
if(ret == -1) {
goto end;
}
@ -1790,7 +1794,7 @@ static int Unified2Test04(void)
goto end;
}
Unified2AlertDeInitCtx(oc);
Unified2AlertDeInitCtx(oc.ctx);
PACKET_RECYCLE(p);
SCFree(p);
@ -1817,7 +1821,7 @@ static int Unified2Test05(void)
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
OutputCtx *oc;
OutputInitResult oc;
LogFileCtx *lf;
Unified2AlertFileCtx *uaf = NULL;
Signature s;
@ -1857,17 +1861,17 @@ static int Unified2Test05(void)
p->action = ACTION_DROP;
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL) {
if (oc.ctx == NULL) {
goto end;
}
uaf = oc->data;
uaf = oc.ctx->data;
if (uaf == NULL)
return 0;
lf = uaf->file_ctx;
if(lf == NULL) {
goto end;
}
ret = Unified2AlertThreadInit(&tv, oc, &data);
ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
if(ret == -1) {
goto end;
}
@ -1880,7 +1884,7 @@ static int Unified2Test05(void)
goto end;
}
Unified2AlertDeInitCtx(oc);
Unified2AlertDeInitCtx(oc.ctx);
PACKET_RECYCLE(p);
SCFree(p);
@ -1905,16 +1909,16 @@ static int Unified2TestRotate01(void)
int ret = 0;
int r = 0;
ThreadVars tv;
OutputCtx *oc;
OutputInitResult oc;
LogFileCtx *lf;
Unified2AlertFileCtx *uaf = NULL;
void *data = NULL;
char *filename = NULL;
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL)
if (oc.ctx == NULL)
return 0;
uaf = oc->data;
uaf = oc.ctx->data;
if (uaf == NULL)
return 0;
lf = uaf->file_ctx;
@ -1926,7 +1930,7 @@ static int Unified2TestRotate01(void)
memset(&tv, 0, sizeof(ThreadVars));
ret = Unified2AlertThreadInit(&tv, oc, &data);
ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
if (ret == TM_ECODE_FAILED) {
LogFileFreeCtx(lf);
if (filename != NULL)
@ -1953,8 +1957,8 @@ error:
if(ret == TM_ECODE_FAILED) {
printf("Unified2AlertThreadDeinit error");
}
if (oc != NULL)
Unified2AlertDeInitCtx(oc);
if (oc.ctx != NULL)
Unified2AlertDeInitCtx(oc.ctx);
if (filename != NULL)
SCFree(filename);
return r;

@ -44,7 +44,7 @@
#define UNIFIED2_EXTRADATA_TYPE_EXTRA_DATA 4
void Unified2AlertRegister(void);
OutputCtx *Unified2AlertInitCtx(ConfNode *);
OutputInitResult Unified2AlertInitCtx(ConfNode *);
#endif /* __ALERT_UNIFIED2_ALERT_H__ */

@ -315,24 +315,25 @@ static void LogDnsLogDeInitCtx(OutputCtx *output_ctx)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
static OutputCtx *LogDnsLogInitCtx(ConfNode *conf)
static OutputInitResult LogDnsLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx* file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_DNS_LOG_GENERIC, "couldn't create new file_ctx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
LogDnsFileCtx *dnslog_ctx = SCMalloc(sizeof(LogDnsFileCtx));
if (unlikely(dnslog_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
memset(dnslog_ctx, 0x00, sizeof(LogDnsFileCtx));
@ -342,7 +343,7 @@ static OutputCtx *LogDnsLogInitCtx(ConfNode *conf)
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(dnslog_ctx);
return NULL;
return result;
}
output_ctx->data = dnslog_ctx;
@ -353,7 +354,9 @@ static OutputCtx *LogDnsLogInitCtx(ConfNode *conf)
AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_DNS);
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DNS);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
#endif /* !HAVE_RUST */

@ -135,34 +135,37 @@ static void LogDropLogDeInitCtx(OutputCtx *output_ctx)
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
static OutputCtx *LogDropLogInitCtx(ConfNode *conf)
static OutputInitResult LogDropLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
if (OutputDropLoggerEnable() != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
"can be enabled");
return NULL;
return result;
}
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
SCLogDebug("LogDropLogInitCtx: Could not create new LogFileCtx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(logfile_ctx);
return NULL;
return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(logfile_ctx);
return NULL;
return result;
}
output_ctx->data = logfile_ctx;
output_ctx->DeInit = LogDropLogDeInitCtx;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
/**

@ -412,22 +412,23 @@ static void LogFileLogDeInitCtx(OutputCtx *output_ctx)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
static OutputCtx *LogFileLogInitCtx(ConfNode *conf)
static OutputInitResult LogFileLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
SCLogDebug("Could not create new LogFileCtx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(logfile_ctx);
return NULL;
return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL))
return NULL;
return result;
output_ctx->data = logfile_ctx;
output_ctx->DeInit = LogFileLogDeInitCtx;
@ -446,7 +447,10 @@ static OutputCtx *LogFileLogInitCtx(ConfNode *conf)
FileForceHashParseCfg(conf);
FileForceTrackingEnable();
SCReturnPtr(output_ctx, "OutputCtx");
result.ctx = output_ctx;
result.ok = true;
SCReturnCT(result, "OutputInitResult");
}
void LogFileLogRegister (void)

@ -572,11 +572,12 @@ static void LogFilestoreLogDeInitCtx(OutputCtx *output_ctx)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFilestoreCtx* to the file_ctx if succesful
* */
static OutputCtx *LogFilestoreLogInitCtx(ConfNode *conf)
static OutputInitResult LogFilestoreLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL))
return NULL;
return result;
output_ctx->data = NULL;
output_ctx->DeInit = LogFilestoreLogDeInitCtx;
@ -660,7 +661,9 @@ static OutputCtx *LogFilestoreLogInitCtx(ConfNode *conf)
SCLogInfo("enabling pid as a part of all file names");
}
SCReturnPtr(output_ctx, "OutputCtx");
result.ctx = output_ctx;
result.ok = true;
SCReturnCT(result, "OutputInitResult");
}

@ -549,23 +549,24 @@ TmEcode LogHttpLogThreadDeinit(ThreadVars *t, void *data)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
OutputCtx *LogHttpLogInitCtx(ConfNode *conf)
OutputInitResult LogHttpLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx* file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_HTTP_LOG_GENERIC, "couldn't create new file_ctx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
LogHttpFileCtx *httplog_ctx = SCMalloc(sizeof(LogHttpFileCtx));
if (unlikely(httplog_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
memset(httplog_ctx, 0x00, sizeof(LogHttpFileCtx));
@ -612,7 +613,9 @@ OutputCtx *LogHttpLogInitCtx(ConfNode *conf)
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_HTTP);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
parsererror:
SCLogError(SC_ERR_INVALID_ARGUMENT,"Syntax error in custom http log format string.");
@ -620,7 +623,7 @@ errorfree:
LogCustomFormatFree(httplog_ctx->cf);
LogFileFreeCtx(file_ctx);
SCFree(httplog_ctx);
return NULL;
return result;
}

@ -27,7 +27,7 @@
void LogHttpLogRegister(void);
void TmModuleLogHttpLogIPv4Register (void);
void TmModuleLogHttpLogIPv6Register (void);
OutputCtx *LogHttpLogInitCtx(ConfNode *);
OutputInitResult LogHttpLogInitCtx(ConfNode *);
#endif /* __LOG_HTTPLOG_H__ */

@ -170,7 +170,7 @@ static int PcapLog(ThreadVars *, void *, const Packet *);
static TmEcode PcapLogDataInit(ThreadVars *, const void *, void **);
static TmEcode PcapLogDataDeinit(ThreadVars *, void *);
static void PcapLogFileDeInitCtx(OutputCtx *);
static OutputCtx *PcapLogInitCtx(ConfNode *);
static OutputInitResult PcapLogInitCtx(ConfNode *);
static void PcapLogProfilingDump(PcapLogData *);
static int PcapLogCondition(ThreadVars *, const Packet *);
@ -931,8 +931,9 @@ error:
* \param conf The configuration node for this output.
* \retval output_ctx
* */
static OutputCtx *PcapLogInitCtx(ConfNode *conf)
static OutputInitResult PcapLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
const char *pcre_errbuf;
int pcre_erroffset;
@ -1162,7 +1163,9 @@ static OutputCtx *PcapLogInitCtx(ConfNode *conf)
output_ctx->DeInit = PcapLogFileDeInitCtx;
g_pcap_data = pl;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
static void PcapLogFileDeInitCtx(OutputCtx *output_ctx)

@ -210,23 +210,24 @@ TmEcode LogStatsLogThreadDeinit(ThreadVars *t, void *data)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
static OutputCtx *LogStatsLogInitCtx(ConfNode *conf)
static OutputInitResult LogStatsLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if (file_ctx == NULL) {
SCLogError(SC_ERR_STATS_LOG_GENERIC, "couldn't create new file_ctx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
LogStatsFileCtx *statslog_ctx = SCMalloc(sizeof(LogStatsFileCtx));
if (unlikely(statslog_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
memset(statslog_ctx, 0x00, sizeof(LogStatsFileCtx));
@ -244,7 +245,7 @@ static OutputCtx *LogStatsLogInitCtx(ConfNode *conf)
SCFree(statslog_ctx);
SCLogError(SC_ERR_STATS_LOG_NEGATED,
"Cannot disable both totals and threads in stats logging");
return NULL;
return result;
}
if (totals != NULL && ConfValIsFalse(totals)) {
@ -265,7 +266,7 @@ static OutputCtx *LogStatsLogInitCtx(ConfNode *conf)
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(statslog_ctx);
return NULL;
return result;
}
output_ctx->data = statslog_ctx;
@ -273,7 +274,9 @@ static OutputCtx *LogStatsLogInitCtx(ConfNode *conf)
SCLogDebug("STATS log output initialized");
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
static void LogStatsLogDeInitCtx(OutputCtx *output_ctx)

@ -225,8 +225,9 @@ TmEcode LogTcpDataLogThreadDeinit(ThreadVars *t, void *data)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
OutputCtx *LogTcpDataLogInitCtx(ConfNode *conf)
OutputInitResult LogTcpDataLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
char filename[PATH_MAX] = "";
char dirname[32] = "";
strlcpy(filename, DEFAULT_LOG_FILENAME, sizeof(filename));
@ -234,13 +235,13 @@ OutputCtx *LogTcpDataLogInitCtx(ConfNode *conf)
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_TCPDATA_LOG_GENERIC, "couldn't create new file_ctx");
return NULL;
return result;
}
LogTcpDataFileCtx *tcpdatalog_ctx = SCMalloc(sizeof(LogTcpDataFileCtx));
if (unlikely(tcpdatalog_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
memset(tcpdatalog_ctx, 0x00, sizeof(LogTcpDataFileCtx));
@ -281,7 +282,7 @@ OutputCtx *LogTcpDataLogInitCtx(ConfNode *conf)
if (SCConfLogOpenGeneric(conf, file_ctx, filename, 1) < 0) {
LogFileFreeCtx(file_ctx);
SCFree(tcpdatalog_ctx);
return NULL;
return result;
}
}
@ -307,13 +308,15 @@ OutputCtx *LogTcpDataLogInitCtx(ConfNode *conf)
output_ctx->DeInit = LogTcpDataLogDeInitCtx;
SCLogDebug("Streaming log output initialized");
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
parsererror:
LogFileFreeCtx(file_ctx);
SCFree(tcpdatalog_ctx);
SCLogError(SC_ERR_INVALID_ARGUMENT,"Syntax error in custom http log format string.");
return NULL;
return result;
}

@ -25,6 +25,6 @@
#define __LOG_TCPDATALOG_H__
void LogTcpDataLogRegister(void);
OutputCtx *LogTcpDataLogInitCtx(ConfNode *);
OutputInitResult LogTcpDataLogInitCtx(ConfNode *);
#endif /* __LOG_TCPDATALOG_H__ */

@ -264,14 +264,15 @@ static void LogTlsLogExitPrintStats(ThreadVars *tv, void *data)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
static OutputCtx *LogTlsLogInitCtx(ConfNode *conf)
static OutputInitResult LogTlsLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx* file_ctx = LogFileNewCtx();
if (file_ctx == NULL) {
SCLogError(SC_ERR_TLS_LOG_GENERIC, "LogTlsLogInitCtx: Couldn't "
"create new file_ctx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
@ -325,7 +326,9 @@ static OutputCtx *LogTlsLogInitCtx(ConfNode *conf)
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
parser_error:
SCLogError(SC_ERR_INVALID_ARGUMENT,"Syntax error in custom tls log format string.");
tlslog_error:
@ -333,7 +336,7 @@ tlslog_error:
SCFree(tlslog_ctx);
filectx_error:
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
/* Custom format logging */

@ -374,12 +374,12 @@ static void LogTlsStoreLogDeInitCtx(OutputCtx *output_ctx)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFilestoreCtx* to the file_ctx if succesful
* */
static OutputCtx *LogTlsStoreLogInitCtx(ConfNode *conf)
static OutputInitResult LogTlsStoreLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL))
return NULL;
return result;
output_ctx->data = NULL;
output_ctx->DeInit = LogTlsStoreLogDeInitCtx;
@ -408,7 +408,9 @@ static OutputCtx *LogTlsStoreLogInitCtx(ConfNode *conf)
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);
SCReturnPtr(output_ctx, "OutputCtx");
result.ctx = output_ctx;
result.ok = true;
SCReturnCT(result, "OutputInitResult");
}
void LogTlsStoreRegister (void)

@ -825,31 +825,32 @@ static void XffSetup(AlertJsonOutputCtx *json_output_ctx, ConfNode *conf)
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
static OutputCtx *JsonAlertLogInitCtx(ConfNode *conf)
static OutputInitResult JsonAlertLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
AlertJsonOutputCtx *json_output_ctx = NULL;
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
SCLogDebug("AlertFastLogInitCtx2: Could not create new LogFileCtx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(logfile_ctx);
return NULL;
return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(logfile_ctx);
return NULL;
return result;
}
json_output_ctx = SCMalloc(sizeof(AlertJsonOutputCtx));
if (unlikely(json_output_ctx == NULL)) {
LogFileFreeCtx(logfile_ctx);
SCFree(output_ctx);
return NULL;
return result;
}
memset(json_output_ctx, 0, sizeof(AlertJsonOutputCtx));
@ -860,7 +861,9 @@ static OutputCtx *JsonAlertLogInitCtx(ConfNode *conf)
output_ctx->data = json_output_ctx;
output_ctx->DeInit = JsonAlertLogDeInitCtx;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
/**
@ -868,14 +871,15 @@ static OutputCtx *JsonAlertLogInitCtx(ConfNode *conf)
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
static OutputCtx *JsonAlertLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult JsonAlertLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
AlertJsonOutputCtx *json_output_ctx = NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL))
return NULL;
return result;
json_output_ctx = SCMalloc(sizeof(AlertJsonOutputCtx));
if (unlikely(json_output_ctx == NULL)) {
@ -890,7 +894,9 @@ static OutputCtx *JsonAlertLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
output_ctx->data = json_output_ctx;
output_ctx->DeInit = JsonAlertLogDeInitCtxSub;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
error:
if (json_output_ctx != NULL) {
@ -900,7 +906,7 @@ error:
SCFree(output_ctx);
}
return NULL;
return result;
}
void JsonAlertLogRegister (void)

@ -362,20 +362,21 @@ static void OutputDNP3LogDeInitCtxSub(OutputCtx *output_ctx)
#define DEFAULT_LOG_FILENAME "dnp3.json"
static OutputCtx *OutputDNP3LogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult OutputDNP3LogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
LogDNP3FileCtx *dnp3log_ctx = SCCalloc(1, sizeof(*dnp3log_ctx));
if (unlikely(dnp3log_ctx == NULL)) {
return NULL;
return result;
}
dnp3log_ctx->file_ctx = ajt->file_ctx;
OutputCtx *output_ctx = SCCalloc(1, sizeof(*output_ctx));
if (unlikely(output_ctx == NULL)) {
SCFree(dnp3log_ctx);
return NULL;
return result;
}
output_ctx->data = dnp3log_ctx;
output_ctx->DeInit = OutputDNP3LogDeInitCtxSub;
@ -384,7 +385,9 @@ static OutputCtx *OutputDNP3LogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DNP3);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
#define OUTPUT_BUFFER_SIZE 65535

@ -851,13 +851,14 @@ static void JsonDnsLogInitFilters(LogDnsFileCtx *dnslog_ctx, ConfNode *conf)
}
}
static OutputCtx *JsonDnsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult JsonDnsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
LogDnsFileCtx *dnslog_ctx = SCMalloc(sizeof(LogDnsFileCtx));
if (unlikely(dnslog_ctx == NULL)) {
return NULL;
return result;
}
memset(dnslog_ctx, 0x00, sizeof(LogDnsFileCtx));
@ -866,7 +867,7 @@ static OutputCtx *JsonDnsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(dnslog_ctx);
return NULL;
return result;
}
output_ctx->data = dnslog_ctx;
@ -879,7 +880,9 @@ static OutputCtx *JsonDnsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_DNS);
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DNS);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
#define DEFAULT_LOG_FILENAME "dns.json"
@ -887,24 +890,25 @@ static OutputCtx *JsonDnsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
static OutputCtx *JsonDnsLogInitCtx(ConfNode *conf)
static OutputInitResult JsonDnsLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_DNS_LOG_GENERIC, "couldn't create new file_ctx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
LogDnsFileCtx *dnslog_ctx = SCMalloc(sizeof(LogDnsFileCtx));
if (unlikely(dnslog_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
memset(dnslog_ctx, 0x00, sizeof(LogDnsFileCtx));
@ -914,7 +918,7 @@ static OutputCtx *JsonDnsLogInitCtx(ConfNode *conf)
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(dnslog_ctx);
return NULL;
return result;
}
output_ctx->data = dnslog_ctx;
@ -927,7 +931,9 @@ static OutputCtx *JsonDnsLogInitCtx(ConfNode *conf)
AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_DNS);
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DNS);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}

@ -250,33 +250,34 @@ static void JsonDropLogDeInitCtxSub(OutputCtx *output_ctx)
}
#define DEFAULT_LOG_FILENAME "drop.json"
static OutputCtx *JsonDropLogInitCtx(ConfNode *conf)
static OutputInitResult JsonDropLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
if (OutputDropLoggerEnable() != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
"can be enabled");
return NULL;
return result;
}
JsonDropOutputCtx *drop_ctx = SCCalloc(1, sizeof(*drop_ctx));
if (drop_ctx == NULL)
return NULL;
return result;
drop_ctx->file_ctx = LogFileNewCtx();
if (drop_ctx->file_ctx == NULL) {
JsonDropOutputCtxFree(drop_ctx);
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, drop_ctx->file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
JsonDropOutputCtxFree(drop_ctx);
return NULL;
return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
JsonDropOutputCtxFree(drop_ctx);
return NULL;
return result;
}
if (conf) {
@ -301,27 +302,31 @@ static OutputCtx *JsonDropLogInitCtx(ConfNode *conf)
output_ctx->data = drop_ctx;
output_ctx->DeInit = JsonDropLogDeInitCtx;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
static OutputCtx *JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
if (OutputDropLoggerEnable() != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
"can be enabled");
return NULL;
return result;
}
OutputJsonCtx *ajt = parent_ctx->data;
JsonDropOutputCtx *drop_ctx = SCCalloc(1, sizeof(*drop_ctx));
if (drop_ctx == NULL)
return NULL;
return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
JsonDropOutputCtxFree(drop_ctx);
return NULL;
return result;
}
if (conf) {
@ -348,7 +353,10 @@ static OutputCtx *JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
output_ctx->data = drop_ctx;
output_ctx->DeInit = JsonDropLogDeInitCtxSub;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
/**

@ -274,18 +274,19 @@ static void OutputFileLogDeinitSub(OutputCtx *output_ctx)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
static OutputCtx *OutputFileLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult OutputFileLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
OutputFileCtx *output_file_ctx = SCMalloc(sizeof(OutputFileCtx));
if (unlikely(output_file_ctx == NULL))
return NULL;
return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(output_file_ctx);
return NULL;
return result;
}
output_file_ctx->file_ctx = ojc->file_ctx;
@ -310,7 +311,9 @@ static OutputCtx *OutputFileLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
output_ctx->DeInit = OutputFileLogDeinitSub;
FileForceTrackingEnable();
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
void JsonFileLogRegister (void)

@ -377,37 +377,40 @@ static void OutputFlowLogDeinit(OutputCtx *output_ctx)
}
#define DEFAULT_LOG_FILENAME "flow.json"
static OutputCtx *OutputFlowLogInit(ConfNode *conf)
static OutputInitResult OutputFlowLogInit(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_FLOW_LOG_GENERIC, "couldn't create new file_ctx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
if (unlikely(flow_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(flow_ctx);
return NULL;
return result;
}
flow_ctx->file_ctx = file_ctx;
output_ctx->data = flow_ctx;
output_ctx->DeInit = OutputFlowLogDeinit;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
static void OutputFlowLogDeinitSub(OutputCtx *output_ctx)
@ -417,18 +420,19 @@ static void OutputFlowLogDeinitSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
static OutputCtx *OutputFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult OutputFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
if (unlikely(flow_ctx == NULL))
return NULL;
return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(flow_ctx);
return NULL;
return result;
}
flow_ctx->file_ctx = ojc->file_ctx;
@ -436,7 +440,9 @@ static OutputCtx *OutputFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
output_ctx->data = flow_ctx;
output_ctx->DeInit = OutputFlowLogDeinitSub;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
#define OUTPUT_BUFFER_SIZE 65535

@ -501,30 +501,31 @@ static void OutputHttpLogDeinit(OutputCtx *output_ctx)
}
#define DEFAULT_LOG_FILENAME "http.json"
static OutputCtx *OutputHttpLogInit(ConfNode *conf)
static OutputInitResult OutputHttpLogInit(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_HTTP_LOG_GENERIC, "couldn't create new file_ctx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
LogHttpFileCtx *http_ctx = SCMalloc(sizeof(LogHttpFileCtx));
if (unlikely(http_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(http_ctx);
return NULL;
return result;
}
http_ctx->file_ctx = file_ctx;
@ -545,7 +546,9 @@ static OutputCtx *OutputHttpLogInit(ConfNode *conf)
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_HTTP);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
static void OutputHttpLogDeinitSub(OutputCtx *output_ctx)
@ -555,19 +558,20 @@ static void OutputHttpLogDeinitSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
static OutputCtx *OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
LogHttpFileCtx *http_ctx = SCMalloc(sizeof(LogHttpFileCtx));
if (unlikely(http_ctx == NULL))
return NULL;
return result;
memset(http_ctx, 0x00, sizeof(*http_ctx));
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(http_ctx);
return NULL;
return result;
}
http_ctx->file_ctx = ojc->file_ctx;
@ -611,7 +615,9 @@ static OutputCtx *OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_HTTP);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
#define OUTPUT_BUFFER_SIZE 65535

@ -334,37 +334,40 @@ static void OutputNetFlowLogDeinit(OutputCtx *output_ctx)
}
#define DEFAULT_LOG_FILENAME "netflow.json"
static OutputCtx *OutputNetFlowLogInit(ConfNode *conf)
static OutputInitResult OutputNetFlowLogInit(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_NETFLOW_LOG_GENERIC, "couldn't create new file_ctx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
if (unlikely(flow_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(flow_ctx);
return NULL;
return result;
}
flow_ctx->file_ctx = file_ctx;
output_ctx->data = flow_ctx;
output_ctx->DeInit = OutputNetFlowLogDeinit;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
static void OutputNetFlowLogDeinitSub(OutputCtx *output_ctx)
@ -374,18 +377,19 @@ static void OutputNetFlowLogDeinitSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
static OutputCtx *OutputNetFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult OutputNetFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
if (unlikely(flow_ctx == NULL))
return NULL;
return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(flow_ctx);
return NULL;
return result;
}
flow_ctx->file_ctx = ojc->file_ctx;
@ -393,7 +397,9 @@ static OutputCtx *OutputNetFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
output_ctx->data = flow_ctx;
output_ctx->DeInit = OutputNetFlowLogDeinitSub;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
#define OUTPUT_BUFFER_SIZE 65535

@ -133,21 +133,22 @@ static void OutputNFSLogDeInitCtxSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
static OutputCtx *OutputNFSLogInitSub(ConfNode *conf,
static OutputInitResult OutputNFSLogInitSub(ConfNode *conf,
OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
LogNFSFileCtx *nfslog_ctx = SCCalloc(1, sizeof(*nfslog_ctx));
if (unlikely(nfslog_ctx == NULL)) {
return NULL;
return result;
}
nfslog_ctx->file_ctx = ajt->file_ctx;
OutputCtx *output_ctx = SCCalloc(1, sizeof(*output_ctx));
if (unlikely(output_ctx == NULL)) {
SCFree(nfslog_ctx);
return NULL;
return result;
}
output_ctx->data = nfslog_ctx;
output_ctx->DeInit = OutputNFSLogDeInitCtxSub;
@ -157,7 +158,9 @@ static OutputCtx *OutputNFSLogInitSub(ConfNode *conf,
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_NFS);
AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_NFS);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
#define OUTPUT_BUFFER_SIZE 65535

@ -151,30 +151,31 @@ static void OutputSmtpLogDeInitCtxSub(OutputCtx *output_ctx)
}
#define DEFAULT_LOG_FILENAME "smtp.json"
static OutputCtx *OutputSmtpLogInit(ConfNode *conf)
static OutputInitResult OutputSmtpLogInit(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_SMTP_LOG_GENERIC, "couldn't create new file_ctx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
OutputJsonEmailCtx *email_ctx = SCMalloc(sizeof(OutputJsonEmailCtx));
if (unlikely(email_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(email_ctx);
return NULL;
return result;
}
email_ctx->file_ctx = file_ctx;
@ -185,21 +186,24 @@ static OutputCtx *OutputSmtpLogInit(ConfNode *conf)
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SMTP);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
static OutputCtx *OutputSmtpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult OutputSmtpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
OutputJsonEmailCtx *email_ctx = SCMalloc(sizeof(OutputJsonEmailCtx));
if (unlikely(email_ctx == NULL))
return NULL;
return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(email_ctx);
return NULL;
return result;
}
email_ctx->file_ctx = ojc->file_ctx;
@ -212,7 +216,9 @@ static OutputCtx *OutputSmtpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SMTP);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
#define OUTPUT_BUFFER_SIZE 65535

@ -182,30 +182,31 @@ static void OutputSshLogDeinit(OutputCtx *output_ctx)
}
#define DEFAULT_LOG_FILENAME "ssh.json"
static OutputCtx *OutputSshLogInit(ConfNode *conf)
static OutputInitResult OutputSshLogInit(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_SSH_LOG_GENERIC, "couldn't create new file_ctx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
OutputSshCtx *ssh_ctx = SCMalloc(sizeof(OutputSshCtx));
if (unlikely(ssh_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(ssh_ctx);
return NULL;
return result;
}
ssh_ctx->file_ctx = file_ctx;
@ -214,7 +215,10 @@ static OutputCtx *OutputSshLogInit(ConfNode *conf)
output_ctx->DeInit = OutputSshLogDeinit;
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SSH);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
static void OutputSshLogDeinitSub(OutputCtx *output_ctx)
@ -224,18 +228,19 @@ static void OutputSshLogDeinitSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
static OutputCtx *OutputSshLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult OutputSshLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
OutputSshCtx *ssh_ctx = SCMalloc(sizeof(OutputSshCtx));
if (unlikely(ssh_ctx == NULL))
return NULL;
return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(ssh_ctx);
return NULL;
return result;
}
ssh_ctx->file_ctx = ojc->file_ctx;
@ -244,7 +249,10 @@ static OutputCtx *OutputSshLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
output_ctx->DeInit = OutputSshLogDeinitSub;
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SSH);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
void JsonSshLogRegister (void)

@ -378,23 +378,24 @@ static void OutputStatsLogDeinit(OutputCtx *output_ctx)
}
#define DEFAULT_LOG_FILENAME "stats.json"
static OutputCtx *OutputStatsLogInit(ConfNode *conf)
static OutputInitResult OutputStatsLogInit(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_STATS_LOG_GENERIC, "couldn't create new file_ctx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
OutputStatsCtx *stats_ctx = SCMalloc(sizeof(OutputStatsCtx));
if (unlikely(stats_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
stats_ctx->flags = JSON_STATS_TOTALS;
@ -420,7 +421,7 @@ static OutputCtx *OutputStatsLogInit(ConfNode *conf)
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(stats_ctx);
return NULL;
return result;
}
stats_ctx->file_ctx = file_ctx;
@ -428,7 +429,9 @@ static OutputCtx *OutputStatsLogInit(ConfNode *conf)
output_ctx->data = stats_ctx;
output_ctx->DeInit = OutputStatsLogDeinit;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
static void OutputStatsLogDeinitSub(OutputCtx *output_ctx)
@ -438,13 +441,13 @@ static void OutputStatsLogDeinitSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
static OutputCtx *OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
OutputStatsCtx *stats_ctx = SCMalloc(sizeof(OutputStatsCtx));
if (unlikely(stats_ctx == NULL))
return NULL;
return result;
stats_ctx->flags = JSON_STATS_TOTALS;
@ -459,7 +462,7 @@ static OutputCtx *OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
SCFree(stats_ctx);
SCLogError(SC_ERR_JSON_STATS_LOG_NEGATED,
"Cannot disable both totals and threads in stats logging");
return NULL;
return result;
}
if (totals != NULL && ConfValIsFalse(totals)) {
@ -477,7 +480,7 @@ static OutputCtx *OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(stats_ctx);
return NULL;
return result;
}
stats_ctx->file_ctx = ajt->file_ctx;
@ -485,7 +488,9 @@ static OutputCtx *OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
output_ctx->data = stats_ctx;
output_ctx->DeInit = OutputStatsLogDeinitSub;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
void JsonStatsLogRegister(void) {

@ -122,21 +122,22 @@ static void OutputTemplateLogDeInitCtxSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
static OutputCtx *OutputTemplateLogInitSub(ConfNode *conf,
static OutputInitResult OutputTemplateLogInitSub(ConfNode *conf,
OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
LogTemplateFileCtx *templatelog_ctx = SCCalloc(1, sizeof(*templatelog_ctx));
if (unlikely(templatelog_ctx == NULL)) {
return NULL;
return result;
}
templatelog_ctx->file_ctx = ajt->file_ctx;
OutputCtx *output_ctx = SCCalloc(1, sizeof(*output_ctx));
if (unlikely(output_ctx == NULL)) {
SCFree(templatelog_ctx);
return NULL;
return result;
}
output_ctx->data = templatelog_ctx;
output_ctx->DeInit = OutputTemplateLogDeInitCtxSub;
@ -145,7 +146,9 @@ static OutputCtx *OutputTemplateLogInitSub(ConfNode *conf,
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TEMPLATE);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
#define OUTPUT_BUFFER_SIZE 65535

@ -503,30 +503,31 @@ static OutputTlsCtx *OutputTlsInitCtx(ConfNode *conf)
return tls_ctx;
}
static OutputCtx *OutputTlsLogInit(ConfNode *conf)
static OutputInitResult OutputTlsLogInit(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if (file_ctx == NULL) {
SCLogError(SC_ERR_TLS_LOG_GENERIC, "couldn't create new file_ctx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
OutputTlsCtx *tls_ctx = OutputTlsInitCtx(conf);
if (unlikely(tls_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL;
return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(tls_ctx);
return NULL;
return result;
}
tls_ctx->file_ctx = file_ctx;
@ -536,7 +537,9 @@ static OutputCtx *OutputTlsLogInit(ConfNode *conf)
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
static void OutputTlsLogDeinitSub(OutputCtx *output_ctx)
@ -546,18 +549,19 @@ static void OutputTlsLogDeinitSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
static OutputCtx *OutputTlsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult OutputTlsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
OutputTlsCtx *tls_ctx = OutputTlsInitCtx(conf);
if (unlikely(tls_ctx == NULL))
return NULL;
return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(tls_ctx);
return NULL;
return result;
}
tls_ctx->file_ctx = ojc->file_ctx;
@ -575,7 +579,9 @@ static OutputCtx *OutputTlsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
void JsonTlsLogRegister (void)

@ -184,31 +184,32 @@ static void JsonVarsLogDeInitCtxSub(OutputCtx *output_ctx)
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
static OutputCtx *JsonVarsLogInitCtx(ConfNode *conf)
static OutputInitResult JsonVarsLogInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
VarsJsonOutputCtx *json_output_ctx = NULL;
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
SCLogDebug("VarsFastLogInitCtx2: Could not create new LogFileCtx");
return NULL;
return result;
}
if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(logfile_ctx);
return NULL;
return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(logfile_ctx);
return NULL;
return result;
}
json_output_ctx = SCMalloc(sizeof(VarsJsonOutputCtx));
if (unlikely(json_output_ctx == NULL)) {
LogFileFreeCtx(logfile_ctx);
SCFree(output_ctx);
return NULL;
return result;
}
memset(json_output_ctx, 0, sizeof(VarsJsonOutputCtx));
@ -217,7 +218,9 @@ static OutputCtx *JsonVarsLogInitCtx(ConfNode *conf)
output_ctx->data = json_output_ctx;
output_ctx->DeInit = JsonVarsLogDeInitCtx;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
/**
@ -225,14 +228,15 @@ static OutputCtx *JsonVarsLogInitCtx(ConfNode *conf)
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
static OutputCtx *JsonVarsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult JsonVarsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
VarsJsonOutputCtx *json_output_ctx = NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL))
return NULL;
return result;
json_output_ctx = SCMalloc(sizeof(VarsJsonOutputCtx));
if (unlikely(json_output_ctx == NULL)) {
@ -245,7 +249,9 @@ static OutputCtx *JsonVarsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
output_ctx->data = json_output_ctx;
output_ctx->DeInit = JsonVarsLogDeInitCtxSub;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
error:
if (json_output_ctx != NULL) {
@ -255,7 +261,7 @@ error:
SCFree(output_ctx);
}
return NULL;
return result;
}
void JsonVarsLogRegister (void)

@ -532,8 +532,9 @@ int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer)
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
OutputCtx *OutputJsonInitCtx(ConfNode *conf)
OutputInitResult OutputJsonInitCtx(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *json_ctx = SCCalloc(1, sizeof(OutputJsonCtx));;
/* First lookup a sensor-name value in this outputs configuration
@ -550,14 +551,14 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
if (unlikely(json_ctx == NULL)) {
SCLogDebug("AlertJsonInitCtx: Could not create new LogFileCtx");
return NULL;
return result;
}
json_ctx->file_ctx = LogFileNewCtx();
if (unlikely(json_ctx->file_ctx == NULL)) {
SCLogDebug("AlertJsonInitCtx: Could not create new LogFileCtx");
SCFree(json_ctx);
return NULL;
return result;
}
if (sensor_name) {
@ -565,7 +566,7 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
if (json_ctx->file_ctx->sensor_name == NULL) {
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
return NULL;
return result;
}
} else {
json_ctx->file_ctx->sensor_name = NULL;
@ -575,7 +576,7 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
return NULL;
return result;
}
output_ctx->data = json_ctx;
@ -637,7 +638,7 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
SCFree(output_ctx);
return NULL;
return result;
}
OutputRegisterFileRotationFlag(&json_ctx->file_ctx->rotation_flag);
} else if (json_ctx->json_out == LOGFILE_TYPE_SYSLOG) {
@ -681,14 +682,14 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
SCFree(output_ctx);
return NULL;
return result;
}
if (SCConfLogOpenRedis(redis_node, json_ctx->file_ctx) < 0) {
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
SCFree(output_ctx);
return NULL;
return result;
}
}
#endif
@ -707,7 +708,10 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
}
SCLogDebug("returning output_ctx %p", output_ctx);
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
}
static void OutputJsonDeInitCtx(OutputCtx *output_ctx)

@ -27,6 +27,7 @@
#include "suricata-common.h"
#include "util-buffer.h"
#include "util-logopenfile.h"
#include "output.h"
void OutputJsonRegister(void);
@ -46,7 +47,7 @@ void JsonFiveTuple(const Packet *, int, json_t *);
json_t *CreateJSONHeader(const Packet *p, int direction_sensative, const char *event_type);
json_t *CreateJSONHeaderWithTxId(const Packet *p, int direction_sensitive, const char *event_type, uint64_t tx_id);
int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer);
OutputCtx *OutputJsonInitCtx(ConfNode *);
OutputInitResult OutputJsonInitCtx(ConfNode *);
/*
* Global configuration context data

@ -664,20 +664,21 @@ static void LogLuaSubFree(OutputCtx *oc) {
*
* Runs script 'setup' function.
*/
static OutputCtx *OutputLuaLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
static OutputInitResult OutputLuaLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
if (conf == NULL)
return NULL;
return result;
LogLuaCtx *lua_ctx = SCMalloc(sizeof(LogLuaCtx));
if (unlikely(lua_ctx == NULL))
return NULL;
return result;
memset(lua_ctx, 0x00, sizeof(*lua_ctx));
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(lua_ctx);
return NULL;
return result;
}
SCMutexInit(&lua_ctx->m, NULL);
@ -707,12 +708,14 @@ static OutputCtx *OutputLuaLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
output_ctx->data = lua_ctx;
output_ctx->DeInit = LogLuaSubFree;
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
error:
SCMutexDestroy(&lua_ctx->m);
SCFree(lua_ctx);
SCFree(output_ctx);
return NULL;
return result;
}
static void LogLuaMasterFree(OutputCtx *oc)
@ -734,8 +737,9 @@ static void LogLuaMasterFree(OutputCtx *oc)
* inspect, then fills the OutputCtx::submodules list with the
* proper Logger function for the data type the script needs.
*/
static OutputCtx *OutputLuaLogInit(ConfNode *conf)
static OutputInitResult OutputLuaLogInit(ConfNode *conf)
{
OutputInitResult result = { NULL, false };
const char *dir = ConfNodeLookupChildValue(conf, "scripts-dir");
if (dir == NULL)
dir = "";
@ -744,19 +748,19 @@ static OutputCtx *OutputLuaLogInit(ConfNode *conf)
if (scripts == NULL) {
/* No "outputs" section in the configuration. */
SCLogInfo("scripts not defined");
return NULL;
return result;
}
/* global output ctx setup */
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
return NULL;
return result;
}
output_ctx->DeInit = LogLuaMasterFree;
output_ctx->data = SCCalloc(1, sizeof(LogLuaMasterCtx));
if (unlikely(output_ctx->data == NULL)) {
SCFree(output_ctx);
return NULL;
return result;
}
LogLuaMasterCtx *master_config = output_ctx->data;
strlcpy(master_config->path, dir, sizeof(master_config->path));
@ -853,12 +857,14 @@ static OutputCtx *OutputLuaLogInit(ConfNode *conf)
TAILQ_INSERT_TAIL(&output_ctx->submodules, om, entries);
}
return output_ctx;
result.ctx = output_ctx;
result.ok = true;
return result;
error:
if (output_ctx->DeInit)
output_ctx->DeInit(output_ctx);
return NULL;
return result;
}
/** \internal

@ -38,8 +38,13 @@
#include "output-streaming.h"
#include "output-stats.h"
typedef OutputCtx *(*OutputInitFunc)(ConfNode *);
typedef OutputCtx *(*OutputInitSubFunc)(ConfNode *, OutputCtx *);
typedef struct OutputInitResult_ {
OutputCtx *ctx;
bool ok;
} OutputInitResult;
typedef OutputInitResult (*OutputInitFunc)(ConfNode *);
typedef OutputInitResult (*OutputInitSubFunc)(ConfNode *, OutputCtx *);
typedef TmEcode (*OutputLogFunc)(ThreadVars *, Packet *, void *);
typedef struct OutputModule_ {

@ -37,8 +37,8 @@
#include "conf.h"
#include "runmodes.h"
#include "runmode-af-packet.h"
#include "log-httplog.h"
#include "output.h"
#include "log-httplog.h"
#include "detect-engine-mpm.h"
#include "alert-fastlog.h"

@ -36,8 +36,8 @@
#include "conf.h"
#include "runmodes.h"
#include "runmode-netmap.h"
#include "log-httplog.h"
#include "output.h"
#include "log-httplog.h"
#include "detect-engine-mpm.h"
#include "alert-fastlog.h"

@ -20,8 +20,8 @@
#include "conf.h"
#include "runmodes.h"
#include "runmode-pcap.h"
#include "log-httplog.h"
#include "output.h"
#include "log-httplog.h"
#include "util-debug.h"
#include "util-time.h"

@ -39,6 +39,8 @@
#include "util-unittest.h"
#include "util-misc.h"
#include "output.h"
#include "alert-fastlog.h"
#include "alert-prelude.h"
#include "alert-unified2-alert.h"
@ -46,8 +48,6 @@
#include "log-httplog.h"
#include "output.h"
#include "source-pfring.h"
#include "tmqh-flow.h"
@ -611,16 +611,15 @@ static void RunModeInitializeEveOutput(ConfNode *conf, OutputCtx *parent_ctx)
// sub_output_config may be NULL if no config
/* pass on parent output_ctx */
OutputCtx *sub_output_ctx =
sub_module->InitSubFunc(sub_output_config,
parent_ctx);
if (sub_output_ctx == NULL) {
OutputInitResult result =
sub_module->InitSubFunc(sub_output_config, parent_ctx);
if (!result.ok || result.ctx == NULL) {
continue;
}
AddOutputToFreeList(sub_module, sub_output_ctx);
AddOutputToFreeList(sub_module, result.ctx);
SetupOutput(sub_module->name, sub_module,
sub_output_ctx);
result.ctx);
}
}
@ -656,15 +655,13 @@ static void RunModeInitializeLuaOutput(ConfNode *conf, OutputCtx *parent_ctx)
BUG_ON(script == NULL);
/* pass on parent output_ctx */
OutputCtx *sub_output_ctx =
m->InitSubFunc(script, parent_ctx);
if (sub_output_ctx == NULL) {
SCLogInfo("sub_output_ctx NULL, skipping");
OutputInitResult result = m->InitSubFunc(script, parent_ctx);
if (!result.ok || result.ctx == NULL) {
continue;
}
AddOutputToFreeList(m, sub_output_ctx);
SetupOutput(m->name, m, sub_output_ctx);
AddOutputToFreeList(m, result.ctx);
SetupOutput(m->name, m, result.ctx);
}
}
@ -756,12 +753,15 @@ void RunModeInitializeOutputs(void)
OutputCtx *output_ctx = NULL;
if (module->InitFunc != NULL) {
output_ctx = module->InitFunc(output_config);
if (output_ctx == NULL) {
OutputInitResult r = module->InitFunc(output_config);
if (!r.ok) {
FatalErrorOnInit(SC_ERR_INVALID_ARGUMENT,
"output module setup failed");
continue;
} else if (r.ctx == NULL) {
continue;
}
output_ctx = r.ctx;
} else if (module->InitSubFunc != NULL) {
SCLogInfo("skipping submodule");
continue;
@ -814,10 +814,15 @@ void RunModeInitializeOutputs(void)
OutputCtx *output_ctx = NULL;
if (module->InitFunc != NULL) {
output_ctx = module->InitFunc(output_config);
if (output_ctx == NULL) {
OutputInitResult r = module->InitFunc(output_config);
if (!r.ok) {
FatalErrorOnInit(SC_ERR_INVALID_ARGUMENT,
"output module setup failed");
continue;
} else if (r.ctx == NULL) {
continue;
}
output_ctx = r.ctx;
}
AddOutputToFreeList(module, output_ctx);

@ -30,8 +30,8 @@
#include "conf.h"
#include "runmodes.h"
#include "runmode-af-packet.h"
#include "log-httplog.h"
#include "output.h"
#include "log-httplog.h"
#include "detect-engine.h"
#include "detect-engine-mpm.h"

Loading…
Cancel
Save