}
rspamd_snprintf (sumbuf, 32, "%.2f%%", final_prob * 100.);
cur = g_list_prepend (NULL, sumbuf);
- insert_result (task,
+ rspamd_task_insert_result (task,
data.statfiles[selected_st].st->symbol,
final_prob,
cur);
sumbuf = rspamd_mempool_alloc (task->task_pool, 32);
rspamd_snprintf (sumbuf, 32, "%.2F", max);
cur = g_list_prepend (NULL, sumbuf);
- insert_result (task, sel->symbol, max, cur);
+ rspamd_task_insert_result (task, sel->symbol, max, cur);
}
return TRUE;
if (act->score >= 0) {
obj = ucl_object_typed_new (UCL_OBJECT);
ucl_object_insert_key (obj,
- ucl_object_fromstring (str_action_metric (
+ ucl_object_fromstring (rspamd_action_to_str (
act->action)), "action", 0, false);
ucl_object_insert_key (obj, ucl_object_fromdouble (
act->score), "value", 0, false);
ucl_object_insert_key (obj, ucl_object_fromstring (
ip_buf), "ip", 0, false);
ucl_object_insert_key (obj,
- ucl_object_fromstring (str_action_metric (
+ ucl_object_fromstring (rspamd_action_to_str (
row->action)), "action", 0, false);
ucl_object_insert_key (obj, ucl_object_fromdouble (
row->score), "score", 0, false);
conn_ent = task->fin_arg;
session = conn_ent->ud;
- if (!learn_task_spam (session->cl, task, session->is_spam, &err)) {
+ if (!rspamd_learn_task_spam (session->cl, task, session->is_spam, &err)) {
rspamd_controller_send_error (conn_ent, 500 + err->code, err->message);
return TRUE;
}
struct rspamd_http_connection_entry *conn_ent;
struct rspamd_http_message *msg;
- process_statfiles (task);
+ rspamd_process_statistics (task);
conn_ent = task->fin_arg;
msg = rspamd_http_new_message (HTTP_RESPONSE);
msg->date = time (NULL);
for (i = METRIC_ACTION_REJECT; i <= METRIC_ACTION_NOACTION; i++) {
ucl_object_insert_key (sub,
ucl_object_fromint (stat->actions_stat[i]),
- str_action_metric (i), 0, false);
+ rspamd_action_to_str (i), 0, false);
if (i < METRIC_ACTION_GREYLIST) {
spam += stat->actions_stat[i];
}
for (i = METRIC_ACTION_REJECT; i <= METRIC_ACTION_NOACTION; i++) {
rspamd_printf_gstring (out,
"Messages with action %s: %ud, %.2f%%" CRLF,
- str_action_metric (
+ rspamd_action_to_str (
i),
stat->actions_stat[i],
(double)stat->actions_stat[i] / (double)stat->messages_scanned *
}
if (is_action) {
- if (!check_action_str (name, &real_act)) {
+ if (!rspamd_action_from_str (name, &real_act)) {
msg_info ("invalid action string: %s", name);
res = FALSE;
}
return FALSE;
}
- if (!learn_task (session->learn_symbol, task, &err)) {
+ if (!rspamd_learn_task (session->learn_symbol, task, &err)) {
rspamd_task_free (task, FALSE);
if (err) {
if (session->restful) {
session->learn_task = task;
session->state = STATE_LEARN_SPAM;
rspamd_dispatcher_pause (session->dispatcher);
- r = process_filters (task);
+ r = rspamd_process_filters (task);
if (r == -1) {
rspamd_dispatcher_restore (session->dispatcher);
session->state = STATE_REPLY;
}
}
else {
- if (!learn_task_spam (session->learn_classifier,
+ if (!rspamd_learn_task_spam (session->learn_classifier,
session->learn_task, session->in_class, &err)) {
if (err) {
if (session->restful) {
}
struct metric_result *
-create_metric_result (struct rspamd_task *task, const gchar *name)
+rspamd_create_metric_result (struct rspamd_task *task, const gchar *name)
{
struct metric_result *metric_res;
struct metric *metric;
gdouble *weight, w;
const ucl_object_t *mobj, *sobj;
- metric_res = create_metric_result (task, metric->name);
+ metric_res = rspamd_create_metric_result (task, metric->name);
weight = g_hash_table_lookup (metric->symbols, symbol);
if (weight == NULL) {
/* Insert result that may be increased on next insertions */
void
-insert_result (struct rspamd_task *task,
+rspamd_task_insert_result (struct rspamd_task *task,
const gchar *symbol,
double flag,
GList * opts)
/* Insert result as a single option */
void
-insert_result_single (struct rspamd_task *task,
+rspamd_task_insert_result_single (struct rspamd_task *task,
const gchar *symbol,
double flag,
GList * opts)
act = ucl_object_find_key (mobj, "actions");
if (act != NULL) {
reject = ucl_object_find_key (act,
- str_action_metric (METRIC_ACTION_REJECT));
+ rspamd_action_to_str (METRIC_ACTION_REJECT));
if (reject != NULL && ucl_object_todouble_safe (reject, &val)) {
*score = val;
return TRUE;
}
gint
-process_filters (struct rspamd_task *task)
+rspamd_process_filters (struct rspamd_task *task)
{
GList *cur;
struct metric *metric;
gpointer item = NULL;
/* Insert default metric to be sure that it exists all the time */
- create_metric_result (task, DEFAULT_METRIC);
+ rspamd_create_metric_result (task, DEFAULT_METRIC);
if (task->settings) {
const ucl_object_t *wl;
s = g_list_next (s);
}
/* Add new symbol */
- insert_result_single (cd->task, key, 1.0, NULL);
+ rspamd_task_insert_result_single (cd->task, key, 1.0, NULL);
msg_info ("%s", logbuf);
}
}
}
void
-make_composites (struct rspamd_task *task)
+rspamd_make_composites (struct rspamd_task *task)
{
g_hash_table_foreach (task->results, composites_metric_callback, task);
}
void
-process_statfiles (struct rspamd_task *task)
+rspamd_process_statistics (struct rspamd_task *task)
{
struct classifiers_cbdata cbdata;
g_list_foreach (task->cfg->classifiers, classifiers_callback, &cbdata);
/* Process results */
- make_composites (task);
+ rspamd_make_composites (task);
}
void
-process_statfiles_threaded (gpointer data, gpointer user_data)
+rspamd_process_statistic_threaded (gpointer data, gpointer user_data)
{
struct rspamd_task *task = (struct rspamd_task *)data;
struct lua_locked_state *nL = user_data;
}
gboolean
-check_action_str (const gchar *data, gint *result)
+rspamd_action_from_str (const gchar *data, gint *result)
{
if (g_ascii_strncasecmp (data, "reject", sizeof ("reject") - 1) == 0) {
*result = METRIC_ACTION_REJECT;
}
const gchar *
-str_action_metric (enum rspamd_metric_action action)
+rspamd_action_to_str (enum rspamd_metric_action action)
{
switch (action) {
case METRIC_ACTION_REJECT:
if (metric) {
act = ucl_object_find_key (metric, "actions");
if (act) {
- sact = ucl_object_find_key (act, str_action_metric (action->action));
+ sact = ucl_object_find_key (act, rspamd_action_to_str (action->action));
if (sact != NULL && ucl_object_todouble_safe (sact, &score)) {
return score;
}
}
gint
-check_metric_action (struct rspamd_task *task,
+rspamd_check_action_metric (struct rspamd_task *task,
double score, double *rscore, struct metric *metric)
{
struct metric_action *action, *selected_action = NULL;
}
gboolean
-learn_task (const gchar *statfile, struct rspamd_task *task, GError **err)
+rspamd_learn_task (const gchar *statfile, struct rspamd_task *task, GError **err)
{
GList *cur, *ex;
struct rspamd_classifier_config *cl;
}
gboolean
-learn_task_spam (struct rspamd_classifier_config *cl,
+rspamd_learn_task_spam (struct rspamd_classifier_config *cl,
struct rspamd_task *task,
gboolean is_spam,
GError **err)
* @param name name of metric
* @return metric result or NULL if metric `name` has not been found
*/
-struct metric_result * create_metric_result (struct rspamd_task *task,
+struct metric_result * rspamd_create_metric_result (struct rspamd_task *task,
const gchar *name);
/**
* @param task worker's task that present message from user
* @return 0 - if there is non-finished tasks and 1 if processing is completed
*/
-gint process_filters (struct rspamd_task *task);
+gint rspamd_process_filters (struct rspamd_task *task);
/**
* Process message with statfiles
* @param task worker's task that present message from user
*/
-void process_statfiles (struct rspamd_task *task);
+void rspamd_process_statistics (struct rspamd_task *task);
/**
* Process message with statfiles threaded
* @param data worker's task that present message from user
*/
-void process_statfiles_threaded (gpointer data, gpointer user_data);
+void rspamd_process_statistic_threaded (gpointer data, gpointer user_data);
/**
* Insert a result to task
* @param flag numeric weight for symbol
* @param opts list of symbol's options
*/
-void insert_result (struct rspamd_task *task,
+void rspamd_task_insert_result (struct rspamd_task *task,
const gchar *symbol,
double flag,
GList *opts);
* @param flag numeric weight for symbol
* @param opts list of symbol's options
*/
-void insert_result_single (struct rspamd_task *task,
+void rspamd_task_insert_result_single (struct rspamd_task *task,
const gchar *symbol,
double flag,
GList *opts);
* Process all results and form composite metrics from existent metrics as it is defined in config
* @param task worker's task that present message from user
*/
-void make_composites (struct rspamd_task *task);
+void rspamd_make_composites (struct rspamd_task *task);
/**
* Default consolidation function for metric, it get all symbols and multiply symbol
* @param metric_name name of metric
* @return result metric weight
*/
-double factor_consolidation_func (struct rspamd_task *task,
+double rspamd_factor_consolidation_func (struct rspamd_task *task,
const gchar *metric_name,
const gchar *unused);
* @param err pointer to GError
* @return true if learn succeed
*/
-gboolean learn_task (const gchar *statfile,
+gboolean rspamd_learn_task (const gchar *statfile,
struct rspamd_task *task,
GError **err);
* @param err pointer to GError
* @return true if learn succeed
*/
-gboolean learn_task_spam (struct rspamd_classifier_config *cl,
+gboolean rspamd_learn_task_spam (struct rspamd_classifier_config *cl,
struct rspamd_task *task,
gboolean is_spam,
GError **err);
/*
* Get action from a string
*/
-gboolean check_action_str (const gchar *data, gint *result);
+gboolean rspamd_action_from_str (const gchar *data, gint *result);
/*
* Return textual representation of action enumeration
*/
-const gchar * str_action_metric (enum rspamd_metric_action action);
+const gchar * rspamd_action_to_str (enum rspamd_metric_action action);
/*
* Get action for specific metric
*/
-gint check_metric_action (struct rspamd_task *task,
+gint rspamd_check_action_metric (struct rspamd_task *task,
double score,
double *rscore,
struct metric *metric);
"(%s: %c (%s): [%.2f/%.2f/%.2f] [",
(gchar *)key,
is_spam ? 'T' : 'F',
- str_action_metric (action),
+ rspamd_action_to_str (action),
metric_res->score,
ms,
rs);
return FALSE;
}
while ((cur = ucl_iterate_object (val, &it, true)) != NULL) {
- if (!check_action_str (ucl_object_key (cur), &action_value) ||
+ if (!rspamd_action_from_str (ucl_object_key (cur), &action_value) ||
!ucl_object_todouble_safe (cur, &action_score)) {
g_set_error (err,
CFG_RCL_ERROR,
act_str = ucl_object_tostring (cur);
semicolon = strchr (act_str, ':');
if (semicolon != NULL) {
- if (check_action_str (act_str, &action_value)) {
+ if (rspamd_action_from_str (act_str, &action_value)) {
action_score = strtod (semicolon + 1, NULL);
action = &metric->actions[action_value];
action->action = action_value;
while ((it_val = ucl_iterate_object (cur_nm, &nit, true))) {
if (ucl_object_find_key (it_val, "name") &&
ucl_object_find_key (it_val, "value")) {
- if (!check_action_str (ucl_object_tostring (
+ if (!rspamd_action_from_str (ucl_object_tostring (
ucl_object_find_key (it_val, "name")), &test_act)) {
msg_err ("unknown action: %s",
ucl_object_tostring (ucl_object_find_key (it_val,
gdouble value)
{
ucl_object_t *metric, *acts;
- const gchar *action_name = str_action_metric (action);
+ const gchar *action_name = rspamd_action_to_str (action);
if (cfg->dynamic_conf == NULL) {
msg_info ("dynamic conf is disabled");
m = mres->metric;
/* XXX: handle settings */
- action = check_metric_action (task, mres->score, &required_score, m);
+ action = rspamd_check_action_metric (task, mres->score, &required_score, m);
is_spam = (action == METRIC_ACTION_REJECT);
if (task->is_skipped) {
action_char = 'S';
}
rspamd_printf_gstring (logbuf, "(%s: %c (%s): [%.2f/%.2f] [",
m->name, action_char,
- str_action_metric (action),
+ rspamd_action_to_str (action),
mres->score, required_score);
obj = ucl_object_typed_new (UCL_OBJECT);
ucl_object_insert_key (obj, ucl_object_fromdouble (required_score),
"required_score", 0, false);
ucl_object_insert_key (obj,
- ucl_object_fromstring (str_action_metric (action)),
+ ucl_object_fromstring (rspamd_action_to_str (action)),
"action", 0, false);
if (action == METRIC_ACTION_REWRITE_SUBJECT) {
/* Update stat for default metric */
metric_res = g_hash_table_lookup (task->results, DEFAULT_METRIC);
if (metric_res != NULL) {
- action = check_metric_action (task, metric_res->score, &required_score,
+ action = rspamd_check_action_metric (task, metric_res->score, &required_score,
metric_res->metric);
if (action <= METRIC_ACTION_NOACTION) {
task->worker->srv->stat->actions_stat[action]++;
}
else {
row->score = metric_res->score;
- row->action = check_metric_action (task, metric_res->score,
+ row->action = rspamd_check_action_metric (task, metric_res->score,
&row->required_score,
metric_res->metric);
cbdata.pos = row->symbols;
/* Process all statfiles */
if (task->classify_pool == NULL) {
/* Non-threaded version */
- process_statfiles (task);
+ rspamd_process_statistics (task);
}
else {
/* Just process composites */
- make_composites (task);
+ rspamd_make_composites (task);
}
if (task->cfg->post_filters) {
/* More to process */
}
else {
task->state = WAIT_FILTER;
- r = process_filters (task);
+ r = rspamd_process_filters (task);
if (r == -1) {
task->last_error = "Filter processing error";
task->error_code = RSPAMD_FILTER_ERROR;
}
task->skip_extra_filters = !process_extra_filters;
if (!process_extra_filters || task->cfg->pre_filters == NULL) {
- r = process_filters (task);
+ r = rspamd_process_filters (task);
if (r == -1) {
task->last_error = "filter processing error";
task->error_code = RSPAMD_FILTER_ERROR;
break;
case READ_MESSAGE:
r = process_message (lmtp->task);
- r = process_filters (lmtp->task);
+ r = rspamd_process_filters (lmtp->task);
if (r == -1) {
return FALSE;
}
rspamd_dispatcher_pause (lmtp->task->dispatcher);
}
else {
- process_statfiles (lmtp->task);
+ rspamd_process_statistics (lmtp->task);
task->state = WRITE_REPLY;
lmtp_write_socket (lmtp);
}
lua_newtable (L);
for (i = METRIC_ACTION_REJECT; i <= METRIC_ACTION_NOACTION; i++) {
- lua_pushstring (L, str_action_metric (i));
+ lua_pushstring (L, rspamd_action_to_str (i));
lua_pushinteger (L, i);
lua_settable (L, -3);
}
rspamd_mempool_strdup (task->task_pool, opt));
}
}
- insert_result (task, cd->symbol, flag, opts);
+ rspamd_task_insert_result (task, cd->symbol, flag, opts);
}
}
lua_pop (cd->L, nresults);
rspamd_mempool_strdup (task->task_pool, param));
}
- insert_result (task, symbol_name, flag, params);
+ rspamd_task_insert_result (task, symbol_name, flag, params);
}
return 0;
}
ret = 2;
}
else {
- if (!learn_task_spam (cl, task, is_spam, &err)) {
+ if (!rspamd_learn_task_spam (cl, task, is_spam, &err)) {
lua_pushboolean (L, FALSE);
if (err != NULL) {
lua_pushstring (L, err->message);
if (task && metric_name) {
if ((metric_res =
g_hash_table_lookup (task->results, metric_name)) != NULL) {
- action = check_metric_action (task, metric_res->score,
+ action = rspamd_check_action_metric (task, metric_res->score,
NULL,
metric_res->metric);
- lua_pushstring (L, str_action_metric (action));
+ lua_pushstring (L, rspamd_action_to_str (action));
}
else {
lua_pushnil (L);
while (cur) {
part = cur->data;
if (!part->is_empty && check_part (part, task->cfg->raw_mode)) {
- insert_result (task, chartable_module_ctx->symbol, 1, NULL);
+ rspamd_task_insert_result (task, chartable_module_ctx->symbol, 1, NULL);
}
cur = g_list_next (cur);
}
}
if (res == DKIM_REJECT) {
- insert_result (task, dkim_module_ctx->symbol_reject, score_deny, NULL);
+ rspamd_task_insert_result (task, dkim_module_ctx->symbol_reject, score_deny, NULL);
}
else if (res == DKIM_TRYAGAIN) {
- insert_result (task, dkim_module_ctx->symbol_tempfail, 1, NULL);
+ rspamd_task_insert_result (task, dkim_module_ctx->symbol_tempfail, 1, NULL);
}
else if (res == DKIM_CONTINUE) {
- insert_result (task, dkim_module_ctx->symbol_allow, score_allow, NULL);
+ rspamd_task_insert_result (task, dkim_module_ctx->symbol_allow, score_allow, NULL);
}
}
/* Insert tempfail symbol */
msg_info ("cannot get key for domain %s", ctx->dns_key);
if (err != NULL) {
- insert_result (task, dkim_module_ctx->symbol_tempfail, 1,
+ rspamd_task_insert_result (task, dkim_module_ctx->symbol_tempfail, 1,
g_list_prepend (NULL,
rspamd_mempool_strdup (task->task_pool, err->message)));
}
else {
- insert_result (task, dkim_module_ctx->symbol_tempfail, 1, NULL);
+ rspamd_task_insert_result (task, dkim_module_ctx->symbol_tempfail, 1, NULL);
}
}
flag,
value,
nval);
- insert_result_single (session->task,
+ rspamd_task_insert_result_single (session->task,
symbol,
nval,
g_list_prepend (NULL,
if (process_regexp_expression (ud->item->expr, ud->item->symbol, ud->task,
NULL, nL)) {
g_mutex_lock (workers_mtx);
- insert_result (ud->task, ud->item->symbol, 1, NULL);
+ rspamd_task_insert_result (ud->task, ud->item->symbol, 1, NULL);
g_mutex_unlock (workers_mtx);
}
remove_async_thread (ud->task->s);
/* Just call function */
if (rspamd_lua_call_expression_func (item->lua_function, task, NULL,
&res) && res) {
- insert_result (task, item->symbol, 1, NULL);
+ rspamd_task_insert_result (task, item->symbol, 1, NULL);
}
}
else {
/* Process expression */
if (process_regexp_expression (item->expr, item->symbol, task, NULL,
NULL)) {
- insert_result (task, item->symbol, 1, NULL);
+ rspamd_task_insert_result (task, item->symbol, 1, NULL);
}
}
}
if (res) {
switch (addr->mech) {
case SPF_FAIL:
- insert_result (task,
+ rspamd_task_insert_result (task,
spf_module_ctx->symbol_fail,
1,
g_list_prepend (NULL, addr->spf_string));
break;
case SPF_SOFT_FAIL:
case SPF_NEUTRAL:
- insert_result (task,
+ rspamd_task_insert_result (task,
spf_module_ctx->symbol_softfail,
1,
g_list_prepend (NULL, addr->spf_string));
"(SPF): spf softfail");
break;
default:
- insert_result (task,
+ rspamd_task_insert_result (task,
spf_module_ctx->symbol_allow,
1,
g_list_prepend (NULL, addr->spf_string));
(gint)ntohl (bit->bit),
(gint)bit->bit & (gint)ntohl (addr));
if (((gint)bit->bit & (gint)ntohl (addr)) != 0) {
- insert_result (task, bit->symbol, 1,
+ rspamd_task_insert_result (task, bit->symbol, 1,
g_list_prepend (NULL,
rspamd_mempool_strdup (task->task_pool, url)));
}
}
}
else {
- insert_result (task, suffix->symbol, 1,
+ rspamd_task_insert_result (task, suffix->symbol, 1,
g_list_prepend (NULL,
rspamd_mempool_strdup (task->task_pool, url)));
}
g_regex_match (re, url->string, 0, NULL))) {
/* If no regexp found or founded regexp matches url string register redirector's call */
if (surbl_module_ctx->redirector_symbol != NULL) {
- insert_result (param->task,
+ rspamd_task_insert_result (param->task,
surbl_module_ctx->redirector_symbol,
1,
g_list_prepend (NULL, red_domain));
goto err;
}
if (session->task->cfg->pre_filters == NULL) {
- r = process_filters (session->task);
+ r = rspamd_process_filters (session->task);
if (r == -1) {
msg_err ("cannot process message");
munmap (session->task->msg->str, st.st_size);
ctx->classify_pool = NULL;
if (ctx->classify_threads > 1) {
nL = rspamd_init_lua_locked (worker->srv->cfg);
- ctx->classify_pool = g_thread_pool_new (process_statfiles_threaded,
+ ctx->classify_pool = g_thread_pool_new (rspamd_process_statistic_threaded,
nL,
ctx->classify_threads,
TRUE,