Clean up header files and improve memory handling.
#ifndef __OUTPUT_DNSLOG_H__
#define __OUTPUT_DNSLOG_H__
-//TmEcode OutputDnsLog(ThreadVars *tv, Packet *p, void *data);
-OutputCtx *DnsJsonInitCtx(ConfNode *);
void TmModuleJsonDnsLogRegister (void);
#endif /* __OUTPUT_DNSLOG_H__ */
return TM_ECODE_OK;
}
+ MemBufferFree(aft->buffer);
+
/* clear memory */
memset(aft, 0, sizeof(*aft));
*
*/
+#ifndef __OUTPUT_DROPLOG_H__
+#define __OUTPUT_DROPLOG_H__
-#ifndef OUTPUT_DROPLOG_H
-#define OUTPUT_DROPLOG_H
-
-TmEcode OutputDropLog (ThreadVars *tv, Packet *p, void *data);
-OutputCtx *OutputDropLogInit(ConfNode *);
void TmModuleJsonDropLogRegister (void);
-#endif /* OUTPUT_DROPLOG_H */
+#endif /* __OUTPUT_DROPLOG_H__ */
#ifndef __OUTPUT_HTTPLOG_H__
#define __OUTPUT_HTTPLOG_H__
-TmEcode OutputHttpLog (ThreadVars *tv, Packet *p, void *data);
-OutputCtx *OutputHttpLogInit(ConfNode *);
-
void TmModuleJsonHttpLogRegister (void);
#endif /* __OUTPUT_HTTPLOG_H__ */
return TM_ECODE_OK;
}
+ MemBufferFree(aft->buffer);
+
/* clear memory */
memset(aft, 0, sizeof(JsonAlertLogThread));
* \author Tom DeCanio <td@npulsetech.com>
*/
-#ifndef __OUTPUT_FILELOG_H__
-#define __OUTPUT_FILELOG_H__
+#ifndef __OUTPUT_JSON_FILE_H__
+#define __OUTPUT_JSON_FILE_H__
-TmEcode OutputFileLog (ThreadVars *tv, Packet *p, void *data);
-OutputCtx *OutputFileLogInit(ConfNode *);
void TmModuleJsonFileLogRegister (void);
-#endif /* __OUTPUT_FILELOG_H__ */
+#endif /* __OUTPUT_JSON_FILE_H__ */
fflush(file_ctx->fp);
}
SCMutexUnlock(&file_ctx->fp_mutex);
+ free(js_s);
return 0;
}
-TmEcode OutputJSON(json_t *js, void *data, uint64_t *count)
-{
- AlertJsonThread *aft = (AlertJsonThread *)data;
- MemBuffer *buffer = (MemBuffer *)aft->buffer;
- char *js_s = json_dumps(js,
- JSON_PRESERVE_ORDER|JSON_COMPACT|JSON_ENSURE_ASCII|
-#ifdef JSON_ESCAPE_SLASH
- JSON_ESCAPE_SLASH
-#else
- 0
-#endif
- );
- if (unlikely(js_s == NULL))
- return TM_ECODE_OK;
-
- SCMutexLock(&aft->file_ctx->fp_mutex);
- if (json_out == ALERT_SYSLOG) {
- syslog(alert_syslog_level, "%s", js_s);
- } else if (json_out == ALERT_FILE) {
- MemBufferWriteString(buffer, "%s\n", js_s);
- (void)MemBufferPrintToFPAsString(buffer, aft->file_ctx->fp);
- fflush(aft->file_ctx->fp);
- }
- *count += 1;
- SCMutexUnlock(&aft->file_ctx->fp_mutex);
- return TM_ECODE_OK;
-}
-
TmEcode OutputJson (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQueue *postpq)
{
return TM_ECODE_OK;
if (unlikely(aft == NULL))
return TM_ECODE_FAILED;
memset(aft, 0, sizeof(AlertJsonThread));
+
if(initdata == NULL)
{
SCLogDebug("Error getting context for AlertJson. \"initdata\" argument NULL");
SCFree(aft);
return TM_ECODE_FAILED;
}
- aft->buffer = MemBufferCreateNew(OUTPUT_BUFFER_SIZE);
- if (aft->buffer == NULL) {
- SCFree(aft);
- return TM_ECODE_FAILED;
- }
-
- /** Use the Ouptut Context (file pointer and mutex) */
- OutputJsonCtx *json_ctx = ((OutputCtx *)initdata)->data;
- if (json_ctx != NULL) {
- aft->file_ctx = json_ctx->file_ctx;
- aft->http_ctx = json_ctx->http_ctx;
- aft->tls_ctx = json_ctx->tls_ctx;
- }
*data = (void *)aft;
return TM_ECODE_OK;
*/
typedef struct OutputJsonCtx_ {
LogFileCtx *file_ctx;
- OutputCtx *drop_ctx;
- OutputCtx *files_ctx;
- OutputCtx *http_ctx;
- OutputCtx *tls_ctx;
} OutputJsonCtx;
typedef struct AlertJsonThread_ {
/** LogFileCtx has the pointer to the file and a mutex to allow multithreading */
LogFileCtx* file_ctx;
-
- void *buffer; /* pointer to MemBuffer */
-
- uint64_t alert_cnt;
- uint64_t dns_cnt;
- uint64_t drop_cnt;
- uint64_t files_cnt;
- uint64_t http_cnt;
- uint64_t tls_cnt;
- OutputCtx *drop_ctx;
- OutputCtx *files_ctx;
- OutputCtx *http_ctx;
- OutputCtx *tls_ctx;
} AlertJsonThread;
#endif /* HAVE_LIBJANSSON */
#ifndef __OUTPUT_TLSLOG_H__
#define __OUTPUT_TLSLOG_H__
-TmEcode OutputTlsLog (ThreadVars *tv, Packet *p, void *data);
-OutputCtx *OutputTlsLogInit(ConfNode *);
void TmModuleJsonTlsLogRegister (void);
#endif /* __OUTPUT_TLSLOG_H__ */