struct rspamd_controller_worker_ctx *ctx;
const gchar *error;
gdouble val;
- struct symbol *sym;
+ struct rspamd_symbol_def *sym;
int added = 0;
ctx = session->ctx;
val = ucl_object_todouble (jvalue);
sym =
g_hash_table_lookup (metric->symbols, ucl_object_tostring (jname));
- if (sym && fabs (sym->score - val) > 0.01) {
+ if (sym && fabs (*sym->weight_ptr - val) > 0.01) {
if (!add_dynamic_symbol (ctx->cfg, DEFAULT_METRIC,
ucl_object_tostring (jname), val)) {
msg_err ("add symbol failed for %s",
{
struct metric_result *metric_res;
struct symbol *s;
- gdouble *weight, w;
+ gdouble w;
+ struct rspamd_symbol_def *sdef;
const ucl_object_t *mobj, *sobj;
metric_res = rspamd_create_metric_result (task, metric->name);
- weight = g_hash_table_lookup (metric->symbols, symbol);
- if (weight == NULL) {
+ sdef = g_hash_table_lookup (metric->symbols, symbol);
+ if (sdef == NULL) {
w = 0.0;
}
else {
- w = (*weight) * flag;
+ w = (*sdef->weight_ptr) * flag;
}
if (task->settings) {
ucl_object_iter_t it = NULL;
struct metric *real_metric;
struct metric_action *cur_action;
- gdouble *w;
+ struct rspamd_symbol_def *s;
while ((cur_elt = ucl_iterate_object (top, &it, true))) {
if (ucl_object_type (cur_elt) != UCL_OBJECT) {
const ucl_object_t *v =
ucl_object_find_key (it_val, "value");
- if((w = g_hash_table_lookup (real_metric->symbols,
+ if((s = g_hash_table_lookup (real_metric->symbols,
ucl_object_tostring (n))) != NULL) {
- *w = ucl_object_todouble (v);
+ *s->weight_ptr = ucl_object_todouble (v);
}
}
else {
struct symbols_cache *pcache = *cache;
GList **target, *cur;
struct metric *m;
- double *w;
+ struct rspamd_symbol_def *s;
gboolean skipped;
if (*cache == NULL) {
/* Handle weight using default metric */
if (pcache->cfg && pcache->cfg->default_metric &&
- (w =
+ (s =
g_hash_table_lookup (pcache->cfg->default_metric->symbols,
name)) != NULL) {
- item->s->weight = weight * (*w);
+ item->s->weight = weight * (*s->weight_ptr);
}
else {
item->s->weight = weight;
struct symbols_cache *cache = (struct symbols_cache *)ud;
GList *cur;
const gchar *sym = k;
- gdouble weight = *(gdouble *)v;
+ struct rspamd_symbol_def *s = (struct rspamd_symbol_def *)v;
+ gdouble weight;
struct cache_item *item;
+ weight = *s->weight_ptr;
cur = cache->negative_items;
while (cur) {
item = cur->data;
gchar *symbol, *old_desc;
const gchar *desc;
struct metric *metric;
- gdouble *score, *old_score;
+ gdouble *score;
+ struct rspamd_symbol_def *s;
/* Get module opt structure */
if ((metric = g_hash_table_lookup (cfg->metrics, name)) == NULL) {
continue;
}
/* Insert symbol */
- if ((old_score =
+ if ((s =
g_hash_table_lookup (metric->symbols, symbol)) != NULL) {
msg_info ("replacing weight for symbol %s: %.2f -> %.2f",
symbol,
- *old_score,
+ *s->weight_ptr,
*score);
- g_hash_table_replace (metric->symbols, symbol, score);
+ s->weight_ptr = score;
}
else {
- g_hash_table_insert (metric->symbols, symbol, score);
+ s = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (*s));
+ s->name = symbol;
+ s->weight_ptr = score;
+ g_hash_table_insert (metric->symbols, symbol, s);
}
if ((metric_list =