]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Reorganize statfiles and classifiers into libstat.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 16 Jan 2015 15:28:40 +0000 (15:28 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 16 Jan 2015 15:28:40 +0000 (15:28 +0000)
22 files changed:
CMakeLists.txt
src/CMakeLists.txt
src/controller.c
src/libmime/filter.c
src/libmime/message.c
src/libserver/CMakeLists.txt
src/libserver/binlog.c
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/libserver/statfile_sync.c
src/libstat/CMakeLists.txt [new file with mode: 0644]
src/libstat/classifiers.h [moved from src/classifiers/classifiers.h with 98% similarity]
src/libstat/classifiers/bayes.c [moved from src/classifiers/bayes.c with 99% similarity]
src/libstat/classifiers/classifiers.c [moved from src/classifiers/classifiers.c with 100% similarity]
src/libstat/classifiers/winnow.c [moved from src/classifiers/winnow.c with 99% similarity]
src/libstat/stat_api.h [new file with mode: 0644]
src/libstat/tokenizers.h [moved from src/tokenizers/tokenizers.h with 100% similarity]
src/libstat/tokenizers/osb.c [moved from src/tokenizers/osb.c with 100% similarity]
src/libstat/tokenizers/tokenizers.c [moved from src/tokenizers/tokenizers.c with 100% similarity]
src/lua/lua_classifier.c
src/lua/lua_config.c
src/lua/lua_task.c

index 924cae91e3c629353d49e6d9c984ac9d01bfe55c..955a6fcbfeda5e1a3d3e5f5e98ec24a229ccab13 100644 (file)
@@ -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})
index ced57d20b69acdd9af54c8dec37fa5be3e864664..1c67416acff7282723de15be6c19c3bb06ea7e54 100644 (file)
@@ -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)
index 33422f78243ae8b11985d17f3f1f6b5d7cd45d48..3b6436490c071ce21692d18cbe94150852a20e43 100644 (file)
@@ -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"
index a1f042aae7f4040185af0588d816b0a0bb8b8f3a..48285ea0a365d65f4ee1020023135b260a180fb2 100644 (file)
@@ -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"
index 94137af157ca73b755927b388e8a2cd14511b320..682e0cf82c80567dca77d85a541f09a460056a18 100644 (file)
@@ -30,7 +30,7 @@
 #include "html.h"
 #include "images.h"
 #include "utlist.h"
-#include "tokenizers/tokenizers.h"
+#include "tokenizers.h"
 
 #include <iconv.h>
 
index 8696da7ba5fd5a34162f27955f60cf64a6790aa0..307611301b22f8d5910f10d88eea2f4f786736e4 100644 (file)
@@ -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)
index 5eeae7ac23f274b723a1ce036a1bd02f75377f50..c4801633927e53d84891bd3f37b37b4943cf5d99 100644 (file)
@@ -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"
index 13ef400ed62e3e94bc9d24d6a442ebb1f32dfb5f..44db06a0bdd86de699554296854d87a26a24e9e5 100644 (file)
@@ -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 {
index e28f6445ec3a8989c854d68e7574ffb4f7fbd9ab..b53a2690c6d1bbba8997ba9d8356b436e023c709 100644 (file)
@@ -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"
index 23ed96e12941d3276d55725896fa3b9af49d4328..62f84805956d787718e39cec043a90b4cd12f656 100644 (file)
@@ -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 (file)
index 0000000..6254a41
--- /dev/null
@@ -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")
similarity index 98%
rename from src/classifiers/classifiers.h
rename to src/libstat/classifiers.h
index 8e59fc5555dc1c240993d09b9a9291c2b65643cc..fd1b63bcfd9f5d265f17b4912f2fad9401f57580 100644 (file)
@@ -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 */
similarity index 99%
rename from src/classifiers/bayes.c
rename to src/libstat/classifiers/bayes.c
index 0afd3109c3fa6ce4bfb57e58161ff0f8171e99dc..34169697e2ce00038ed6606e3204c8c3d41268e8 100644 (file)
@@ -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"
similarity index 99%
rename from src/classifiers/winnow.c
rename to src/libstat/classifiers/winnow.c
index 4bfe086bfc175fb4c211d86875398361772dcde3..68d4569686431374ebd039fc1c3fd352c3242080 100644 (file)
@@ -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 (file)
index 0000000..0e2bf86
--- /dev/null
@@ -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_ */
index 1edca48576b1a09dc78946296a88e1deb45f3778..346f5d64ba272ca9280cb4783af59c2288e6bf75 100644 (file)
@@ -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);
index 3043013bae5a902f2fe3b5cab2db6003dde5c668..c1eec7655bf70a8cf883f103de2bd247e601b727 100644 (file)
@@ -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
index 0a81e3d8bcbb95ab4631ee7c425af1bf80c2fcd4..4f1a461760113a498b6f748c45b411b899963f9c 100644 (file)
@@ -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"