From: cebka@mailsupport.rambler.ru Date: Tue, 23 Sep 2008 21:53:39 +0000 (+0400) Subject: * Implement factors consolidation function (default consolidation function for metrics) X-Git-Tag: 0.2.7~369 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=774c6c63fa0e185e597e5899c0bc610ed7854379;p=rspamd.git * Implement factors consolidation function (default consolidation function for metrics) --- diff --git a/filter.c b/filter.c index 7fcd4a4f7..9130a9e9c 100644 --- a/filter.c +++ b/filter.c @@ -36,6 +36,38 @@ insert_result (struct worker_task *task, const char *metric_name, const char *sy LIST_INSERT_HEAD (&metric_res->results, result, next); } +/* + * Default consolidation function based on factors in config file + */ +int +factor_consolidation_func (struct worker_task *task, const char *metric_name) +{ + struct metric_result *metric_res; + struct filter_result *result; + double *factor; + int res = 0; + + metric_res = g_hash_table_lookup (task->results, metric_name); + if (metric_res == NULL) { + return res; + } + + LIST_FOREACH (result, &metric_res->results, next) { + if (result->flag) { + factor = g_hash_table_lookup (task->worker->srv->cfg->factors, result->symbol); + if (factor == NULL) { + /* Default multiplier is 1 */ + res ++; + } + else { + res += *factor; + } + } + } + + return res; +} + int process_filters (struct worker_task *task) { diff --git a/filter.h b/filter.h index 3eb97ac93..9f0a96da9 100644 --- a/filter.h +++ b/filter.h @@ -11,7 +11,7 @@ struct worker_task; -typedef void (*metric_cons_func)(struct worker_task *task, const char *metric_name); +typedef int (*metric_cons_func)(struct worker_task *task, const char *metric_name); typedef void (*filter_func)(struct worker_task *task); enum filter_type { C_FILTER, PERL_FILTER }; @@ -42,5 +42,6 @@ struct metric_result { int process_filters (struct worker_task *task); void insert_result (struct worker_task *task, const char *metric_name, const char *symbol, u_char flag); +int factor_consolidation_func (struct worker_task *task, const char *metric_name); #endif