# define NBYTES(nbits) (((nbits) + BITSPERBYTE - 1) / BITSPERBYTE)
#endif
-/* Forwarded declaration */
-struct module_ctx;
-struct rspamd_config;
-struct rspamd_worker;
-
-typedef struct module_s {
- const gchar *name;
- int (*module_init_func)(struct rspamd_config *cfg, struct module_ctx **ctx);
- int (*module_config_func)(struct rspamd_config *cfg);
- int (*module_reconfig_func)(struct rspamd_config *cfg);
- int (*module_attach_controller_func)(struct module_ctx *ctx,
- GHashTable *custom_commands);
-} module_t;
-
-typedef struct worker_s {
- const gchar *name;
- gpointer (*worker_init_func)(struct rspamd_config *cfg);
- void (*worker_start_func)(struct rspamd_worker *worker);
- gboolean has_socket;
- gboolean unique;
- gboolean threaded;
- gboolean killable;
- gint listen_type;
-} worker_t;
-
-extern module_t *modules[];
-extern worker_t *workers[];
#endif
SET(MODULES_ID ${_MODULES_ID} CACHE INTERNAL "Modules ID" FORCE)
SET(MODULES_C "${CMAKE_CURRENT_BINARY_DIR}/modules.c")
FILE(WRITE "${MODULES_C}"
- "/* ${MODULES_ID} */\n#include \"config.h\"\n")
+ "/* ${MODULES_ID} */\n#include \"main.h\"\n")
# Handle even old cmake
LIST(LENGTH ${MLIST} MLIST_COUNT)
MACRO(_AddWorkersForced WLIST)
SET(WORKERS_C "${CMAKE_CURRENT_BINARY_DIR}/workers.c")
FILE(WRITE "${WORKERS_C}"
- "#include \"config.h\"\n")
+ "#include \"main.h\"\n")
# Handle even old cmake
LIST(LENGTH ${WLIST} WLIST_COUNT)
#include "libutil/map.h"
#include "libstat/stat_api.h"
#include "main.h"
+#include "libserver/worker_util.h"
#include "utlist.h"
#include "blake2.h"
#include "fuzzy_storage.h"
#include "fuzzy_backend.h"
#include "ottery.h"
+#include "libserver/worker_util.h"
/* This number is used as expire time in seconds for cache items (2 days) */
#define DEFAULT_EXPIRE 172800L
#include "libserver/dns.h"
#include "libmime/message.h"
#include "main.h"
+#include "libserver/worker_util.h"
#include "keypairs_cache.h"
#include "ottery.h"
struct rspamd_settings;
struct rspamd_classifier_config;
-typedef double (*metric_cons_func)(struct rspamd_task *task,
- const gchar *metric_name, const gchar *func_name);
-typedef void (*filter_func)(struct rspamd_task *task);
-
-enum filter_type { C_FILTER, PERL_FILTER };
-
-/**
- * Filter structure
- */
-struct filter {
- gchar *func_name; /**< function name */
- enum filter_type type; /**< filter type (c or perl) */
- module_t *module;
-};
-
/**
* Rspamd symbol
*/
struct metric {
const gchar *name; /**< name of metric */
gchar *func_name; /**< name of consolidation function */
- metric_cons_func func; /**< c consolidation function */
gboolean accept_unknown_symbols; /**< if true unknown symbols are registered here */
gdouble unknown_weight; /**< weight of unknown symbols */
gdouble grow_factor; /**< grow factor for metric */
struct expression;
struct tokenizer;
struct rspamd_stat_classifier;
+struct module_s;
+struct worker_s;
enum { VAL_UNDEF=0, VAL_TRUE, VAL_FALSE };
* Config params for rspamd worker
*/
struct rspamd_worker_conf {
- worker_t *worker; /**< pointer to worker type */
+ struct worker_s *worker; /**< pointer to worker type */
GQuark type; /**< type of worker */
struct rspamd_worker_bind_conf *bind_conf; /**< bind configuration */
guint16 count; /**< number of workers */
guint32 min_word_len; /**< minimum length of the word to be considered */
GList *classify_headers; /**< list of headers using for statistics */
- module_t *compiled_modules; /**< list of compiled C modules */
+ struct module_s **compiled_modules; /**< list of compiled C modules */
+ struct worker_s **compiled_workers; /**< list of compiled C modules */
};
#include "lua/lua_common.h"
#include "expression.h"
#include "composites.h"
+#include "libserver/worker_util.h"
struct rspamd_rcl_default_handler_data {
struct rspamd_rcl_struct_parser pd;
qtype = g_quark_try_string (worker_type);
if (qtype != 0) {
wrk = rspamd_config_new_worker (cfg, NULL);
- wrk->worker = rspamd_get_worker_by_type (qtype);
+ wrk->worker = rspamd_get_worker_by_type (cfg, qtype);
if (wrk->worker == NULL) {
g_set_error (err,
CFG_RCL_ERROR,
/* Init all compiled modules */
if (!reconfig) {
- for (pmod = cfg->compiled_modules; *pmod != NULL; pmod ++) {
+ for (pmod = cfg->compiled_modules; pmod != NULL && *pmod != NULL; pmod ++) {
mod = *pmod;
mod_ctx = g_slice_alloc0 (sizeof (struct module_ctx));
#include "main.h"
#include "message.h"
#include "lua/lua_common.h"
+#include "worker_util.h"
/**
* Return worker's control structure by its type
* @return worker's control structure or NULL
*/
worker_t *
-rspamd_get_worker_by_type (GQuark type)
+rspamd_get_worker_by_type (struct rspamd_config *cfg, GQuark type)
{
worker_t **cur;
- cur = &workers[0];
- while (*cur) {
+ cur = cfg->compiled_workers;
+ while (cur && *cur) {
if (g_quark_from_string ((*cur)->name) == type) {
return *cur;
}
#include "config.h"
#include "util.h"
#include "http.h"
-
-/**
- * Return worker's control structure by its type
- * @param type
- * @return worker's control structure or NULL
- */
-worker_t * rspamd_get_worker_by_type (GQuark type);
+#include "main.h"
#ifndef HAVE_SA_SIGINFO
typedef void (*rspamd_sig_handler_t) (gint);
void rspamd_controller_send_ucl (struct rspamd_http_connection_entry *entry,
ucl_object_t *obj);
+/**
+ * Return worker's control structure by its type
+ * @param type
+ * @return worker's control structure or NULL
+ */
+worker_t * rspamd_get_worker_by_type (struct rspamd_config *cfg, GQuark type);
+
+void rspamd_worker_stop_accept (struct rspamd_worker *worker);
+
#endif /* WORKER_UTIL_H_ */
#include "config.h"
#include "util.h"
#include "main.h"
+#include "libserver/worker_util.h"
#include "protocol.h"
#include "upstream.h"
#include "cfg_file.h"
#include "kvstorage_server.h"
#include "libserver/symbols_cache.h"
#include "lua/lua_common.h"
+#include "libserver/worker_util.h"
#include "ottery.h"
#include "xxhash.h"
#include "utlist.h"
struct rspamd_main *rspamd_main;
+/* Defined in modules.c */
+extern module_t *modules[];
+extern worker_t *workers[];
+
/* Commandline options */
static GOptionEntry entries[] =
{
load_rspamd_config (struct rspamd_config *cfg, gboolean init_modules)
{
cfg->cache = rspamd_symbols_cache_new ();
+ cfg->compiled_modules = modules;
+ cfg->compiled_workers = workers;
if (!rspamd_config_read (cfg, cfg->cfg_name, NULL,
config_logger, rspamd_main, vars)) {
#include "libserver/events.h"
#include "libserver/roll_history.h"
#include "libserver/task.h"
-#include "libserver/worker_util.h"
-#include "libmime/filter.h"
/* Default values */
gsize key_len;
};
+/**
+ * Common structure representing C module context
+ */
+struct module_s;
+struct module_ctx {
+ gint (*filter)(struct rspamd_task *task); /**< pointer to headers process function */
+ struct module_s *mod; /**< module pointer */
+ gboolean enabled; /**< true if module is enabled in configuration */
+};
/**
* Module
*/
+typedef struct module_s {
+ const gchar *name;
+ int (*module_init_func)(struct rspamd_config *cfg, struct module_ctx **ctx);
+ int (*module_config_func)(struct rspamd_config *cfg);
+ int (*module_reconfig_func)(struct rspamd_config *cfg);
+ int (*module_attach_controller_func)(struct module_ctx *ctx,
+ GHashTable *custom_commands);
+} module_t;
+
+typedef struct worker_s {
+ const gchar *name;
+ gpointer (*worker_init_func)(struct rspamd_config *cfg);
+ void (*worker_start_func)(struct rspamd_worker *worker);
+ gboolean has_socket;
+ gboolean unique;
+ gboolean threaded;
+ gboolean killable;
+ gint listen_type;
+} worker_t;
struct pidfh;
struct rspamd_config;
struct event_base *ev_base; /**< Event base */
};
-/**
- * Common structure representing C module context
- */
-struct module_ctx {
- gint (*filter)(struct rspamd_task *task); /**< pointer to headers process function */
- module_t *mod; /**< module pointer */
- gboolean enabled; /**< true if module is enabled in configuration */
-};
/**
* Register custom controller function
controller_func_t handler,
gboolean privilleged,
gboolean require_message);
-
/**
* If set, reopen log file on next write
*/
#include "libmime/message.h"
#include "libutil/map.h"
#include "libmime/images.h"
+#include "libserver/worker_util.h"
#include "fuzzy_storage.h"
#include "utlist.h"
#include "main.h"
#include "libserver/proxy.h"
#include "main.h"
#include "smtp.h"
+#include "libserver/worker_util.h"
/*
* SMTP proxy is a simple smtp proxy worker for dns resolving and
#include "main.h"
#include "keypairs_cache.h"
#include "libstat/stat_api.h"
+#include "libserver/worker_util.h"
#include "lua/lua_common.h"