Browse Source

Hide workers and modules definitions.

pull/344/head
Vsevolod Stakhov 10 years ago
parent
commit
2a5e10cd47
  1. 27
      config.h.in
  2. 4
      src/CMakeLists.txt
  3. 1
      src/controller.c
  4. 1
      src/fuzzy_storage.c
  5. 1
      src/http_proxy.c
  6. 16
      src/libmime/filter.h
  7. 7
      src/libserver/cfg_file.h
  8. 3
      src/libserver/cfg_rcl.c
  9. 2
      src/libserver/cfg_utils.c
  10. 7
      src/libserver/worker_util.c
  11. 17
      src/libserver/worker_util.h
  12. 1
      src/lua_worker.c
  13. 7
      src/main.c
  14. 39
      src/main.h
  15. 1
      src/plugins/fuzzy_check.c
  16. 1
      src/smtp_proxy.c
  17. 1
      src/worker.c

27
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

4
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)

1
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"

1
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

1
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"

16
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 */

7
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 */
};

3
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,

2
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));

7
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;
}

17
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_ */

1
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"

7
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)) {

39
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
*/

1
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"

1
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

1
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"

Loading…
Cancel
Save