* described below
*/
#define MSG_CMD_CHECK "check"
+
+/*
+ * Modern check version
+ */
+#define MSG_CMD_CHECK_V2 "checkv2"
+
/*
* Check if message is spam or not, and return score plus list
* of symbols hit
case 'c':
case 'C':
/* check */
- if (g_ascii_strncasecmp (p, MSG_CMD_CHECK, pathlen) == 0) {
+ if (g_ascii_strncasecmp (p, MSG_CMD_CHECK_V2, pathlen) == 0) {
+ task->cmd = CMD_CHECK_V2;
+ }
+ else if (g_ascii_strncasecmp (p, MSG_CMD_CHECK, pathlen) == 0) {
task->cmd = CMD_CHECK;
}
else {
}
if (flags & RSPAMD_PROTOCOL_METRICS) {
- g_hash_table_iter_init (&hiter, task->results);
- /* Convert results to an ucl object */
- while (g_hash_table_iter_next (&hiter, &h, &v)) {
- metric_res = (struct rspamd_metric_result *)v;
- obj = rspamd_metric_result_ucl (task, metric_res);
- ucl_object_insert_key (top, obj, h, 0, false);
- }
+ obj = rspamd_metric_result_ucl (task, task->result);
+ ucl_object_insert_key (top, obj, DEFAULT_METRIC, 0, false);
}
if (flags & RSPAMD_PROTOCOL_MESSAGES) {
end:
if (!(task->flags & RSPAMD_TASK_FLAG_NO_STAT)) {
/* Update stat for default metric */
- metric_res = g_hash_table_lookup (task->results, DEFAULT_METRIC);
+ metric_res = task->result;
+
if (metric_res != NULL) {
if (metric_res->action != METRIC_ACTION_MAX) {
if (lp->fd != -1) {
switch (lp->type) {
case RSPAMD_LOG_PIPE_SYMBOLS:
- mres = g_hash_table_lookup (task->results, DEFAULT_METRIC);
+ mres = task->result;
if (mres) {
n = g_hash_table_size (mres->symbols);
if (action < METRIC_ACTION_MAX && action >= METRIC_ACTION_REJECT) {
/* We also need to set the default metric to that result */
- mres = rspamd_create_metric_result (task, DEFAULT_METRIC);
+ mres = rspamd_create_metric_result (task);
if (mres != NULL) {
mres->score = mres->metric->actions[action].score;
mres->action = action;
static inline gboolean
lua_push_symbol_result (lua_State *L,
struct rspamd_task *task,
- struct rspamd_metric *metric,
const gchar *symbol,
struct rspamd_symbol_result *symbol_result,
gboolean add_metric,
gint j = 1, e = 4;
if (!symbol_result) {
- metric_res = g_hash_table_lookup (task->results, metric->name);
+ metric_res = task->result;
+
if (metric_res) {
s = g_hash_table_lookup (metric_res->symbols, symbol);
}
lua_createtable (L, 0, e);
- if (add_metric) {
- lua_pushstring (L, "metric");
- lua_pushstring (L, metric->name);
- lua_settable (L, -3);
- }
if (add_name) {
lua_pushstring (L, "name");
lua_pushstring (L, symbol);
{
struct rspamd_task *task = lua_check_task (L, 1);
const gchar *symbol;
- struct rspamd_metric *metric;
- GList *cur = NULL, *metric_list;
gboolean found = FALSE;
gint i = 1;
symbol = luaL_checkstring (L, 2);
if (task && symbol) {
- metric_list = g_hash_table_lookup (task->cfg->metrics_symbols, symbol);
- if (metric_list) {
- lua_createtable (L, 1, 0);
- cur = metric_list;
- }
- else {
- metric = task->cfg->default_metric;
- }
+ lua_createtable (L, 1, 0);
- if (!cur && metric) {
- lua_createtable (L, 1, 0);
-
- if ((found = lua_push_symbol_result (L, task, metric, symbol,
- NULL, TRUE, FALSE))) {
- lua_rawseti (L, -2, i++);
- }
- else {
- /* Pop table */
- lua_pop (L, 1);
- }
+ if ((found = lua_push_symbol_result (L, task, symbol,
+ NULL, TRUE, FALSE))) {
+ lua_rawseti (L, -2, i++);
}
else {
- while (cur) {
- metric = cur->data;
- if (lua_push_symbol_result (L, task, metric, symbol,
- NULL, TRUE, FALSE)) {
- lua_rawseti (L, -2, i++);
- found = TRUE;
- }
- cur = g_list_next (cur);
- }
+ /* Pop table */
+ lua_pop (L, 1);
}
}
else {
symbol = luaL_checkstring (L, 2);
if (task && symbol) {
- mres = g_hash_table_lookup (task->results, DEFAULT_METRIC);
+ mres = task->result;
if (mres) {
found = g_hash_table_lookup (mres->symbols, symbol) != NULL;
struct rspamd_symbol_result *s;
if (task) {
- mres = g_hash_table_lookup (task->results, DEFAULT_METRIC);
+ mres = task->result;
if (mres) {
lua_createtable (L, g_hash_table_size (mres->symbols), 0);
lua_task_get_symbols_all (lua_State *L)
{
struct rspamd_task *task = lua_check_task (L, 1);
- struct rspamd_metric *metric;
struct rspamd_metric_result *mres;
GHashTableIter it;
gpointer k, v;
gint i = 1;
if (task) {
- metric = task->cfg->default_metric;
- mres = g_hash_table_lookup (task->results, DEFAULT_METRIC);
+ mres = task->result;
+
if (mres) {
found = TRUE;
lua_createtable (L, g_hash_table_size (mres->symbols), 0);
g_hash_table_iter_init (&it, mres->symbols);
while (g_hash_table_iter_next (&it, &k, &v)) {
- lua_push_symbol_result (L, task, metric, k, v, FALSE, TRUE);
+ lua_push_symbol_result (L, task, k, v, FALSE, TRUE);
lua_rawseti (L, -2, i++);
}
}
struct rspamd_symbol_result *s;
if (task) {
- mres = g_hash_table_lookup (task->results, DEFAULT_METRIC);
+ mres = task->result;
if (mres) {
lua_createtable (L, g_hash_table_size (mres->symbols), 0);
if (act) {
/* Adjust desired actions */
- mres = g_hash_table_lookup (task->results, DEFAULT_METRIC);
+ mres = task->result;
if (mres == NULL) {
- mres = rspamd_create_metric_result (task, DEFAULT_METRIC);
+ mres = rspamd_create_metric_result (task);
}
for (i = 0; i < METRIC_ACTION_MAX; i++) {
lua_task_get_metric_score (lua_State *L)
{
struct rspamd_task *task = lua_check_task (L, 1);
- const gchar *metric_name;
gdouble rs;
struct rspamd_metric_result *metric_res;
- metric_name = luaL_checkstring (L, 2);
-
- if (task && metric_name) {
- if ((metric_res =
- g_hash_table_lookup (task->results, metric_name)) != NULL) {
+ if (task) {
+ if ((metric_res = task->result) != NULL) {
lua_createtable (L, 2, 0);
lua_pushnumber (L, isnan (metric_res->score) ? 0.0 : metric_res->score);
rs = rspamd_task_get_required_score (task, metric_res);
lua_task_get_metric_action (lua_State *L)
{
struct rspamd_task *task = lua_check_task (L, 1);
- const gchar *metric_name;
struct rspamd_metric_result *metric_res;
enum rspamd_metric_action action;
- metric_name = luaL_checkstring (L, 2);
-
- if (metric_name == NULL) {
- metric_name = DEFAULT_METRIC;
- }
-
- if (task && metric_name) {
- if ((metric_res =
- g_hash_table_lookup (task->results, metric_name)) != NULL) {
+ if (task) {
+ if ((metric_res = task->result) != NULL) {
action = rspamd_check_action_metric (task, metric_res);
lua_pushstring (L, rspamd_action_to_str (action));
}
lua_task_set_metric_score (lua_State *L)
{
struct rspamd_task *task = lua_check_task (L, 1);
- const gchar *metric_name;
struct rspamd_metric_result *metric_res;
gdouble nscore;
- metric_name = luaL_checkstring (L, 2);
- nscore = luaL_checknumber (L, 3);
-
- if (metric_name == NULL) {
- metric_name = DEFAULT_METRIC;
+ if (lua_isnumber (L, 2)) {
+ nscore = luaL_checknumber (L, 2);
+ }
+ else {
+ nscore = luaL_checknumber (L, 3);
}
- if (task && metric_name) {
- if ((metric_res =
- g_hash_table_lookup (task->results, metric_name)) != NULL) {
+ if (task) {
+ if ((metric_res = task->result) != NULL) {
msg_debug_task ("set metric score from %.2f to %.2f",
metric_res->score, nscore);
metric_res->score = nscore;
action_name = luaL_checkstring (L, 3);
if (task && metric_name && action_name) {
- if ((metric_res =
- g_hash_table_lookup (task->results, metric_name)) != NULL) {
+ if ((metric_res = task->result) != NULL) {
if (rspamd_action_from_str (action_name, &action)) {
metric_res->action = action;