rspamd_set_counter_ema (&symbols_count, kh_size (r->symbols), 0.5);
+ if (r->symbol_cbref != -1) {
+ luaL_unref (r->task->cfg->lua_state, LUA_REGISTRYINDEX, r->symbol_cbref);
+ }
+
kh_foreach_value (r->symbols, sres, {
if (sres.options) {
kh_destroy (rspamd_options_hash, sres.options);
}
struct rspamd_scan_result *
-rspamd_create_metric_result (struct rspamd_task *task)
+rspamd_create_metric_result (struct rspamd_task *task,
+ const gchar *name, gint lua_sym_cbref)
{
struct rspamd_scan_result *metric_res;
guint i;
- metric_res = task->result;
-
- if (metric_res != NULL) {
- return metric_res;
- }
-
metric_res = rspamd_mempool_alloc0 (task->task_pool,
sizeof (struct rspamd_scan_result));
metric_res->symbols = kh_init (rspamd_symbols_hash);
metric_res->sym_groups = kh_init (rspamd_symbols_group_hash);
+ metric_res->name = name;
+ metric_res->symbol_cbref = lua_sym_cbref;
+ metric_res->task = task;
/* Optimize allocation */
kh_resize (rspamd_symbols_group_hash, metric_res->sym_groups, 4);
rspamd_mempool_add_destructor (task->task_pool,
rspamd_scan_result_dtor,
metric_res);
+ DL_APPEND (task->result, metric_res);
return metric_res;
}
struct rspamd_symbol_option *opts_head; /**< head of linked list of options */
const gchar *name;
struct rspamd_symbol *sym; /**< symbol configuration */
- gssize opts_len; /**< total size of all options (negative if truncated option is added) */
+ gssize opts_len; /**< total size of all options (negative if truncated option is added) */
guint nshots;
enum rspamd_symbol_result_flags flags;
};
double score; /**< total score */
double grow_factor; /**< current grow factor */
struct rspamd_passthrough_result *passthrough_result;
- guint npositive;
- guint nnegative;
double positive_score;
double negative_score;
struct kh_rspamd_symbols_hash_s *symbols; /**< symbols of metric */
struct kh_rspamd_symbols_group_hash_s *sym_groups; /**< groups of symbols */
struct rspamd_action_result *actions_limits;
+ const gchar *name; /**< for named results, NULL is the default result */
+ struct rspamd_task *task; /**< back reference */
+ gint symbol_cbref; /**< lua function that defines if a symbol can be inserted, -1 if unused */
guint nactions;
+ guint npositive;
+ guint nnegative;
+ struct rspamd_scan_result *prev, *next; /**< double linked list of results */
};
/**
* @param task task object
* @return metric result or NULL if metric `name` has not been found
*/
-struct rspamd_scan_result *rspamd_create_metric_result (struct rspamd_task *task);
+struct rspamd_scan_result *rspamd_create_metric_result (struct rspamd_task *task,
+ const gchar *name, gint lua_sym_cbref);
/**
* Adds a new passthrough result to a task
new_task->request_headers = kh_init (rspamd_req_headers_hash);
new_task->sock = -1;
new_task->flags |= (RSPAMD_TASK_FLAG_MIME);
- new_task->result = rspamd_create_metric_result (new_task);
+ /* Default results chain */
+ rspamd_create_metric_result (new_task, NULL, -1);
new_task->queue_id = "undef";
new_task->messages = ucl_object_typed_new (UCL_OBJECT);