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)
"${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"
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)
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()
#cmakedefine WITH_TORCH 1
#cmakedefine WITH_LIBUNWIND 1
#cmakedefine WITH_LUA_TRACE 1
+#cmakedefine WITH_LUA_REPL 1
#cmakedefine DISABLE_PTHREAD_MUTEX 1
| 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 |
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)
#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>
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;
}
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()