symbol_str = (const gchar *)sym_arg->data;
- if (rspamd_task_find_symbol_result (task, symbol_str)) {
+ if (rspamd_task_find_symbol_result (task, symbol_str, NULL)) {
return TRUE;
}
return noaction->action;
}
-struct rspamd_symbol_result*
-rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym)
+struct rspamd_symbol_result *
+rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym,
+ struct rspamd_scan_result *result)
{
struct rspamd_symbol_result *res = NULL;
khiter_t k;
+ if (result == NULL) {
+ /* Use default result */
+ result = task->result;
+ }
- if (task->result) {
- k = kh_get (rspamd_symbols_hash, task->result->symbols, sym);
+ k = kh_get (rspamd_symbols_hash, result->symbols, sym);
- if (k != kh_end (task->result->symbols)) {
- res = &kh_value (task->result->symbols, k);
- }
+ if (k != kh_end (result->symbols)) {
+ res = &kh_value (result->symbols, k);
}
return res;
void
rspamd_task_symbol_result_foreach (struct rspamd_task *task,
- GHFunc func,
- gpointer ud)
+ struct rspamd_scan_result *result, GHFunc func,
+ gpointer ud)
{
const gchar *kk;
struct rspamd_symbol_result res;
- if (func && task->result) {
- kh_foreach (task->result->symbols, kk, res, {
+ if (result == NULL) {
+ /* Use default result */
+ result = task->result;
+ }
+
+ if (func) {
+ kh_foreach (result->symbols, kk, res, {
func ((gpointer)kk, (gpointer)&res, ud);
});
}
* @param sym
* @return
*/
-struct rspamd_symbol_result *rspamd_task_find_symbol_result (
- struct rspamd_task *task, const char *sym);
+struct rspamd_symbol_result *
+rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym,
+ struct rspamd_scan_result *result);
/**
* Compatibility function to iterate on symbols hash
* @param func
* @param ud
*/
-void rspamd_task_symbol_result_foreach (struct rspamd_task *task,
- GHFunc func,
+void rspamd_task_symbol_result_foreach (struct rspamd_task *task, struct rspamd_scan_result *result, GHFunc func,
gpointer ud);
/**
struct rspamd_composite *ncomp;
struct rspamd_task *task = cd->task;
- if ((ms = rspamd_task_find_symbol_result (cd->task, sym)) == NULL) {
+ if ((ms = rspamd_task_find_symbol_result (cd->task, sym, NULL)) == NULL) {
msg_debug_composites ("not found symbol %s in composite %s", sym,
cd->composite->sym);
if ((ncomp =
cd->composite = saved;
clrbit (cd->checked, cd->composite->id * 2);
- ms = rspamd_task_find_symbol_result (cd->task, sym);
+ ms = rspamd_task_find_symbol_result (cd->task, sym, NULL);
}
else {
/*
* XXX: in case of cyclic references this would return 0
*/
if (isset (cd->checked, ncomp->id * 2 + 1)) {
- ms = rspamd_task_find_symbol_result (cd->task, sym);
+ ms = rspamd_task_find_symbol_result (cd->task, sym, NULL);
}
}
}
if (isset (cd->checked, cd->composite->id * 2)) {
/* We have already checked this composite, so just return its value */
if (isset (cd->checked, cd->composite->id * 2 + 1)) {
- ms = rspamd_task_find_symbol_result (cd->task, sym);
+ ms = rspamd_task_find_symbol_result (cd->task, sym, NULL);
}
if (ms) {
clrbit (cd->checked, comp->id * 2 + 1);
}
else {
- if (rspamd_task_find_symbol_result (cd->task, key) != NULL) {
+ if (rspamd_task_find_symbol_result (cd->task, key, NULL) != NULL) {
/* Already set, no need to check */
msg_debug_composites ("composite %s is already in metric "
"in composites bitfield", cd->composite->sym);
}
}
- ms = rspamd_task_find_symbol_result (task, rd->sym);
+ ms = rspamd_task_find_symbol_result (task, rd->sym, NULL);
if (has_valid_op && ms && !(ms->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {
row->required_score = rspamd_task_get_required_score (task, metric_res);
cbdata.pos = row->symbols;
cbdata.remain = sizeof (row->symbols);
- rspamd_task_symbol_result_foreach (task,
+ rspamd_task_symbol_result_foreach (task, NULL,
roll_history_symbols_callback,
&cbdata);
if (cbdata.remain > 0) {
id = g_array_index (cl->statfiles_ids, gint, i);
st = g_ptr_array_index (st_ctx->statfiles, id);
- if (rspamd_task_find_symbol_result (task, st->stcf->symbol)) {
+ if (rspamd_task_find_symbol_result (task, st->stcf->symbol, NULL)) {
if (is_spam == !!st->stcf->is_spam) {
msg_debug_bayes ("do not autolearn %s as symbol %s is already "
"added", is_spam ? "spam" : "ham", st->stcf->symbol);
metric_res = task->result;
if (metric_res) {
- s = rspamd_task_find_symbol_result (task, symbol_name);
+ s = rspamd_task_find_symbol_result (task, symbol_name, NULL);
}
else {
return luaL_error (L, "no metric result");
metric_res = task->result;
if (metric_res) {
- s = rspamd_task_find_symbol_result (task, symbol);
+ s = rspamd_task_find_symbol_result (task, symbol, NULL);
}
}
else {
symbol = luaL_checkstring (L, 2);
if (task && symbol) {
- found = (rspamd_task_find_symbol_result (task, symbol) != NULL);
+ found = (rspamd_task_find_symbol_result (task, symbol, NULL) != NULL);
lua_pushboolean (L, found);
}
else {
return;
}
- if ((s = rspamd_task_find_symbol_result (cbd->task, sym)) != NULL) {
+ if ((s = rspamd_task_find_symbol_result (cbd->task, sym, NULL)) != NULL) {
if (s->flags & RSPAMD_SYMBOL_RESULT_IGNORED) {
lua_pushnumber (cbd->L, 0.0);
}
*
* That would lead to N_results lookups which is usually MUCH smaller
*/
- sres = rspamd_task_find_symbol_result (task, sym);
+ sres = rspamd_task_find_symbol_result (task, sym, NULL);
if (sres && !(sres->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {