aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-01-23 16:26:55 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-01-23 16:26:55 +0000
commit82612bf153debaff5a11e5542caca454e921eeaf (patch)
treeda3a5c9e7fcb90855543af1d36b0d437c88a960e /src
parent2b1f046085b35e685fad03a88c827eee1f483093 (diff)
downloadrspamd-82612bf153debaff5a11e5542caca454e921eeaf.tar.gz
rspamd-82612bf153debaff5a11e5542caca454e921eeaf.zip
Refactor structures names.
Diffstat (limited to 'src')
-rw-r--r--src/libserver/cfg_file.h2
-rw-r--r--src/libstat/CMakeLists.txt12
-rw-r--r--src/libstat/backends/backends.h5
-rw-r--r--src/libstat/backends/mmaped_file.c4
-rw-r--r--src/libstat/classifiers/classifiers.h2
-rw-r--r--src/libstat/stat_api.h6
-rw-r--r--src/libstat/stat_config.c81
-rw-r--r--src/libstat/stat_internal.h16
-rw-r--r--src/main.h2
9 files changed, 110 insertions, 20 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 23e785443..611f1c371 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -18,7 +18,7 @@
struct expression;
struct tokenizer;
-struct classifier;
+struct rspamd_stat_classifier;
enum { VAL_UNDEF=0, VAL_TRUE, VAL_FALSE };
diff --git a/src/libstat/CMakeLists.txt b/src/libstat/CMakeLists.txt
index 97725d2f9..17c553989 100644
--- a/src/libstat/CMakeLists.txt
+++ b/src/libstat/CMakeLists.txt
@@ -1,11 +1,13 @@
# Librspamdserver
-SET(LIBSTATSRC stat_config.c)
-SET(TOKENIZERSSRC tokenizers/tokenizers.c
- tokenizers/osb.c)
+SET(LIBSTATSRC stat_config.c
+ stat_process.c)
-SET(CLASSIFIERSSRC classifiers/bayes.c)
+SET(TOKENIZERSSRC tokenizers/tokenizers.c
+ tokenizers/osb.c)
+
+SET(CLASSIFIERSSRC classifiers/bayes.c)
-SET(BACKENDSSRC backends/mmaped_file.c)
+SET(BACKENDSSRC backends/mmaped_file.c)
ADD_LIBRARY(rspamd-stat ${LINK_TYPE} ${LIBSTATSRC}
${TOKENIZERSSRC}
diff --git a/src/libstat/backends/backends.h b/src/libstat/backends/backends.h
index 37a7560cd..45a8cd314 100644
--- a/src/libstat/backends/backends.h
+++ b/src/libstat/backends/backends.h
@@ -33,13 +33,14 @@
struct rspamd_classifier_config;
struct rspamd_statfile_config;
struct rspamd_config;
+struct rspamd_stat_ctx;
struct rspamd_stat_backend {
const char *name;
- gpointer (*init)(struct rspamd_statfile_config *cfg);
+ gpointer (*init)(struct rspamd_stat_ctx *ctx, struct rspamd_config *cfg);
gpointer ctx;
};
-gpointer rspamd_mmaped_file_init(struct rspamd_config *cfg);
+gpointer rspamd_mmaped_file_init(struct rspamd_stat_ctx *ctx, struct rspamd_config *cfg);
#endif /* BACKENDS_H_ */
diff --git a/src/libstat/backends/mmaped_file.c b/src/libstat/backends/mmaped_file.c
index cef17f465..49f4d5ba4 100644
--- a/src/libstat/backends/mmaped_file.c
+++ b/src/libstat/backends/mmaped_file.c
@@ -801,7 +801,7 @@ rspamd_mmaped_file_get_total (rspamd_mmaped_file_t *file)
}
gpointer
-rspamd_mmaped_file_init (struct rspamd_config *cfg)
+rspamd_mmaped_file_init (struct rspamd_stat_ctx *ctx, struct rspamd_config *cfg)
{
rspamd_mmaped_file_ctx *new;
struct rspamd_classifier_config *clf;
@@ -852,6 +852,8 @@ rspamd_mmaped_file_init (struct rspamd_config *cfg)
size = ucl_object_toint (sizeo);
rspamd_mmaped_file_open (new, filename, size);
+
+ ctx->statfiles ++;
}
curst = curst->next;
diff --git a/src/libstat/classifiers/classifiers.h b/src/libstat/classifiers/classifiers.h
index 4ae1ba23d..6a77f5aed 100644
--- a/src/libstat/classifiers/classifiers.h
+++ b/src/libstat/classifiers/classifiers.h
@@ -17,7 +17,7 @@ struct classifier_ctx {
struct rspamd_classifier_config *cfg;
};
-struct classifier {
+struct rspamd_stat_classifier {
char *name;
struct classifier_ctx * (*init_func)(rspamd_mempool_t *pool,
struct rspamd_classifier_config *cf);
diff --git a/src/libstat/stat_api.h b/src/libstat/stat_api.h
index 0e2bf86b8..2dbf19372 100644
--- a/src/libstat/stat_api.h
+++ b/src/libstat/stat_api.h
@@ -25,6 +25,7 @@
#include "config.h"
#include "task.h"
+#include <lua.h>
/**
* @file stat_api.h
@@ -42,7 +43,7 @@ void rspamd_stat_init (struct rspamd_config *cfg);
* @param task
* @return TRUE if task has been classified
*/
-gboolean rspamd_stat_classify (struct rspamd_task *task, GError **err);
+gboolean rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err);
/**
@@ -51,7 +52,8 @@ gboolean rspamd_stat_classify (struct rspamd_task *task, GError **err);
* @param spam if TRUE learn spam, otherwise learn ham
* @return TRUE if task has been learned
*/
-gboolean rspamd_stat_learn (struct rspamd_task *task, gboolean spam, GError **err);
+gboolean rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L,
+ GError **err);
void rspamd_stat_unload (void);
diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c
index a539f3c80..cd25ad0c5 100644
--- a/src/libstat/stat_config.c
+++ b/src/libstat/stat_config.c
@@ -28,11 +28,10 @@
#include "main.h"
#include "cfg_rcl.h"
#include "stat_internal.h"
-#include "backends/mmaped_file.h"
static struct rspamd_stat_ctx *stat_ctx = NULL;
-static struct classifier classifiers[] = {
+static struct rspamd_stat_classifier stat_classifiers[] = {
{
.name = "bayes",
.init_func = bayes_init,
@@ -41,11 +40,11 @@ static struct classifier classifiers[] = {
}
};
-static struct tokenizer tokenizers[] = {
- {"osb-text", osb_tokenize_text, rspamd_tokenizer_get_word},
+static struct rspamd_stat_tokenizer stat_tokenizers[] = {
+ {"osb-text", osb_tokenize_text},
};
-struct rspamd_stat_backend statfile_backends[] = {
+struct rspamd_stat_backend stat_backends[] = {
{
.name = RSPAMD_DEFAULT_BACKEND,
.init = rspamd_mmaped_file_init,
@@ -56,5 +55,77 @@ struct rspamd_stat_backend statfile_backends[] = {
void
rspamd_stat_init (struct rspamd_config *cfg)
{
+ guint i;
+ if (stat_ctx == NULL) {
+ stat_ctx = g_slice_alloc0 (sizeof (*stat_ctx));
+ }
+
+ stat_ctx->backends = stat_backends;
+ stat_ctx->backends_count = G_N_ELEMENTS (stat_backends);
+ stat_ctx->classifiers = stat_classifiers;
+ stat_ctx->classifiers_count = G_N_ELEMENTS (stat_classifiers);
+ stat_ctx->tokenizers = stat_tokenizers;
+ stat_ctx->tokenizers_count = G_N_ELEMENTS (stat_tokenizers);
+
+ /* Init backends */
+ for (i = 0; i < stat_ctx->backends_count; i ++) {
+ stat_ctx->backends[i].ctx = stat_ctx->backends[i].init (stat_ctx, cfg);
+ }
+}
+
+struct rspamd_stat_ctx *
+rspamd_stat_get_ctx (void)
+{
+ return stat_ctx;
+}
+
+struct rspamd_stat_classifier *
+rspamd_stat_get_classifier (const gchar *name)
+{
+ guint i;
+
+ for (i = 0; i < stat_ctx->classifiers_count; i ++) {
+ if (strcmp (name, stat_ctx->classifiers[i].name) == 0) {
+ return &stat_ctx->classifiers[i];
+ }
+ }
+
+ return NULL;
+}
+
+struct rspamd_stat_backend *
+rspamd_stat_get_backend (const gchar *name)
+{
+ guint i;
+
+ if (name == NULL || name[0] == '\0') {
+ name = RSPAMD_DEFAULT_BACKEND;
+ }
+
+ for (i = 0; i < stat_ctx->backends_count; i ++) {
+ if (strcmp (name, stat_ctx->backends[i].name) == 0) {
+ return &stat_ctx->backends[i];
+ }
+ }
+
+ return NULL;
+}
+
+struct rspamd_stat_tokenizer *
+rspamd_stat_get_tokenizer (const gchar *name)
+{
+ guint i;
+
+ if (name == NULL || name[0] == '\0') {
+ name = RSPAMD_DEFAULT_TOKENIZER;
+ }
+
+ for (i = 0; i < stat_ctx->tokenizers_count; i ++) {
+ if (strcmp (name, stat_ctx->tokenizers[i].name) == 0) {
+ return &stat_ctx->tokenizers[i];
+ }
+ }
+
+ return NULL;
}
diff --git a/src/libstat/stat_internal.h b/src/libstat/stat_internal.h
index 4aa625b27..15b5f03af 100644
--- a/src/libstat/stat_internal.h
+++ b/src/libstat/stat_internal.h
@@ -59,12 +59,24 @@ typedef struct token_node_s {
} rspamd_token_t;
struct rspamd_stat_ctx {
- struct classifier *classifiers;
+ struct rspamd_stat_classifier *classifiers;
guint classifiers_count;
- struct tokenizer *tokenizers;
+ struct rspamd_stat_tokenizer *tokenizers;
guint tokenizers_count;
struct rspamd_stat_backend *backends;
guint backends_count;
+
+ guint statfiles;
};
+struct rspamd_stat_ctx * rspamd_stat_get_ctx (void);
+struct rspamd_stat_classifier * rspamd_stat_get_classifier (const gchar *name);
+struct rspamd_stat_backend * rspamd_stat_get_backend (const gchar *name);
+struct rspamd_stat_tokenizer * rspamd_stat_get_tokenizer (const gchar *name);
+
+static GQuark rspamd_stat_quark (void)
+{
+ return g_quark_from_static_string ("rspamd-statistics");
+}
+
#endif /* STAT_INTERNAL_H_ */
diff --git a/src/main.h b/src/main.h
index 741e0d350..14ed7281e 100644
--- a/src/main.h
+++ b/src/main.h
@@ -77,7 +77,7 @@ struct rspamd_worker_signal_handler {
struct pidfh;
struct rspamd_config;
struct tokenizer;
-struct classifier;
+struct rspamd_stat_classifier;
struct rspamd_classifier_config;
struct mime_part;
struct rspamd_dns_resolver;