Browse Source

Place symbol definition in metric->symbols hash.

tags/0.7.2
Vsevolod Stakhov 9 years ago
parent
commit
aeb484cac6
5 changed files with 25 additions and 18 deletions
  1. 2
    2
      src/controller.c
  2. 5
    4
      src/libmime/filter.c
  3. 3
    3
      src/libserver/dynamic_cfg.c
  4. 6
    4
      src/libserver/symbols_cache.c
  5. 9
    5
      src/lua/lua_cfg_file.c

+ 2
- 2
src/controller.c View 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",

+ 5
- 4
src/libmime/filter.c View 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) {

+ 3
- 3
src/libserver/dynamic_cfg.c View 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 {

+ 6
- 4
src/libserver/symbols_cache.c View 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;

+ 9
- 5
src/lua/lua_cfg_file.c View 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 =

Loading…
Cancel
Save