init_cfg_cache (struct config_file *cfg)
{
- if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg->cache_filename)) {
+ if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg, cfg->cache_filename)) {
exit (EXIT_FAILURE);
}
}
struct cache_item *item;
int i;
- if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg->cache_filename)) {
+ if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg, cfg->cache_filename)) {
exit (EXIT_FAILURE);
}
if (cfg->cache) {
if (! load_rspamd_config (rspamd->cfg, TRUE)) {
exit (EXIT_FAILURE);
}
+
+ /* Pre-init of cache */
+ rspamd->cfg->cache = g_new0 (struct symbols_cache, 1);
+ rspamd->cfg->cache->static_pool = memory_pool_new (memory_pool_get_size ());
+ rspamd->cfg->cache->cfg = rspamd->cfg;
if (rspamd->cfg->config_test || dump_vars || dump_cache) {
/* Init events to test modules */
{
struct stat st;
int r;
+ GList *cur, *t;
if (fstat (session->temp_fd, &st) == -1) {
goto err;
goto err;
}
session->task->helo = session->helo;
+ /* Save MAIL FROM */
+ cur = session->from;
+ if (cur && (cur = g_list_next (cur))) {
+ session->task->from = cur->data;
+ }
+ /* Save recipients */
+ t = session->rcpt;
+ while (t) {
+ cur = t->data;
+ if (cur && (cur = g_list_next (cur))) {
+ session->task->rcpt = g_list_prepend (session->task->rcpt, cur->data);
+ }
+ t = g_list_next (t);
+ }
+
memcpy (&session->task->from_addr, &session->client_addr, sizeof (struct in_addr));
session->task->cmd = CMD_CHECK;
r = process_filters (session->task);
{
struct cache_item *item = NULL;
struct symbols_cache *pcache = *cache;
- GList **target;
+ GList **target;
+ double *w;
if (*cache == NULL) {
pcache = g_new0 (struct symbols_cache, 1);
g_strlcpy (item->s->symbol, name, sizeof (item->s->symbol));
item->func = func;
item->user_data = user_data;
- item->s->weight = weight;
+
+ /* Handle weight using default metric */
+ if (pcache->cfg && pcache->cfg->default_metric && (w = g_hash_table_lookup (pcache->cfg->default_metric->symbols, name)) != NULL) {
+ item->s->weight = weight * (*w);
+ }
+ else {
+ item->s->weight = weight;
+ }
pcache->used_items++;
msg_debug ("used items: %d, added symbol: %s", (*cache)->used_items, name);
set_counter (item->s->symbol, 0);
struct symbols_cache *pcache = *cache;
GList *t, *cur;
uintptr_t r;
+ double *w;
uint32_t mask = 0xFFFFFFFF;
struct dynamic_map_item *it;
g_strlcpy (item->s->symbol, name, sizeof (item->s->symbol));
item->func = func;
item->user_data = user_data;
- item->s->weight = weight;
+ /* Handle weight using default metric */
+ if (pcache->cfg && pcache->cfg->default_metric && (w = g_hash_table_lookup (pcache->cfg->default_metric->symbols, name)) != NULL) {
+ item->s->weight = weight * (*w);
+ }
+ else {
+ item->s->weight = weight;
+ }
item->is_dynamic = TRUE;
pcache->used_items++;
}
gboolean
-init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, const char *filename)
+init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, struct config_file *cfg, const char *filename)
{
struct stat st;
int fd;
/* Init locking */
cache->lock = memory_pool_get_rwlock (pool);
+ cache->cfg = cfg;
+
/* Just in-memory cache */
if (filename == NULL) {
post_cache_init (cache);
#define MAX_SYMBOL 128
struct worker_task;
+struct config_file;
typedef void (*symbol_func_t)(struct worker_task *task, gpointer user_data);
guint uses;
gpointer map;
memory_pool_rwlock_t *lock;
+ struct config_file *cfg;
};
/**
* Load symbols cache from file, must be called _after_ init_symbols_cache
*/
-gboolean init_symbols_cache (memory_pool_t *pool, struct symbols_cache *cache, const char *filename);
+gboolean init_symbols_cache (memory_pool_t *pool, struct symbols_cache *cache, struct config_file *cfg, const char *filename);
/**
* Register function for symbols parsing