]> source.dussan.org Git - rspamd.git/commitdiff
Place symbol definition in metric->symbols hash.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 9 Oct 2014 00:08:58 +0000 (01:08 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 9 Oct 2014 00:08:58 +0000 (01:08 +0100)
src/controller.c
src/libmime/filter.c
src/libserver/dynamic_cfg.c
src/libserver/symbols_cache.c
src/lua/lua_cfg_file.c

index 5c65d88e75afd6c9e62e21a02cc40d76b8325738..02a5d4d2eb8b7e134e27e767f885d0700c4dc337 100644 (file)
@@ -1053,7 +1053,7 @@ rspamd_controller_handle_savesymbols (
        struct rspamd_controller_worker_ctx *ctx;
        const gchar *error;
        gdouble val;
-       struct symbol *sym;
+       struct rspamd_symbol_def *sym;
        int added = 0;
 
        ctx = session->ctx;
@@ -1119,7 +1119,7 @@ rspamd_controller_handle_savesymbols (
                val = ucl_object_todouble (jvalue);
                sym =
                        g_hash_table_lookup (metric->symbols, ucl_object_tostring (jname));
-               if (sym && fabs (sym->score - val) > 0.01) {
+               if (sym && fabs (*sym->weight_ptr - val) > 0.01) {
                        if (!add_dynamic_symbol (ctx->cfg, DEFAULT_METRIC,
                                ucl_object_tostring (jname), val)) {
                                msg_err ("add symbol failed for %s",
index 540502a47152cab5d6e98dd8cf9cf61f10c99cb1..c7258f1bfd1b40d0ce781df56cda8064b8b30410 100644 (file)
@@ -108,17 +108,18 @@ insert_metric_result (struct rspamd_task *task,
 {
        struct metric_result *metric_res;
        struct symbol *s;
-       gdouble *weight, w;
+       gdouble w;
+       struct rspamd_symbol_def *sdef;
        const ucl_object_t *mobj, *sobj;
 
        metric_res = rspamd_create_metric_result (task, metric->name);
 
-       weight = g_hash_table_lookup (metric->symbols, symbol);
-       if (weight == NULL) {
+       sdef = g_hash_table_lookup (metric->symbols, symbol);
+       if (sdef == NULL) {
                w = 0.0;
        }
        else {
-               w = (*weight) * flag;
+               w = (*sdef->weight_ptr) * flag;
        }
 
        if (task->settings) {
index 97bb2c91ec8e02d0adfcba1715f4ab1e42940043..01bfb83b555a0c8b9b207ec204d45709b49304c4 100644 (file)
@@ -48,7 +48,7 @@ apply_dynamic_conf (const ucl_object_t *top, struct rspamd_config *cfg)
        ucl_object_iter_t it = NULL;
        struct metric *real_metric;
        struct metric_action *cur_action;
-       gdouble *w;
+       struct rspamd_symbol_def *s;
 
        while ((cur_elt = ucl_iterate_object (top, &it, true))) {
                if (ucl_object_type (cur_elt) != UCL_OBJECT) {
@@ -82,9 +82,9 @@ apply_dynamic_conf (const ucl_object_t *top, struct rspamd_config *cfg)
                                        const ucl_object_t *v =
                                                        ucl_object_find_key (it_val, "value");
 
-                                       if((w = g_hash_table_lookup (real_metric->symbols,
+                                       if((s = g_hash_table_lookup (real_metric->symbols,
                                                        ucl_object_tostring (n))) != NULL) {
-                                               *w = ucl_object_todouble (v);
+                                               *s->weight_ptr = ucl_object_todouble (v);
                                        }
                                }
                                else {
index 6b24f3935bc480190dc4fbeb2caceaa956c1665e..f40847bd37fca60c47d59a89aa52de5e2f036745 100644 (file)
@@ -315,7 +315,7 @@ register_symbol_common (struct symbols_cache **cache,
        struct symbols_cache *pcache = *cache;
        GList **target, *cur;
        struct metric *m;
-       double *w;
+       struct rspamd_symbol_def *s;
        gboolean skipped;
 
        if (*cache == NULL) {
@@ -355,10 +355,10 @@ register_symbol_common (struct symbols_cache **cache,
 
        /* Handle weight using default metric */
        if (pcache->cfg && pcache->cfg->default_metric &&
-               (w =
+               (s =
                g_hash_table_lookup (pcache->cfg->default_metric->symbols,
                name)) != NULL) {
-               item->s->weight = weight * (*w);
+               item->s->weight = weight * (*s->weight_ptr);
        }
        else {
                item->s->weight = weight;
@@ -679,9 +679,11 @@ rspamd_symbols_cache_metric_cb (gpointer k, gpointer v, gpointer ud)
        struct symbols_cache *cache = (struct symbols_cache *)ud;
        GList *cur;
        const gchar *sym = k;
-       gdouble weight = *(gdouble *)v;
+       struct rspamd_symbol_def *s = (struct rspamd_symbol_def *)v;
+       gdouble weight;
        struct cache_item *item;
 
+       weight = *s->weight_ptr;
        cur = cache->negative_items;
        while (cur) {
                item = cur->data;
index 08f9e40dba7da2ccae03932401f9fed2cdf17535..c29b4b2b14b50bac390435aec0d0f442411de6f8 100644 (file)
@@ -41,7 +41,8 @@ lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
        gchar *symbol, *old_desc;
        const gchar *desc;
        struct metric *metric;
-       gdouble *score, *old_score;
+       gdouble *score;
+       struct rspamd_symbol_def *s;
 
        /* Get module opt structure */
        if ((metric = g_hash_table_lookup (cfg->metrics, name)) == NULL) {
@@ -100,16 +101,19 @@ lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
                                continue;
                        }
                        /* Insert symbol */
-                       if ((old_score =
+                       if ((s =
                                g_hash_table_lookup (metric->symbols, symbol)) != NULL) {
                                msg_info ("replacing weight for symbol %s: %.2f -> %.2f",
                                        symbol,
-                                       *old_score,
+                                       *s->weight_ptr,
                                        *score);
-                               g_hash_table_replace (metric->symbols, symbol, score);
+                               s->weight_ptr = score;
                        }
                        else {
-                               g_hash_table_insert (metric->symbols, symbol, score);
+                               s = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (*s));
+                               s->name = symbol;
+                               s->weight_ptr = score;
+                               g_hash_table_insert (metric->symbols, symbol, s);
                        }
 
                        if ((metric_list =