#include "contrib/uthash/utlist.h"
-#define COMMON_PART_FACTOR 95
-
struct rspamd_metric_result *
rspamd_create_metric_result (struct rspamd_task *task)
{
}
metric_res = rspamd_mempool_alloc (task->task_pool,
- sizeof (struct rspamd_metric_result));
+ sizeof (struct rspamd_metric_result));
metric_res->symbols = g_hash_table_new (rspamd_str_hash,
rspamd_str_equal);
rspamd_mempool_add_destructor (task->task_pool,
if (gr != NULL && group_score && gr->max_score > 0.0 && w > 0.0) {
if (*group_score >= gr->max_score && w > 0) {
msg_info_task ("maximum group score %.2f for group %s has been reached,"
- " ignoring symbol %s with weight %.2f", gr->max_score,
+ " ignoring symbol %s with weight %.2f", gr->max_score,
gr->name, symbol, w);
return NAN;
}
static struct rspamd_symbol_result *
insert_metric_result (struct rspamd_task *task,
- const gchar *symbol,
- double flag,
- const gchar *opt,
- gboolean single)
+ const gchar *symbol,
+ double flag,
+ const gchar *opt,
+ enum rspamd_symbol_insert_flags flags)
{
struct rspamd_metric_result *metric_res;
struct rspamd_symbol_result *s = NULL;
struct rspamd_symbols_group *gr = NULL;
const ucl_object_t *mobj, *sobj;
gint max_shots;
+ gboolean single = !!(flags & RSPAMD_SYMBOL_INSERT_SINGLE);
metric_res = rspamd_create_metric_result (task);
sdef = g_hash_table_lookup (task->cfg->symbols, symbol);
if (sdef == NULL) {
- w = 0.0;
+ if (flags & RSPAMD_SYMBOL_INSERT_ENFORCE) {
+ w = 1.0 * flag; /* Enforce static weight to 1.0 */
+ }
+ else {
+ w = 0.0;
+ }
}
else {
w = (*sdef->weight_ptr) * flag;
return s;
}
-static struct rspamd_symbol_result *
-insert_result_common (struct rspamd_task *task,
- const gchar *symbol,
- double flag,
- const gchar *opt,
- gboolean single)
+struct rspamd_symbol_result *
+rspamd_task_insert_result_full (struct rspamd_task *task,
+ const gchar *symbol,
+ double flag,
+ const gchar *opt,
+ enum rspamd_symbol_insert_flags flags)
{
struct rspamd_symbol_result *s = NULL;
if (task->processed_stages & (RSPAMD_TASK_STAGE_IDEMPOTENT >> 1)) {
msg_err_task ("cannot insert symbol %s on idempotent phase",
- symbol);
+ symbol);
return NULL;
}
symbol,
flag,
opt,
- single);
+ flags);
/* Process cache item */
if (task->cfg->cache) {
return s;
}
-/* Insert result that may be increased on next insertions */
-struct rspamd_symbol_result *
-rspamd_task_insert_result (struct rspamd_task *task,
- const gchar *symbol,
- double flag,
- const gchar *opt)
-{
- return insert_result_common (task, symbol, flag, opt,
- FALSE);
-}
-
-/* Insert result as a single option */
-struct rspamd_symbol_result *
-rspamd_task_insert_result_single (struct rspamd_task *task,
- const gchar *symbol,
- double flag,
- const gchar *opt)
-{
- return insert_result_common (task, symbol, flag, opt, TRUE);
-}
-
gboolean
rspamd_task_add_result_option (struct rspamd_task *task,
struct rspamd_symbol_result *s, const gchar *val)
*/
struct rspamd_metric_result * rspamd_create_metric_result (struct rspamd_task *task);
+enum rspamd_symbol_insert_flags {
+ RSPAMD_SYMBOL_INSERT_DEFAULT = 0,
+ RSPAMD_SYMBOL_INSERT_SINGLE = (1 << 0),
+ RSPAMD_SYMBOL_INSERT_ENFORCE = (1 << 1),
+};
+
/**
* Insert a result to task
* @param task worker's task that present message from user
* @param flag numeric weight for symbol
* @param opts list of symbol's options
*/
-struct rspamd_symbol_result* rspamd_task_insert_result (struct rspamd_task *task,
+struct rspamd_symbol_result* rspamd_task_insert_result_full (struct rspamd_task *task,
const gchar *symbol,
double flag,
- const gchar *opts);
+ const gchar *opts,
+ enum rspamd_symbol_insert_flags flags);
-/**
- * Insert a single result to task
- * @param task worker's task that present message from user
- * @param metric_name metric's name to which we need to insert result
- * @param symbol symbol to insert
- * @param flag numeric weight for symbol
- * @param opts list of symbol's options
- */
-struct rspamd_symbol_result* rspamd_task_insert_result_single (struct rspamd_task *task,
- const gchar *symbol,
- double flag,
- const gchar *opts);
+#define rspamd_task_insert_result_single(task, symbol, flag, opts) \
+ rspamd_task_insert_result_full (task, symbol, flag, opts, RSPAMD_SYMBOL_INSERT_SINGLE)
+#define rspamd_task_insert_result(task, symbol, flag, opts) \
+ rspamd_task_insert_result_full (task, symbol, flag, opts, RSPAMD_SYMBOL_INSERT_DEFAULT)
/**
*/
LUA_FUNCTION_DEF (task, get_worker);
/***
- * @method task:insert_result(symbol, weight[, option1, ...])
+ * @method task:insert_result([enforce_symbol,]symbol, weight[, option1, ...])
* Insert specific symbol to the tasks scanning results assigning the initial
* weight to it.
+ * @param {boolean} enforce_symbol if represented and true, then insert symbol even if it is not registered in the metric
* @param {string} symbol symbol to insert
* @param {number} weight initial weight (this weight is multiplied by the metric weight)
* @param {string} options list of optional options attached to a symbol inserted