]> source.dussan.org Git - rspamd.git/commitdiff
Adopt the rest of the code.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 26 May 2015 21:27:39 +0000 (22:27 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 26 May 2015 21:27:39 +0000 (22:27 +0100)
src/controller.c
src/libmime/filter.c
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/libserver/symbols_cache.c
src/main.c

index 46f4ed66ece224051ef9d46f07a006a0c8869870..3a5fb26fe011c1992293e81b75a6bc28e4e8e28a 100644 (file)
@@ -1580,6 +1580,8 @@ rspamd_controller_handle_statreset (
        return rspamd_controller_handle_stat_common (conn_ent, msg, TRUE);
 }
 
+#if 0
+/* XXX: restore counters */
 static ucl_object_t *
 rspamd_controller_cache_item_to_ucl (struct cache_item *item)
 {
@@ -1597,6 +1599,7 @@ rspamd_controller_cache_item_to_ucl (struct cache_item *item)
 
        return obj;
 }
+#endif
 
 /*
  * Counters command handler:
@@ -1622,6 +1625,8 @@ rspamd_controller_handle_counters (
        cache = session->ctx->cfg->cache;
        top = ucl_object_typed_new (UCL_ARRAY);
        if (cache != NULL) {
+#if 0
+/* XXX: restore counters */
                cur = cache->negative_items;
                while (cur) {
                        item = cur->data;
@@ -1640,6 +1645,7 @@ rspamd_controller_handle_counters (
                        }
                        cur = g_list_next (cur);
                }
+#endif
        }
        rspamd_controller_send_ucl (conn_ent, top);
        ucl_object_unref (top);
index e23bb8f87a8baf96e84556d63759a7e64163d22a..a2c214d31d7d6b4726f3ff5dc621fdbed14eafdb 100644 (file)
@@ -267,7 +267,6 @@ insert_result_common (struct rspamd_task *task,
        gboolean single)
 {
        struct metric *metric;
-       struct cache_item *item;
        GList *cur, *metric_list;
 
        /* Avoid concurrenting inserting of results */
@@ -298,10 +297,7 @@ insert_result_common (struct rspamd_task *task,
 
        /* Process cache item */
        if (task->cfg->cache) {
-               item = g_hash_table_lookup (task->cfg->cache->items_by_symbol, symbol);
-               if (item != NULL) {
-                       item->s->frequency++;
-               }
+               /* XXX: increase frequency here */
        }
 
        if (opts != NULL) {
index 7c898431fe1ef3dca7329a2f5c287595d5a0826d..3686fde0629176cd20ee23233d8425009f660072 100644 (file)
@@ -1136,7 +1136,7 @@ rspamd_rcl_composite_handler (rspamd_mempool_t *pool,
                composite);
 
        if (new) {
-               register_virtual_symbol (&cfg->cache, composite_name, 1);
+               register_virtual_symbol (cfg->cache, composite_name, 1);
        }
 
        return TRUE;
index da444cba212e9413fafd9f79c3bec98a69b68d74..12199436cc27ea8ab3f2123562e1ce2efc937486 100644 (file)
@@ -680,7 +680,7 @@ symbols_classifiers_callback (gpointer key, gpointer value, gpointer ud)
 {
        struct rspamd_config *cfg = ud;
 
-       register_virtual_symbol (&cfg->cache, key, 1.0);
+       register_virtual_symbol (cfg->cache, key, 1.0);
 }
 
 void
@@ -910,13 +910,4 @@ rspamd_init_cfg (struct rspamd_config *cfg, gboolean init_lua)
                rspamd_mempool_add_destructor (cfg->cfg_pool,
                                (rspamd_mempool_destruct_t)lua_close, cfg->lua_state);
        }
-
-       /* Pre-init of cache */
-       cfg->cache = g_new0 (struct symbols_cache, 1);
-       cfg->cache->static_pool = rspamd_mempool_new (
-               rspamd_mempool_suggest_size ());
-       cfg->cache->cfg = cfg;
-       cfg->cache->items_by_symbol = g_hash_table_new (
-               rspamd_str_hash,
-               rspamd_str_equal);
 }
index 30cc2a5e01197b3add7f8cecaf15591608f8528d..e9663142cb7681760ca9deea452c5c3a56c9aa27 100644 (file)
 
 /* After which number of messages try to resort cache */
 #define MAX_USES 100
-static const guchar rspamd_symbols_cache_magic[] = {'r', 's', 'c', 1, 0, 0 };
+static const guchar rspamd_symbols_cache_magic[8] = {'r', 's', 'c', 1, 0, 0, 0, 0 };
 
 struct rspamd_symbols_cache_header {
-       guchar magic;
+       guchar magic[8];
        guint nitems;
        guchar checksum[BLAKE2B_OUTBYTES];
        guchar unused[128];
@@ -167,7 +167,7 @@ rspamd_symbols_cache_load_items (struct symbols_cache *cache, const gchar *name)
                return FALSE;
        }
 
-       if (st.st_size < sizeof (*hdr)) {
+       if (st.st_size < (gint)sizeof (*hdr)) {
                close (fd);
                errno = EINVAL;
                msg_info ("cannot use file %s, error %d, %s", name,
@@ -188,14 +188,14 @@ rspamd_symbols_cache_load_items (struct symbols_cache *cache, const gchar *name)
        hdr = map;
 
        if (memcmp (hdr->magic, rspamd_symbols_cache_magic,
-                       sizeof (rspamd_symbols_cache_magic)) == NULL) {
+                       sizeof (rspamd_symbols_cache_magic)) != 0) {
                msg_info ("cannot use file %s, bad magic", name);
                munmap (map, st.st_size);
                return FALSE;
        }
 
        parser = ucl_parser_new (0);
-       p = hdr + 1;
+       p = (const guchar *)(hdr + 1);
 
        if (!ucl_parser_add_chunk (parser, p, st.st_size - sizeof (*hdr))) {
                msg_info ("cannot use file %s, cannot parse: %s", name,
@@ -269,7 +269,7 @@ rspamd_symbols_cache_save_items (struct symbols_cache *cache, const gchar *name)
        }
 
        memset (&hdr, 0, sizeof (hdr));
-       memcpy (hdr->magic, rspamd_symbols_cache_magic,
+       memcpy (hdr.magic, rspamd_symbols_cache_magic,
                        sizeof (rspamd_symbols_cache_magic));
 
        if (write (fd, &hdr, sizeof (hdr)) == -1) {
@@ -314,7 +314,7 @@ register_symbol_common (struct symbols_cache *cache,
        enum rspamd_symbol_type type)
 {
        struct cache_item *item = NULL;
-       GList **target, *cur;
+       GList *cur;
        struct metric *m;
        struct rspamd_symbol_def *s;
        gboolean skipped, ghost = (weight == 0.0);
@@ -438,7 +438,7 @@ register_virtual_symbol (struct symbols_cache *cache,
 }
 
 void
-register_callback_symbol (struct symbols_cache **cache,
+register_callback_symbol (struct symbols_cache *cache,
        const gchar *name,
        double weight,
        symbol_func_t func,
@@ -454,7 +454,7 @@ register_callback_symbol (struct symbols_cache **cache,
 }
 
 void
-register_callback_symbol_priority (struct symbols_cache **cache,
+register_callback_symbol_priority (struct symbols_cache *cache,
        const gchar *name,
        double weight,
        gint priority,
@@ -509,11 +509,6 @@ gboolean
 init_symbols_cache (struct symbols_cache* cache,
                struct rspamd_config *cfg)
 {
-       struct stat st;
-       gint fd;
-       GChecksum *cksum;
-       u_char *mem_sum, *file_sum;
-       gsize cklen;
        gboolean res;
 
        g_assert (cache != NULL);
@@ -528,6 +523,8 @@ init_symbols_cache (struct symbols_cache* cache,
        /* Copy saved cache entries */
        res = rspamd_symbols_cache_load_items (cache, cfg->cache_filename);
 
+       post_cache_init (cache);
+
        return res;
 }
 
@@ -571,7 +568,6 @@ validate_cache (struct symbols_cache *cache,
 {
        struct cache_item *item;
        GList *cur, *metric_symbols;
-       gboolean res;
 
        if (cache == NULL) {
                msg_err ("empty cache is invalid");
@@ -582,9 +578,9 @@ validate_cache (struct symbols_cache *cache,
        metric_symbols = g_hash_table_get_keys (cfg->metrics_symbols);
        cur = metric_symbols;
        while (cur) {
-               res = g_hash_table_lookup (cache->items_by_symbol, cur->data);
+               item = g_hash_table_lookup (cache->items_by_symbol, cur->data);
 
-               if (!res) {
+               if (item == NULL) {
                        msg_warn (
                                "symbol '%s' has its score defined but there is no "
                                "corresponding rule registered",
@@ -626,7 +622,7 @@ call_symbol_callback (struct rspamd_task * task,
        if (s == NULL) {
                s =
                        rspamd_mempool_alloc0 (task->task_pool,
-                               sizeof (struct symbol_callback_data));
+                               sizeof (gpointer));
                *save = s;
        }
 
index d13f5255bc5de74d2b5740fbc6a483ebbfe9e46d..e58b783d1b7bbe85b5a95992fd0cab1aa78d9c98 100644 (file)
@@ -764,6 +764,8 @@ reopen_log_handler (gpointer key, gpointer value, gpointer unused)
 static gboolean
 load_rspamd_config (struct rspamd_config *cfg, gboolean init_modules)
 {
+       cfg->cache = rspamd_symbols_cache_new ();
+
        if (!rspamd_config_read (cfg, cfg->cfg_name, NULL,
                config_logger, rspamd_main)) {
                return FALSE;
@@ -795,68 +797,11 @@ static void
 init_cfg_cache (struct rspamd_config *cfg)
 {
 
-       if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg,
-               cfg->cache_filename, FALSE)) {
+       if (!init_symbols_cache (cfg->cache, cfg)) {
                exit (EXIT_FAILURE);
        }
 }
 
-static void
-print_symbols_cache (struct rspamd_config *cfg)
-{
-       GList *cur;
-       struct cache_item *item;
-       gint i;
-
-       if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg,
-               cfg->cache_filename, TRUE)) {
-               exit (EXIT_FAILURE);
-       }
-       if (cfg->cache) {
-               printf ("Symbols cache\n");
-               printf (
-                       "-----------------------------------------------------------------\n");
-               printf (
-                       "| Pri  | Symbol                | Weight | Frequency | Avg. time |\n");
-               i = 0;
-               cur = cfg->cache->negative_items;
-               while (cur) {
-                       item = cur->data;
-                       if (!item->is_callback) {
-                               printf (
-                                               "-----------------------------------------------------------------\n");
-                               printf ("| %3d | %22s | %6.1f | %9d | %9.3f |\n",
-                                       i,
-                                       item->s->symbol,
-                                       item->s->weight,
-                                       item->s->frequency,
-                                       item->s->avg_time);
-                       }
-                       cur = g_list_next (cur);
-                       i++;
-               }
-               cur = cfg->cache->static_items;
-               while (cur) {
-                       item = cur->data;
-                       if (!item->is_callback) {
-                               printf (
-                                               "-----------------------------------------------------------------\n");
-                               printf ("| %3d | %22s | %6.1f | %9d | %9.3f |\n",
-                                       i,
-                                       item->s->symbol,
-                                       item->s->weight,
-                                       item->s->frequency,
-                                       item->s->avg_time);
-                       }
-                       cur = g_list_next (cur);
-                       i++;
-               }
-
-               printf (
-                       "-----------------------------------------------------------------\n");
-       }
-}
-
 static gint
 perform_lua_tests (struct rspamd_config *cfg)
 {
@@ -1206,8 +1151,8 @@ main (gint argc, gchar **argv, gchar **env)
                        res = FALSE;
                }
                if (dump_cache) {
-                       print_symbols_cache (rspamd_main->cfg);
-                       exit (EXIT_SUCCESS);
+                       msg_err ("Use rspamc counters for dumping cache");
+                       exit (EXIT_FAILURE);
                }
                fprintf (stderr, "syntax %s\n", res ? "OK" : "BAD");
                return res ? EXIT_SUCCESS : EXIT_FAILURE;