]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
alert-pcapinfo: clean up
authorVictor Julien <victor@inliniac.net>
Tue, 14 Jan 2014 15:08:47 +0000 (16:08 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 27 Jan 2014 14:20:59 +0000 (15:20 +0100)
Make functions static.
Move registration to the bottom.

src/alert-pcapinfo.c
src/alert-pcapinfo.h

index 8f2e79919f101d27bb86c053cc8b1a6c3205edc1..e31bd37a55ae37f585065b4aebb6ec53ab595ed6 100644 (file)
 
 #define MODULE_NAME "AlertPcapInfo"
 
-TmEcode AlertPcapInfo (ThreadVars *, Packet *, void *, PacketQueue *, PacketQueue *);
-TmEcode AlertPcapInfoThreadInit(ThreadVars *, void *, void **);
-TmEcode AlertPcapInfoThreadDeinit(ThreadVars *, void *);
-void AlertPcapInfoExitPrintStats(ThreadVars *, void *);
-static int AlertPcapInfoOpenFileCtx(LogFileCtx *, const char *, const char *);
-static void AlertPcapInfoDeInitCtx(OutputCtx *);
-
-void TmModuleAlertPcapInfoRegister (void) {
-    tmm_modules[TMM_ALERTPCAPINFO].name = MODULE_NAME;
-    tmm_modules[TMM_ALERTPCAPINFO].ThreadInit = AlertPcapInfoThreadInit;
-    tmm_modules[TMM_ALERTPCAPINFO].Func = AlertPcapInfo;
-    tmm_modules[TMM_ALERTPCAPINFO].ThreadExitPrintStats = AlertPcapInfoExitPrintStats;
-    tmm_modules[TMM_ALERTPCAPINFO].ThreadDeinit = AlertPcapInfoThreadDeinit;
-    tmm_modules[TMM_ALERTPCAPINFO].RegisterTests = NULL;
-    tmm_modules[TMM_ALERTPCAPINFO].cap_flags = 0;
-
-    OutputRegisterModule(MODULE_NAME, "pcap-info", AlertPcapInfoInitCtx);
-}
-
 typedef struct AlertPcapInfoThread_ {
     /** LogFileCtx has the pointer to the file and a mutex to allow multithreading */
     LogFileCtx* file_ctx;
 } AlertPcapInfoThread;
 
-
-TmEcode AlertPcapInfo (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQueue *postpq)
+static TmEcode AlertPcapInfo (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQueue *postpq)
 {
     AlertPcapInfoThread *aft = (AlertPcapInfoThread *)data;
     int i;
@@ -116,7 +96,7 @@ TmEcode AlertPcapInfo (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, P
     return TM_ECODE_OK;
 }
 
-TmEcode AlertPcapInfoThreadInit(ThreadVars *t, void *initdata, void **data)
+static TmEcode AlertPcapInfoThreadInit(ThreadVars *t, void *initdata, void **data)
 {
     AlertPcapInfoThread *aft = SCMalloc(sizeof(AlertPcapInfoThread));
     if (unlikely(aft == NULL))
@@ -135,7 +115,7 @@ TmEcode AlertPcapInfoThreadInit(ThreadVars *t, void *initdata, void **data)
     return TM_ECODE_OK;
 }
 
-TmEcode AlertPcapInfoThreadDeinit(ThreadVars *t, void *data)
+static TmEcode AlertPcapInfoThreadDeinit(ThreadVars *t, void *data)
 {
     AlertPcapInfoThread *aft = (AlertPcapInfoThread *)data;
     if (aft == NULL) {
@@ -149,7 +129,7 @@ TmEcode AlertPcapInfoThreadDeinit(ThreadVars *t, void *data)
     return TM_ECODE_OK;
 }
 
-void AlertPcapInfoExitPrintStats(ThreadVars *tv, void *data) {
+static void AlertPcapInfoExitPrintStats(ThreadVars *tv, void *data) {
     AlertPcapInfoThread *aft = (AlertPcapInfoThread *)data;
     if (aft == NULL) {
         return;
@@ -158,12 +138,50 @@ void AlertPcapInfoExitPrintStats(ThreadVars *tv, void *data) {
     SCLogInfo("(%s) Alerts %" PRIu64 "", tv->name, aft->file_ctx->alerts);
 }
 
+static void AlertPcapInfoDeInitCtx(OutputCtx *output_ctx)
+{
+    LogFileCtx *logfile_ctx = (LogFileCtx *)output_ctx->data;
+    LogFileFreeCtx(logfile_ctx);
+    SCFree(output_ctx);
+}
+
+/** \brief Read the config set the file pointer, open the file
+ *  \param file_ctx pointer to a created LogFileCtx using LogFileNewCtx()
+ *  \param filename name of log file
+ *  \param mode append mode (bool)
+ *  \return -1 if failure, 0 if succesful
+ * */
+static int AlertPcapInfoOpenFileCtx(LogFileCtx *file_ctx, const char *filename,
+                                    const char *mode)
+{
+    char log_path[PATH_MAX];
+    char *log_dir;
+
+    log_dir = ConfigGetLogDirectory();
+
+    snprintf(log_path, PATH_MAX, "%s/%s", log_dir, filename);
+
+    if (ConfValIsTrue(mode)) {
+        file_ctx->fp = fopen(log_path, "a");
+    } else {
+        file_ctx->fp = fopen(log_path, "w");
+    }
+
+    if (file_ctx->fp == NULL) {
+        SCLogError(SC_ERR_FOPEN, "failed to open %s: %s", log_path,
+                strerror(errno));
+        return -1;
+    }
+
+    return 0;
+}
+
 /**
  * \brief Create a new LogFileCtx for "fast" output style.
  * \param conf The configuration node for this output.
  * \return A LogFileCtx pointer on success, NULL on failure.
  */
-OutputCtx *AlertPcapInfoInitCtx(ConfNode *conf)
+static OutputCtx *AlertPcapInfoInitCtx(ConfNode *conf)
 {
     LogFileCtx *logfile_ctx = LogFileNewCtx();
     if (logfile_ctx == NULL) {
@@ -195,40 +213,14 @@ OutputCtx *AlertPcapInfoInitCtx(ConfNode *conf)
     return output_ctx;
 }
 
-static void AlertPcapInfoDeInitCtx(OutputCtx *output_ctx)
-{
-    LogFileCtx *logfile_ctx = (LogFileCtx *)output_ctx->data;
-    LogFileFreeCtx(logfile_ctx);
-    SCFree(output_ctx);
-}
-
-/** \brief Read the config set the file pointer, open the file
- *  \param file_ctx pointer to a created LogFileCtx using LogFileNewCtx()
- *  \param filename name of log file
- *  \param mode append mode (bool)
- *  \return -1 if failure, 0 if succesful
- * */
-static int AlertPcapInfoOpenFileCtx(LogFileCtx *file_ctx, const char *filename,
-                                    const char *mode)
-{
-    char log_path[PATH_MAX];
-    char *log_dir;
-
-    log_dir = ConfigGetLogDirectory();
-
-    snprintf(log_path, PATH_MAX, "%s/%s", log_dir, filename);
-
-    if (ConfValIsTrue(mode)) {
-        file_ctx->fp = fopen(log_path, "a");
-    } else {
-        file_ctx->fp = fopen(log_path, "w");
-    }
-
-    if (file_ctx->fp == NULL) {
-        SCLogError(SC_ERR_FOPEN, "failed to open %s: %s", log_path,
-                strerror(errno));
-        return -1;
-    }
+void TmModuleAlertPcapInfoRegister (void) {
+    tmm_modules[TMM_ALERTPCAPINFO].name = MODULE_NAME;
+    tmm_modules[TMM_ALERTPCAPINFO].ThreadInit = AlertPcapInfoThreadInit;
+    tmm_modules[TMM_ALERTPCAPINFO].Func = AlertPcapInfo;
+    tmm_modules[TMM_ALERTPCAPINFO].ThreadExitPrintStats = AlertPcapInfoExitPrintStats;
+    tmm_modules[TMM_ALERTPCAPINFO].ThreadDeinit = AlertPcapInfoThreadDeinit;
+    tmm_modules[TMM_ALERTPCAPINFO].RegisterTests = NULL;
+    tmm_modules[TMM_ALERTPCAPINFO].cap_flags = 0;
 
-    return 0;
+    OutputRegisterModule(MODULE_NAME, "pcap-info", AlertPcapInfoInitCtx);
 }
index 871c23f5128af4d12cb7a59f920b92a781c28f2e..f4a0024a565addf358b56c9f36305e9c29d2f282 100644 (file)
@@ -25,6 +25,5 @@
 #define __ALERT_PCAPINFO_H__
 
 void TmModuleAlertPcapInfoRegister (void);
-OutputCtx *AlertPcapInfoInitCtx(ConfNode *);
 
 #endif /* __ALERT_PCAPINFO_H__ */