]> source.dussan.org Git - rspamd.git/commitdiff
Hide workers and modules definitions.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 6 Aug 2015 14:30:10 +0000 (15:30 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 6 Aug 2015 14:30:10 +0000 (15:30 +0100)
17 files changed:
config.h.in
src/CMakeLists.txt
src/controller.c
src/fuzzy_storage.c
src/http_proxy.c
src/libmime/filter.h
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/libserver/worker_util.c
src/libserver/worker_util.h
src/lua_worker.c
src/main.c
src/main.h
src/plugins/fuzzy_check.c
src/smtp_proxy.c
src/worker.c

index ca03751cf2c7f7d553b0de931de2c2327dd6c26c..38c15903022699ba5bb99090256c78cce376975f 100644 (file)
@@ -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
index 2ffe3a4b9fbf22e6b3e05862e63869653754197f..494f5b6c0e88c861aa1dad7bcb69ea0b194d790e 100644 (file)
@@ -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)
index f3762050153687076c91f796a6a3c0363a782660..f01b5a566d423dbf00c1f96a50be45a9807d5479 100644 (file)
@@ -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" 
index 507c99349615016903cdc27de0e6edfad16b469b..4b9d118dc3b304235bde850258797fbd9badffdb 100644 (file)
@@ -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
index b24057cc82b671a09a288708aee212d22e71282c..cdd712931daa3877dba26887f10602554be3af3b 100644 (file)
@@ -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"
 
index d0a3d17ec3f9eb4c7e0826f0a79433fd057bfceb..41292056394b4e54ce522c0e5e3576698b3baccb 100644 (file)
@@ -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                                                     */
index 37d65bd74ec33b06eab2e3aeccb7bf975a93483c..7ec39fa88720ded7100adb8011bfc451fa2dde7c 100644 (file)
@@ -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                                                 */
 };
 
 
index 46dd1b60fc844c70cf2d7242cbf620b356a0f3a6..ef2644dd9875e1d01b5e9c156b42e3f98f6558de 100644 (file)
@@ -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,
index c877be37d3a675427d1826f14b85510c21172bfd..96beb0621a6d163da5cfa8d1a11fb35bfca81581 100644 (file)
@@ -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));
 
index 94ad5bd6c4dc35aaa62ff156dbba6aca23826ac5..4d62da5147995768f9093f69295bb14cc8cb95a6 100644 (file)
@@ -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
  * @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;
                }
index f8cbccfa5b215a43bdb1c03148aca577d0cfc054..04109b9b009c0638ca1be3d8fb0dd0190fb2bb27 100644 (file)
 #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_ */
index 50db9ea6befa944b7e9dbf5df363591451d84f64..6819716612436b1debf844efeacbd2307b076bdf 100644 (file)
@@ -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"
index 2bd47cdc33d13f39d45efb8789cee942b8f43317..fb2a362df5c580638362444b68bd411cf74d76ec 100644 (file)
@@ -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)) {
index 301e82c476391c08b76b17c23404d1b42cde19a8..a4faa1d1628b909aedb9b8c7fac60fdf944f9881 100644 (file)
@@ -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
  */
index 857033ec058e47ed27d8c893e1ec78ad355da113..5d1ebe316d7088ac32757f0005c135ca95fb4d24 100644 (file)
@@ -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"
index bb53a7e7d884d2bd19b276db59da06cc1f875a72..7bf5b6db073441a21da01422bd6202a8641da00d 100644 (file)
@@ -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
index c0f30a94469ef160c9c3f4e626c4893f4b6b846f..da9ab77453813fdb62877d075306f5ac6d20d347 100644 (file)
@@ -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"