From: Vsevolod Stakhov Date: Thu, 28 May 2015 11:25:25 +0000 (+0100) Subject: Adopt internal modules. X-Git-Tag: 1.0.0~591 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5645cc20de577a60111b42ac15a8c931391307fc;p=rspamd.git Adopt internal modules. --- diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index 9a7fc3323..4ffbb9672 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -111,7 +111,7 @@ gint dkim_module_config (struct rspamd_config *cfg) { const ucl_object_t *value; - gint res = TRUE; + gint res = TRUE, cb_id; guint cache_size, cache_expire; gboolean got_trusted = FALSE; @@ -223,17 +223,19 @@ dkim_module_config (struct rspamd_config *cfg) "trusted_only option is set and no trusted domains are defined; disabling dkim module completely as it is useless in this case"); } else { - rspamd_symbols_cache_add_symbol_normal (cfg->cache, + cb_id = rspamd_symbols_cache_add_symbol_normal (cfg->cache, dkim_module_ctx->symbol_reject, 1, dkim_symbol_callback, NULL); rspamd_symbols_cache_add_symbol_virtual (cfg->cache, dkim_module_ctx->symbol_tempfail, - 1); + 1, + cb_id); rspamd_symbols_cache_add_symbol_virtual (cfg->cache, dkim_module_ctx->symbol_allow, - 1); + 1, + cb_id); dkim_module_ctx->dkim_hash = rspamd_lru_hash_new ( cache_size, diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 8233fb43b..848d5d54b 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -142,7 +142,8 @@ module_t fuzzy_check_module = { static void parse_flags (struct fuzzy_rule *rule, struct rspamd_config *cfg, - const ucl_object_t *val) + const ucl_object_t *val, + gint cb_id) { const ucl_object_t *elt; struct fuzzy_mapping *map; @@ -174,7 +175,8 @@ parse_flags (struct fuzzy_rule *rule, /* Add flag to hash table */ g_hash_table_insert (rule->mappings, GINT_TO_POINTER (map->fuzzy_flag), map); - rspamd_symbols_cache_add_symbol_virtual (cfg->cache, map->symbol, 1.0); + rspamd_symbols_cache_add_symbol_virtual (cfg->cache, + map->symbol, 1.0, cb_id); } else { msg_err ("fuzzy_map parameter has no flag definition"); @@ -293,7 +295,7 @@ fuzzy_free_rule (gpointer r) } static gint -fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj) +fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj, gint cb_id) { const ucl_object_t *value, *cur; struct fuzzy_rule *rule; @@ -345,7 +347,7 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj) if ((value = ucl_object_find_key (obj, "fuzzy_map")) != NULL) { it = NULL; while ((cur = ucl_iterate_object (value, &it, true)) != NULL) { - parse_flags (rule, cfg, cur); + parse_flags (rule, cfg, cur, cb_id); } } @@ -383,7 +385,8 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj) fuzzy_module_ctx->fuzzy_rules, rule); if (rule->symbol != fuzzy_module_ctx->default_symbol) { - rspamd_symbols_cache_add_symbol_virtual (cfg->cache, rule->symbol, 1.0); + rspamd_symbols_cache_add_symbol_virtual (cfg->cache, rule->symbol, + 1.0, cb_id); } } @@ -411,7 +414,7 @@ gint fuzzy_check_module_config (struct rspamd_config *cfg) { const ucl_object_t *value, *cur; - gint res = TRUE; + gint res = TRUE, cb_id; if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "symbol")) != NULL) { @@ -478,16 +481,16 @@ fuzzy_check_module_config (struct rspamd_config *cfg) if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "rule")) != NULL) { + + cb_id = rspamd_symbols_cache_add_symbol_callback (cfg->cache, + 1.0, fuzzy_symbol_callback, NULL); + LL_FOREACH (value, cur) { - fuzzy_parse_rule (cfg, cur); + fuzzy_parse_rule (cfg, cur, cb_id); } } - if (fuzzy_module_ctx->fuzzy_rules != NULL) { - rspamd_symbols_cache_add_symbol_callback (cfg->cache, fuzzy_module_ctx->default_symbol, - 1.0, fuzzy_symbol_callback, NULL); - } - else { + if (fuzzy_module_ctx->fuzzy_rules == NULL) { msg_warn ("fuzzy module is enabled but no rules are defined"); } diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 8c477cca9..eab58c1d2 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -93,7 +93,7 @@ gint spf_module_config (struct rspamd_config *cfg) { const ucl_object_t *value; - gint res = TRUE; + gint res = TRUE, cb_id; guint cache_size, cache_expire; spf_module_ctx->whitelist_ip = radix_create_compressed (); @@ -151,14 +151,17 @@ spf_module_config (struct rspamd_config *cfg) } } - rspamd_symbols_cache_add_symbol_normal (cfg->cache, + cb_id = rspamd_symbols_cache_add_symbol_normal (cfg->cache, spf_module_ctx->symbol_fail, 1, spf_symbol_callback, NULL); - rspamd_symbols_cache_add_symbol_virtual (cfg->cache, spf_module_ctx->symbol_softfail, 1); - rspamd_symbols_cache_add_symbol_virtual (cfg->cache, spf_module_ctx->symbol_neutral, 1); - rspamd_symbols_cache_add_symbol_virtual (cfg->cache, spf_module_ctx->symbol_allow, 1); + rspamd_symbols_cache_add_symbol_virtual (cfg->cache, + spf_module_ctx->symbol_softfail, 1, cb_id); + rspamd_symbols_cache_add_symbol_virtual (cfg->cache, + spf_module_ctx->symbol_neutral, 1, cb_id); + rspamd_symbols_cache_add_symbol_virtual (cfg->cache, + spf_module_ctx->symbol_allow, 1, cb_id); spf_module_ctx->spf_hash = rspamd_lru_hash_new ( cache_size, diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 48b0bba32..7528a802d 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -302,7 +302,8 @@ surbl_module_init (struct rspamd_config *cfg, struct module_ctx **ctx) * Register virtual symbols for suffixes with bit wildcard */ static void -register_bit_symbols (struct rspamd_config *cfg, struct suffix_item *suffix) +register_bit_symbols (struct rspamd_config *cfg, struct suffix_item *suffix, + gint parent_id) { guint i; GHashTableIter it; @@ -314,18 +315,21 @@ register_bit_symbols (struct rspamd_config *cfg, struct suffix_item *suffix) while (g_hash_table_iter_next (&it, &k, &v)) { bit = v; - rspamd_symbols_cache_add_symbol_virtual (cfg->cache, bit->symbol, 1); + rspamd_symbols_cache_add_symbol_virtual (cfg->cache, bit->symbol, + 1, parent_id); msg_debug ("bit: %d", bit->bit); } } else if (suffix->bits != NULL) { for (i = 0; i < suffix->bits->len; i++) { bit = &g_array_index (suffix->bits, struct surbl_bit_item, i); - rspamd_symbols_cache_add_symbol_virtual (cfg->cache, bit->symbol, 1); + rspamd_symbols_cache_add_symbol_virtual (cfg->cache, bit->symbol, + 1, parent_id); } } else { - rspamd_symbols_cache_add_symbol_virtual (cfg->cache, suffix->symbol, 1); + rspamd_symbols_cache_add_symbol_virtual (cfg->cache, suffix->symbol, + 1, parent_id); } } @@ -335,12 +339,12 @@ surbl_module_config (struct rspamd_config *cfg) GList *cur_opt; struct suffix_item *new_suffix, *cur_suffix = NULL; struct surbl_bit_item *new_bit; - const ucl_object_t *value, *cur, *cur_rule, *cur_bit; ucl_object_iter_t it = NULL; const gchar *redir_val, *ip_val; guint32 bit; - + gint cb_id; + gboolean has_subsymbols; if ((value = rspamd_config_get_module_opt (cfg, "surbl", "redirector")) != NULL) { @@ -361,9 +365,9 @@ surbl_module_config (struct rspamd_config *cfg) rspamd_config_get_module_opt (cfg, "surbl", "redirector_symbol")) != NULL) { surbl_module_ctx->redirector_symbol = ucl_obj_tostring (value); - rspamd_symbols_cache_add_symbol_virtual (cfg->cache, + rspamd_symbols_cache_add_symbol (cfg->cache, surbl_module_ctx->redirector_symbol, - 1.0); + 1.0, 0, NULL, NULL, SYMBOL_TYPE_COMPOSITE, -1); } else { surbl_module_ctx->redirector_symbol = NULL; @@ -477,6 +481,14 @@ surbl_module_config (struct rspamd_config *cfg) new_suffix->options |= SURBL_OPTION_NOIP; } } + + cb_id = rspamd_symbols_cache_add_symbol_callback (cfg->cache, + 1, + surbl_test_url, + new_suffix); + new_suffix->callback_id = cb_id; + has_subsymbols = FALSE; + cur = ucl_obj_get_key (cur_rule, "bits"); if (cur != NULL && cur->type == UCL_OBJECT) { it = NULL; @@ -504,10 +516,13 @@ surbl_module_config (struct rspamd_config *cfg) msg_debug ("add new bit suffix: %d with symbol: %s", (gint)new_bit->bit, new_bit->symbol); g_array_append_val (new_suffix->bits, *new_bit); + has_subsymbols = TRUE; } } } + cur = ucl_obj_get_key (cur_rule, "ips"); + if (cur != NULL && cur->type == UCL_OBJECT) { it = NULL; new_suffix->ips = g_hash_table_new (g_int_hash, g_int_equal); @@ -546,18 +561,21 @@ surbl_module_config (struct rspamd_config *cfg) (gint)new_bit->bit, new_bit->symbol); g_hash_table_insert (new_suffix->ips, &new_bit->bit, new_bit); + has_subsymbols = TRUE; } } } + if (!has_subsymbols) { + /* Register just a symbol itself */ + rspamd_symbols_cache_add_symbol_virtual (cfg->cache, + new_suffix->symbol, + 1, + cb_id); + } surbl_module_ctx->suffixes = g_list_prepend ( surbl_module_ctx->suffixes, new_suffix); - rspamd_symbols_cache_add_symbol_callback (cfg->cache, - new_suffix->symbol, - 1, - surbl_test_url, - new_suffix); } } /* Add default suffix */ @@ -576,7 +594,7 @@ surbl_module_config (struct rspamd_config *cfg) while (cur_opt) { cur_suffix = cur_opt->data; if (cur_suffix->bits != NULL || cur_suffix->ips != NULL) { - register_bit_symbols (cfg, cur_suffix); + register_bit_symbols (cfg, cur_suffix, cur_suffix->callback_id); } cur_opt = g_list_next (cur_opt); } diff --git a/src/plugins/surbl.h b/src/plugins/surbl.h index 5d0f16ce4..e7342be52 100644 --- a/src/plugins/surbl.h +++ b/src/plugins/surbl.h @@ -45,6 +45,7 @@ struct suffix_item { guint32 options; GArray *bits; GHashTable *ips; + gint callback_id; }; struct dns_param {