]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow rspamadm commands to export methods in Lua
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 2 Dec 2017 13:45:36 +0000 (13:45 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 2 Dec 2017 13:45:36 +0000 (13:45 +0000)
15 files changed:
src/rspamadm/configdump.c
src/rspamadm/confighelp.c
src/rspamadm/configtest.c
src/rspamadm/control.c
src/rspamadm/dkim_keygen.c
src/rspamadm/fuzzy_convert.c
src/rspamadm/fuzzy_merge.c
src/rspamadm/grep.c
src/rspamadm/keypair.c
src/rspamadm/lua_repl.c
src/rspamadm/pw.c
src/rspamadm/rspamadm.c
src/rspamadm/rspamadm.h
src/rspamadm/signtool.c
src/rspamadm/stat_convert.c

index 60cd75c3679376cf5e14271b8cfac07fb640898e..cf49f463256518661ce7b6a263d7329f58e423db 100644 (file)
@@ -39,7 +39,8 @@ struct rspamadm_command configdump_command = {
                .name = "configdump",
                .flags = 0,
                .help = rspamadm_configdump_help,
-               .run = rspamadm_configdump
+               .run = rspamadm_configdump,
+               .lua_subrs = NULL,
 };
 
 static GOptionEntry entries[] = {
@@ -244,7 +245,7 @@ rspamadm_configdump (gint argc, gchar **argv)
        gint i;
 
        context = g_option_context_new (
-                       "keypair - create encryption keys");
+                       "configdump - dumps Rspamd configuration");
        g_option_context_set_summary (context,
                        "Summary:\n  Rspamd administration utility version "
                                        RVERSION
index 5f8e1cfccc63a179b3081e66a472eb49739552be..ac25cd18f85fb9b38ef6c5da4faefea4920900c3 100644 (file)
@@ -38,7 +38,8 @@ struct rspamadm_command confighelp_command = {
                .name = "confighelp",
                .flags = 0,
                .help = rspamadm_confighelp_help,
-               .run = rspamadm_confighelp
+               .run = rspamadm_confighelp,
+               .lua_subrs = NULL,
 };
 
 static GOptionEntry entries[] = {
index 59f466de2ca332a139f02735823945cbb0ebdbce..18104c1092936de9c8c2889818780e966f81a39a 100644 (file)
@@ -35,7 +35,8 @@ struct rspamadm_command configtest_command = {
                .name = "configtest",
                .flags = 0,
                .help = rspamadm_configtest_help,
-               .run = rspamadm_configtest
+               .run = rspamadm_configtest,
+               .lua_subrs = NULL,
 };
 
 static GOptionEntry entries[] = {
index 62a7e26ae39804b746519c527314efaed3e0820f..a65ff554c93d7d0b8df162013543649fb358cd06 100644 (file)
@@ -38,7 +38,8 @@ struct rspamadm_command control_command = {
                .name = "control",
                .flags = 0,
                .help = rspamadm_control_help,
-               .run = rspamadm_control
+               .run = rspamadm_control,
+               .lua_subrs = NULL,
 };
 
 struct rspamadm_control_cbdata {
index 14a2e18f2d6d951c13d3d212942c1573dcd41f13..b29621978c9400fb969075f1549dc09b005c20bd 100644 (file)
@@ -33,7 +33,8 @@ struct rspamadm_command dkim_keygen_command = {
                .name = "dkim_keygen",
                .flags = 0,
                .help = rspamadm_dkim_keygen_help,
-               .run = rspamadm_dkim_keygen
+               .run = rspamadm_dkim_keygen,
+               .lua_subrs = NULL,
 };
 
 static GOptionEntry entries[] = {
index a143b89d9c8213c5517c5fa8548f5ac5e18be9e0..a65f3a39790f267fcbda5e666d6409801d45070d 100644 (file)
@@ -31,7 +31,8 @@ struct rspamadm_command fuzzyconvert_command = {
                .name = "fuzzyconvert",
                .flags = 0,
                .help = rspamadm_fuzzyconvert_help,
-               .run = rspamadm_fuzzyconvert
+               .run = rspamadm_fuzzyconvert,
+               .lua_subrs = NULL,
 };
 
 static GOptionEntry entries[] = {
index c286bffa951380a7ae2e6f0eb6c2b076d930cf1b..94631137c70e328773d2d51e8f832c38df93206f 100644 (file)
@@ -29,7 +29,8 @@ struct rspamadm_command fuzzy_merge_command = {
                .name = "fuzzy_merge",
                .flags = 0,
                .help = rspamadm_fuzzy_merge_help,
-               .run = rspamadm_fuzzy_merge
+               .run = rspamadm_fuzzy_merge,
+               .lua_subrs = NULL,
 };
 
 static GOptionEntry entries[] = {
index 2ce4f2c7671866f7145ac99a740e6a7ce4bb7c23..309b1e769d930273a2b3e4dbc308ede015866f16 100644 (file)
@@ -33,7 +33,8 @@ struct rspamadm_command grep_command = {
                .name = "grep",
                .flags = 0,
                .help = rspamadm_grep_help,
-               .run = rspamadm_grep
+               .run = rspamadm_grep,
+               .lua_subrs = NULL,
 };
 
 static GOptionEntry entries[] = {
index 4f54d0b556c70d1370bbfbda952e54e3b31683a0..4214e005258d9d79000a3f8619c37983c8446404 100644 (file)
@@ -32,7 +32,8 @@ struct rspamadm_command keypair_command = {
                .name = "keypair",
                .flags = 0,
                .help = rspamadm_keypair_help,
-               .run = rspamadm_keypair
+               .run = rspamadm_keypair,
+               .lua_subrs = NULL,
 };
 
 static GOptionEntry entries[] = {
index f959c6bf3541ae21a7ad9b790fb832367083d0ab..0edfeb05e023bef45cb7a7936f61a1a6039d5da3 100644 (file)
@@ -54,7 +54,8 @@ struct rspamadm_command lua_command = {
                .name = "lua",
                .flags = 0,
                .help = rspamadm_lua_help,
-               .run = rspamadm_lua
+               .run = rspamadm_lua,
+               .lua_subrs = NULL,
 };
 
 /*
index fb2817c593bc36e81912143697a11f9a8a0f6e24..4345ff1c592c81b5d95caf1b28b452eb27b51630 100644 (file)
@@ -35,7 +35,8 @@ struct rspamadm_command pw_command = {
        .name = "pw",
        .flags = 0,
        .help = rspamadm_pw_help,
-       .run = rspamadm_pw
+       .run = rspamadm_pw,
+       .lua_subrs = NULL,
 };
 
 static GOptionEntry entries[] = {
index f58da84afd9a42ad56a3102e1c76d8734ab0b474..67b93149a8e998eeb25490426df9c02ef2bed837 100644 (file)
@@ -193,11 +193,26 @@ rspamadm_execute_lua_ucl_subr (gpointer pL, gint argc, gchar **argv,
        gint err_idx, i, ret;
        GString *tb;
        gchar str[PATH_MAX];
+       const struct rspamadm_command **cmd;
 
        g_assert (script_name != NULL);
        g_assert (res != NULL);
        g_assert (L != NULL);
 
+       /* Init internal rspamadm routines */
+       lua_newtable (L);
+       cmd = commands;
+
+       while (*cmd) {
+               if ((*cmd)->lua_subrs != NULL) {
+                       (*cmd)->lua_subrs (L);
+               }
+
+               cmd ++;
+       }
+
+       lua_setglobal (L, "rspamadm");
+
        rspamd_snprintf (str, sizeof (str), "return require \"%s.%s\"", "rspamadm",
                        script_name);
 
index a778457bc376acacdf81478ad4e58d6781e4b9c2..9a209fd91c82da322ad3b9e47d32e6758c972bb0 100644 (file)
@@ -25,6 +25,7 @@ GQuark rspamadm_error (void);
 
 typedef const gchar* (*rspamadm_help_func) (gboolean full_help);
 typedef void (*rspamadm_run_func) (gint argc, gchar **argv);
+typedef void (*rspamadm_lua_exports_func) (gpointer lua_state);
 
 #define RSPAMADM_FLAG_NOHELP (1 << 0)
 
@@ -33,6 +34,7 @@ struct rspamadm_command {
        guint flags;
        rspamadm_help_func help;
        rspamadm_run_func run;
+       rspamadm_lua_exports_func lua_subrs;
 };
 
 extern const struct rspamadm_command *commands[];
index 1acd46745cdcf7e2199864c2fcbb6ebdab5e0a08..0ae7e22c57fbd08e69fdaf1f85a9368cfdc08885 100644 (file)
@@ -46,7 +46,8 @@ struct rspamadm_command signtool_command = {
                .name = "signtool",
                .flags = 0,
                .help = rspamadm_signtool_help,
-               .run = rspamadm_signtool
+               .run = rspamadm_signtool,
+               .lua_subrs = NULL,
 };
 
 static GOptionEntry entries[] = {
index 98eb337000361874e0077e0e1558e20bbb474f2d..cd15fb8a075acb7b7372b4a5dcdb8afc45b718d6 100644 (file)
@@ -32,7 +32,8 @@ struct rspamadm_command statconvert_command = {
                .name = "statconvert",
                .flags = 0,
                .help = rspamadm_statconvert_help,
-               .run = rspamadm_statconvert
+               .run = rspamadm_statconvert,
+               .lua_subrs = NULL,
 };
 
 static GOptionEntry entries[] = {