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)
{
return obj;
}
+#endif
/*
* Counters command handler:
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;
}
cur = g_list_next (cur);
}
+#endif
}
rspamd_controller_send_ucl (conn_ent, top);
ucl_object_unref (top);
gboolean single)
{
struct metric *metric;
- struct cache_item *item;
GList *cur, *metric_list;
/* Avoid concurrenting inserting of results */
/* 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) {
composite);
if (new) {
- register_virtual_symbol (&cfg->cache, composite_name, 1);
+ register_virtual_symbol (cfg->cache, composite_name, 1);
}
return TRUE;
{
struct rspamd_config *cfg = ud;
- register_virtual_symbol (&cfg->cache, key, 1.0);
+ register_virtual_symbol (cfg->cache, key, 1.0);
}
void
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);
}
/* 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];
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,
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,
}
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) {
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);
}
void
-register_callback_symbol (struct symbols_cache **cache,
+register_callback_symbol (struct symbols_cache *cache,
const gchar *name,
double weight,
symbol_func_t func,
}
void
-register_callback_symbol_priority (struct symbols_cache **cache,
+register_callback_symbol_priority (struct symbols_cache *cache,
const gchar *name,
double weight,
gint priority,
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);
/* Copy saved cache entries */
res = rspamd_symbols_cache_load_items (cache, cfg->cache_filename);
+ post_cache_init (cache);
+
return res;
}
{
struct cache_item *item;
GList *cur, *metric_symbols;
- gboolean res;
if (cache == NULL) {
msg_err ("empty cache is invalid");
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",
if (s == NULL) {
s =
rspamd_mempool_alloc0 (task->task_pool,
- sizeof (struct symbol_callback_data));
+ sizeof (gpointer));
*save = s;
}
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;
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)
{
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;