return TRUE;
}
+gboolean
+rspamd_mmaped_file_dec_revision (rspamd_mmaped_file_t *file)
+{
+ struct stat_file_header *header;
+
+ if (file == NULL || file->map == NULL) {
+ return FALSE;
+ }
+
+ header = (struct stat_file_header *)file->map;
+
+ header->revision--;
+
+ return TRUE;
+}
+
+
gboolean
rspamd_mmaped_file_get_revision (rspamd_mmaped_file_t *file, guint64 *rev, time_t *time)
{
memcpy (&h2, tok->data + sizeof (h1), sizeof (h2));
rspamd_mmaped_file_set_block (ctx, mf, h1, h2, res->value);
- if (res->value > 0.0) {
- return TRUE;
- }
-
- return FALSE;
+ return TRUE;
}
gulong
return rev;
}
+gulong
+rspamd_mmaped_file_dec_learns (struct rspamd_statfile_runtime *runtime,
+ gpointer ctx)
+{
+ rspamd_mmaped_file_t *mf = (rspamd_mmaped_file_t *)runtime;
+ guint64 rev = 0;
+ time_t t;
+
+ if (mf != NULL) {
+ rspamd_mmaped_file_dec_revision (mf);
+ rspamd_mmaped_file_get_revision (mf, &rev, &t);
+ }
+
+ return rev;
+}
+
+
ucl_object_t *
rspamd_mmaped_file_get_stat (struct rspamd_statfile_runtime *runtime,
gpointer ctx)
#include "lua/lua_common.h"
#include <utlist.h>
+#define RSPAMD_CLASSIFY_OP 0
+#define RSPAMD_LEARN_OP 1
+#define RSPAMD_UNLEARN_OP 2
+
struct preprocess_cb_data {
struct rspamd_task *task;
GList *classifier_runtimes;
struct rspamd_tokenizer_runtime *tok;
guint results_count;
gboolean unlearn;
+ gboolean spam;
};
static struct rspamd_tokenizer_runtime *
static GList*
rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx,
struct rspamd_task *task, struct rspamd_tokenizer_runtime *tklist,
- lua_State *L, gboolean learn, gboolean spam, GError **err)
+ lua_State *L, gint op, gboolean spam, GError **err)
{
struct rspamd_classifier_config *clcf;
struct rspamd_statfile_config *stcf;
stcf = (struct rspamd_statfile_config *)curst->data;
/* On learning skip statfiles that do not belong to class */
- if (learn && (spam != stcf->is_spam)) {
+ if (op == RSPAMD_LEARN_OP && (spam != stcf->is_spam)) {
curst = g_list_next (curst);
continue;
}
continue;
}
- backend_runtime = bk->runtime (stcf, learn, bk->ctx);
+ backend_runtime = bk->runtime (stcf, op != RSPAMD_CLASSIFY_OP,
+ bk->ctx);
st_runtime = rspamd_mempool_alloc0 (task->task_pool,
sizeof (*st_runtime));
/* Initialize classifiers and statfiles runtime */
if ((cl_runtimes = rspamd_stat_preprocess (st_ctx, task, tklist, L,
- FALSE, FALSE, err)) == NULL) {
+ RSPAMD_CLASSIFY_OP, FALSE, err)) == NULL) {
return RSPAMD_STAT_PROCESS_ERROR;
}
continue;
}
- res = &g_array_index (t->results, struct rspamd_token_result, i);
- curst = res->cl_runtime->st_runtime;
+
+ curst = cl_runtime->st_runtime;
while (curst) {
+ res = &g_array_index (t->results, struct rspamd_token_result, i);
st_runtime = (struct rspamd_statfile_runtime *)curst->data;
if (st_runtime->backend->learn_token (t, res,
i ++;
curst = g_list_next (curst);
}
+
cur = g_list_next (cur);
}
/* Initialize classifiers and statfiles runtime */
if ((cl_runtimes = rspamd_stat_preprocess (st_ctx, task, tklist, L,
- TRUE, spam, err)) == NULL) {
+ unlearn ? RSPAMD_UNLEARN_OP : RSPAMD_LEARN_OP, spam, err)) == NULL) {
return RSPAMD_STAT_PROCESS_ERROR;
}
cbdata.task = task;
cbdata.tok = cl_run->tok;
cbdata.unlearn = unlearn;
+ cbdata.spam = spam;
g_tree_foreach (cl_run->tok->tokens, rspamd_stat_learn_token,
&cbdata);
while (curst) {
st_run = (struct rspamd_statfile_runtime *)curst->data;
- nrev = st_run->backend->inc_learns (st_run->backend_runtime,
+ if (unlearn && spam != st_run->st->is_spam) {
+ nrev = st_run->backend->dec_learns (st_run->backend_runtime,
+ st_run->backend->ctx);
+ msg_debug ("unlearned %s, new revision: %ul",
+ st_run->st->symbol, nrev);
+ }
+ else {
+ nrev = st_run->backend->inc_learns (st_run->backend_runtime,
st_run->backend->ctx);
-
- msg_debug ("learned %s, new revision: %ul",
+ msg_debug ("learned %s, new revision: %ul",
st_run->st->symbol, nrev);
+ }
curst = g_list_next (curst);
}