Skip to content

Commit

Permalink
[Minor] Fix id priorities application
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Feb 3, 2020
1 parent 5c31b20 commit 91c623b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/lua/lua_task.c
Expand Up @@ -5593,8 +5593,11 @@ lua_task_set_settings_id (lua_State *L)

if (task->settings_elt) {
if (task->settings_elt->id != id) {
return luaL_error (L, "settings id has been already set to %d (%s)",
task->settings_elt->id, task->settings_elt->name);
return luaL_error (L, "settings id has been already set to %d (%s); "
"trying to set it to %d",
task->settings_elt->id,
task->settings_elt->name,
id);
}
}
else {
Expand Down
30 changes: 22 additions & 8 deletions src/plugins/lua/settings.lua
Expand Up @@ -253,6 +253,18 @@ local function check_ip_setting(expected, ip)
return false
end

local function priority_to_string(pri)
if pri then
if pri >= 3 then
return "high"
elseif pri >= 2 then
return "medium"
end
end

return "low"
end

-- Check limit for a task
local function check_settings(task)
local function check_specific_setting(rule, matched)
Expand Down Expand Up @@ -296,20 +308,21 @@ local function check_settings(task)
if query_apply then
if id_elt then
apply_settings(task, query_apply, id_elt.id)
rspamd_logger.infox(task, "applied settings id %s(%s)",
id_elt.name, id_elt.id)
rspamd_logger.infox(task, "applied settings id %s(%s); priority %s",
id_elt.name, id_elt.id, priority_to_string(priority))
else
apply_settings(task, query_apply, nil)
rspamd_logger.infox(task, "applied settings from query")
rspamd_logger.infox(task, "applied settings from query; priority %s",
priority_to_string(priority))
end
end
end

local min_pri = 1
if query_apply then
if priority > min_pri then
-- Do not check lower priorities
min_pri = priority
if priority >= min_pri then
-- Do not check lower or equal priorities
min_pri = priority + 1
end

if priority > max_pri then
Expand Down Expand Up @@ -347,10 +360,11 @@ local function check_settings(task)
if not cached or not cached.settings or not cached.settings.apply then
rspamd_logger.errx(task, 'unregistered settings id found: %s!', s.rule.id)
else
rspamd_logger.infox(task, "<%s> apply static settings %s (id = %s); %s matched",
rspamd_logger.infox(task, "<%s> apply static settings %s (id = %s); %s matched; priority %s",
task:get_message_id(),
cached.name, s.rule.id,
table.concat(matched, ','))
table.concat(matched, ','),
priority_to_string(pri))
apply_settings(task, cached.settings.apply, s.rule.id)
end

Expand Down

0 comments on commit 91c623b

Please sign in to comment.