diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-06-18 16:40:47 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-06-18 16:40:47 +0400 |
commit | e4977d9bfe416a230c4b74ecbeab3681a87db404 (patch) | |
tree | 0c80243ea96bf925a6d6a2d2d52ca431c82fdd02 | |
parent | fee46c0b872c559d451a7b4be486febda6ca7388 (diff) | |
download | rspamd-e4977d9bfe416a230c4b74ecbeab3681a87db404.tar.gz rspamd-e4977d9bfe416a230c4b74ecbeab3681a87db404.zip |
* Get weights of symbol from default metric for symbols cache
* Fix setting task->from/task->rctp in smtp client
-rw-r--r-- | src/main.c | 9 | ||||
-rw-r--r-- | src/smtp.c | 16 | ||||
-rw-r--r-- | src/symbols_cache.c | 25 | ||||
-rw-r--r-- | src/symbols_cache.h | 4 |
4 files changed, 47 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c index 3365b67c4..37f2ac498 100644 --- a/src/main.c +++ b/src/main.c @@ -691,7 +691,7 @@ static void init_cfg_cache (struct config_file *cfg) { - if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg->cache_filename)) { + if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg, cfg->cache_filename)) { exit (EXIT_FAILURE); } } @@ -703,7 +703,7 @@ print_symbols_cache (struct config_file *cfg) struct cache_item *item; int i; - if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg->cache_filename)) { + if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg, cfg->cache_filename)) { exit (EXIT_FAILURE); } if (cfg->cache) { @@ -809,6 +809,11 @@ main (int argc, char **argv, char **env) if (! load_rspamd_config (rspamd->cfg, TRUE)) { exit (EXIT_FAILURE); } + + /* Pre-init of cache */ + rspamd->cfg->cache = g_new0 (struct symbols_cache, 1); + rspamd->cfg->cache->static_pool = memory_pool_new (memory_pool_get_size ()); + rspamd->cfg->cache->cfg = rspamd->cfg; if (rspamd->cfg->config_test || dump_vars || dump_cache) { /* Init events to test modules */ diff --git a/src/smtp.c b/src/smtp.c index 97cb53b1e..a77c24467 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -317,6 +317,7 @@ process_smtp_data (struct smtp_session *session) { struct stat st; int r; + GList *cur, *t; if (fstat (session->temp_fd, &st) == -1) { goto err; @@ -342,6 +343,21 @@ process_smtp_data (struct smtp_session *session) goto err; } session->task->helo = session->helo; + /* Save MAIL FROM */ + cur = session->from; + if (cur && (cur = g_list_next (cur))) { + session->task->from = cur->data; + } + /* Save recipients */ + t = session->rcpt; + while (t) { + cur = t->data; + if (cur && (cur = g_list_next (cur))) { + session->task->rcpt = g_list_prepend (session->task->rcpt, cur->data); + } + t = g_list_next (t); + } + memcpy (&session->task->from_addr, &session->client_addr, sizeof (struct in_addr)); session->task->cmd = CMD_CHECK; r = process_filters (session->task); diff --git a/src/symbols_cache.c b/src/symbols_cache.c index fd8454c31..046d2f6d7 100644 --- a/src/symbols_cache.c +++ b/src/symbols_cache.c @@ -248,7 +248,8 @@ register_symbol (struct symbols_cache **cache, const char *name, double weight, { struct cache_item *item = NULL; struct symbols_cache *pcache = *cache; - GList **target; + GList **target; + double *w; if (*cache == NULL) { pcache = g_new0 (struct symbols_cache, 1); @@ -269,7 +270,14 @@ register_symbol (struct symbols_cache **cache, const char *name, double weight, g_strlcpy (item->s->symbol, name, sizeof (item->s->symbol)); item->func = func; item->user_data = user_data; - item->s->weight = weight; + + /* Handle weight using default metric */ + if (pcache->cfg && pcache->cfg->default_metric && (w = g_hash_table_lookup (pcache->cfg->default_metric->symbols, name)) != NULL) { + item->s->weight = weight * (*w); + } + else { + item->s->weight = weight; + } pcache->used_items++; msg_debug ("used items: %d, added symbol: %s", (*cache)->used_items, name); set_counter (item->s->symbol, 0); @@ -286,6 +294,7 @@ register_dynamic_symbol (memory_pool_t *dynamic_pool, struct symbols_cache **cac struct symbols_cache *pcache = *cache; GList *t, *cur; uintptr_t r; + double *w; uint32_t mask = 0xFFFFFFFF; struct dynamic_map_item *it; @@ -300,7 +309,13 @@ register_dynamic_symbol (memory_pool_t *dynamic_pool, struct symbols_cache **cac g_strlcpy (item->s->symbol, name, sizeof (item->s->symbol)); item->func = func; item->user_data = user_data; - item->s->weight = weight; + /* Handle weight using default metric */ + if (pcache->cfg && pcache->cfg->default_metric && (w = g_hash_table_lookup (pcache->cfg->default_metric->symbols, name)) != NULL) { + item->s->weight = weight * (*w); + } + else { + item->s->weight = weight; + } item->is_dynamic = TRUE; pcache->used_items++; @@ -423,7 +438,7 @@ free_cache (gpointer arg) } gboolean -init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, const char *filename) +init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, struct config_file *cfg, const char *filename) { struct stat st; int fd; @@ -439,6 +454,8 @@ init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, const cha /* Init locking */ cache->lock = memory_pool_get_rwlock (pool); + cache->cfg = cfg; + /* Just in-memory cache */ if (filename == NULL) { post_cache_init (cache); diff --git a/src/symbols_cache.h b/src/symbols_cache.h index 9f67ca486..81e6e3bc8 100644 --- a/src/symbols_cache.h +++ b/src/symbols_cache.h @@ -7,6 +7,7 @@ #define MAX_SYMBOL 128 struct worker_task; +struct config_file; typedef void (*symbol_func_t)(struct worker_task *task, gpointer user_data); @@ -59,12 +60,13 @@ struct symbols_cache { guint uses; gpointer map; memory_pool_rwlock_t *lock; + struct config_file *cfg; }; /** * Load symbols cache from file, must be called _after_ init_symbols_cache */ -gboolean init_symbols_cache (memory_pool_t *pool, struct symbols_cache *cache, const char *filename); +gboolean init_symbols_cache (memory_pool_t *pool, struct symbols_cache *cache, struct config_file *cfg, const char *filename); /** * Register function for symbols parsing |