aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-05-26 22:27:39 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-05-26 22:27:39 +0100
commit08c063c5b33938f29fd8ad64f4d75ad96ddeedda (patch)
tree7fe697984ed85eb48dd97302fdbb8c36a6c4adab /src
parent6d230abb527752ef25e352d8d09669020774e75f (diff)
downloadrspamd-08c063c5b33938f29fd8ad64f4d75ad96ddeedda.tar.gz
rspamd-08c063c5b33938f29fd8ad64f4d75ad96ddeedda.zip
Adopt the rest of the code.
Diffstat (limited to 'src')
-rw-r--r--src/controller.c6
-rw-r--r--src/libmime/filter.c6
-rw-r--r--src/libserver/cfg_rcl.c2
-rw-r--r--src/libserver/cfg_utils.c11
-rw-r--r--src/libserver/symbols_cache.c32
-rw-r--r--src/main.c65
6 files changed, 28 insertions, 94 deletions
diff --git a/src/controller.c b/src/controller.c
index 46f4ed66e..3a5fb26fe 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -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);
diff --git a/src/libmime/filter.c b/src/libmime/filter.c
index e23bb8f87..a2c214d31 100644
--- a/src/libmime/filter.c
+++ b/src/libmime/filter.c
@@ -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) {
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index 7c898431f..3686fde06 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -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;
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index da444cba2..12199436c 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -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);
}
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index 30cc2a5e0..e9663142c 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -32,10 +32,10 @@
/* 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;
}
diff --git a/src/main.c b/src/main.c
index d13f5255b..e58b783d1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;