]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Remove weight definition from symbols cache.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 12 Aug 2015 15:59:35 +0000 (16:59 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 12 Aug 2015 15:59:35 +0000 (16:59 +0100)
src/libserver/symbols_cache.c
src/libserver/symbols_cache.h

index 6e97dbd38188641b158c7b942cdf2ac26c8d4876..0cc2850942492238559c54c797d927ceb9929b28 100644 (file)
@@ -80,7 +80,6 @@ struct cache_item {
        /* Priority */
        gint priority;
        gint id;
-       gdouble metric_weight;
 
        /* Dependencies */
        GPtrArray *deps;
@@ -332,6 +331,11 @@ rspamd_symbols_cache_load_items (struct symbols_cache *cache, const gchar *name)
 
                if (item) {
                        /* Copy saved info */
+                       /*
+                        * XXX: don't save or load weight, it should be obtained from the
+                        * metric
+                        */
+#if 0
                        elt = ucl_object_find_key (cur, "weight");
 
                        if (elt) {
@@ -340,7 +344,7 @@ rspamd_symbols_cache_load_items (struct symbols_cache *cache, const gchar *name)
                                        item->weight = w;
                                }
                        }
-
+#endif
                        elt = ucl_object_find_key (cur, "time");
                        if (elt) {
                                item->avg_time = ucl_object_todouble (elt);
@@ -447,7 +451,6 @@ rspamd_symbols_cache_save_items (struct symbols_cache *cache, const gchar *name)
 gint
 rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
        const gchar *name,
-       double weight,
        gint priority,
        symbol_func_t func,
        gpointer user_data,
@@ -490,9 +493,8 @@ rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
        item->user_data = user_data;
        item->priority = priority;
        item->type = type;
-       item->weight = weight;
 
-       if (item->weight < 0 && item->priority == 0) {
+       if ((type & SYMBOL_TYPE_FINE) && item->priority == 0) {
                /* Make priority for negative weighted symbols */
                item->priority = 1;
        }
@@ -518,69 +520,6 @@ rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
        return item->id;
 }
 
-gint
-rspamd_symbols_cache_add_symbol_normal (struct symbols_cache *cache,
-       const gchar *name, double weight,
-       symbol_func_t func, gpointer user_data)
-{
-       return rspamd_symbols_cache_add_symbol (cache,
-               name,
-               weight,
-               0,
-               func,
-               user_data,
-               SYMBOL_TYPE_NORMAL,
-               -1);
-}
-
-gint
-rspamd_symbols_cache_add_symbol_virtual (struct symbols_cache *cache,
-       const gchar *name,
-       double weight,
-       gint parent)
-{
-       return rspamd_symbols_cache_add_symbol (cache,
-               name,
-               weight,
-               0,
-               NULL,
-               NULL,
-               SYMBOL_TYPE_VIRTUAL,
-               parent);
-}
-
-gint
-rspamd_symbols_cache_add_symbol_callback (struct symbols_cache *cache,
-       double weight,
-       symbol_func_t func,
-       gpointer user_data)
-{
-       return rspamd_symbols_cache_add_symbol (cache,
-               NULL,
-               weight,
-               0,
-               func,
-               user_data,
-               SYMBOL_TYPE_CALLBACK,
-               -1);
-}
-
-gint
-rspamd_symbols_cache_add_symbol_callback_prio (struct symbols_cache *cache,
-       double weight,
-       gint priority,
-       symbol_func_t func,
-       gpointer user_data)
-{
-       return rspamd_symbols_cache_add_symbol (cache,
-               NULL,
-               weight,
-               priority,
-               func,
-               user_data,
-               SYMBOL_TYPE_CALLBACK,
-               -1);
-}
 
 void
 rspamd_symbols_cache_destroy (struct symbols_cache *cache)
@@ -662,21 +601,6 @@ rspamd_symbols_cache_init (struct symbols_cache* cache,
        return res;
 }
 
-static gboolean
-check_debug_symbol (struct rspamd_config *cfg, const gchar *symbol)
-{
-       GList *cur;
-
-       cur = cfg->debug_symbols;
-       while (cur) {
-               if (strcmp (symbol, (const gchar *)cur->data) == 0) {
-                       return TRUE;
-               }
-               cur = g_list_next (cur);
-       }
-
-       return FALSE;
-}
 
 static void
 rspamd_symbols_cache_validate_cb (gpointer k, gpointer v, gpointer ud)
@@ -776,11 +700,7 @@ rspamd_symbols_cache_metric_validate_cb (gpointer k, gpointer v, gpointer ud)
        item = g_hash_table_lookup (cache->items_by_symbol, sym);
 
        if (item) {
-               item->metric_weight = weight;
-
-               if (fabs (item->weight) < fabs (weight) || weight < 0) {
-                       item->weight = weight;
-               }
+               item->weight = weight;
        }
 }
 
index 7dd33ad8f6a46383c9e269368d5250bc42641b62..bc3386eba7809a891127731612c85516125824c8 100644 (file)
@@ -37,12 +37,13 @@ struct symbols_cache;
 typedef void (*symbol_func_t)(struct rspamd_task *task, gpointer user_data);
 
 enum rspamd_symbol_type {
-       SYMBOL_TYPE_NORMAL,
-       SYMBOL_TYPE_VIRTUAL,
-       SYMBOL_TYPE_CALLBACK,
-       SYMBOL_TYPE_GHOST,
-       SYMBOL_TYPE_SKIPPED,
-       SYMBOL_TYPE_COMPOSITE
+       SYMBOL_TYPE_NORMAL = (1 << 0),
+       SYMBOL_TYPE_VIRTUAL = (1 << 1),
+       SYMBOL_TYPE_CALLBACK = (1 << 2),
+       SYMBOL_TYPE_GHOST = (1 << 3),
+       SYMBOL_TYPE_SKIPPED = (1 << 4),
+       SYMBOL_TYPE_COMPOSITE = (1 << 5),
+       SYMBOL_TYPE_FINE = (1 << 6)
 };
 
 /**
@@ -63,53 +64,6 @@ void rspamd_symbols_cache_destroy (struct symbols_cache *cache);
 gboolean rspamd_symbols_cache_init (struct symbols_cache* cache,
        struct rspamd_config *cfg);
 
-/**
- * Register function for symbols parsing
- * @param name name of symbol
- * @param func pointer to handler
- * @param user_data pointer to user_data
- */
-gint rspamd_symbols_cache_add_symbol_normal (struct symbols_cache *cache,
-       const gchar *name,
-       double weight,
-       symbol_func_t func,
-       gpointer user_data);
-
-
-/**
- * Register virtual symbol
- * @param name name of symbol
- * @param weight initial weight
- * @param parent associated callback parent
- */
-gint rspamd_symbols_cache_add_symbol_virtual (struct symbols_cache *cache,
-       const gchar *name,
-       double weight,
-       gint parent);
-
-/**
- * Register callback function for symbols parsing
- * @param name name of symbol
- * @param func pointer to handler
- * @param user_data pointer to user_data
- */
-gint rspamd_symbols_cache_add_symbol_callback (struct symbols_cache *cache,
-       double weight,
-       symbol_func_t func,
-       gpointer user_data);
-
-/**
- * Register function for symbols parsing with strict priority
- * @param name name of symbol
- * @param func pointer to handler
- * @param user_data pointer to user_data
- */
-gint rspamd_symbols_cache_add_symbol_callback_prio (struct symbols_cache *cache,
-       double weight,
-       gint priority,
-       symbol_func_t func,
-       gpointer user_data);
-
 /**
  * Generic function to register a symbol
  * @param cache
@@ -123,7 +77,6 @@ gint rspamd_symbols_cache_add_symbol_callback_prio (struct symbols_cache *cache,
  */
 gint rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
        const gchar *name,
-       double weight,
        gint priority,
        symbol_func_t func,
        gpointer user_data,