aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstat/classifiers
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-06 17:43:17 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-06 18:13:04 +0100
commit34e24051282cab18f3da7a55d247bf61448defda (patch)
treef564f8ac8ab1b43eb61d6c121818f06c0b57a8f8 /src/libstat/classifiers
parent11332ebba77d12d62dcc13966ea24379c2ee94b4 (diff)
downloadrspamd-34e24051282cab18f3da7a55d247bf61448defda.tar.gz
rspamd-34e24051282cab18f3da7a55d247bf61448defda.zip
[Feature] Add a generic lua classifier
Diffstat (limited to 'src/libstat/classifiers')
-rw-r--r--src/libstat/classifiers/bayes.c4
-rw-r--r--src/libstat/classifiers/classifiers.h18
-rw-r--r--src/libstat/classifiers/lua_classifier.c46
3 files changed, 65 insertions, 3 deletions
diff --git a/src/libstat/classifiers/bayes.c b/src/libstat/classifiers/bayes.c
index 5ebba8d56..40dcdf36f 100644
--- a/src/libstat/classifiers/bayes.c
+++ b/src/libstat/classifiers/bayes.c
@@ -185,10 +185,12 @@ bayes_normalize_prob (gdouble x)
return a*x4 + b*x3 + c*x2 + d*xx;
}
-void
+gboolean
bayes_init (rspamd_mempool_t *pool, struct rspamd_classifier *cl)
{
cl->cfg->flags |= RSPAMD_FLAG_CLASSIFIER_INTEGER;
+
+ return TRUE;
}
gboolean
diff --git a/src/libstat/classifiers/classifiers.h b/src/libstat/classifiers/classifiers.h
index 6bafa8507..e30f2153a 100644
--- a/src/libstat/classifiers/classifiers.h
+++ b/src/libstat/classifiers/classifiers.h
@@ -16,7 +16,7 @@ struct token_node_s;
struct rspamd_stat_classifier {
char *name;
- void (*init_func)(rspamd_mempool_t *pool,
+ gboolean (*init_func)(rspamd_mempool_t *pool,
struct rspamd_classifier *cl);
gboolean (*classify_func)(struct rspamd_classifier * ctx,
GPtrArray *tokens,
@@ -30,7 +30,7 @@ struct rspamd_stat_classifier {
};
/* Bayes algorithm */
-void bayes_init (rspamd_mempool_t *pool,
+gboolean bayes_init (rspamd_mempool_t *pool,
struct rspamd_classifier *);
gboolean bayes_classify (struct rspamd_classifier *ctx,
GPtrArray *tokens,
@@ -42,6 +42,20 @@ gboolean bayes_learn_spam (struct rspamd_classifier *ctx,
gboolean unlearn,
GError **err);
+/* Generic lua classifier */
+gboolean lua_classifier_init (rspamd_mempool_t *pool,
+ struct rspamd_classifier *);
+gboolean lua_classifier_classify (struct rspamd_classifier *ctx,
+ GPtrArray *tokens,
+ struct rspamd_task *task);
+gboolean lua_classifier_learn_spam (struct rspamd_classifier *ctx,
+ GPtrArray *tokens,
+ struct rspamd_task *task,
+ gboolean is_spam,
+ gboolean unlearn,
+ GError **err);
+
+
#endif
/*
* vi:ts=4
diff --git a/src/libstat/classifiers/lua_classifier.c b/src/libstat/classifiers/lua_classifier.c
new file mode 100644
index 000000000..dea0f6a24
--- /dev/null
+++ b/src/libstat/classifiers/lua_classifier.c
@@ -0,0 +1,46 @@
+/*-
+ * Copyright 2016 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "classifiers.h"
+#include "cfg_file.h"
+#include "stat_internal.h"
+
+gboolean
+lua_classifier_init (rspamd_mempool_t *pool,
+ struct rspamd_classifier *cl)
+{
+ cl->cfg->flags |= RSPAMD_FLAG_CLASSIFIER_NO_BACKEND;
+
+ return TRUE;
+}
+gboolean
+lua_classifier_classify (struct rspamd_classifier *ctx,
+ GPtrArray *tokens,
+ struct rspamd_task *task)
+{
+ return TRUE;
+}
+
+gboolean
+lua_classifier_learn_spam (struct rspamd_classifier *ctx,
+ GPtrArray *tokens,
+ struct rspamd_task *task,
+ gboolean is_spam,
+ gboolean unlearn,
+ GError **err)
+{
+ return TRUE;
+}