json outputs: cleanups

Clean up header files and improve memory handling.
pull/805/head
Victor Julien 12 years ago
parent 3fc63d3656
commit b5ef269b03

@ -24,8 +24,6 @@
#ifndef __OUTPUT_DNSLOG_H__ #ifndef __OUTPUT_DNSLOG_H__
#define __OUTPUT_DNSLOG_H__ #define __OUTPUT_DNSLOG_H__
//TmEcode OutputDnsLog(ThreadVars *tv, Packet *p, void *data);
OutputCtx *DnsJsonInitCtx(ConfNode *);
void TmModuleJsonDnsLogRegister (void); void TmModuleJsonDnsLogRegister (void);
#endif /* __OUTPUT_DNSLOG_H__ */ #endif /* __OUTPUT_DNSLOG_H__ */

@ -175,6 +175,8 @@ static TmEcode JsonDropLogThreadDeinit(ThreadVars *t, void *data)
return TM_ECODE_OK; return TM_ECODE_OK;
} }
MemBufferFree(aft->buffer);
/* clear memory */ /* clear memory */
memset(aft, 0, sizeof(*aft)); memset(aft, 0, sizeof(*aft));

@ -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); void TmModuleJsonDropLogRegister (void);
#endif /* OUTPUT_DROPLOG_H */ #endif /* __OUTPUT_DROPLOG_H__ */

@ -24,9 +24,6 @@
#ifndef __OUTPUT_HTTPLOG_H__ #ifndef __OUTPUT_HTTPLOG_H__
#define __OUTPUT_HTTPLOG_H__ #define __OUTPUT_HTTPLOG_H__
TmEcode OutputHttpLog (ThreadVars *tv, Packet *p, void *data);
OutputCtx *OutputHttpLogInit(ConfNode *);
void TmModuleJsonHttpLogRegister (void); void TmModuleJsonHttpLogRegister (void);
#endif /* __OUTPUT_HTTPLOG_H__ */ #endif /* __OUTPUT_HTTPLOG_H__ */

@ -254,6 +254,8 @@ static TmEcode JsonAlertLogThreadDeinit(ThreadVars *t, void *data)
return TM_ECODE_OK; return TM_ECODE_OK;
} }
MemBufferFree(aft->buffer);
/* clear memory */ /* clear memory */
memset(aft, 0, sizeof(JsonAlertLogThread)); memset(aft, 0, sizeof(JsonAlertLogThread));

@ -21,11 +21,9 @@
* \author Tom DeCanio <td@npulsetech.com> * \author Tom DeCanio <td@npulsetech.com>
*/ */
#ifndef __OUTPUT_FILELOG_H__ #ifndef __OUTPUT_JSON_FILE_H__
#define __OUTPUT_FILELOG_H__ #define __OUTPUT_JSON_FILE_H__
TmEcode OutputFileLog (ThreadVars *tv, Packet *p, void *data);
OutputCtx *OutputFileLogInit(ConfNode *);
void TmModuleJsonFileLogRegister (void); void TmModuleJsonFileLogRegister (void);
#endif /* __OUTPUT_FILELOG_H__ */ #endif /* __OUTPUT_JSON_FILE_H__ */

@ -322,37 +322,10 @@ int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer *buffer) {
fflush(file_ctx->fp); fflush(file_ctx->fp);
} }
SCMutexUnlock(&file_ctx->fp_mutex); SCMutexUnlock(&file_ctx->fp_mutex);
free(js_s);
return 0; 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) TmEcode OutputJson (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQueue *postpq)
{ {
return TM_ECODE_OK; return TM_ECODE_OK;
@ -364,25 +337,13 @@ TmEcode OutputJsonThreadInit(ThreadVars *t, void *initdata, void **data)
if (unlikely(aft == NULL)) if (unlikely(aft == NULL))
return TM_ECODE_FAILED; return TM_ECODE_FAILED;
memset(aft, 0, sizeof(AlertJsonThread)); memset(aft, 0, sizeof(AlertJsonThread));
if(initdata == NULL) if(initdata == NULL)
{ {
SCLogDebug("Error getting context for AlertJson. \"initdata\" argument NULL"); SCLogDebug("Error getting context for AlertJson. \"initdata\" argument NULL");
SCFree(aft); SCFree(aft);
return TM_ECODE_FAILED; 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; *data = (void *)aft;
return TM_ECODE_OK; return TM_ECODE_OK;

@ -43,28 +43,11 @@ OutputCtx *OutputJsonInitCtx(ConfNode *);
*/ */
typedef struct OutputJsonCtx_ { typedef struct OutputJsonCtx_ {
LogFileCtx *file_ctx; LogFileCtx *file_ctx;
OutputCtx *drop_ctx;
OutputCtx *files_ctx;
OutputCtx *http_ctx;
OutputCtx *tls_ctx;
} OutputJsonCtx; } OutputJsonCtx;
typedef struct AlertJsonThread_ { typedef struct AlertJsonThread_ {
/** LogFileCtx has the pointer to the file and a mutex to allow multithreading */ /** LogFileCtx has the pointer to the file and a mutex to allow multithreading */
LogFileCtx* file_ctx; 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; } AlertJsonThread;
#endif /* HAVE_LIBJANSSON */ #endif /* HAVE_LIBJANSSON */

@ -24,8 +24,6 @@
#ifndef __OUTPUT_TLSLOG_H__ #ifndef __OUTPUT_TLSLOG_H__
#define __OUTPUT_TLSLOG_H__ #define __OUTPUT_TLSLOG_H__
TmEcode OutputTlsLog (ThreadVars *tv, Packet *p, void *data);
OutputCtx *OutputTlsLogInit(ConfNode *);
void TmModuleJsonTlsLogRegister (void); void TmModuleJsonTlsLogRegister (void);
#endif /* __OUTPUT_TLSLOG_H__ */ #endif /* __OUTPUT_TLSLOG_H__ */

Loading…
Cancel
Save