diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-10-16 19:13:06 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-10-16 19:13:06 +0400 |
commit | d7a22c22ccc8aa3cd95c461d13f538b6d321ddc1 (patch) | |
tree | 007c1c8bc33899e76965ccfbb5b75021092d6b01 /src | |
parent | 8909ac45092c23bb6283ae389a5f6c94de49ad9d (diff) | |
download | rspamd-d7a22c22ccc8aa3cd95c461d13f538b6d321ddc1.tar.gz rspamd-d7a22c22ccc8aa3cd95c461d13f538b6d321ddc1.zip |
* Add growing coefficient to factors consolidation callback
* Fix registering functions from lua
Diffstat (limited to 'src')
-rw-r--r-- | src/cfg_file.h | 1 | ||||
-rw-r--r-- | src/cfg_file.l | 1 | ||||
-rw-r--r-- | src/cfg_file.y | 10 | ||||
-rw-r--r-- | src/cfg_utils.c | 1 | ||||
-rw-r--r-- | src/filter.c | 29 | ||||
-rw-r--r-- | src/lua/lua_config.c | 2 |
6 files changed, 37 insertions, 7 deletions
diff --git a/src/cfg_file.h b/src/cfg_file.h index afa150a4c..6a0835f51 100644 --- a/src/cfg_file.h +++ b/src/cfg_file.h @@ -238,6 +238,7 @@ struct config_file { GHashTable *classifiers_symbols; /**< hashtable indexed by symbol name of classifiers */ GHashTable* cfg_params; /**< all cfg params indexed by its name in this structure */ int clock_res; /**< resolution of clock used */ + double grow_factor; /**< grow factor for consolidation callback */ GList *views; /**< views */ GHashTable* domain_settings; /**< settings per-domains */ GHashTable* user_settings; /**< settings per-user */ diff --git a/src/cfg_file.l b/src/cfg_file.l index a497aa4b6..1b677a4f4 100644 --- a/src/cfg_file.l +++ b/src/cfg_file.l @@ -64,6 +64,7 @@ domain_settings return DOMAIN_SETTINGS; filters return FILTERS; factors return FACTORS; +grow_factor return GROW_FACTOR; metric return METRIC; name return NAME; required_score return REQUIRED_SCORE; diff --git a/src/cfg_file.y b/src/cfg_file.y index 6e0b8a20f..c51e5a853 100644 --- a/src/cfg_file.y +++ b/src/cfg_file.y @@ -59,7 +59,7 @@ struct rspamd_view *cur_view = NULL; %token DELIVERY LMTP ENABLED AGENT SECTION LUACODE RAW_MODE PROFILE_FILE COUNT %token VIEW IP FROM SYMBOLS %token AUTOLEARN MIN_MARK MAX_MARK -%token SETTINGS USER_SETTINGS DOMAIN_SETTINGS SYMBOL PATH SKIP_CHECK +%token SETTINGS USER_SETTINGS DOMAIN_SETTINGS SYMBOL PATH SKIP_CHECK GROW_FACTOR %type <string> STRING %type <string> VARIABLE @@ -465,7 +465,13 @@ factorparam: double *tmp = memory_pool_alloc (cfg->cfg_pool, sizeof (double)); *tmp = $3; g_hash_table_insert (cfg->factors, $1, tmp); - }; + } + | GROW_FACTOR EQSIGN FRACT { + cfg->grow_factor = $3; + } + | GROW_FACTOR EQSIGN NUMBER { + cfg->grow_factor = $3; + } modules: MODULES OBRACE modulesbody EBRACE diff --git a/src/cfg_utils.c b/src/cfg_utils.c index a1113f516..7b6470028 100644 --- a/src/cfg_utils.c +++ b/src/cfg_utils.c @@ -186,6 +186,7 @@ init_defaults (struct config_file *cfg) cfg->max_statfile_size = DEFAULT_STATFILE_SIZE; + cfg->grow_factor = 1; cfg->modules_opts = g_hash_table_new (g_str_hash, g_str_equal); cfg->variables = g_hash_table_new (g_str_hash, g_str_equal); cfg->metrics = g_hash_table_new (g_str_hash, g_str_equal); diff --git a/src/filter.c b/src/filter.c index efda9fa72..4269e29d5 100644 --- a/src/filter.c +++ b/src/filter.c @@ -117,17 +117,28 @@ insert_result (struct worker_task *task, const char *metric_name, const char *sy struct consolidation_callback_data { struct worker_task *task; double score; + int count; }; static void consolidation_callback (gpointer key, gpointer value, gpointer arg) { - double *factor, fs; + double *factor, fs, grow = 1; struct symbol *s = (struct symbol *)value; struct consolidation_callback_data *data = (struct consolidation_callback_data *)arg; + + if (data->count > 0) { + grow = 1. + (data->task->cfg->grow_factor - 1.) * data->count; + } if (check_factor_settings (data->task, key, &fs)) { - data->score += fs * s->score; + if (s->score > 0) { + data->score += fs * s->score * grow; + data->count ++; + } + else { + data->score += fs * s->score; + } } else { factor = g_hash_table_lookup (data->task->worker->srv->cfg->factors, key); @@ -136,7 +147,13 @@ consolidation_callback (gpointer key, gpointer value, gpointer arg) data->score += s->score; } else { - data->score += *factor * s->score; + if (s->score > 0) { + data->score += *factor * s->score * grow; + data->count ++; + } + else { + data->score += *factor * s->score; + } msg_debug ("consolidation_callback: got %.2f score for metric %s, factor: %.2f", s->score, (char *)key, *factor); } } @@ -147,7 +164,11 @@ factor_consolidation_func (struct worker_task *task, const char *metric_name, co { struct metric_result *metric_res; double res = 0.; - struct consolidation_callback_data data = { task, 0 }; + struct consolidation_callback_data data = { + .task = task, + .score = 0, + .count = 0 + }; metric_res = g_hash_table_lookup (task->results, metric_name); if (metric_res == NULL) { diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 2cc03fb1a..c25103f77 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -199,7 +199,7 @@ lua_config_register_function (lua_State *L) cd = g_malloc (sizeof (struct lua_callback_data)); cd->name = g_strdup (callback); cd->L = L; - register_expression_function (cd->name, lua_config_function_callback, cd); + register_expression_function (name, lua_config_function_callback, cd); } } return 0; |