mirror of https://github.com/OISF/suricata
Have output modules register themselves so run mode configurator becomes aware of them for purposes of being configured from the config file.
parent
9b90c553b5
commit
e204d07717
@ -0,0 +1,78 @@
|
|||||||
|
/* Copyright (c) 2009 Open Information Security Foundation */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* \author Endace Technology Limited, Jason Ish <jason.ish@endace.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "suricata-common.h"
|
||||||
|
#include "flow.h"
|
||||||
|
#include "conf.h"
|
||||||
|
#include "tm-modules.h"
|
||||||
|
#include "util-error.h"
|
||||||
|
#include "util-debug.h"
|
||||||
|
#include "output.h"
|
||||||
|
|
||||||
|
static TAILQ_HEAD(, OutputModule_) output_modules =
|
||||||
|
TAILQ_HEAD_INITIALIZER(output_modules);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Register an output 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
|
||||||
|
OutputRegisterModule(char *name, char *conf_name, LogFileCtx *(*InitFunc)(ConfNode *))
|
||||||
|
{
|
||||||
|
OutputModule *module = calloc(1, sizeof(*module));
|
||||||
|
if (module == NULL) {
|
||||||
|
SCLogError(SC_ERR_MEM_ALLOC,
|
||||||
|
"Failed to allocated memory for new output module");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
module->name = strdup(name);
|
||||||
|
module->conf_name = strdup(conf_name);
|
||||||
|
module->InitFunc = InitFunc;
|
||||||
|
TAILQ_INSERT_TAIL(&output_modules, module, entries);
|
||||||
|
|
||||||
|
SCLogInfo("Output module \"%s\" registered.", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Get an output module by name.
|
||||||
|
*
|
||||||
|
* \retval The OutputModule with the given name or NULL if no output module
|
||||||
|
* with the given name is registered.
|
||||||
|
*/
|
||||||
|
OutputModule *
|
||||||
|
OutputGetModuleByConfName(char *conf_name)
|
||||||
|
{
|
||||||
|
OutputModule *module;
|
||||||
|
|
||||||
|
TAILQ_FOREACH(module, &output_modules, entries) {
|
||||||
|
if (strcmp(module->conf_name, conf_name) == 0)
|
||||||
|
return module;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Deregister all modules. Useful for a memory clean exit.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
OutputDeregisterAll(void)
|
||||||
|
{
|
||||||
|
OutputModule *module;
|
||||||
|
|
||||||
|
while ((module = TAILQ_FIRST(&output_modules))) {
|
||||||
|
TAILQ_REMOVE(&output_modules, module, entries);
|
||||||
|
free(module->name);
|
||||||
|
free(module->conf_name);
|
||||||
|
free(module);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
/* Copyright (c) 2009 Open Information Security Foundation */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* \author Endace Technology Limited, Jason Ish <jason.ish@endace.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __OUTPUT_H__
|
||||||
|
#define __OUTPUT_H__
|
||||||
|
|
||||||
|
typedef struct OutputModule_ {
|
||||||
|
char *name;
|
||||||
|
char *conf_name;
|
||||||
|
LogFileCtx *(*InitFunc)(ConfNode *);
|
||||||
|
|
||||||
|
TAILQ_ENTRY(OutputModule_) entries;
|
||||||
|
} OutputModule;
|
||||||
|
|
||||||
|
void OutputRegisterModule(char *, char *, LogFileCtx *(*)(ConfNode *));
|
||||||
|
OutputModule *OutputGetModuleByConfName(char *name);
|
||||||
|
void OutputDeregisterAll(void);
|
||||||
|
|
||||||
|
#endif /* ! __OUTPUT_H__ */
|
||||||
Loading…
Reference in New Issue