From: Vsevolod Stakhov Date: Thu, 9 Oct 2014 00:08:58 +0000 (+0100) Subject: Place symbol definition in metric->symbols hash. X-Git-Tag: 0.7.2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aeb484cac64fbdc876f0e1a58efa1490cdf029f5;p=thirdparty%2Frspamd.git Place symbol definition in metric->symbols hash. --- diff --git a/src/controller.c b/src/controller.c index 5c65d88e75..02a5d4d2eb 100644 --- a/src/controller.c +++ b/src/controller.c @@ -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", diff --git a/src/libmime/filter.c b/src/libmime/filter.c index 540502a471..c7258f1bfd 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -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) { diff --git a/src/libserver/dynamic_cfg.c b/src/libserver/dynamic_cfg.c index 97bb2c91ec..01bfb83b55 100644 --- a/src/libserver/dynamic_cfg.c +++ b/src/libserver/dynamic_cfg.c @@ -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 { diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c index 6b24f3935b..f40847bd37 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/symbols_cache.c @@ -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; diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c index 08f9e40dba..c29b4b2b14 100644 --- a/src/lua/lua_cfg_file.c +++ b/src/lua/lua_cfg_file.c @@ -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 =