]> source.dussan.org Git - rspamd.git/commitdiff
* Add growing coefficient to factors consolidation callback
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 16 Oct 2009 15:13:06 +0000 (19:13 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 16 Oct 2009 15:13:06 +0000 (19:13 +0400)
* Fix registering functions from lua

src/cfg_file.h
src/cfg_file.l
src/cfg_file.y
src/cfg_utils.c
src/filter.c
src/lua/lua_config.c

index afa150a4cec6a9360ac1fef0315cf94ff33de5ab..6a0835f51b3b975e0020b051c8a8fc4800f8c371 100644 (file)
@@ -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                                  */
index a497aa4b6a03fccbf0b5572f859661c1f1b62ef7..1b677a4f44b2f4404efcf7081f8d9d24dcc0e872 100644 (file)
@@ -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;
index 6e0b8a20f2599cb1efe1d9370c4627b67837f151..c51e5a85381b72acf5d4c8340bed1d47d1f79b42 100644 (file)
@@ -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
index a1113f516b858ff3c6a9419c312890176ad01341..7b64700281cc6629cb816f7521edaffacad3cfc3 100644 (file)
@@ -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);
index efda9fa727ac585c561f9640950175088279ff16..4269e29d55cbcd084d0121be97625b3bc9b11d71 100644 (file)
@@ -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) {
index 2cc03fb1aab4dc79397946e841fd11b383a3af76..c25103f77da028727b6a2825c907e7d54db9aa12 100644 (file)
@@ -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;