@@ -60,6 +60,7 @@ OPTION(ENABLE_FULL_DEBUG "Build rspamd with all possible debug [default: OFF]" | |||
OPTION(ENABLE_UTILS "Build rspamd internal utils [default: OFF]" OFF) | |||
OPTION(ENABLE_LIBUNWIND "Use libunwind to print crash traces [default: OFF]" OFF) | |||
OPTION(ENABLE_LUA_TRACE "Trace all Lua C API invocations [default: OFF]" OFF) | |||
OPTION(ENABLE_LUA_REPL "Enables Lua repl (requires C++11 compiler) [default: ON]" ON) | |||
INCLUDE(FindArch.cmake) | |||
TARGET_ARCHITECTURE(ARCH) | |||
@@ -478,7 +479,7 @@ INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/" | |||
"${CMAKE_SOURCE_DIR}/src/libstat" | |||
"${CMAKE_SOURCE_DIR}/src/libcryptobox" | |||
"${CMAKE_SOURCE_DIR}/contrib/libucl" | |||
"${CMAKE_SOURCE_DIR}/contrib/linenoise" | |||
"${CMAKE_SOURCE_DIR}/contrib/replxx/include" | |||
"${CMAKE_SOURCE_DIR}/contrib/uthash" | |||
"${CMAKE_SOURCE_DIR}/contrib/http-parser" | |||
"${CMAKE_SOURCE_DIR}/contrib/fpconv" | |||
@@ -1175,7 +1176,6 @@ ADD_SUBDIRECTORY(contrib/libucl) | |||
ADD_SUBDIRECTORY(contrib/librdns) | |||
ADD_SUBDIRECTORY(contrib/aho-corasick) | |||
ADD_SUBDIRECTORY(contrib/lua-lpeg) | |||
ADD_SUBDIRECTORY(contrib/linenoise) | |||
ADD_SUBDIRECTORY(contrib/t1ha) | |||
ADD_SUBDIRECTORY(contrib/libev) | |||
ADD_SUBDIRECTORY(contrib/kann) | |||
@@ -1184,6 +1184,12 @@ IF (NOT WITH_LUAJIT) | |||
ADD_SUBDIRECTORY(contrib/lua-bit) | |||
ENDIF() | |||
IF (ENABLE_LUA_REPL MATCHES "ON") | |||
ADD_SUBDIRECTORY(contrib/replxx) | |||
SET(WITH_LUA_REPL 1) | |||
LIST(APPEND RSPAMD_REQUIRED_LIBRARIES rspamd-replxx) | |||
ENDIF() | |||
IF (ENABLE_SNOWBALL MATCHES "ON") | |||
LIST(APPEND RSPAMD_REQUIRED_LIBRARIES stemmer) | |||
ENDIF() |
@@ -156,6 +156,7 @@ | |||
#cmakedefine WITH_TORCH 1 | |||
#cmakedefine WITH_LIBUNWIND 1 | |||
#cmakedefine WITH_LUA_TRACE 1 | |||
#cmakedefine WITH_LUA_REPL 1 | |||
#cmakedefine DISABLE_PTHREAD_MUTEX 1 | |||
@@ -8,7 +8,7 @@ | |||
| libottery | ? | Public Domain / CC0 | YES | | |||
| librdns | ? | BSD-2-Clause | YES | | |||
| libucl | ? | BSD-2-Clause | YES | | |||
| linenoise | 1.0 | BSD-2-Clause | YES | | |||
| replxx | 0.0.2 | BSD-2-Clause | YES | | |||
| lua-argparse | ? | MIT | YES | | |||
| lua-fun | ? | MIT | NO | | |||
| lua-lpeg | 1.0 | MIT | NO | |
@@ -206,7 +206,6 @@ IF (ENABLE_HYPERSCAN MATCHES "ON") | |||
TARGET_LINK_LIBRARIES(rspamd-server hs) | |||
ENDIF() | |||
TARGET_LINK_LIBRARIES(rspamd-server rspamd-linenoise) | |||
TARGET_LINK_LIBRARIES(rspamd-server ${RSPAMD_REQUIRED_LIBRARIES}) | |||
ADD_EXECUTABLE(rspamd ${RSPAMDSRC} ${CMAKE_CURRENT_BINARY_DIR}/workers.c) |
@@ -23,7 +23,11 @@ | |||
#include "libmime/content_type.h" | |||
#include "libmime/mime_headers.h" | |||
#include "libutil/hash.h" | |||
#include "linenoise.h" | |||
#ifdef WITH_LUA_REPL | |||
#include "replxx.h" | |||
#endif | |||
#include <math.h> | |||
#include <glob.h> | |||
#include <zlib.h> | |||
@@ -2865,17 +2869,41 @@ lua_util_readline (lua_State *L) | |||
if (lua_type (L, 1) == LUA_TSTRING) { | |||
prompt = lua_tostring (L, 1); | |||
} | |||
#ifdef WITH_LUA_REPL | |||
static Replxx *rx_instance = NULL; | |||
if (rx_instance == NULL) { | |||
rx_instance = replxx_init (); | |||
} | |||
input = linenoise (prompt); | |||
input = (gchar *)replxx_input (rx_instance, prompt); | |||
if (input) { | |||
lua_pushstring (L, input); | |||
linenoiseHistoryAdd (input); | |||
linenoiseFree (input); | |||
} | |||
else { | |||
lua_pushnil (L); | |||
} | |||
#else | |||
size_t linecap = 0; | |||
ssize_t linelen; | |||
fprintf (stdout, "%s ", prompt); | |||
linelen = getline (&input, &linecap, stdin); | |||
if (linelen > 0) { | |||
if (input[linelen - 1] == '\n') { | |||
linelen --; | |||
} | |||
lua_pushlstring (L, input, linelen); | |||
free (input); | |||
} | |||
else { | |||
lua_pushnil (L); | |||
} | |||
#endif | |||
return 1; | |||
} |
@@ -17,7 +17,6 @@ MACRO(ADD_UTIL NAME) | |||
TARGET_LINK_LIBRARIES("${NAME}" stemmer) | |||
ENDIF() | |||
TARGET_LINK_LIBRARIES("${NAME}" rspamd-hiredis) | |||
TARGET_LINK_LIBRARIES(${NAME} rspamd-linenoise) | |||
TARGET_LINK_LIBRARIES("${NAME}" ${RSPAMD_REQUIRED_LIBRARIES}) | |||
ENDMACRO() | |||