From: Victor Julien Date: Thu, 30 Jan 2014 08:14:59 +0000 (+0100) Subject: log api: convert all names to const X-Git-Tag: suricata-2.0rc1~78 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=52c3d3ad7c1c075a8b6a1ffd44f63bd8f8723e7c;p=thirdparty%2Fsuricata.git log api: convert all names to const Instead of strdupping all names w/o a need, use const ptrs. --- diff --git a/src/output-file.c b/src/output-file.c index 382d959874..c8c2178d30 100644 --- a/src/output-file.c +++ b/src/output-file.c @@ -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; diff --git a/src/output-file.h b/src/output-file.h index cc17abf7fd..2e2009681b 100644 --- a/src/output-file.h +++ b/src/output-file.h @@ -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); diff --git a/src/output-filedata.c b/src/output-filedata.c index 967dcffd70..65c5ce6e65 100644 --- a/src/output-filedata.c +++ b/src/output-filedata.c @@ -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; diff --git a/src/output-filedata.h b/src/output-filedata.h index c35fd21ab3..334ad60d23 100644 --- a/src/output-filedata.h +++ b/src/output-filedata.h @@ -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); diff --git a/src/output-packet.c b/src/output-packet.c index aa8daf9d1c..fcc073043c 100644 --- a/src/output-packet.c +++ b/src/output-packet.c @@ -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; diff --git a/src/output-packet.h b/src/output-packet.h index 42e524c4a5..1173282f68 100644 --- a/src/output-packet.h +++ b/src/output-packet.h @@ -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); diff --git a/src/output-tx.c b/src/output-tx.c index 0293775f69..d250fcab75 100644 --- a/src/output-tx.c +++ b/src/output-tx.c @@ -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; diff --git a/src/output-tx.h b/src/output-tx.h index 249747a12f..badc18351a 100644 --- a/src/output-tx.h +++ b/src/output-tx.h @@ -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); diff --git a/src/output.c b/src/output.c index 2b8a04b3f9..5e7d88f2a3 100644 --- a/src/output.c +++ b/src/output.c @@ -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); } } diff --git a/src/output.h b/src/output.h index e02b60c6d3..88659b59f6 100644 --- a/src/output.h +++ b/src/output.h @@ -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__ */ diff --git a/src/tm-modules.c b/src/tm-modules.c index d0a8a7f400..0ed4d0a2e5 100644 --- a/src/tm-modules.c +++ b/src/tm-modules.c @@ -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; diff --git a/src/tm-modules.h b/src/tm-modules.h index 6789888fa3..08f8a55561 100644 --- a/src/tm-modules.h +++ b/src/tm-modules.h @@ -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 *));