]> source.dussan.org Git - rspamd.git/commitdiff
[Rework] Start moving to replxx
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 3 Sep 2019 16:57:01 +0000 (17:57 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 3 Sep 2019 16:57:01 +0000 (17:57 +0100)
CMakeLists.txt
config.h.in
contrib/DEPENDENCY_INFO.md
src/CMakeLists.txt
src/lua/lua_util.c
utils/CMakeLists.txt

index 0cc4f91e062d5648f3a1921b5dfc94e7d20b9f18..22c4b817b29fd7bce8166084f75a56c4c21b1306 100644 (file)
@@ -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()
index 83f8a721c4f526911e03321cf058f30706f42096..57b887b85726a6f432e0f1bbc33d3d07a6544bbf 100644 (file)
 #cmakedefine WITH_TORCH          1
 #cmakedefine WITH_LIBUNWIND      1
 #cmakedefine WITH_LUA_TRACE      1
+#cmakedefine WITH_LUA_REPL       1
 
 #cmakedefine DISABLE_PTHREAD_MUTEX 1
 
index ea2fbe30c453190f9af62cd4364728b40874d82a..d4431245585e6675ea91e9b6169520d1bb32444c 100644 (file)
@@ -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      |
index c5871b665b46bbb27ae40dc2a5cbf338ed7401e1..6411601fa2ab34bb6530ef2ccd63f6bd3bdd3b23 100644 (file)
@@ -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)
index be795bc55128d1839abbcb8bbb44f48fc841e64c..e18912e9a3b25dbb6a56b671845a9bb9b6e8e831 100644 (file)
 #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;
 }
index 036365439375d74561de44f402fde0c00a082430..8cc5978e0c60b75b301dd19461ffa556a5e9abab 100644 (file)
@@ -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()