]> source.dussan.org Git - rspamd.git/commitdiff
* Get weights of symbol from default metric for symbols cache
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 18 Jun 2010 12:40:47 +0000 (16:40 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 18 Jun 2010 12:40:47 +0000 (16:40 +0400)
* Fix setting task->from/task->rctp in smtp client

src/main.c
src/smtp.c
src/symbols_cache.c
src/symbols_cache.h

index 3365b67c4ef866801c29e51a3045237316a37a3c..37f2ac498e247dfafec013fae9adb20428bc287e 100644 (file)
@@ -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 */
index 97cb53b1ec78253d644d20af2624ef46d7bccfc4..a77c244673ed21cbdfbb6e49f952c87e5569045d 100644 (file)
@@ -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);
index fd8454c3151acbc50cb80137fcc8d531e1dd3b9e..046d2f6d73b28a8f192bf42982fb3ffe2f13da82 100644 (file)
@@ -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);
index 9f67ca486e967476bf040323fc7887af2b6f6e44..81e6e3bc815efbe4fc0a41463b484ee36e23aa00 100644 (file)
@@ -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