aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-11-04 12:42:14 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-11-04 12:42:14 +0000
commit3cf2f3130034e46ff0224cc576626599422e8401 (patch)
tree11c85e27beda01882a63b6ff3920610816d5ab4b
parent4d589bd8919effafcdb79005a3c2a5eb461480f3 (diff)
downloadrspamd-3cf2f3130034e46ff0224cc576626599422e8401.tar.gz
rspamd-3cf2f3130034e46ff0224cc576626599422e8401.zip
[Rework] Stop embedding rspamadm scripts into C
-rw-r--r--lualib/rspamadm/ansicolors.lua (renamed from src/rspamadm/ansicolors.lua.in)4
-rw-r--r--lualib/rspamadm/confighelp.lua (renamed from src/rspamadm/confighelp.lua)7
-rw-r--r--lualib/rspamadm/fuzzy_convert.lua (renamed from src/rspamadm/fuzzy_convert.lua)0
-rw-r--r--lualib/rspamadm/fuzzy_stat.lua (renamed from src/rspamadm/fuzzy_stat.lua)4
-rw-r--r--lualib/rspamadm/getopt.lua (renamed from src/rspamadm/getopt.lua.in)3
-rw-r--r--lualib/rspamadm/grep.lua (renamed from src/rspamadm/grep.lua)0
-rw-r--r--lualib/rspamadm/stat_convert.lua (renamed from src/rspamadm/stat_convert.lua)0
-rw-r--r--src/rspamadm/CMakeLists.txt9
-rw-r--r--src/rspamadm/confighelp.c3
-rw-r--r--src/rspamadm/fuzzy_convert.c4
-rw-r--r--src/rspamadm/grep.c4
-rw-r--r--src/rspamadm/rspamadm.c20
-rw-r--r--src/rspamadm/rspamadm.h2
-rw-r--r--src/rspamadm/stat_convert.c4
14 files changed, 31 insertions, 33 deletions
diff --git a/src/rspamadm/ansicolors.lua.in b/lualib/rspamadm/ansicolors.lua
index 1e9ca2065..739cf427c 100644
--- a/src/rspamadm/ansicolors.lua.in
+++ b/lualib/rspamadm/ansicolors.lua
@@ -10,7 +10,7 @@ function colormt:__concat(other)
end
function colormt:__call(s)
- return self .. s .. _M.reset
+ return self .. s .. ansicolors.reset
end
colormt.__metatable = {}
@@ -54,3 +54,5 @@ local colors = {
for c, v in pairs(colors) do
ansicolors[c] = makecolor(v)
end
+
+return ansicolors \ No newline at end of file
diff --git a/src/rspamadm/confighelp.lua b/lualib/rspamadm/confighelp.lua
index e95dd0b36..a03578b6e 100644
--- a/src/rspamadm/confighelp.lua
+++ b/lualib/rspamadm/confighelp.lua
@@ -7,9 +7,8 @@ local known_attrs = {
default = 1,
}
---.USE "getopt"
---.USE "ansicolors"
-
+local getopt = require "rspamadm/getopt"
+local ansicolors = require "rspamadm/ansicolors"
local function maybe_print_color(key)
if not opts['no-color'] then
@@ -101,7 +100,7 @@ local function print_help(key, value, tabs)
end
return function(args, res)
- opts = getopt(args, '')
+ opts = getopt.getopt(args, '')
local sorted = sort_values(res)
diff --git a/src/rspamadm/fuzzy_convert.lua b/lualib/rspamadm/fuzzy_convert.lua
index 2d473ca46..2d473ca46 100644
--- a/src/rspamadm/fuzzy_convert.lua
+++ b/lualib/rspamadm/fuzzy_convert.lua
diff --git a/src/rspamadm/fuzzy_stat.lua b/lualib/rspamadm/fuzzy_stat.lua
index 401b297d1..748dbda20 100644
--- a/src/rspamadm/fuzzy_stat.lua
+++ b/lualib/rspamadm/fuzzy_stat.lua
@@ -141,13 +141,13 @@ local function print_result(r)
return print_num(r)
end
---.USE "getopt"
+local getopt = require "rspamadm/getopt"
return function(args, res)
local res_ips = {}
local res_databases = {}
local wrk = res['workers']
- opts = getopt(args, '')
+ opts = getopt.getopt(args, '')
if wrk then
for _,pr in pairs(wrk) do
diff --git a/src/rspamadm/getopt.lua.in b/lualib/rspamadm/getopt.lua
index d069d2d5f..bd0a2f67e 100644
--- a/src/rspamadm/getopt.lua.in
+++ b/lualib/rspamadm/getopt.lua
@@ -29,3 +29,6 @@ local function getopt(arg, options)
return tab
end
+return {
+ getopt = getopt
+}
diff --git a/src/rspamadm/grep.lua b/lualib/rspamadm/grep.lua
index a9d4b084a..a9d4b084a 100644
--- a/src/rspamadm/grep.lua
+++ b/lualib/rspamadm/grep.lua
diff --git a/src/rspamadm/stat_convert.lua b/lualib/rspamadm/stat_convert.lua
index 7b6de9836..7b6de9836 100644
--- a/src/rspamadm/stat_convert.lua
+++ b/lualib/rspamadm/stat_convert.lua
diff --git a/src/rspamadm/CMakeLists.txt b/src/rspamadm/CMakeLists.txt
index 752e23d8b..7e991372a 100644
--- a/src/rspamadm/CMakeLists.txt
+++ b/src/rspamadm/CMakeLists.txt
@@ -21,16 +21,7 @@ SET(RSPAMADMSRC rspamadm.c
${CMAKE_SOURCE_DIR}/src/worker.c
${CMAKE_SOURCE_DIR}/src/rspamd_proxy.c
${CMAKE_SOURCE_DIR}/src/log_helper.c)
-SET(RSPAMADMLUASRC
- ${CMAKE_CURRENT_SOURCE_DIR}/fuzzy_stat.lua
- ${CMAKE_CURRENT_SOURCE_DIR}/confighelp.lua)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
-ADD_CUSTOM_TARGET(rspamadm_lua_preprocess
- ${PERL_EXECUTABLE}
- "${CMAKE_SOURCE_DIR}/lua_preprocess.pl"
- "${CMAKE_CURRENT_SOURCE_DIR}"
- "${CMAKE_CURRENT_BINARY_DIR}"
- SOURCES ${RSPAMADMLUASRC} ${CMAKE_SOURCE_DIR}/lua_preprocess.pl)
IF (ENABLE_HYPERSCAN MATCHES "ON")
LIST(APPEND RSPAMADMSRC "${CMAKE_SOURCE_DIR}/src/hs_helper.c")
ENDIF()
diff --git a/src/rspamadm/confighelp.c b/src/rspamadm/confighelp.c
index a64afe4b0..f3da9422d 100644
--- a/src/rspamadm/confighelp.c
+++ b/src/rspamadm/confighelp.c
@@ -85,6 +85,7 @@ rspamadm_confighelp_show (struct rspamd_config *cfg, gint argc, gchar **argv,
{
rspamd_fstring_t *out;
+ rspamd_lua_set_path (cfg->lua_state, NULL, NULL);
out = rspamd_fstring_new ();
if (json) {
@@ -107,7 +108,7 @@ rspamadm_confighelp_show (struct rspamd_config *cfg, gint argc, gchar **argv,
argc,
argv,
obj,
- rspamadm_script_confighelp);
+ "confighelp");
rspamd_fstring_free (out);
return;
diff --git a/src/rspamadm/fuzzy_convert.c b/src/rspamadm/fuzzy_convert.c
index dc15b7e38..a143b89d9 100644
--- a/src/rspamadm/fuzzy_convert.c
+++ b/src/rspamadm/fuzzy_convert.c
@@ -17,7 +17,6 @@
#include "config.h"
#include "rspamadm.h"
#include "lua/lua_common.h"
-#include "fuzzy_convert.lua.h"
static gchar *source_db = NULL;
static gchar *redis_host = NULL;
@@ -109,6 +108,7 @@ rspamadm_fuzzyconvert (gint argc, gchar **argv)
}
L = rspamd_lua_init ();
+ rspamd_lua_set_path (L, NULL, NULL);
obj = ucl_object_typed_new (UCL_OBJECT);
ucl_object_insert_key (obj, ucl_object_fromstring (source_db),
@@ -132,7 +132,7 @@ rspamadm_fuzzyconvert (gint argc, gchar **argv)
argc,
argv,
obj,
- rspamadm_script_fuzzy_convert);
+ "fuzzy_convert");
lua_close (L);
ucl_object_unref (obj);
diff --git a/src/rspamadm/grep.c b/src/rspamadm/grep.c
index 9665b40e8..2ce4f2c76 100644
--- a/src/rspamadm/grep.c
+++ b/src/rspamadm/grep.c
@@ -17,7 +17,6 @@
#include "config.h"
#include "rspamadm.h"
#include "lua/lua_common.h"
-#include "grep.lua.h"
static gchar *string = NULL;
static gchar *pattern = NULL;
@@ -115,6 +114,7 @@ rspamadm_grep (gint argc, gchar **argv)
}
L = rspamd_lua_init ();
+ rspamd_lua_set_path (L, NULL, NULL);
obj = ucl_object_typed_new (UCL_OBJECT);
if (string) {
@@ -148,7 +148,7 @@ rspamadm_grep (gint argc, gchar **argv)
argc,
argv,
obj,
- rspamadm_script_grep);
+ "grep");
lua_close (L);
ucl_object_unref (obj);
diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c
index d524a8f61..f58da84af 100644
--- a/src/rspamadm/rspamadm.c
+++ b/src/rspamadm/rspamadm.c
@@ -187,28 +187,30 @@ rspamadm_parse_ucl_var (const gchar *option_name,
gboolean
rspamadm_execute_lua_ucl_subr (gpointer pL, gint argc, gchar **argv,
- const ucl_object_t *res, const gchar *script)
+ const ucl_object_t *res, const gchar *script_name)
{
lua_State *L = pL;
gint err_idx, i, ret;
GString *tb;
+ gchar str[PATH_MAX];
- g_assert (script != NULL);
+ g_assert (script_name != NULL);
g_assert (res != NULL);
g_assert (L != NULL);
- if (luaL_dostring (L, script) != 0) {
- msg_err ("cannot execute lua script: %s",
- lua_tostring (L, -1));
+ rspamd_snprintf (str, sizeof (str), "return require \"%s.%s\"", "rspamadm",
+ script_name);
+
+ if (luaL_dostring (L, str) != 0) {
+ msg_err ("cannot execute lua script %s: %s",
+ str, lua_tostring (L, -1));
return FALSE;
}
else {
if (lua_type (L, -1) != LUA_TFUNCTION) {
msg_err ("lua script must return "
"function and not %s",
- lua_typename (L,
- lua_type (L, -1)));
- lua_settop (L, 0);
+ lua_typename (L, lua_type (L, -1)));
return FALSE;
}
@@ -233,7 +235,7 @@ rspamadm_execute_lua_ucl_subr (gpointer pL, gint argc, gchar **argv,
if ((ret = lua_pcall (L, 2, 0, err_idx)) != 0) {
tb = lua_touserdata (L, -1);
- msg_err ("call to adm lua script failed (%d): %v", ret, tb);
+ msg_err ("call to rspamadm lua script failed (%d): %v", ret, tb);
if (tb) {
g_string_free (tb, TRUE);
diff --git a/src/rspamadm/rspamadm.h b/src/rspamadm/rspamadm.h
index 3c4da9aca..a778457bc 100644
--- a/src/rspamadm/rspamadm.h
+++ b/src/rspamadm/rspamadm.h
@@ -41,6 +41,6 @@ extern struct rspamadm_command help_command;
const struct rspamadm_command *rspamadm_search_command (const gchar *name);
gboolean rspamadm_execute_lua_ucl_subr (gpointer L, gint argc, gchar **argv,
- const ucl_object_t *res, const gchar *script);
+ const ucl_object_t *res, const gchar *script_name);
#endif
diff --git a/src/rspamadm/stat_convert.c b/src/rspamadm/stat_convert.c
index 48acbc9bd..98eb33700 100644
--- a/src/rspamadm/stat_convert.c
+++ b/src/rspamadm/stat_convert.c
@@ -16,7 +16,6 @@
#include "config.h"
#include "rspamadm.h"
#include "lua/lua_common.h"
-#include "stat_convert.lua.h"
static gchar *source_db = NULL;
static gchar *redis_host = NULL;
@@ -117,6 +116,7 @@ rspamadm_statconvert (gint argc, gchar **argv)
}
L = rspamd_lua_init ();
+ rspamd_lua_set_path (L, NULL, NULL);
obj = ucl_object_typed_new (UCL_OBJECT);
ucl_object_insert_key (obj, ucl_object_fromstring (source_db),
@@ -147,7 +147,7 @@ rspamadm_statconvert (gint argc, gchar **argv)
argc,
argv,
obj,
- rspamadm_script_stat_convert);
+ "stat_convert");
lua_close (L);
ucl_object_unref (obj);