score = 0.0;
/* Also set priority to 0 to allow override by anything */
sym_def->priority = 0;
+ flags |= RSPAMD_SYMBOL_FLAG_UNSCORED;
}
else {
sym_def->priority = priority;
}
}
- if (sym_def->priority > priority) {
+ if (sym_def->priority > priority &&
+ (isnan(score) || !(sym_def->flags & RSPAMD_SYMBOL_FLAG_UNSCORED))) {
msg_debug_config ("symbol %s has been already registered with "
"priority %ud, do not override (new priority: %ud)",
symbol,
*sym_def->weight_ptr = score;
sym_def->score = score;
sym_def->priority = priority;
+ sym_def->flags &= ~RSPAMD_SYMBOL_FLAG_UNSCORED;
}
sym_def->flags = flags;
}
else {
rspamd_config_add_symbol (cfg, name,
- 0.0, description, group, flags,
+ NAN, description, group, flags,
0, nshots);
}
struct rspamd_config *cfg = lua_check_config (L, 1);
const gchar *description = NULL,
*group = NULL, *name = NULL, *flags_str = NULL;
- double weight;
+ double score;
gboolean one_shot = FALSE, one_param = FALSE;
GError *err = NULL;
gdouble priority = 0.0;
"*name=S;score=N;description=S;"
"group=S;one_shot=B;one_param=B;priority=N;flags=S;"
"nshots=I",
- &name, &weight, &description,
+ &name, &score, &description,
&group, &one_shot, &one_param,
&priority, &flags_str, &nshots)) {
msg_err_config ("bad arguments: %e", err);
}
else {
name = luaL_checkstring (L, 2);
- weight = luaL_checknumber (L, 3);
+ score = luaL_checknumber (L, 3);
if (lua_gettop (L) > 3 && lua_type (L, 4) == LUA_TSTRING) {
description = luaL_checkstring (L, 4);
}
rspamd_config_add_symbol (cfg, name,
- weight, description, group, flags, (guint) priority, nshots);
+ score, description, group, flags, (guint) priority, nshots);
if (lua_type (L, 2) == LUA_TTABLE) {
* Now check if a symbol has not been registered in any metric and
* insert default value if applicable
*/
- if (g_hash_table_lookup (cfg->symbols, name) == NULL) {
+ struct rspamd_symbol *sym = g_hash_table_lookup (cfg->symbols, name);
+ if (sym == NULL || (sym->flags & RSPAMD_SYMBOL_FLAG_UNSCORED)) {
nshots = cfg->default_max_shots;
lua_pushstring (L, "score");
if (lua_type (L, -1) == LUA_TNUMBER) {
score = lua_tonumber (L, -1);
+ if (sym) {
+ /* Reset unscored flag */
+ sym->flags &= ~RSPAMD_SYMBOL_FLAG_UNSCORED;
+ }
}
lua_pop (L, 1);
}
else if (group) {
/* Add with zero score */
- rspamd_config_add_symbol (cfg, name, 0.0,
+ rspamd_config_add_symbol (cfg, name, NAN,
description, group, flags, 0, nshots);
}