From: Victor Julien Date: Thu, 30 Jan 2014 12:20:47 +0000 (+0100) Subject: json outputs: cleanups X-Git-Tag: suricata-2.0rc1~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F805%2Fhead;p=thirdparty%2Fsuricata.git json outputs: cleanups Clean up header files and improve memory handling. --- diff --git a/src/output-dnslog.h b/src/output-dnslog.h index 3c08b0f4bd..cc077ebfed 100644 --- a/src/output-dnslog.h +++ b/src/output-dnslog.h @@ -24,8 +24,6 @@ #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__ */ diff --git a/src/output-droplog.c b/src/output-droplog.c index 4a865bfa41..e8a93bc7aa 100644 --- a/src/output-droplog.c +++ b/src/output-droplog.c @@ -175,6 +175,8 @@ static TmEcode JsonDropLogThreadDeinit(ThreadVars *t, void *data) return TM_ECODE_OK; } + MemBufferFree(aft->buffer); + /* clear memory */ memset(aft, 0, sizeof(*aft)); diff --git a/src/output-droplog.h b/src/output-droplog.h index 12ccf5e5d0..d195f29bf7 100644 --- a/src/output-droplog.h +++ b/src/output-droplog.h @@ -22,12 +22,9 @@ * */ +#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__ */ diff --git a/src/output-httplog.h b/src/output-httplog.h index dc1434aaf3..c054dd20e0 100644 --- a/src/output-httplog.h +++ b/src/output-httplog.h @@ -24,9 +24,6 @@ #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__ */ diff --git a/src/output-json-alert.c b/src/output-json-alert.c index 7acc363ba4..05c98d315f 100644 --- a/src/output-json-alert.c +++ b/src/output-json-alert.c @@ -254,6 +254,8 @@ static TmEcode JsonAlertLogThreadDeinit(ThreadVars *t, void *data) return TM_ECODE_OK; } + MemBufferFree(aft->buffer); + /* clear memory */ memset(aft, 0, sizeof(JsonAlertLogThread)); diff --git a/src/output-json-file.h b/src/output-json-file.h index cb39618157..e101897f7b 100644 --- a/src/output-json-file.h +++ b/src/output-json-file.h @@ -21,11 +21,9 @@ * \author Tom DeCanio */ -#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__ */ diff --git a/src/output-json.c b/src/output-json.c index 226cc4d35c..a78cf987fb 100644 --- a/src/output-json.c +++ b/src/output-json.c @@ -322,37 +322,10 @@ int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer *buffer) { 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; @@ -364,25 +337,13 @@ TmEcode OutputJsonThreadInit(ThreadVars *t, void *initdata, void **data) 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; diff --git a/src/output-json.h b/src/output-json.h index fade780d03..aa5485e526 100644 --- a/src/output-json.h +++ b/src/output-json.h @@ -43,28 +43,11 @@ OutputCtx *OutputJsonInitCtx(ConfNode *); */ 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 */ diff --git a/src/output-tlslog.h b/src/output-tlslog.h index 71835e78bd..b6e52abf3a 100644 --- a/src/output-tlslog.h +++ b/src/output-tlslog.h @@ -24,8 +24,6 @@ #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__ */