From: Victor Julien Date: Wed, 29 Jan 2014 17:19:27 +0000 (+0100) Subject: output: sub-module support for other log api's X-Git-Tag: suricata-2.0rc1~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79771ff570086701d31e6ba5649cb2fbcc8a010f;p=thirdparty%2Fsuricata.git output: sub-module support for other log api's Packets: void OutputRegisterPacketSubModule(const char *parent_name, char *name, char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), PacketLogger LogFunc, PacketLogCondition ConditionFunc); Files: void OutputRegisterFileSubModule(const char *parent_name, char *name, char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), FileLogger FileLogFunc); Filedata: void OutputRegisterFiledataSubModule(const char *parent_name, char *name, char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), FiledataLogger FiledataLogFunc); --- diff --git a/src/output.c b/src/output.c index b56eb316e1..2b8a04b3f9 100644 --- a/src/output.c +++ b/src/output.c @@ -108,6 +108,49 @@ error: exit(EXIT_FAILURE); } +/** + * \brief Register a packet output sub-module. + * + * This function will register an output module so it can be + * configured with the configuration file. + * + * \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), + PacketLogger PacketLogFunc, PacketLogCondition PacketConditionFunc) +{ + if (unlikely(PacketLogFunc == NULL || PacketConditionFunc == NULL)) { + goto error; + } + + 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->parent_name = SCStrdup(parent_name); + if (unlikely(module->conf_name == NULL)) + goto error; + module->InitSubFunc = InitFunc; + module->PacketLogFunc = PacketLogFunc; + module->PacketConditionFunc = PacketConditionFunc; + TAILQ_INSERT_TAIL(&output_modules, module, entries); + + SCLogDebug("Packet logger \"%s\" registered.", name); + return; +error: + SCLogError(SC_ERR_FATAL, "Fatal error encountered. Exiting..."); + exit(EXIT_FAILURE); +} + /** * \brief Register a tx output module. * @@ -221,6 +264,47 @@ error: exit(EXIT_FAILURE); } +/** + * \brief Register a file output sub-module. + * + * This function will register an output module so it can be + * configured with the configuration file. + * + * \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) +{ + if (unlikely(FileLogFunc == NULL)) { + goto error; + } + + 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->parent_name = SCStrdup(parent_name); + if (unlikely(module->parent_name == NULL)) + goto error; + module->InitSubFunc = InitFunc; + module->FileLogFunc = FileLogFunc; + TAILQ_INSERT_TAIL(&output_modules, module, entries); + + SCLogDebug("File logger \"%s\" registered.", name); + return; +error: + SCLogError(SC_ERR_FATAL, "Fatal error encountered. Exiting..."); + exit(EXIT_FAILURE); +} + /** * \brief Register a file data output module. * @@ -259,6 +343,47 @@ error: exit(EXIT_FAILURE); } +/** + * \brief Register a file data output sub-module. + * + * This function will register an output module so it can be + * configured with the configuration file. + * + * \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) +{ + if (unlikely(FiledataLogFunc == NULL)) { + goto error; + } + + 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->parent_name = SCStrdup(parent_name); + if (unlikely(module->parent_name == NULL)) + goto error; + module->InitSubFunc = InitFunc; + module->FiledataLogFunc = FiledataLogFunc; + TAILQ_INSERT_TAIL(&output_modules, module, entries); + + SCLogDebug("Filedata logger \"%s\" registered.", name); + return; +error: + SCLogError(SC_ERR_FATAL, "Fatal error encountered. Exiting..."); + exit(EXIT_FAILURE); +} + /** * \brief Get an output module by name. * diff --git a/src/output.h b/src/output.h index 6d668238a9..e02b60c6d3 100644 --- a/src/output.h +++ b/src/output.h @@ -57,16 +57,26 @@ void OutputRegisterModule(char *, char *, OutputCtx *(*)(ConfNode *)); void OutputRegisterPacketModule(char *name, 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 *), + PacketLogger LogFunc, PacketLogCondition ConditionFunc); + void OutputRegisterTxModule(char *name, 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 OutputRegisterFileModule(char *name, 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 OutputRegisterFiledataModule(char *name, 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); OutputModule *OutputGetModuleByConfName(char *name); void OutputDeregisterAll(void);