diff options
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | config.h.in | 1 | ||||
-rw-r--r-- | contrib/DEPENDENCY_INFO.md | 2 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/lua/lua_util.c | 36 | ||||
-rw-r--r-- | utils/CMakeLists.txt | 1 |
6 files changed, 42 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cc4f91e0..22c4b817b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/config.h.in b/config.h.in index 83f8a721c..57b887b85 100644 --- a/config.h.in +++ b/config.h.in @@ -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 diff --git a/contrib/DEPENDENCY_INFO.md b/contrib/DEPENDENCY_INFO.md index ea2fbe30c..d44312455 100644 --- a/contrib/DEPENDENCY_INFO.md +++ b/contrib/DEPENDENCY_INFO.md @@ -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 | diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c5871b665..6411601fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index be795bc55..e18912e9a 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.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; } diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 036365439..8cc5978e0 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -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() |