From 2a5e10cd472278a35dc4a7980a8130bcb9ca6430 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 6 Aug 2015 15:30:10 +0100 Subject: [PATCH] Hide workers and modules definitions. --- config.h.in | 27 ------------------------- src/CMakeLists.txt | 4 ++-- src/controller.c | 1 + src/fuzzy_storage.c | 1 + src/http_proxy.c | 1 + src/libmime/filter.h | 16 --------------- src/libserver/cfg_file.h | 7 +++++-- src/libserver/cfg_rcl.c | 3 ++- src/libserver/cfg_utils.c | 2 +- src/libserver/worker_util.c | 7 ++++--- src/libserver/worker_util.h | 17 +++++++++------- src/lua_worker.c | 1 + src/main.c | 7 +++++++ src/main.h | 39 ++++++++++++++++++++++++++----------- src/plugins/fuzzy_check.c | 1 + src/smtp_proxy.c | 1 + src/worker.c | 1 + 17 files changed, 66 insertions(+), 70 deletions(-) diff --git a/config.h.in b/config.h.in index ca03751cf..38c159030 100644 --- a/config.h.in +++ b/config.h.in @@ -508,32 +508,5 @@ typedef off_t goffset; # 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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2ffe3a4b9..494f5b6c0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,7 +4,7 @@ MACRO(_AddModulesForced MLIST) 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) @@ -28,7 +28,7 @@ ENDMACRO(_AddModulesForced MLIST) 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) diff --git a/src/controller.c b/src/controller.c index f37620501..f01b5a566 100644 --- a/src/controller.c +++ b/src/controller.c @@ -28,6 +28,7 @@ #include "libutil/map.h" #include "libstat/stat_api.h" #include "main.h" +#include "libserver/worker_util.h" #include "utlist.h" #include "blake2.h" diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 507c99349..4b9d118dc 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -39,6 +39,7 @@ #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 diff --git a/src/http_proxy.c b/src/http_proxy.c index b24057cc8..cdd712931 100644 --- a/src/http_proxy.c +++ b/src/http_proxy.c @@ -32,6 +32,7 @@ #include "libserver/dns.h" #include "libmime/message.h" #include "main.h" +#include "libserver/worker_util.h" #include "keypairs_cache.h" #include "ottery.h" diff --git a/src/libmime/filter.h b/src/libmime/filter.h index d0a3d17ec..412920563 100644 --- a/src/libmime/filter.h +++ b/src/libmime/filter.h @@ -14,21 +14,6 @@ struct rspamd_task; 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 */ @@ -50,7 +35,6 @@ struct metric_action { 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 */ diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 37d65bd74..7ec39fa88 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -20,6 +20,8 @@ struct expression; struct tokenizer; struct rspamd_stat_classifier; +struct module_s; +struct worker_s; enum { VAL_UNDEF=0, VAL_TRUE, VAL_FALSE }; @@ -145,7 +147,7 @@ struct rspamd_worker_bind_conf { * 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 */ @@ -265,7 +267,8 @@ struct rspamd_config { 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 */ }; diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index 46dd1b60f..ef2644dd9 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -29,6 +29,7 @@ #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; @@ -576,7 +577,7 @@ rspamd_rcl_worker_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, 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, diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index c877be37d..96beb0621 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -873,7 +873,7 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig) /* 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)); diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index 94ad5bd6c..4d62da514 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -25,6 +25,7 @@ #include "main.h" #include "message.h" #include "lua/lua_common.h" +#include "worker_util.h" /** * Return worker's control structure by its type @@ -32,12 +33,12 @@ * @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; } diff --git a/src/libserver/worker_util.h b/src/libserver/worker_util.h index f8cbccfa5..04109b9b0 100644 --- a/src/libserver/worker_util.h +++ b/src/libserver/worker_util.h @@ -26,13 +26,7 @@ #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); @@ -98,4 +92,13 @@ void rspamd_controller_send_string (struct rspamd_http_connection_entry *entry, 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_ */ diff --git a/src/lua_worker.c b/src/lua_worker.c index 50db9ea6b..681971661 100644 --- a/src/lua_worker.c +++ b/src/lua_worker.c @@ -25,6 +25,7 @@ #include "config.h" #include "util.h" #include "main.h" +#include "libserver/worker_util.h" #include "protocol.h" #include "upstream.h" #include "cfg_file.h" diff --git a/src/main.c b/src/main.c index 2bd47cdc3..fb2a362df 100644 --- a/src/main.c +++ b/src/main.c @@ -31,6 +31,7 @@ #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" @@ -101,6 +102,10 @@ static GHashTable *listen_sockets = NULL; struct rspamd_main *rspamd_main; +/* Defined in modules.c */ +extern module_t *modules[]; +extern worker_t *workers[]; + /* Commandline options */ static GOptionEntry entries[] = { @@ -769,6 +774,8 @@ static gboolean 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)) { diff --git a/src/main.h b/src/main.h index 301e82c47..a4faa1d16 100644 --- a/src/main.h +++ b/src/main.h @@ -19,8 +19,6 @@ #include "libserver/events.h" #include "libserver/roll_history.h" #include "libserver/task.h" -#include "libserver/worker_util.h" -#include "libmime/filter.h" /* Default values */ @@ -76,10 +74,38 @@ struct rspamd_controller_pbkdf { 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; @@ -193,14 +219,6 @@ struct controller_session { 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 @@ -209,7 +227,6 @@ void register_custom_controller_command (const gchar *name, controller_func_t handler, gboolean privilleged, gboolean require_message); - /** * If set, reopen log file on next write */ diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 857033ec0..5d1ebe316 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -43,6 +43,7 @@ #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" diff --git a/src/smtp_proxy.c b/src/smtp_proxy.c index bb53a7e7d..7bf5b6db0 100644 --- a/src/smtp_proxy.c +++ b/src/smtp_proxy.c @@ -26,6 +26,7 @@ #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 diff --git a/src/worker.c b/src/worker.c index c0f30a944..da9ab7745 100644 --- a/src/worker.c +++ b/src/worker.c @@ -38,6 +38,7 @@ #include "main.h" #include "keypairs_cache.h" #include "libstat/stat_api.h" +#include "libserver/worker_util.h" #include "lua/lua_common.h" -- 2.39.5