]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
log api: convert all names to const
authorVictor Julien <victor@inliniac.net>
Thu, 30 Jan 2014 08:14:59 +0000 (09:14 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 30 Jan 2014 09:51:26 +0000 (10:51 +0100)
Instead of strdupping all names w/o a need, use const ptrs.

12 files changed:
src/output-file.c
src/output-file.h
src/output-filedata.c
src/output-filedata.h
src/output-packet.c
src/output-packet.h
src/output-tx.c
src/output-tx.h
src/output.c
src/output.h
src/tm-modules.c
src/tm-modules.h

index 382d95987429f539be4b281a8c78b8b63acc5fc2..c8c2178d3058c2fb3d6807493c8c6852d6ca83db 100644 (file)
@@ -53,7 +53,8 @@ typedef struct OutputFileLogger_ {
 
 static OutputFileLogger *list = NULL;
 
-int OutputRegisterFileLogger(char *name, FileLogger LogFunc, OutputCtx *output_ctx) {
+int OutputRegisterFileLogger(const char *name, FileLogger LogFunc, OutputCtx *output_ctx)
+{
     OutputFileLogger *op = SCMalloc(sizeof(*op));
     if (op == NULL)
         return -1;
@@ -61,11 +62,7 @@ int OutputRegisterFileLogger(char *name, FileLogger LogFunc, OutputCtx *output_c
 
     op->LogFunc = LogFunc;
     op->output_ctx = output_ctx;
-    op->name = SCStrdup(name);
-    if (op->name == NULL) {
-        SCFree(op);
-        return -1;
-    }
+    op->name = name;
 
     if (list == NULL)
         list = op;
index cc17abf7fd689dc4e5edaf74c9068e8ec7e22391..2e2009681b86cfe67d5a2bef838e3c52b724c08f 100644 (file)
@@ -37,7 +37,7 @@ typedef int (*FileLogger)(ThreadVars *, void *thread_data, const Packet *, const
  */
 //typedef int (*TxLogCondition)(ThreadVars *, const Packet *);
 
-int OutputRegisterFileLogger(char *name, FileLogger LogFunc, OutputCtx *);
+int OutputRegisterFileLogger(const char *name, FileLogger LogFunc, OutputCtx *);
 
 void TmModuleFileLoggerRegister (void);
 
index 967dcffd70dd5c21f902e45a9c34ed884ad687bc..65c5ce6e65cbf4be3b25ca1cb12bc2cea9ed582a 100644 (file)
@@ -58,7 +58,8 @@ static SCMutex g_waldo_mutex = SCMUTEX_INITIALIZER;
 static int g_waldo_init = 0;
 static int g_waldo_deinit = 0;
 
-int OutputRegisterFiledataLogger(char *name, FiledataLogger LogFunc, OutputCtx *output_ctx) {
+int OutputRegisterFiledataLogger(const char *name, FiledataLogger LogFunc, OutputCtx *output_ctx)
+{
     OutputFiledataLogger *op = SCMalloc(sizeof(*op));
     if (op == NULL)
         return -1;
@@ -66,11 +67,7 @@ int OutputRegisterFiledataLogger(char *name, FiledataLogger LogFunc, OutputCtx *
 
     op->LogFunc = LogFunc;
     op->output_ctx = output_ctx;
-    op->name = SCStrdup(name);
-    if (op->name == NULL) {
-        SCFree(op);
-        return -1;
-    }
+    op->name = name;
 
     if (list == NULL)
         list = op;
index c35fd21ab3b3c2849ca121b622804a5f5ec78db9..334ad60d239c6473c64f7f087a587c5663a9bb02 100644 (file)
@@ -41,7 +41,7 @@ typedef int (*FiledataLogger)(ThreadVars *, void *thread_data, const Packet *,
  */
 //typedef int (*TxLogCondition)(ThreadVars *, const Packet *);
 
-int OutputRegisterFiledataLogger(char *name, FiledataLogger LogFunc, OutputCtx *);
+int OutputRegisterFiledataLogger(const char *name, FiledataLogger LogFunc, OutputCtx *);
 
 void TmModuleFiledataLoggerRegister (void);
 
index aa8daf9d1cda64fa4d5fccd6872063d9d57d3790..fcc073043ced8e5d251fd4bba5d328f4d5ba1d25 100644 (file)
@@ -51,7 +51,7 @@ typedef struct OutputPacketLogger_ {
 
 static OutputPacketLogger *list = NULL;
 
-int OutputRegisterPacketLogger(char *name, PacketLogger LogFunc, PacketLogCondition ConditionFunc, OutputCtx *output_ctx) {
+int OutputRegisterPacketLogger(const char *name, PacketLogger LogFunc, PacketLogCondition ConditionFunc, OutputCtx *output_ctx) {
     OutputPacketLogger *op = SCMalloc(sizeof(*op));
     if (op == NULL)
         return -1;
@@ -60,11 +60,7 @@ int OutputRegisterPacketLogger(char *name, PacketLogger LogFunc, PacketLogCondit
     op->LogFunc = LogFunc;
     op->ConditionFunc = ConditionFunc;
     op->output_ctx = output_ctx;
-    op->name = SCStrdup(name);
-    if (op->name == NULL) {
-        SCFree(op);
-        return -1;
-    }
+    op->name = name;
 
     if (list == NULL)
         list = op;
index 42e524c4a5b2b0b8f72300a036b13bc8dccdd3a8..1173282f68a7ef0f278e51c2bfa65fa67f2b5688 100644 (file)
@@ -36,7 +36,7 @@ typedef int (*PacketLogger)(ThreadVars *, void *thread_data, const Packet *);
  */
 typedef int (*PacketLogCondition)(ThreadVars *, const Packet *);
 
-int OutputRegisterPacketLogger(char *name, PacketLogger LogFunc,
+int OutputRegisterPacketLogger(const char *name, PacketLogger LogFunc,
         PacketLogCondition ConditionFunc, OutputCtx *);
 
 void TmModulePacketLoggerRegister (void);
index 0293775f69d6efd69ecfa9b139cc8e7c1acfc0da..d250fcab75156d03accace672305a06d0b7837d6 100644 (file)
@@ -53,7 +53,8 @@ typedef struct OutputTxLogger_ {
 
 static OutputTxLogger *list = NULL;
 
-int OutputRegisterTxLogger(char *name, uint16_t alproto, TxLogger LogFunc, OutputCtx *output_ctx) {
+int OutputRegisterTxLogger(const char *name, uint16_t alproto, TxLogger LogFunc, OutputCtx *output_ctx)
+{
     OutputTxLogger *op = SCMalloc(sizeof(*op));
     if (op == NULL)
         return -1;
@@ -62,11 +63,7 @@ int OutputRegisterTxLogger(char *name, uint16_t alproto, TxLogger LogFunc, Outpu
     op->alproto = alproto;
     op->LogFunc = LogFunc;
     op->output_ctx = output_ctx;
-    op->name = SCStrdup(name);
-    if (op->name == NULL) {
-        SCFree(op);
-        return -1;
-    }
+    op->name = name;
 
     if (list == NULL)
         list = op;
index 249747a12f9fd5fa3fb6286b45f3776a8857c825..badc18351a3a1c93e1657ee8a0a30e3b9bcd9fd4 100644 (file)
@@ -36,7 +36,7 @@ typedef int (*TxLogger)(ThreadVars *, void *thread_data, const Packet *, Flow *f
  */
 //typedef int (*TxLogCondition)(ThreadVars *, const Packet *);
 
-int OutputRegisterTxLogger(char *name, uint16_t alproto, TxLogger LogFunc, OutputCtx *);
+int OutputRegisterTxLogger(const char *name, uint16_t alproto, TxLogger LogFunc, OutputCtx *);
 
 void TmModuleTxLoggerRegister (void);
 
index 2b8a04b3f94e8263bf2e79a9225dd15d66928b3b..5e7d88f2a35af26b216652a96dc1038c92e08b27 100644 (file)
@@ -43,19 +43,15 @@ static TAILQ_HEAD(, OutputModule_) output_modules =
  * \retval Returns 0 on success, -1 on failure.
  */
 void
-OutputRegisterModule(char *name, char *conf_name,
+OutputRegisterModule(const char *name, const char *conf_name,
     OutputCtx *(*InitFunc)(ConfNode *))
 {
     OutputModule *module = SCCalloc(1, sizeof(*module));
     if (unlikely(module == NULL))
         goto error;
 
-    module->name = SCStrdup(name);
-    if (unlikely(module->name == NULL))
-        goto error;
-    module->conf_name = SCStrdup(conf_name);
-    if (unlikely(module->conf_name == NULL))
-        goto error;
+    module->name = name;
+    module->conf_name = conf_name;
     module->InitFunc = InitFunc;
     TAILQ_INSERT_TAIL(&output_modules, module, entries);
 
@@ -77,7 +73,7 @@ error:
  * \retval Returns 0 on success, -1 on failure.
  */
 void
-OutputRegisterPacketModule(char *name, char *conf_name,
+OutputRegisterPacketModule(const char *name, const char *conf_name,
     OutputCtx *(*InitFunc)(ConfNode *),
     PacketLogger PacketLogFunc, PacketLogCondition PacketConditionFunc)
 {
@@ -90,12 +86,8 @@ OutputRegisterPacketModule(char *name, char *conf_name,
         goto error;
     }
 
-    module->name = SCStrdup(name);
-    if (unlikely(module->name == NULL))
-        goto error;
-    module->conf_name = SCStrdup(conf_name);
-    if (unlikely(module->conf_name == NULL))
-        goto error;
+    module->name = name;
+    module->conf_name = conf_name;
     module->InitFunc = InitFunc;
     module->PacketLogFunc = PacketLogFunc;
     module->PacketConditionFunc = PacketConditionFunc;
@@ -117,8 +109,8 @@ error:
  * \retval Returns 0 on success, -1 on failure.
  */
 void
-OutputRegisterPacketSubModule(const char *parent_name, char *name, char *conf_name,
-    OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *parent_ctx),
+OutputRegisterPacketSubModule(const char *parent_name, const char *name,
+    const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *parent_ctx),
     PacketLogger PacketLogFunc, PacketLogCondition PacketConditionFunc)
 {
     if (unlikely(PacketLogFunc == NULL || PacketConditionFunc == NULL)) {
@@ -130,15 +122,9 @@ OutputRegisterPacketSubModule(const char *parent_name, char *name, char *conf_na
         goto error;
     }
 
-    module->name = SCStrdup(name);
-    if (unlikely(module->name == NULL))
-        goto error;
-    module->conf_name = SCStrdup(conf_name);
-    if (unlikely(module->conf_name == NULL))
-        goto error;
-    module->parent_name = SCStrdup(parent_name);
-    if (unlikely(module->conf_name == NULL))
-        goto error;
+    module->name = name;
+    module->conf_name = conf_name;
+    module->parent_name = parent_name;
     module->InitSubFunc = InitFunc;
     module->PacketLogFunc = PacketLogFunc;
     module->PacketConditionFunc = PacketConditionFunc;
@@ -160,7 +146,7 @@ error:
  * \retval Returns 0 on success, -1 on failure.
  */
 void
-OutputRegisterTxModule(char *name, char *conf_name,
+OutputRegisterTxModule(const char *name, const char *conf_name,
     OutputCtx *(*InitFunc)(ConfNode *), uint16_t alproto,
     TxLogger TxLogFunc)
 {
@@ -173,12 +159,8 @@ OutputRegisterTxModule(char *name, char *conf_name,
         goto error;
     }
 
-    module->name = SCStrdup(name);
-    if (unlikely(module->name == NULL))
-        goto error;
-    module->conf_name = SCStrdup(conf_name);
-    if (unlikely(module->conf_name == NULL))
-        goto error;
+    module->name = name;
+    module->conf_name = conf_name;
     module->InitFunc = InitFunc;
     module->TxLogFunc = TxLogFunc;
     module->alproto = alproto;
@@ -192,9 +174,9 @@ error:
 }
 
 void
-OutputRegisterTxSubModule(const char *parent_name, char *name, char *conf_name,
-    OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *parent_ctx), uint16_t alproto,
-    TxLogger TxLogFunc)
+OutputRegisterTxSubModule(const char *parent_name, const char *name,
+    const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *parent_ctx),
+    uint16_t alproto, TxLogger TxLogFunc)
 {
     if (unlikely(TxLogFunc == NULL)) {
         goto error;
@@ -205,15 +187,9 @@ OutputRegisterTxSubModule(const char *parent_name, char *name, char *conf_name,
         goto error;
     }
 
-    module->name = SCStrdup(name);
-    if (unlikely(module->name == NULL))
-        goto error;
-    module->conf_name = SCStrdup(conf_name);
-    if (unlikely(module->conf_name == NULL))
-        goto error;
-    module->parent_name = SCStrdup(parent_name);
-    if (unlikely(module->parent_name == NULL))
-        goto error;
+    module->name = name;
+    module->conf_name = conf_name;
+    module->parent_name = parent_name;
     module->InitSubFunc = InitFunc;
     module->TxLogFunc = TxLogFunc;
     module->alproto = alproto;
@@ -235,7 +211,7 @@ error:
  * \retval Returns 0 on success, -1 on failure.
  */
 void
-OutputRegisterFileModule(char *name, char *conf_name,
+OutputRegisterFileModule(const char *name, const char *conf_name,
     OutputCtx *(*InitFunc)(ConfNode *), FileLogger FileLogFunc)
 {
     if (unlikely(FileLogFunc == NULL)) {
@@ -247,12 +223,8 @@ OutputRegisterFileModule(char *name, char *conf_name,
         goto error;
     }
 
-    module->name = SCStrdup(name);
-    if (unlikely(module->name == NULL))
-        goto error;
-    module->conf_name = SCStrdup(conf_name);
-    if (unlikely(module->conf_name == NULL))
-        goto error;
+    module->name = name;
+    module->conf_name = conf_name;
     module->InitFunc = InitFunc;
     module->FileLogFunc = FileLogFunc;
     TAILQ_INSERT_TAIL(&output_modules, module, entries);
@@ -273,8 +245,9 @@ error:
  * \retval Returns 0 on success, -1 on failure.
  */
 void
-OutputRegisterFileSubModule(const char *parent_name, char *name, char *conf_name,
-    OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), FileLogger FileLogFunc)
+OutputRegisterFileSubModule(const char *parent_name, const char *name,
+    const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *),
+    FileLogger FileLogFunc)
 {
     if (unlikely(FileLogFunc == NULL)) {
         goto error;
@@ -285,15 +258,9 @@ OutputRegisterFileSubModule(const char *parent_name, char *name, char *conf_name
         goto error;
     }
 
-    module->name = SCStrdup(name);
-    if (unlikely(module->name == NULL))
-        goto error;
-    module->conf_name = SCStrdup(conf_name);
-    if (unlikely(module->conf_name == NULL))
-        goto error;
-    module->parent_name = SCStrdup(parent_name);
-    if (unlikely(module->parent_name == NULL))
-        goto error;
+    module->name = name;
+    module->conf_name = conf_name;
+    module->parent_name = parent_name;
     module->InitSubFunc = InitFunc;
     module->FileLogFunc = FileLogFunc;
     TAILQ_INSERT_TAIL(&output_modules, module, entries);
@@ -314,7 +281,7 @@ error:
  * \retval Returns 0 on success, -1 on failure.
  */
 void
-OutputRegisterFiledataModule(char *name, char *conf_name,
+OutputRegisterFiledataModule(const char *name, const char *conf_name,
     OutputCtx *(*InitFunc)(ConfNode *), FiledataLogger FiledataLogFunc)
 {
     if (unlikely(FiledataLogFunc == NULL)) {
@@ -326,12 +293,8 @@ OutputRegisterFiledataModule(char *name, char *conf_name,
         goto error;
     }
 
-    module->name = SCStrdup(name);
-    if (unlikely(module->name == NULL))
-        goto error;
-    module->conf_name = SCStrdup(conf_name);
-    if (unlikely(module->conf_name == NULL))
-        goto error;
+    module->name = name;
+    module->conf_name = conf_name;
     module->InitFunc = InitFunc;
     module->FiledataLogFunc = FiledataLogFunc;
     TAILQ_INSERT_TAIL(&output_modules, module, entries);
@@ -352,8 +315,9 @@ error:
  * \retval Returns 0 on success, -1 on failure.
  */
 void
-OutputRegisterFiledataSubModule(const char *parent_name, char *name, char *conf_name,
-    OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), FiledataLogger FiledataLogFunc)
+OutputRegisterFiledataSubModule(const char *parent_name, const char *name,
+    const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *),
+    FiledataLogger FiledataLogFunc)
 {
     if (unlikely(FiledataLogFunc == NULL)) {
         goto error;
@@ -364,15 +328,9 @@ OutputRegisterFiledataSubModule(const char *parent_name, char *name, char *conf_
         goto error;
     }
 
-    module->name = SCStrdup(name);
-    if (unlikely(module->name == NULL))
-        goto error;
-    module->conf_name = SCStrdup(conf_name);
-    if (unlikely(module->conf_name == NULL))
-        goto error;
-    module->parent_name = SCStrdup(parent_name);
-    if (unlikely(module->parent_name == NULL))
-        goto error;
+    module->name = name;
+    module->conf_name = conf_name;
+    module->parent_name = parent_name;
     module->InitSubFunc = InitFunc;
     module->FiledataLogFunc = FiledataLogFunc;
     TAILQ_INSERT_TAIL(&output_modules, module, entries);
@@ -391,7 +349,7 @@ error:
  * with the given name is registered.
  */
 OutputModule *
-OutputGetModuleByConfName(char *conf_name)
+OutputGetModuleByConfName(const char *conf_name)
 {
     OutputModule *module;
 
@@ -413,8 +371,6 @@ OutputDeregisterAll(void)
 
     while ((module = TAILQ_FIRST(&output_modules))) {
         TAILQ_REMOVE(&output_modules, module, entries);
-        SCFree(module->name);
-        SCFree(module->conf_name);
         SCFree(module);
     }
 }
index e02b60c6d355fbea8622d6fc4270e105c87f95a0..88659b59f65ac31a77a002718e3d764fec4cd584 100644 (file)
@@ -36,9 +36,9 @@
 #include "output-filedata.h"
 
 typedef struct OutputModule_ {
-    char *name;
-    char *conf_name;
-    char *parent_name;
+    const char *name;
+    const char *conf_name;
+    const char *parent_name;
     OutputCtx *(*InitFunc)(ConfNode *);
     OutputCtx *(*InitSubFunc)(ConfNode *, OutputCtx *parent_ctx);
 
@@ -52,33 +52,35 @@ typedef struct OutputModule_ {
     TAILQ_ENTRY(OutputModule_) entries;
 } OutputModule;
 
-void OutputRegisterModule(char *, char *, OutputCtx *(*)(ConfNode *));
+void OutputRegisterModule(const char *, const char *, OutputCtx *(*)(ConfNode *));
 
-void OutputRegisterPacketModule(char *name, char *conf_name,
+void OutputRegisterPacketModule(const char *name, const char *conf_name,
     OutputCtx *(*InitFunc)(ConfNode *),
     PacketLogger LogFunc, PacketLogCondition ConditionFunc);
-void OutputRegisterPacketSubModule(const char *parent_name, char *name, char *conf_name,
-    OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *),
+void OutputRegisterPacketSubModule(const char *parent_name, const char *name,
+    const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *),
     PacketLogger LogFunc, PacketLogCondition ConditionFunc);
 
-void OutputRegisterTxModule(char *name, char *conf_name,
+void OutputRegisterTxModule(const char *name, const char *conf_name,
     OutputCtx *(*InitFunc)(ConfNode *), uint16_t alproto,
     TxLogger TxLogFunc);
-void OutputRegisterTxSubModule(const char *parent_name, char *name, char *conf_name,
-    OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *parent_ctx), uint16_t alproto,
-    TxLogger TxLogFunc);
+void OutputRegisterTxSubModule(const char *parent_name, const char *name,
+    const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *parent_ctx),
+    uint16_t alproto, TxLogger TxLogFunc);
 
-void OutputRegisterFileModule(char *name, char *conf_name,
+void OutputRegisterFileModule(const char *name, const char *conf_name,
     OutputCtx *(*InitFunc)(ConfNode *), FileLogger FileLogFunc);
-void OutputRegisterFileSubModule(const char *parent_name, char *name, char *conf_name,
-    OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), FileLogger FileLogFunc);
+void OutputRegisterFileSubModule(const char *parent_name, const char *name,
+    const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *),
+    FileLogger FileLogFunc);
 
-void OutputRegisterFiledataModule(char *name, char *conf_name,
+void OutputRegisterFiledataModule(const char *name, const char *conf_name,
     OutputCtx *(*InitFunc)(ConfNode *), FiledataLogger FiledataLogFunc);
-void OutputRegisterFiledataSubModule(const char *parent_name, char *name, char *conf_name,
-    OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), FiledataLogger FiledataLogFunc);
+void OutputRegisterFiledataSubModule(const char *parent_name, const char *name,
+    const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *),
+    FiledataLogger FiledataLogFunc);
 
-OutputModule *OutputGetModuleByConfName(char *name);
+OutputModule *OutputGetModuleByConfName(const char *name);
 void OutputDeregisterAll(void);
 
 #endif /* ! __OUTPUT_H__ */
index d0a8a7f400cf0c87a0d4f72afc886cb7038a0017..0ed4d0a2e55833a358291ef4582ed98078678519 100644 (file)
@@ -46,7 +46,7 @@ void TmModuleDebugList(void) {
 /** \brief get a tm module ptr by name
  *  \param name name string
  *  \retval ptr to the module or NULL */
-TmModule *TmModuleGetByName(char *name) {
+TmModule *TmModuleGetByName(const char *name) {
     TmModule *t;
     uint16_t i;
 
index 6789888fa37a620dea58525722d4183d7288ab2e..08f8a55561cc67177640a12e6742264a8f1af482 100644 (file)
@@ -104,7 +104,7 @@ typedef struct OutputCtx_ {
 LogFileCtx *LogFileNewCtx();
 int LogFileFreeCtx(LogFileCtx *);
 
-TmModule *TmModuleGetByName(char *name);
+TmModule *TmModuleGetByName(const char *name);
 TmModule *TmModuleGetById(int id);
 int TmModuleGetIDForTM(TmModule *tm);
 TmEcode TmModuleRegister(char *name, int (*module_func)(ThreadVars *, Packet *, void *));