]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
json outputs: cleanups 805/head
authorVictor Julien <victor@inliniac.net>
Thu, 30 Jan 2014 12:20:47 +0000 (13:20 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 30 Jan 2014 12:20:47 +0000 (13:20 +0100)
Clean up header files and improve memory handling.

src/output-dnslog.h
src/output-droplog.c
src/output-droplog.h
src/output-httplog.h
src/output-json-alert.c
src/output-json-file.h
src/output-json.c
src/output-json.h
src/output-tlslog.h

index 3c08b0f4bd6ffcaf287c7063f73e96def5f73b27..cc077ebfeda40ac654516d8202127008a8c0bd67 100644 (file)
@@ -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__ */
index 4a865bfa4183deea1a67cc0b749a7db320f2d6d9..e8a93bc7aa6cbf091c5a2c500c2489fee896f458 100644 (file)
@@ -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));
 
index 12ccf5e5d0346b926b466e132db06e67a6c637e3..d195f29bf728970f2065040db570bb91d9bddd7f 100644 (file)
  *
  */
 
+#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__ */
index dc1434aaf3d08d4d7277e227e7f573d6ecb35887..c054dd20e080f7b49ed67bba7168de9b5b48cda8 100644 (file)
@@ -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__ */
index 7acc363ba4084128dc66dbb33f75b3d03993ef81..05c98d315f97c92f749a044d7c6390c85e5f1ba4 100644 (file)
@@ -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));
 
index cb39618157bd79b4a6c4bb8ffc7185d7ee0bd48f..e101897f7bf278172b98b12b217a1af6e1a31bee 100644 (file)
  * \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__ */
index 226cc4d35ccea701355aab3adcc96e5aceb7b337..a78cf987fb673db252368432f6565ff0c4be3711 100644 (file)
@@ -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;
index fade780d037eaf9aa721f5342ce6b00f858fb0f2..aa5485e526d12260ecf1e55261f3e6f984b9b4c9 100644 (file)
@@ -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 */
index 71835e78bd69f50d7e85692cde2d8203f3bdf562..b6e52abf3a61f41d3a5489bc0c7ba0941bc08cf6 100644 (file)
@@ -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__ */