aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt112
-rw-r--r--clang-plugin/CMakeLists.txt20
-rw-r--r--clang-plugin/FindLLVM.cmake127
-rw-r--r--clang-plugin/plugin.cc114
-rw-r--r--src/CMakeLists.txt30
5 files changed, 339 insertions, 64 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6e1af8555..f6b916f1e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,7 @@ OPTION(INSTALL_EXAMPLES "Install examples [default: OFF]"
OPTION(INSTALL_WEBUI "Install web interface [default: ON]" ON)
OPTION(WANT_SYSTEMD_UNITS "Install systemd unit files on Linux [default: OFF]" OFF)
OPTION(ENABLE_SNOWBALL "Enable snowball stemmer [default: ON]" ON)
+OPTION(ENABLE_CLANG_PLUGIN "Enable clang static analysing plugin [default: OFF]" OFF)
# Build optimized code for following CPU (default i386)
#SET(CPU_TUNE "i686")
@@ -171,23 +172,23 @@ MACRO(FindLua)
HINTS
"${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}"
$ENV{LUA_DIR}
- PATH_SUFFIXES "include/luajit-2.0"
- "include/luajit${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
- "include/luajit${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+ PATH_SUFFIXES "include/luajit-2.0"
+ "include/luajit${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
+ "include/luajit${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
"include/luajit-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
- "include/luajit"
- "include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
- "include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+ "include/luajit"
+ "include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
+ "include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
"include/lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
include/lua include
PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS}
)
- FIND_LIBRARY(LUA_LIBRARY
- NAMES luajit
+ FIND_LIBRARY(LUA_LIBRARY
+ NAMES luajit
"luajit-2.0"
"luajit2.0"
"luajit${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
- "luajit${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+ "luajit${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
"luajit-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
HINTS
"${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}"
@@ -196,7 +197,7 @@ MACRO(FindLua)
PATHS ${RSPAMD_DEFAULT_LIBRARY_PATHS}
DOC "Lua library"
)
-
+
IF(NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR)
MESSAGE(STATUS "Fallback from luajit to plain lua")
SET(ENABLE_LUAJIT "OFF")
@@ -205,16 +206,16 @@ MACRO(FindLua)
HINTS
"${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}"
$ENV{LUA_DIR}
- PATH_SUFFIXES "include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
- "include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+ PATH_SUFFIXES "include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
+ "include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
"include/lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
include/lua include
PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS}
)
- FIND_LIBRARY(LUA_LIBRARY
- NAMES lua
+ FIND_LIBRARY(LUA_LIBRARY
+ NAMES lua
"lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
- "lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+ "lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
"lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
HINTS
"${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}"
@@ -230,16 +231,16 @@ MACRO(FindLua)
HINTS
"${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}"
$ENV{LUA_DIR}
- PATH_SUFFIXES "include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
- "include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+ PATH_SUFFIXES "include/lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
+ "include/lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
"include/lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
include/lua include
PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS}
)
- FIND_LIBRARY(LUA_LIBRARY
- NAMES lua
+ FIND_LIBRARY(LUA_LIBRARY
+ NAMES lua
"lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}"
- "lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
+ "lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
"lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
HINTS
"${RSPAMD_SEARCH_PATH}" "${LUA_ROOT}"
@@ -300,13 +301,13 @@ ENDFUNCTION(INSTALL_IF_NOT_EXISTS)
# OPTIONAL - do not fail if a package has not been found
# ROOT - defines root directory for a package
# INCLUDE - name of the include file to check
-# LIBRARY - name of the library to check
+# LIBRARY - name of the library to check
# INCLUDE_SUFFIXES - list of include suffixes (relative to ROOT)
# LIB_SUFFIXES - list of library suffixes
# MODULES - modules to search using pkg_config
MACRO(ProcessPackage PKG_NAME)
- CMAKE_PARSE_ARGUMENTS(PKG "OPTIONAL" "ROOT;INCLUDE"
+ CMAKE_PARSE_ARGUMENTS(PKG "OPTIONAL" "ROOT;INCLUDE"
"LIBRARY;INCLUDE_SUFFIXES;LIB_SUFFIXES;MODULES" ${ARGN})
IF(NOT PKG_LIBRARY)
@@ -319,7 +320,7 @@ MACRO(ProcessPackage PKG_NAME)
IF(NOT PKG_ROOT AND PKG_MODULES)
PKG_SEARCH_MODULE(${PKG_NAME} ${PKG_MODULES})
ENDIF()
-
+
IF(${PKG_NAME}_FOUND)
MESSAGE(STATUS "Found package ${PKG_NAME} in pkg-config modules ${PKG_MODULES}")
SET(WITH_${PKG_NAME} 1 CACHE INTERNAL "")
@@ -359,7 +360,7 @@ MACRO(ProcessPackage PKG_NAME)
MESSAGE(FATAL_ERROR "Cannot find library ${PKG_LIBRARY} for package ${PKG_NAME}")
ENDIF()
ENDIF(NOT _lib)
-
+
FIND_PATH(_incl ${PKG_INCLUDE}
HINTS ${PKG_ROOT} ${RSPAMD_SEARCH_PATH}
PATH_SUFFIXES ${PKG_INCLUDE_SUFFIXES} include
@@ -371,7 +372,7 @@ MACRO(ProcessPackage PKG_NAME)
MESSAGE(FATAL_ERROR "Cannot find header ${PKG_INCLUDE} for package ${PKG_NAME}")
ENDIF()
ENDIF(NOT _incl)
-
+
IF(_incl AND _lib)
GET_FILENAME_COMPONENT(_lib_path "${_lib}" PATH)
INCLUDE_DIRECTORIES("${_incl}")
@@ -384,7 +385,7 @@ MACRO(ProcessPackage PKG_NAME)
SET(WITH_${PKG_NAME} 1 CACHE INTERNAL "")
MESSAGE(STATUS "Found package ${PKG_NAME} in '${_lib_path}' (${_lib}) and '${_incl}' (${PKG_INCLUDE}).")
ENDIF()
-
+
ELSE()
MESSAGE(STATUS "Found package ${PKG_NAME} (cached)")
INCLUDE_DIRECTORIES("${${PKG_NAME}_INCLUDE}")
@@ -509,11 +510,11 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
SET(CMAKE_C_FLAGS "-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE ${CMAKE_C_FLAGS}")
ENDIF(BUILD_CPU_MODE STREQUAL "32")
# Workaround with architecture specific includes
- IF(IS_DIRECTORY "/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/")
+ IF(IS_DIRECTORY "/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/")
INCLUDE_DIRECTORIES("/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/")
LIST(APPEND CMAKE_REQUIRED_INCLUDES "/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/")
ENDIF(IS_DIRECTORY "/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/")
-
+
LIST(APPEND CMAKE_REQUIRED_LIBRARIES rt)
LIST(APPEND CMAKE_REQUIRED_LIBRARIES dl)
#XXX: gio bug workaround
@@ -533,7 +534,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
IF(NOT BUILD_CPU_MODE)
SET (BUILD_CPU_MODE "32")
ENDIF(NOT BUILD_CPU_MODE)
-
+
IF("${CMAKE_C_COMPILER_ID}" MATCHES SunPro)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Xa -xregs=no%frameptr -xstrconst -xc99")
SET(SUN_BUILD32 "-xtarget=generic")
@@ -545,7 +546,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
ENDIF(ENABLE_OPTIMIZATION MATCHES "ON")
ELSE("${CMAKE_C_COMPILER_ID}" MATCHES SunPro)
set(SUN_BUILD32 "-m32")
- set(SUN_BUILD64 "-m64")
+ set(SUN_BUILD64 "-m64")
ENDIF("${CMAKE_C_COMPILER_ID}" MATCHES SunPro)
IF (BUILD_CPU_MODE STREQUAL "32")
@@ -561,7 +562,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
ENDIF (BUILD_CPU_MODE STREQUAL "32")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__EXTENSIONS__ -DSOLARIS -D_POSIX_SOURCE -D_POSIX_C_SOURCE=200112L")
-
+
LIST(APPEND CMAKE_REQUIRED_LIBRARIES rt)
LIST(APPEND CMAKE_REQUIRED_LIBRARIES dl)
LIST(APPEND CMAKE_REQUIRED_LIBRARIES resolv)
@@ -600,15 +601,15 @@ ELSE(ENABLE_LUAJIT MATCHES "ON")
ENDIF(NOT LUA_FOUND)
ENDIF(ENABLE_LUAJIT MATCHES "ON")
-ProcessPackage(GLIB2 LIBRARY glib-2.0 INCLUDE glib.h INCLUDE_SUFFIXES include/glib
+ProcessPackage(GLIB2 LIBRARY glib-2.0 INCLUDE glib.h INCLUDE_SUFFIXES include/glib
ROOT ${GLIB_ROOT_DIR} MODULES glib-2.0>=2.28)
-ProcessPackage(PCRE LIBRARY pcre INCLUDE pcre.h INCLUDE_SUFFIXES include/pcre
+ProcessPackage(PCRE LIBRARY pcre INCLUDE pcre.h INCLUDE_SUFFIXES include/pcre
ROOT ${PCRE_ROOT_DIR} MODULES pcre libpcre pcre3 libpcre3)
-ProcessPackage(GMIME LIBRARY gmime-2.6 gmime-2.4 gmime-2.2 gmime-2 INCLUDE gmime.h INCLUDE_SUFFIXES include/gmime
+ProcessPackage(GMIME LIBRARY gmime-2.6 gmime-2.4 gmime-2.2 gmime-2 INCLUDE gmime.h INCLUDE_SUFFIXES include/gmime
ROOT ${GMIME_ROOT_DIR} MODULES gmime-2.6 gmime-2.4 gmime-2.0)
-ProcessPackage(LIBEVENT LIBRARY event INCLUDE event.h INCLUDE_SUFFIXES include/event
+ProcessPackage(LIBEVENT LIBRARY event INCLUDE event.h INCLUDE_SUFFIXES include/event
ROOT ${LIBEVENT_ROOT_DIR} MODULES event libevent)
-ProcessPackage(SQLITE3 LIBRARY sqlite3 INCLUDE sqlite3.h INCLUDE_SUFFIXES include/sqlite3 include/sqlite
+ProcessPackage(SQLITE3 LIBRARY sqlite3 INCLUDE sqlite3.h INCLUDE_SUFFIXES include/sqlite3 include/sqlite
ROOT ${SQLITE3_ROOT_DIR} MODULES sqlite3 sqlite)
ProcessPackage(ICONV LIBRARY iconv libiconv libiconv-2 c INCLUDE iconv.h INCLUDE_SUFFIXES include/libiconv
ROOT ${ICONV_ROOT_DIR} MODULES iconv)
@@ -690,12 +691,12 @@ ENDIF(SUPPORT_PEDANTIC_FLAG)
IF(SUPPORT_STD_FLAG)
SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -std=c99")
ENDIF(SUPPORT_STD_FLAG)
-
+
CHECK_C_COMPILER_FLAG(-fPIC SUPPORT_FPIC)
IF(SUPPORT_FPIC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
ENDIF(SUPPORT_FPIC)
-
+
# Optimization flags
IF(NOT CMAKE_C_OPT_FLAGS)
IF(ENABLE_OPTIMIZATION MATCHES "ON")
@@ -710,7 +711,7 @@ IF(NOT CMAKE_C_OPT_FLAGS)
ENDIF(NOT CMAKE_C_OPT_FLAGS)
SET(CMAKE_C_FLAGS "${CMAKE_C_OPT_FLAGS} ${CMAKE_C_FLAGS} ${CMAKE_C_WARN_FLAGS}")
-
+
# Check platform specific includes
CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H)
@@ -835,20 +836,20 @@ CHECK_SYMBOL_EXISTS(O_ASYNC "sys/types.h;sys/fcntl.h" HAVE_OASYNC)
# Some PCRE implementations are lacking of pcre_jit_exec fast path
SET(_PCRE_FAST_TEST "
#include \"pcre.h\"
-int main (void)
+int main (void)
{
int rc;
int ovector[30];
pcre *re;
pcre_extra *extra;
pcre_jit_stack *jit_stack;
-
+
re = pcre_compile(\"abc\", 0, NULL, NULL, NULL);
extra = pcre_study(re, PCRE_STUDY_JIT_COMPILE, NULL);
jit_stack = pcre_jit_stack_alloc(32*1024, 512*1024);
pcre_assign_jit_stack(extra, NULL, jit_stack);
rc = pcre_jit_exec(re, extra, \"abc\", 3, 0, 0, ovector, 30, jit_stack);
-
+
return rc;
}
")
@@ -928,13 +929,13 @@ IF(ENABLE_URL_INCLUDE MATCHES "ON")
DOC "Path where the libfetch library can be found")
IF(LIBFETCH_LIBRARY)
FIND_FILE(HAVE_FETCH_H HINTS "${RSPAMD_SEARCH_PATH}"
- NAMES fetch.h
+ NAMES fetch.h
PATH_SUFFIXES include
PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS}
DOC "Path to libfetch header")
ELSE(LIBFETCH_LIBRARY)
# Try to find libcurl
- ProcessPackage(CURL LIBRARY curl INCLUDE curl.h INCLUDE_SUFFIXES include/curl
+ ProcessPackage(CURL LIBRARY curl INCLUDE curl.h INCLUDE_SUFFIXES include/curl
ROOT ${CURL_ROOT})
IF(NOT WITH_CURL)
MESSAGE(WARNING "Neither libcurl nor libfetch were found, no support of URL includes in configuration")
@@ -951,14 +952,14 @@ SET(ID "unknown")
FIND_PROGRAM(HG "git")
IF(HG)
- EXECUTE_PROCESS(COMMAND "${HG}" rev-parse --verify HEAD
+ EXECUTE_PROCESS(COMMAND "${HG}" rev-parse --verify HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE HG_ID ERROR_QUIET)
IF(HG_ID)
STRING(SUBSTRING "${HG_ID}" 0 10 RSPAMD_ID)
MESSAGE(STATUS "Git revision: ${RSPAMD_ID}")
ELSE(HG_ID)
- FIND_FILE(HG_ARCH ".hg_archival.txt" "${CMAKE_CURRENT_SOURCE_DIR}")
+ FIND_FILE(HG_ARCH ".hg_archival.txt" "${CMAKE_CURRENT_SOURCE_DIR}")
IF(HG_ARCH)
FILE(READ ${HG_ARCH} HG_ID)
IF(HG_ID)
@@ -969,7 +970,7 @@ IF(HG)
ENDIF(HG_ID)
ELSE(HG)
# Now check .hg_archival.txt
- FIND_FILE(HG_ARCH ".hg_archival.txt" "${CMAKE_CURRENT_SOURCE_DIR}")
+ FIND_FILE(HG_ARCH ".hg_archival.txt" "${CMAKE_CURRENT_SOURCE_DIR}")
IF(HG_ARCH)
FILE(READ ${HG_ARCH} HG_ID)
IF(HG_ID)
@@ -1020,6 +1021,11 @@ ENDIF()
ADD_SUBDIRECTORY(contrib/libucl)
ADD_SUBDIRECTORY(contrib/librdns)
ADD_SUBDIRECTORY(contrib/aho-corasick)
+
+IF(ENABLE_CLANG_PLUGIN MATCHES "ON")
+ ADD_SUBDIRECTORY(clang-plugin)
+ENDIF()
+
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(test)
ADD_SUBDIRECTORY(utils)
@@ -1043,12 +1049,12 @@ INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${RULESDIR})")
LIST(LENGTH CONFFILES CONFLIST_COUNT)
MATH(EXPR CONFLIST_MAX ${CONFLIST_COUNT}-1)
-FILE(GLOB_RECURSE CONF_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/conf"
+FILE(GLOB_RECURSE CONF_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/conf"
"${CMAKE_CURRENT_SOURCE_DIR}/conf/*" )
FOREACH(CONF_FILE ${CONF_FILES})
GET_FILENAME_COMPONENT(_rp ${CONF_FILE} PATH)
INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${CONFDIR}/${_rp})")
- INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/conf/${CONF_FILE}"
+ INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/conf/${CONF_FILE}"
DESTINATION ${CONFDIR}/${_rp})
ENDFOREACH(CONF_FILE)
@@ -1073,7 +1079,7 @@ ENDIF(INSTALL_EXAMPLES MATCHES "ON")
# Lua plugins
-FILE(GLOB LUA_PLUGINS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/lua"
+FILE(GLOB LUA_PLUGINS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/lua"
"${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/lua/*.lua" )
FOREACH(LUA_PLUGIN ${LUA_PLUGINS})
GET_FILENAME_COMPONENT(_rp ${LUA_PLUGIN} PATH)
@@ -1085,11 +1091,11 @@ ENDFOREACH(LUA_PLUGIN)
INSTALL(FILES "contrib/lua-fun/fun.lua" DESTINATION ${PLUGINSDIR}/lua)
# Install TLD list
-INSTALL(FILES "contrib/publicsuffix/effective_tld_names.dat" DESTINATION
+INSTALL(FILES "contrib/publicsuffix/effective_tld_names.dat" DESTINATION
"${PLUGINSDIR}")
# Lua config
-FILE(GLOB_RECURSE LUA_CONFIGS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/rules"
+FILE(GLOB_RECURSE LUA_CONFIGS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/rules"
"${CMAKE_CURRENT_SOURCE_DIR}/rules/*.lua")
FOREACH(LUA_CONF ${LUA_CONFIGS})
GET_FILENAME_COMPONENT(_rp ${LUA_CONF} PATH)
@@ -1121,4 +1127,4 @@ ADD_CUSTOM_TARGET(dist ${CMAKE_SOURCE_DIR}/dist.sh
IF(NOT DEBIAN_BUILD)
ADD_CUSTOM_TARGET(check DEPENDS rspamd-test)
ADD_CUSTOM_TARGET(run-test DEPENDS check COMMAND test/rspamd-test)
-ENDIF(NOT DEBIAN_BUILD) \ No newline at end of file
+ENDIF(NOT DEBIAN_BUILD)
diff --git a/clang-plugin/CMakeLists.txt b/clang-plugin/CMakeLists.txt
new file mode 100644
index 000000000..02ffdc173
--- /dev/null
+++ b/clang-plugin/CMakeLists.txt
@@ -0,0 +1,20 @@
+IF (ENABLE_CLANG_PLUGIN MATCHES "ON")
+ # Clang plugin for static analysis
+ if (NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
+ MESSAGE(FATAL_ERROR "Cannot build clang plugin when compiler is not clang")
+ endif ()
+
+ SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}")
+ ENABLE_LANGUAGE(CXX)
+ FIND_PACKAGE(LLVM REQUIRED)
+
+ SET(CLANGPLUGINSRC plugin.cc)
+
+ ADD_LIBRARY(rspamd-clang SHARED ${CLANGPLUGINSRC})
+ SET_TARGET_PROPERTIES(rspamd-clang PROPERTIES
+ COMPILE_FLAGS "${LLVM_CXX_FLAGS} ${LLVM_CPP_FLAGS} ${LLVM_C_FLAGS}"
+ INCLUDE_DIRECTORIES ${LIBCLANG_INCLUDE_DIR}
+ LINKER_LANGUAGE CXX)
+ TARGET_LINK_LIBRARIES(rspamd-clang ${LIBCLANG_LIBRARIES})
+ LINK_DIRECTORIES(${LLVM_LIBRARY_DIRS})
+ENDIF()
diff --git a/clang-plugin/FindLLVM.cmake b/clang-plugin/FindLLVM.cmake
new file mode 100644
index 000000000..fca9984ea
--- /dev/null
+++ b/clang-plugin/FindLLVM.cmake
@@ -0,0 +1,127 @@
+# Copyright (c) 2007-2015 University of Illinois at Urbana-Champaign.
+# Copyright (c) 2015, Vsevolod Stakhov
+# - Find LLVM
+# This module can be used to find LLVM.
+# It requires that the llvm-config executable be available on the system path.
+# Once found, llvm-config is used for everything else.
+#
+# Typical usage could be:
+# find_package(LLVM QUIET REQUIRED COMPONENTS jit native interpreter)
+#
+# If the QUIET flag is not set, the specified components and LLVM version are
+# outputted.
+#
+# If the COMPONENTS are not set, the default set of "all" is used.
+#
+# The following variables are set:
+#
+# LLVM_FOUND - Set to YES if LLVM is found.
+# LLVM_VERSION - Set to the decimal version of the LLVM library.
+# LLVM_C_FLAGS - All flags that should be passed to a C compiler.
+# LLVM_CXX_FLAGS - All flags that should be passed to a C++ compiler.
+# LLVM_CPP_FLAGS - All flags that should be passed to the C pre-processor.
+# LLVM_LD_FLAGS - Additional flags to pass to the linker.
+# LLVM_LIBRARY_DIRS - A list of directories where the LLVM libraries are located.
+# LLVM_INCLUDE_DIRS - A list of directories where the LLVM headers are located.
+# LLVM_LIBRARIES - A list of libraries which should be linked against.
+
+# A macro to run llvm config
+macro(_llvm_config _var_name)
+ # Firstly, locate the LLVM config executable
+ find_program(_llvm_config_exe
+ NAMES llvm-config
+ DOC "llvm-config executable location"
+ )
+
+ # If no llvm-config executable was found, set the output variable to not
+ # found.
+ if (NOT _llvm_config_exe)
+ set(${_var_name} "${_var_name}-NOTFOUND")
+ else (NOT _llvm_config_exe)
+ # Otherwise, run llvm-config
+ execute_process(
+ COMMAND ${_llvm_config_exe} ${ARGN}
+ OUTPUT_VARIABLE ${_var_name}
+ RESULT_VARIABLE _llvm_config_retval
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if (RESULT_VARIABLE)
+ message(SEND_ERROR
+ "Error running llvm-config with arguments: ${ARGN}")
+ endif (RESULT_VARIABLE)
+ endif (NOT _llvm_config_exe)
+endmacro(_llvm_config)
+
+# The default set of components
+set(_llvm_components all)
+
+# If components have been specified via find_package, use them
+if (LLVM_FIND_COMPONENTS)
+ set(_llvm_components ${LLVM_FIND_COMPONENTS})
+endif (LLVM_FIND_COMPONENTS)
+
+if (NOT LLVM_FIND_QUIETLY)
+ message(STATUS "Looking for LLVM components: ${_llvm_components}")
+endif (NOT LLVM_FIND_QUIETLY)
+
+_llvm_config(LLVM_VERSION --version)
+_llvm_config(LLVM_C_FLAGS --cflags)
+_llvm_config(LLVM_CXX_FLAGS --cxxflags)
+_llvm_config(LLVM_CPP_FLAGS --cppflags)
+_llvm_config(LLVM_LD_FLAGS --ldflags)
+_llvm_config(LLVM_LIBRARY_DIRS --libdir)
+_llvm_config(LLVM_INCLUDE_DIRS --includedir)
+_llvm_config(LLVM_LIBRARIES --libs ${_llvm_components})
+
+if (NOT LLVM_FIND_QUIETLY)
+ message(STATUS "Found LLVM version: ${LLVM_VERSION}")
+endif (NOT LLVM_FIND_QUIETLY)
+
+SET(libclang_llvm_header_search_paths
+ # LLVM Debian/Ubuntu nightly packages: http://llvm.org/apt/
+ "/usr/lib/llvm-${LLVM_VERSION}/include/"
+ # LLVM MacPorts
+ "/opt/local/libexec/llvm-${LLVM_VERSION}/include"
+ # LLVM Homebrew
+ "/usr/local/Cellar/llvm/${LLVM_VERSION}/include"
+ # LLVM Homebrew/versions
+ "/usr/local/lib/llvm-${LLVM_VERSION}/include"
+ # FreeBSD ports versions
+ "/usr/local/llvm${LLVM_VERSION}/include"
+)
+
+SET(libclang_llvm_lib_search_paths
+ # LLVM Debian/Ubuntu nightly packages: http://llvm.org/apt/
+ "/usr/lib/llvm-${LLVM_VERSION}/lib/"
+ # LLVM MacPorts
+ "/opt/local/libexec/llvm-${LLVM_VERSION}/lib"
+ # LLVM Homebrew
+ "/usr/local/Cellar/llvm/${LLVM_VERSION}/lib"
+ # LLVM Homebrew/versions
+ "/usr/local/lib/llvm-${LLVM_VERSION}/lib"
+ # FreeBSD ports versions
+ "/usr/local/llvm${LLVM_VERSION}/lib"
+)
+
+find_path(LIBCLANG_INCLUDE_DIR clang-c/Index.h
+ PATHS ${libclang_llvm_header_search_paths}
+ PATH_SUFFIXES LLVM/include #Windows package from http://llvm.org/releases/
+ DOC "The path to the directory that contains clang-c/Index.h")
+find_library(LIBCLANG_LIBRARY NAMES libclang.imp libclang clang
+ PATHS ${libclang_llvm_lib_search_paths}
+ PATH_SUFFIXES LLVM/lib #Windows package from http://llvm.org/releases/
+ DOC "The file that corresponds to the libclang library.")
+
+get_filename_component(LIBCLANG_LIBRARY_DIR ${LIBCLANG_LIBRARY} PATH)
+
+set(LIBCLANG_LIBRARIES ${LIBCLANG_LIBRARY})
+set(LIBCLANG_INCLUDE_DIRS ${LIBCLANG_INCLUDE_DIR})
+
+# handle the QUIETLY and REQUIRED arguments and set LLVM_FOUND to TRUE if
+# all listed variables are TRUE
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LLVM
+ DEFAULT_MSG
+ LLVM_LIBRARIES
+ LLVM_INCLUDE_DIRS
+ LLVM_LIBRARY_DIRS)
diff --git a/clang-plugin/plugin.cc b/clang-plugin/plugin.cc
new file mode 100644
index 000000000..204ce7b6f
--- /dev/null
+++ b/clang-plugin/plugin.cc
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2007-2015 University of Illinois at Urbana-Champaign.
+ * 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 BY AUTHOR ''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.
+ */
+
+
+#include "clang/Frontend/FrontendPluginRegistry.h"
+#include "clang/AST/AST.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+namespace {
+
+ class RspamdASTConsumer : public ASTConsumer {
+ CompilerInstance &Instance;
+
+ public:
+ RspamdASTConsumer (CompilerInstance &Instance)
+ : Instance (Instance)
+ {
+ }
+
+ bool HandleTopLevelDecl (DeclGroupRef DG) override
+ {
+ for (DeclGroupRef::iterator i = DG.begin (), e = DG.end (); i != e;
+ ++i) {
+ const Decl *D = *i;
+ if (const NamedDecl *ND = dyn_cast<NamedDecl> (D))
+ llvm::errs () << "top-level-decl: \"" <<
+ ND->getNameAsString () << "\"\n";
+ }
+
+ return true;
+ }
+
+ void HandleTranslationUnit (ASTContext &context) override
+ {
+ struct Visitor : public RecursiveASTVisitor<Visitor> {
+
+ Visitor (void)
+ {
+ }
+
+ bool VisitFunctionDecl (FunctionDecl *FD)
+ {
+ if (FD->isLateTemplateParsed ())
+ LateParsedDecls.insert (FD);
+ return true;
+ }
+
+ std::set<FunctionDecl *> LateParsedDecls;
+ } v;
+ v.TraverseDecl (context.getTranslationUnitDecl ());
+ clang::Sema &sema = Instance.getSema ();
+ for (const FunctionDecl *FD : v.LateParsedDecls) {
+ clang::LateParsedTemplate *LPT = sema.LateParsedTemplateMap.lookup (
+ FD);
+ sema.LateTemplateParser (sema.OpaqueParser, *LPT);
+ llvm::errs () << "late-parsed-decl: \"" <<
+ FD->getNameAsString () << "\"\n";
+ }
+ }
+ };
+
+ class RspamdASTAction : public PluginASTAction {
+ protected:
+ std::unique_ptr <ASTConsumer> CreateASTConsumer (CompilerInstance &CI,
+ llvm::StringRef) override
+ {
+ return llvm::make_unique<RspamdASTConsumer> (CI);
+ }
+
+ bool ParseArgs (const CompilerInstance &CI,
+ const std::vector <std::string> &args) override
+ {
+ return true;
+ }
+
+ void PrintHelp (llvm::raw_ostream &ros)
+ {
+ ros << "Nothing here\n";
+ }
+
+ };
+
+}
+
+static FrontendPluginRegistry::Add <RspamdASTAction>
+ X ("rspamd-ast", "rspamd ast checker");
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b58067210..9e3f6c788 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -5,23 +5,23 @@ MACRO(_AddModulesForced MLIST)
SET(MODULES_C "${CMAKE_CURRENT_BINARY_DIR}/modules.c")
FILE(WRITE "${MODULES_C}"
"/* ${MODULES_ID} */\n#include \"rspamd.h\"\n")
-
+
# Handle even old cmake
LIST(LENGTH ${MLIST} MLIST_COUNT)
MATH(EXPR MLIST_MAX ${MLIST_COUNT}-1)
-
+
FOREACH(MOD_IDX RANGE ${MLIST_MAX})
LIST(GET ${MLIST} ${MOD_IDX} MOD)
FILE(APPEND "${MODULES_C}" "extern module_t ${MOD}_module;\n")
ENDFOREACH(MOD_IDX RANGE ${MLIST_MAX})
-
+
FILE(APPEND "${MODULES_C}" "\n\nmodule_t *modules[] = {\n")
-
+
FOREACH(MOD_IDX RANGE ${MLIST_MAX})
LIST(GET ${MLIST} ${MOD_IDX} MOD)
FILE(APPEND "${MODULES_C}" "&${MOD}_module,\n")
ENDFOREACH(MOD_IDX RANGE ${MLIST_MAX})
-
+
FILE(APPEND "${MODULES_C}" "NULL\n};\n")
ENDMACRO(_AddModulesForced MLIST)
@@ -29,7 +29,7 @@ MACRO(_AddWorkersForced WLIST)
SET(WORKERS_C "${CMAKE_CURRENT_BINARY_DIR}/workers.c")
FILE(WRITE "${WORKERS_C}"
"#include \"rspamd.h\"\n")
-
+
# Handle even old cmake
LIST(LENGTH ${WLIST} WLIST_COUNT)
MATH(EXPR WLIST_MAX ${WLIST_COUNT}-1)
@@ -37,9 +37,9 @@ MACRO(_AddWorkersForced WLIST)
LIST(GET ${WLIST} ${MOD_IDX} WRK)
FILE(APPEND "${WORKERS_C}" "extern worker_t ${WRK}_worker;\n")
ENDFOREACH(MOD_IDX RANGE ${WLIST_MAX})
-
+
FILE(APPEND "${WORKERS_C}" "\n\nworker_t *workers[] = {\n")
-
+
FOREACH(MOD_IDX RANGE ${WLIST_MAX})
LIST(GET ${WLIST} ${MOD_IDX} WRK)
FILE(APPEND "${WORKERS_C}" "&${WRK}_worker,\n")
@@ -63,6 +63,10 @@ MACRO(AddModules MLIST WLIST)
ENDMACRO(AddModules MLIST WLIST)
# Rspamd core components
+IF (ENABLE_CLANG_PLUGIN MATCHES "ON")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Xclang -load -Xclang ${CMAKE_CURRENT_BINARY_DIR}/../clang-plugin/librspamd-clang.so -Xclang -plugin -Xclang rspamd-ast")
+ENDIF ()
+
ADD_SUBDIRECTORY(lua)
ADD_SUBDIRECTORY(libcryptobox)
ADD_SUBDIRECTORY(libutil)
@@ -71,7 +75,7 @@ ADD_SUBDIRECTORY(libmime)
ADD_SUBDIRECTORY(libstat)
ADD_SUBDIRECTORY(client)
ADD_SUBDIRECTORY(rspamadm)
-
+
SET(RSPAMDSRC controller.c
fuzzy_storage.c
lua_worker.c
@@ -86,7 +90,7 @@ SET(PLUGINSSRC plugins/surbl.c
plugins/fuzzy_check.c
plugins/spf.c
plugins/dkim_check.c libutil/unix-std.h libserver/rspamd_control.c libserver/rspamd_control.h libcryptobox/curve25519/curve25519.c libcryptobox/curve25519/avx.c)
-
+
SET(MODULES_LIST surbl regexp chartable fuzzy_check spf dkim)
SET(WORKERS_LIST normal controller smtp_proxy fuzzy lua http_proxy)
@@ -95,11 +99,15 @@ LIST(LENGTH PLUGINSSRC RSPAMD_MODULES_NUM)
######################### LINK SECTION ###############################
ADD_LIBRARY(rspamd-server STATIC ${RSPAMD_UTIL} ${RSPAMD_LUA} ${RSPAMD_SERVER}
- ${RSPAMD_STAT} ${RSPAMD_MIME} ${RSPAMD_CRYPTOBOX}
+ ${RSPAMD_STAT} ${RSPAMD_MIME} ${RSPAMD_CRYPTOBOX}
${CMAKE_CURRENT_BINARY_DIR}/modules.c ${PLUGINSSRC})
TARGET_LINK_LIBRARIES(rspamd-server rspamd-http-parser)
TARGET_LINK_LIBRARIES(rspamd-server rspamd-cdb)
+IF (ENABLE_CLANG_PLUGIN MATCHES "ON")
+ ADD_DEPENDENCIES(rspamd-server rspamd-clang)
+ENDIF()
+
ADD_EXECUTABLE(rspamd ${RSPAMDSRC} ${CMAKE_CURRENT_BINARY_DIR}/workers.c)
SET_TARGET_PROPERTIES(rspamd PROPERTIES LINKER_LANGUAGE C)
SET_TARGET_PROPERTIES(rspamd PROPERTIES COMPILE_FLAGS "-DRSPAMD_MAIN")