summaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-17 13:49:11 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-17 13:49:11 +0100
commit775530cc7484286079af2ca103fbe4dc351726d9 (patch)
treee4ade64a797fbc18400af5fcd65503c990a76549 /src/libserver
parent85cb173e351c97dc559f1319ad2fc5ec8efd3bbf (diff)
downloadrspamd-775530cc7484286079af2ca103fbe4dc351726d9.tar.gz
rspamd-775530cc7484286079af2ca103fbe4dc351726d9.zip
Rework filters initialization.
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/cfg_file.h9
-rw-r--r--src/libserver/cfg_rcl.c4
-rw-r--r--src/libserver/cfg_utils.c49
3 files changed, 59 insertions, 3 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 3e611b323..25f19d216 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -209,7 +209,6 @@ struct rspamd_config {
GList *filters; /**< linked list of all filters */
GList *workers; /**< linked list of all workers params */
struct rspamd_worker_cfg_parser *wrk_parsers; /**< hash for worker config parsers, indexed by worker quarks */
- gchar *filters_str; /**< string of filters */
ucl_object_t *rcl_obj; /**< rcl object */
GHashTable * metrics; /**< hash of metrics indexed by metric name */
GHashTable * symbols_groups; /**< groups of symbols */
@@ -388,6 +387,14 @@ void rspamd_ucl_add_conf_macros (struct ucl_parser *parser,
void rspamd_ucl_add_conf_variables (struct ucl_parser *parser);
+/**
+ * Initialize rspamd filtering system (lua and C filters)
+ * @param cfg
+ * @param reconfig
+ * @return
+ */
+gboolean rspamd_init_filters (struct rspamd_config *cfg, bool reconfig);
+
#endif /* ifdef CFG_FILE_H */
/*
* vi:ts=4
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index 05ba79eda..19b920c69 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -1316,8 +1316,8 @@ rspamd_rcl_config_init (void)
RSPAMD_CL_FLAG_STRING_PATH);
rspamd_rcl_add_default_handler (sub,
"filters",
- rspamd_rcl_parse_struct_string,
- G_STRUCT_OFFSET (struct rspamd_config, filters_str),
+ rspamd_rcl_parse_struct_string_list,
+ G_STRUCT_OFFSET (struct rspamd_config, filters),
0);
rspamd_rcl_add_default_handler (sub,
"max_diff",
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index cf9179d0a..510a6661a 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -815,6 +815,55 @@ rspamd_ucl_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data)
}
}
+gboolean
+rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
+{
+ GList *cur;
+ module_t *mod, **pmod;
+ struct module_ctx *mod_ctx;
+
+ /* Init all compiled modules */
+ for (pmod = modules; *pmod != NULL; pmod ++) {
+ mod = *pmod;
+ mod_ctx = g_slice_alloc0 (sizeof (struct module_ctx));
+
+ if (mod->module_init_func (cfg, &mod_ctx) == 0) {
+ g_hash_table_insert (cfg->c_modules,
+ (gpointer) mod->name,
+ mod_ctx);
+ }
+ }
+
+ cur = g_list_first (cfg->filters);
+
+ while (cur) {
+ /* Perform modules configuring */
+ mod = NULL;
+ for (pmod = modules; *pmod != NULL; pmod ++) {
+ if ((*pmod)->name && g_ascii_strcasecmp ((*pmod)->name,
+ cur->data) == 0) {
+ mod = *pmod;
+
+ if (reconfig) {
+ (void)mod->module_reconfig_func (cfg);
+ msg_debug ("reconfig of %s", mod->name);
+ }
+ else {
+ (void)mod->module_config_func (cfg);
+ }
+ }
+ }
+
+ if (mod == NULL) {
+ msg_warn ("requested unknown module %s", cur->data);
+ }
+
+ cur = g_list_next (cur);
+ }
+
+ return rspamd_init_lua_filters (cfg);
+}
+
/*
* vi:ts=4
*/