aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-01-16 15:28:40 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-01-16 15:28:40 +0000
commitb5597411a2a4f9b46c0076ccddb95f8eacc1cb7f (patch)
treea647a4306708df37a3ea1d97666fd2d325e24464
parentffd95d7c71307bb9540f07bbaac3b04859226837 (diff)
downloadrspamd-b5597411a2a4f9b46c0076ccddb95f8eacc1cb7f.tar.gz
rspamd-b5597411a2a4f9b46c0076ccddb95f8eacc1cb7f.zip
Reorganize statfiles and classifiers into libstat.
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/controller.c4
-rw-r--r--src/libmime/filter.c4
-rw-r--r--src/libmime/message.c2
-rw-r--r--src/libserver/CMakeLists.txt9
-rw-r--r--src/libserver/binlog.c2
-rw-r--r--src/libserver/cfg_rcl.c4
-rw-r--r--src/libserver/cfg_utils.c2
-rw-r--r--src/libserver/statfile_sync.c4
-rw-r--r--src/libstat/CMakeLists.txt27
-rw-r--r--src/libstat/classifiers.h (renamed from src/classifiers/classifiers.h)2
-rw-r--r--src/libstat/classifiers/bayes.c (renamed from src/classifiers/bayes.c)2
-rw-r--r--src/libstat/classifiers/classifiers.c (renamed from src/classifiers/classifiers.c)0
-rw-r--r--src/libstat/classifiers/winnow.c (renamed from src/classifiers/winnow.c)2
-rw-r--r--src/libstat/stat_api.h59
-rw-r--r--src/libstat/tokenizers.h (renamed from src/tokenizers/tokenizers.h)0
-rw-r--r--src/libstat/tokenizers/osb.c (renamed from src/tokenizers/osb.c)0
-rw-r--r--src/libstat/tokenizers/tokenizers.c (renamed from src/tokenizers/tokenizers.c)0
-rw-r--r--src/lua/lua_classifier.c2
-rw-r--r--src/lua/lua_config.c2
-rw-r--r--src/lua/lua_task.c4
22 files changed, 108 insertions, 27 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 924cae91e..955a6fcbf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -278,7 +278,7 @@ ENDMACRO()
############################# CONFIG SECTION #############################################
# Initial set
-INCLUDE_DIRECTORIES(src/libutil src/libserver src/libmime)
+INCLUDE_DIRECTORIES(src/libutil src/libserver src/libmime src/libstat)
IF(CMAKE_INSTALL_PREFIX)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ced57d20b..1c67416ac 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -66,6 +66,7 @@ ADD_SUBDIRECTORY(lua)
ADD_SUBDIRECTORY(libutil)
ADD_SUBDIRECTORY(libserver)
ADD_SUBDIRECTORY(libmime)
+ADD_SUBDIRECTORY(libstat)
ADD_SUBDIRECTORY(client)
SET(RSPAMDSRC ${CMAKE_CURRENT_BINARY_DIR}/modules.c
@@ -97,6 +98,7 @@ IF(NOT DEBIAN_BUILD)
SET_TARGET_PROPERTIES(rspamd PROPERTIES VERSION ${RSPAMD_VERSION})
ENDIF(NOT DEBIAN_BUILD)
+TARGET_LINK_LIBRARIES(rspamd rspamd-stat)
TARGET_LINK_LIBRARIES(rspamd rspamd-mime)
TARGET_LINK_LIBRARIES(rspamd rspamd-server)
TARGET_LINK_LIBRARIES(rspamd rspamd-util)
diff --git a/src/controller.c b/src/controller.c
index 33422f782..3b6436490 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -23,8 +23,8 @@
#include "config.h"
-#include "tokenizers/tokenizers.h"
-#include "classifiers/classifiers.h"
+#include "tokenizers.h"
+#include "classifiers.h"
#include "libserver/dynamic_cfg.h"
#include "libutil/rrd.h"
#include "libutil/map.h"
diff --git a/src/libmime/filter.c b/src/libmime/filter.c
index a1f042aae..48285ea0a 100644
--- a/src/libmime/filter.c
+++ b/src/libmime/filter.c
@@ -32,8 +32,8 @@
#include "expressions.h"
#include "binlog.h"
#include "diff.h"
-#include "classifiers/classifiers.h"
-#include "tokenizers/tokenizers.h"
+#include "classifiers.h"
+#include "tokenizers.h"
#ifdef WITH_LUA
# include "lua/lua_common.h"
diff --git a/src/libmime/message.c b/src/libmime/message.c
index 94137af15..682e0cf82 100644
--- a/src/libmime/message.c
+++ b/src/libmime/message.c
@@ -30,7 +30,7 @@
#include "html.h"
#include "images.h"
#include "utlist.h"
-#include "tokenizers/tokenizers.h"
+#include "tokenizers.h"
#include <iconv.h>
diff --git a/src/libserver/CMakeLists.txt b/src/libserver/CMakeLists.txt
index 8696da7ba..307611301 100644
--- a/src/libserver/CMakeLists.txt
+++ b/src/libserver/CMakeLists.txt
@@ -21,13 +21,6 @@ SET(LIBRSPAMDSERVERSRC
url.c
worker_util.c)
-SET(TOKENIZERSSRC ../tokenizers/tokenizers.c
- ../tokenizers/osb.c)
-
-SET(CLASSIFIERSSRC ../classifiers/classifiers.c
- ../classifiers/bayes.c
- ../classifiers/winnow.c)
-
# Librspamd-server
#IF(WITH_DB)
@@ -37,7 +30,7 @@ SET(CLASSIFIERSSRC ../classifiers/classifiers.c
# LIST(APPEND LIBRSPAMDSERVERSRC kvstorage_sqlite.c)
#ENDIF(WITH_SQLITE)
-ADD_LIBRARY(rspamd-server ${LINK_TYPE} ${LIBRSPAMDSERVERSRC} ${TOKENIZERSSRC} ${CLASSIFIERSSRC})
+ADD_LIBRARY(rspamd-server ${LINK_TYPE} ${LIBRSPAMDSERVERSRC})
IF(NOT DEBIAN_BUILD)
SET_TARGET_PROPERTIES(rspamd-server PROPERTIES VERSION ${RSPAMD_VERSION})
ENDIF(NOT DEBIAN_BUILD)
diff --git a/src/libserver/binlog.c b/src/libserver/binlog.c
index 5eeae7ac2..c48016339 100644
--- a/src/libserver/binlog.c
+++ b/src/libserver/binlog.c
@@ -25,7 +25,7 @@
#include "config.h"
#include "binlog.h"
#include "cfg_file.h"
-#include "tokenizers/tokenizers.h"
+#include "tokenizers.h"
#define BINLOG_SUFFIX ".binlog"
#define BACKUP_SUFFIX ".old"
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index 13ef400ed..44db06a0b 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -28,8 +28,8 @@
#include "cfg_file.h"
#include "lua/lua_common.h"
#include "expressions.h"
-#include "classifiers/classifiers.h"
-#include "tokenizers/tokenizers.h"
+#include "classifiers.h"
+#include "tokenizers.h"
struct rspamd_rcl_default_handler_data {
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index e28f6445e..b53a2690c 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -29,7 +29,7 @@
#include "main.h"
#include "uthash_strcase.h"
#include "filter.h"
-#include "classifiers/classifiers.h"
+#include "classifiers.h"
#include "lua/lua_common.h"
#include "kvstorage_config.h"
#include "map.h"
diff --git a/src/libserver/statfile_sync.c b/src/libserver/statfile_sync.c
index 23ed96e12..62f848059 100644
--- a/src/libserver/statfile_sync.c
+++ b/src/libserver/statfile_sync.c
@@ -24,8 +24,8 @@
#include "config.h"
#include "cfg_file.h"
-#include "tokenizers/tokenizers.h"
-#include "classifiers/classifiers.h"
+#include "tokenizers.h"
+#include "classifiers.h"
#include "statfile.h"
#include "binlog.h"
#include "buffer.h"
diff --git a/src/libstat/CMakeLists.txt b/src/libstat/CMakeLists.txt
new file mode 100644
index 000000000..6254a41a6
--- /dev/null
+++ b/src/libstat/CMakeLists.txt
@@ -0,0 +1,27 @@
+# Librspamdserver
+SET(LIBSTATSRC
+ )
+SET(TOKENIZERSSRC tokenizers/tokenizers.c
+ tokenizers/osb.c)
+
+SET(CLASSIFIERSSRC classifiers/classifiers.c
+ classifiers/bayes.c
+ classifiers/winnow.c)
+
+ADD_LIBRARY(rspamd-stat ${LINK_TYPE} ${LIBSTATSRC} ${TOKENIZERSSRC} ${CLASSIFIERSSRC})
+IF(NOT DEBIAN_BUILD)
+ SET_TARGET_PROPERTIES(rspamd-stat PROPERTIES VERSION ${RSPAMD_VERSION})
+ENDIF(NOT DEBIAN_BUILD)
+SET_TARGET_PROPERTIES(rspamd-stat PROPERTIES LINKER_LANGUAGE C COMPILE_FLAGS "-DRSPAMD_LIB")
+TARGET_LINK_LIBRARIES(rspamd-stat rspamd-server)
+
+IF(CMAKE_COMPILER_IS_GNUCC)
+SET_TARGET_PROPERTIES(rspamd-stat PROPERTIES COMPILE_FLAGS "-DRSPAMD_LIB -fno-strict-aliasing")
+ENDIF(CMAKE_COMPILER_IS_GNUCC)
+
+
+IF(NO_SHARED MATCHES "OFF")
+ INSTALL(TARGETS rspamd-stat
+ LIBRARY DESTINATION ${LIBDIR}
+ PUBLIC_HEADER DESTINATION ${INCLUDEDIR})
+ENDIF(NO_SHARED MATCHES "OFF")
diff --git a/src/classifiers/classifiers.h b/src/libstat/classifiers.h
index 8e59fc555..fd1b63bcf 100644
--- a/src/classifiers/classifiers.h
+++ b/src/libstat/classifiers.h
@@ -4,7 +4,7 @@
#include "config.h"
#include "mem_pool.h"
#include "statfile.h"
-#include "tokenizers/tokenizers.h"
+#include "tokenizers.h"
#include <lua.h>
/* Consider this value as 0 */
diff --git a/src/classifiers/bayes.c b/src/libstat/classifiers/bayes.c
index 0afd3109c..34169697e 100644
--- a/src/classifiers/bayes.c
+++ b/src/libstat/classifiers/bayes.c
@@ -26,7 +26,7 @@
* Bayesian classifier
*/
#include "classifiers.h"
-#include "tokenizers/tokenizers.h"
+#include "tokenizers.h"
#include "main.h"
#include "filter.h"
#include "cfg_file.h"
diff --git a/src/classifiers/classifiers.c b/src/libstat/classifiers/classifiers.c
index 95dd52c44..95dd52c44 100644
--- a/src/classifiers/classifiers.c
+++ b/src/libstat/classifiers/classifiers.c
diff --git a/src/classifiers/winnow.c b/src/libstat/classifiers/winnow.c
index 4bfe086bf..68d456968 100644
--- a/src/classifiers/winnow.c
+++ b/src/libstat/classifiers/winnow.c
@@ -27,7 +27,7 @@
*/
#include "classifiers.h"
-#include "tokenizers/tokenizers.h"
+#include "tokenizers.h"
#include "main.h"
#include "filter.h"
#include "cfg_file.h"
diff --git a/src/libstat/stat_api.h b/src/libstat/stat_api.h
new file mode 100644
index 000000000..0e2bf86b8
--- /dev/null
+++ b/src/libstat/stat_api.h
@@ -0,0 +1,59 @@
+/* Copyright (c) 2015, Vsevolod Stakhov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef STAT_API_H_
+#define STAT_API_H_
+
+#include "config.h"
+#include "task.h"
+
+/**
+ * @file stat_api.h
+ * High level statistics API
+ */
+
+/**
+ * Initialise statistics modules
+ * @param cfg
+ */
+void rspamd_stat_init (struct rspamd_config *cfg);
+
+/**
+ * Classify the task specified and insert symbols if needed
+ * @param task
+ * @return TRUE if task has been classified
+ */
+gboolean rspamd_stat_classify (struct rspamd_task *task, GError **err);
+
+
+/**
+ * Learn task as spam or ham, task must be processed prior to this call
+ * @param task task to learn
+ * @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);
+
+
+void rspamd_stat_unload (void);
+
+#endif /* STAT_API_H_ */
diff --git a/src/tokenizers/tokenizers.h b/src/libstat/tokenizers.h
index ed47e0add..ed47e0add 100644
--- a/src/tokenizers/tokenizers.h
+++ b/src/libstat/tokenizers.h
diff --git a/src/tokenizers/osb.c b/src/libstat/tokenizers/osb.c
index 9dd12a8dd..9dd12a8dd 100644
--- a/src/tokenizers/osb.c
+++ b/src/libstat/tokenizers/osb.c
diff --git a/src/tokenizers/tokenizers.c b/src/libstat/tokenizers/tokenizers.c
index 3e6c745ec..3e6c745ec 100644
--- a/src/tokenizers/tokenizers.c
+++ b/src/libstat/tokenizers/tokenizers.c
diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c
index 1edca4857..346f5d64b 100644
--- a/src/lua/lua_classifier.c
+++ b/src/lua/lua_classifier.c
@@ -25,7 +25,7 @@
#include "lua_common.h"
#include "cfg_file.h"
-#include "classifiers/classifiers.h"
+#include "classifiers.h"
/* Classifier methods */
LUA_FUNCTION_DEF (classifier, register_pre_callback);
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 3043013ba..c1eec7655 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -29,7 +29,7 @@
#include "message.h"
#include "radix.h"
#include "trie.h"
-#include "classifiers/classifiers.h"
+#include "classifiers.h"
/***
* This module is used to configure rspamd and is normally available as global
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 0a81e3d8b..4f1a46176 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -33,8 +33,8 @@
#include "images.h"
#include "cfg_file.h"
#include "statfile.h"
-#include "tokenizers/tokenizers.h"
-#include "classifiers/classifiers.h"
+#include "tokenizers.h"
+#include "classifiers.h"
#include "binlog.h"
#include "statfile_sync.h"
#include "diff.h"