gboolean enable_experimental; /**< Enable experimental plugins */
gboolean disable_pcre_jit; /**< Disable pcre JIT */
gboolean disable_lua_squeeze; /**< Disable lua rules squeezing */
+ gboolean own_lua_state; /**< True if we have created lua_state internally */
gsize max_diff; /**< maximum diff size for text parts */
gsize max_cores_size; /**< maximum size occupied by rspamd core files */
gboolean rspamd_parse_bind_line (struct rspamd_config *cfg,
struct rspamd_worker_conf *cf, const gchar *str);
+
+enum rspamd_config_init_flags {
+ RSPAMD_CONFIG_INIT_DEFAULT = 0,
+ RSPAMD_CONFIG_INIT_SKIP_LUA = (1 << 0)
+};
/**
* Init default values
* @param cfg config file
*/
-struct rspamd_config *rspamd_config_new (void);
+struct rspamd_config *rspamd_config_new (enum rspamd_config_init_flags flags);
/**
* Free memory used by config structure
}
struct rspamd_config *
-rspamd_config_new (void)
+rspamd_config_new (enum rspamd_config_init_flags flags)
{
struct rspamd_config *cfg;
cfg->min_word_len = DEFAULT_MIN_WORD;
cfg->max_word_len = DEFAULT_MAX_WORD;
- cfg->lua_state = rspamd_lua_init ();
+ if (!(flags & RSPAMD_CONFIG_INIT_SKIP_LUA)) {
+ cfg->lua_state = rspamd_lua_init ();
+ cfg->own_lua_state = TRUE;
+ }
+
cfg->cache = rspamd_symbols_cache_new (cfg);
cfg->ups_ctx = rspamd_upstreams_library_init ();
cfg->re_cache = rspamd_re_cache_new ();
rspamd_re_cache_unref (cfg->re_cache);
rspamd_upstreams_library_unref (cfg->ups_ctx);
rspamd_mempool_delete (cfg->cfg_pool);
- lua_close (cfg->lua_state);
+
+ if (cfg->lua_state && cfg->own_lua_state) {
+ lua_close (cfg->lua_state);
+ }
REF_RELEASE (cfg->libs_ctx);
DL_FOREACH_SAFE (cfg->log_pipes, lp, ltmp) {
cur = g_list_next (cur);
}
- /* Assign state */
- cfg->lua_state = L;
-
return TRUE;
}
cfg_name = luaL_checkstring (L, 1);
if (cfg_name) {
- cfg = rspamd_config_new ();
+ cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_SKIP_LUA);
+ cfg->lua_state = L;
if (rspamd_config_read (cfg, cfg_name, NULL, NULL, NULL, NULL)) {
msg_err_config ("cannot load config from %s", cfg_name);
if (obj) {
cfg = g_malloc0 (sizeof (struct rspamd_config));
- cfg = rspamd_config_new ();
+ cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_SKIP_LUA);
+ cfg->lua_state = L;
cfg->rcl_obj = obj;
cfg->cache = rspamd_symbols_cache_new (cfg);
* limitations under the License.
*/
#include "rspamadm.h"
+#include "libutil/util.h"
extern struct rspamadm_command pw_command;
extern struct rspamadm_command keypair_command;
const struct rspamadm_command *
-rspamadm_search_command (const gchar *name)
+rspamadm_search_command (const gchar *name, GPtrArray *all_commands)
{
- const struct rspamadm_command *ret = NULL;
+ const struct rspamadm_command *ret = NULL, *cmd;
guint i;
if (name == NULL) {
name = "help";
}
- for (i = 0; i < G_N_ELEMENTS (commands); i ++) {
- if (commands[i] != NULL) {
- if (strcmp (name, commands[i]->name) == 0) {
- ret = commands[i];
+ PTR_ARRAY_FOREACH (all_commands, i, cmd) {
+ if (strcmp (name, cmd->name) == 0) {
+ ret = cmd;
break;
}
- }
}
return ret;
}
+
+void
+rspamadm_fill_internal_commands (GPtrArray *dest)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (commands); i ++) {
+ if (commands[i]) {
+ g_ptr_array_add (dest, (gpointer)commands[i]);
+ }
+ }
+}
extern module_t *modules[];
extern worker_t *workers[];
-static void rspamadm_configdump (gint argc, gchar **argv);
-static const char *rspamadm_configdump_help (gboolean full_help);
+static void rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *);
+static const char *rspamadm_configdump_help (gboolean full_help, const struct rspamadm_command *);
struct rspamadm_command configdump_command = {
.name = "configdump",
};
static const char *
-rspamadm_configdump_help (gboolean full_help)
+rspamadm_configdump_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_configdump (gint argc, gchar **argv)
+rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
extern module_t *modules[];
extern worker_t *workers[];
-static void rspamadm_confighelp (gint argc, gchar **argv);
+static void rspamadm_confighelp (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
-static const char *rspamadm_confighelp_help (gboolean full_help);
+static const char *rspamadm_confighelp_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command confighelp_command = {
.name = "confighelp",
};
static const char *
-rspamadm_confighelp_help (gboolean full_help)
+rspamadm_confighelp_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_confighelp (gint argc, gchar **argv)
+rspamadm_confighelp (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
struct rspamd_config *cfg;
ucl_object_t *doc_obj;
pworker++;
}
- cfg = rspamd_config_new ();
+ cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_SKIP_LUA);
+ cfg->lua_state = L;
cfg->compiled_modules = modules;
cfg->compiled_workers = workers;
extern module_t *modules[];
extern worker_t *workers[];
-static void rspamadm_configtest (gint argc, gchar **argv);
-static const char *rspamadm_configtest_help (gboolean full_help);
+static void rspamadm_configtest (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_configtest_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command configtest_command = {
.name = "configtest",
};
static const char *
-rspamadm_configtest_help (gboolean full_help)
+rspamadm_configtest_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_configtest (gint argc, gchar **argv)
+rspamadm_configtest (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
extern module_t *modules[];
extern worker_t *workers[];
-static void rspamadm_configwizard (gint argc, gchar **argv);
-static const char *rspamadm_configwizard_help (gboolean full_help);
+static void rspamadm_configwizard (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_configwizard_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command configwizard_command = {
.name = "configwizard",
};
static const char *
-rspamadm_configwizard_help (gboolean full_help)
+rspamadm_configwizard_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_configwizard (gint argc, gchar **argv)
+rspamadm_configwizard (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
static gboolean compact = FALSE;
static gdouble timeout = 1.0;
-static void rspamadm_control (gint argc, gchar **argv);
-static const char *rspamadm_control_help (gboolean full_help);
+static void rspamadm_control (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_control_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command control_command = {
.name = "control",
};
static const char *
-rspamadm_control_help (gboolean full_help)
+rspamadm_control_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_control (gint argc, gchar **argv)
+rspamadm_control (gint argc, gchar **argv, const struct rspamadm_command *_cmd)
{
GOptionContext *context;
GError *error = NULL;
static gint connections = 10;
static gdouble timeout = 60.0;
-static void rspamadm_corpus_test (gint argc, gchar **argv);
-static const char *rspamadm_corpus_test_help (gboolean full_help);
+static void rspamadm_corpus_test (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_corpus_test_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command corpus_test_command = {
.name = "corpus_test",
};
static const char *
-rspamadm_corpus_test_help (gboolean full_help)
+rspamadm_corpus_test_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_corpus_test (gint argc, gchar **argv)
+rspamadm_corpus_test (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
static gchar *domain = NULL;
static guint bits = 1024;
-static void rspamadm_dkim_keygen (gint argc, gchar **argv);
-static const char *rspamadm_dkim_keygen_help (gboolean full_help);
+static void rspamadm_dkim_keygen (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_dkim_keygen_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
static void rspamadm_dkim_keygen_lua_subrs (gpointer pL);
struct rspamadm_command dkim_keygen_command = {
};
static const char *
-rspamadm_dkim_keygen_help (gboolean full_help)
+rspamadm_dkim_keygen_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_dkim_keygen (gint argc, gchar **argv)
+rspamadm_dkim_keygen (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
static gchar *redis_password = NULL;
static int64_t fuzzy_expiry = 0;
-static void rspamadm_fuzzyconvert (gint argc, gchar **argv);
-static const char *rspamadm_fuzzyconvert_help (gboolean full_help);
+static void rspamadm_fuzzyconvert (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_fuzzyconvert_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command fuzzyconvert_command = {
.name = "fuzzyconvert",
static const char *
-rspamadm_fuzzyconvert_help (gboolean full_help)
+rspamadm_fuzzyconvert_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_fuzzyconvert (gint argc, gchar **argv)
+rspamadm_fuzzyconvert (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
static gchar **sources = NULL;
static gboolean quiet;
-static void rspamadm_fuzzy_merge (gint argc, gchar **argv);
-static const char *rspamadm_fuzzy_merge_help (gboolean full_help);
+static void rspamadm_fuzzy_merge (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_fuzzy_merge_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command fuzzy_merge_command = {
.name = "fuzzy_merge",
};
static const char *
-rspamadm_fuzzy_merge_help (gboolean full_help)
+rspamadm_fuzzy_merge_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_fuzzy_merge (gint argc, gchar **argv)
+rspamadm_fuzzy_merge (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
static gboolean partial = FALSE;
static gboolean luapat = FALSE;
-static void rspamadm_grep (gint argc, gchar **argv);
-static const char *rspamadm_grep_help (gboolean full_help);
+static void rspamadm_grep (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_grep_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command grep_command = {
.name = "grep",
static const char *
-rspamadm_grep_help (gboolean full_help)
+rspamadm_grep_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_grep (gint argc, gchar **argv)
+rspamadm_grep (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
static gboolean ucl = FALSE;
static gboolean sign = FALSE;
-static void rspamadm_keypair (gint argc, gchar **argv);
-static const char *rspamadm_keypair_help (gboolean full_help);
+static void rspamadm_keypair (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_keypair_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command keypair_command = {
.name = "keypair",
};
static const char *
-rspamadm_keypair_help (gboolean full_help)
+rspamadm_keypair_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_keypair (gint argc, gchar **argv)
+rspamadm_keypair (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
#endif
#define MULTILINE_PROMPT "... "
-static void rspamadm_lua (gint argc, gchar **argv);
-static const char *rspamadm_lua_help (gboolean full_help);
+static void rspamadm_lua (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_lua_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command lua_command = {
.name = "lua",
};
static const char *
-rspamadm_lua_help (gboolean full_help)
+rspamadm_lua_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_lua (gint argc, gchar **argv)
+rspamadm_lua (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
}
}
- L = rspamd_lua_init ();
- rspamd_lua_set_path (L, NULL, ucl_vars);
-
if (paths) {
for (elt = paths; *elt != NULL; elt ++) {
rspamadm_lua_add_path (L, *elt);
#include "rspamadm.h"
#include "unix-std.h"
-static void rspamadm_pw (gint argc, gchar **argv);
-static const char *rspamadm_pw_help (gboolean full_help);
+static void rspamadm_pw (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_pw_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
static void rspamadm_pw_lua_subrs (gpointer pL);
static gboolean do_encrypt = FALSE;
};
static const char *
-rspamadm_pw_help (gboolean full_help)
+rspamadm_pw_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_pw (gint argc, gchar **argv)
+rspamadm_pw (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
#include "rspamadm.h"
#include "lua/lua_common.h"
-#if !defined(WITH_TORCH) || !defined(WITH_LUAJIT)
-#define HAS_TORCH false
-#else
-#define HAS_TORCH true
-#endif
-
static gchar *logdir = NULL;
static gchar *output = "new.scores";
static gboolean score_diff = false; /* Print score diff flag */
extern module_t *modules[];
extern worker_t *workers[];
-static void rspamadm_rescore (gint argc, gchar **argv);
+static void rspamadm_rescore (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
-static const char *rspamadm_rescore_help (gboolean full_help);
+static const char *rspamadm_rescore_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command rescore_command = {
.name = "rescore",
}
static const char *
-rspamadm_rescore_help (gboolean full_help) {
-
+rspamadm_rescore_help (gboolean full_help, const struct rspamadm_command *cmd)
+{
const char *help_str;
if (full_help) {
}
static void
-rspamadm_rescore (gint argc, gchar **argv) {
-
+rspamadm_rescore (gint argc, gchar **argv, const struct rspamadm_command *cmd)
+{
GOptionContext *context;
GError *error = NULL;
- lua_State *L;
struct rspamd_config *cfg = rspamd_main->cfg, **pcfg;
gboolean ret = TRUE;
worker_t **pworker;
const gchar *confdir;
+#ifndef WITH_TORCH
+ rspamd_fprintf (stderr, "Torch is not enabled. "
+ "Use -DENABLE_TORCH=ON option while running cmake.\n");
+ exit (EXIT_FAILURE);
+#endif
+
context = g_option_context_new (
"rescore - estimate optimal symbol weights from log files");
exit (EXIT_FAILURE);
}
- if (!HAS_TORCH) {
- rspamd_fprintf (stderr, "Torch is not enabled. "
- "Use -DENABLE_TORCH=ON option while running cmake.\n");
- exit (EXIT_FAILURE);
- }
-
if (logdir == NULL) {
rspamd_fprintf (stderr, "Please specify log directory.\n");
exit (EXIT_FAILURE);
}
if (ret) {
- L = cfg->lua_state;
- rspamd_lua_set_path (L, cfg->rcl_obj, ucl_vars);
ucl_object_insert_key (cfg->rcl_obj, ucl_object_fromstring (cfg->cfg_name),
"config_path", 0, false);
ucl_object_insert_key (cfg->rcl_obj, ucl_object_fromstring (logdir),
static gboolean show_version = FALSE;
GHashTable *ucl_vars = NULL;
struct rspamd_main *rspamd_main = NULL;
+lua_State *L = NULL;
-static void rspamadm_help (gint argc, gchar **argv);
-static const char* rspamadm_help_help (gboolean full_help);
+static void rspamadm_help (gint argc, gchar **argv, const struct rspamadm_command *);
+static const char* rspamadm_help_help (gboolean full_help, const struct rspamadm_command *);
struct rspamadm_command help_command = {
.name = "help",
}
static void
-rspamadm_commands (void)
+rspamadm_commands (GPtrArray *all_commands)
{
- const struct rspamadm_command **cmd;
+ const struct rspamadm_command *cmd;
+ guint i;
printf ("Rspamadm %s\n", RVERSION);
printf ("Usage: rspamadm [global_options] command [command_options]\n");
printf ("\nAvailable commands:\n");
- cmd = commands;
-
- while (*cmd) {
- if (!((*cmd)->flags & RSPAMADM_FLAG_NOHELP)) {
- printf (" %-18s %-60s\n", (*cmd)->name, (*cmd)->help (FALSE));
+ PTR_ARRAY_FOREACH (all_commands, i, cmd) {
+ if (!(cmd->flags & RSPAMADM_FLAG_NOHELP)) {
+ printf (" %-18s %-60s\n", cmd->name, cmd->help (FALSE, cmd));
}
+
cmd ++;
}
}
static const char *
-rspamadm_help_help (gboolean full_help)
+rspamadm_help_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_help (gint argc, gchar **argv)
+rspamadm_help (gint argc, gchar **argv, const struct rspamadm_command *command)
{
const gchar *cmd_name;
- const struct rspamadm_command *cmd, **cmd_list;
+ const struct rspamadm_command *cmd;
+ GPtrArray *all_commands = (GPtrArray *)command->command_data;
printf ("Rspamadm %s\n", RVERSION);
printf ("Usage: rspamadm [global_options] command [command_options]\n\n");
printf ("Showing help for %s command\n\n", cmd_name);
}
- cmd = rspamadm_search_command (cmd_name);
+ cmd = rspamadm_search_command (cmd_name, all_commands);
if (cmd == NULL) {
fprintf (stderr, "Invalid command name: %s\n", cmd_name);
}
if (strcmp (cmd_name, "help") == 0) {
+ guint i;
printf ("Available commands:\n");
- cmd_list = commands;
-
- while (*cmd_list) {
- if (!((*cmd_list)->flags & RSPAMADM_FLAG_NOHELP)) {
- printf (" %-18s %-60s\n", (*cmd_list)->name,
- (*cmd_list)->help (FALSE));
+ PTR_ARRAY_FOREACH (all_commands, i, cmd) {
+ if (!(cmd->flags & RSPAMADM_FLAG_NOHELP)) {
+ printf (" %-18s %-60s\n", cmd->name,
+ cmd->help (FALSE, cmd));
}
- cmd_list++;
}
}
else {
- printf ("%s\n", cmd->help (TRUE));
+ printf ("%s\n", cmd->help (TRUE, cmd));
}
}
return FALSE;
}
else {
+ if (lua_type (L, -1) == LUA_TTABLE) {
+ lua_pushstring (L, "handler");
+ lua_gettable (L, -2);
+ }
+
if (lua_type (L, -1) != LUA_TFUNCTION) {
msg_err ("lua script must return "
"function and not %s",
gchar **nargv, **targv;
const gchar *cmd_name;
const struct rspamadm_command *cmd;
+ GPtrArray *all_commands = g_ptr_array_new (); /* Discovered during check */
gint i, nargc, targc;
ucl_vars = g_hash_table_new_full (rspamd_strcase_hash,
rspamd_strcase_equal, g_free, g_free);
process_quark = g_quark_from_static_string ("rspamadm");
- cfg = rspamd_config_new ();
+ cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_DEFAULT);
cfg->libs_ctx = rspamd_init_libs ();
rspamd_main = g_malloc0 (sizeof (*rspamd_main));
rspamd_main->cfg = cfg;
rspamd_main->type = process_quark;
rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
"rspamadm");
+ rspamadm_fill_internal_commands (all_commands);
+ help_command.command_data = all_commands;
/* Setup logger */
if (verbose) {
exit (1);
}
+ L = cfg->lua_state;
+ rspamd_lua_set_path (L, NULL, ucl_vars);
+
g_strfreev (nargv);
if (show_version) {
exit (EXIT_SUCCESS);
}
if (list_commands) {
- rspamadm_commands ();
+ rspamadm_commands (all_commands);
exit (EXIT_SUCCESS);
}
cmd_name = "help";
}
- cmd = rspamadm_search_command (cmd_name);
+ cmd = rspamadm_search_command (cmd_name, all_commands);
if (cmd == NULL) {
fprintf (stderr, "Invalid command name: %s\n", cmd_name);
targc = argc - nargc;
targv = nargv;
- cmd->run (targc, targv);
+ cmd->run (targc, targv, cmd);
g_strfreev (nargv);
}
else {
- cmd->run (0, NULL);
+ cmd->run (0, NULL, cmd);
}
rspamd_log_close (rspamd_main->logger);
REF_RELEASE (rspamd_main->cfg);
+ lua_close (L);
g_free (rspamd_main);
+ g_ptr_array_free (all_commands, TRUE);
return 0;
}
#include "config.h"
#include "ucl.h"
+#include <lua.h>
+#include <lauxlib.h>
+#include <lualib.h>
extern GHashTable *ucl_vars;
+extern lua_State *L;
GQuark rspamadm_error (void);
-typedef const gchar* (*rspamadm_help_func) (gboolean full_help);
-typedef void (*rspamadm_run_func) (gint argc, gchar **argv);
+struct rspamadm_command;
+typedef const gchar* (*rspamadm_help_func) (gboolean full_help,
+ const struct rspamadm_command *cmd);
+typedef void (*rspamadm_run_func) (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
typedef void (*rspamadm_lua_exports_func) (gpointer lua_state);
#define RSPAMADM_FLAG_NOHELP (1 << 0)
+#define RSPAMADM_FLAG_LUA (1 << 0)
struct rspamadm_command {
const gchar *name;
rspamadm_help_func help;
rspamadm_run_func run;
rspamadm_lua_exports_func lua_subrs;
+ gint cbref;
+ gpointer command_data; /* Opaque data */
};
extern const struct rspamadm_command *commands[];
extern struct rspamadm_command help_command;
-const struct rspamadm_command *rspamadm_search_command (const gchar *name);
+const struct rspamadm_command *rspamadm_search_command (const gchar *name,
+ GPtrArray *all_commands);
+void rspamadm_fill_internal_commands (GPtrArray *dest);
gboolean rspamadm_execute_lua_ucl_subr (gpointer L, gint argc, gchar **argv,
- const ucl_object_t *res, const gchar *script_name);
+ const ucl_object_t *res,
+ const gchar *script_name);
#endif
static gboolean edit = FALSE;
enum rspamd_cryptobox_mode mode = RSPAMD_CRYPTOBOX_MODE_25519;
-static void rspamadm_signtool (gint argc, gchar **argv);
-static const char *rspamadm_signtool_help (gboolean full_help);
+static void rspamadm_signtool (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_signtool_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command signtool_command = {
.name = "signtool",
};
static const char *
-rspamadm_signtool_help (gboolean full_help)
+rspamadm_signtool_help (gboolean full_help,
+ const struct rspamadm_command *cmd)
{
const char *help_str;
static void
-rspamadm_signtool (gint argc, gchar **argv)
+rspamadm_signtool (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
static gchar *redis_password = NULL;
static gboolean reset_previous = FALSE;
-static void rspamadm_statconvert (gint argc, gchar **argv);
-static const char *rspamadm_statconvert_help (gboolean full_help);
+static void rspamadm_statconvert (gint argc, gchar **argv,
+ const struct rspamadm_command *cmd);
+static const char *rspamadm_statconvert_help (gboolean full_help,
+ const struct rspamadm_command *cmd);
struct rspamadm_command statconvert_command = {
.name = "statconvert",
static const char *
-rspamadm_statconvert_help (gboolean full_help)
+rspamadm_statconvert_help (gboolean full_help, const struct rspamadm_command *cmd)
{
const char *help_str;
}
static void
-rspamadm_statconvert (gint argc, gchar **argv)
+rspamadm_statconvert (gint argc, gchar **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
gchar *cfg_file;
rspamd_symbols_cache_save (rspamd_main->cfg->cache);
- tmp_cfg = rspamd_config_new ();
+ tmp_cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_DEFAULT);
g_hash_table_unref (tmp_cfg->c_modules);
tmp_cfg->c_modules = g_hash_table_ref (rspamd_main->cfg->c_modules);
tmp_cfg->libs_ctx = rspamd_main->cfg->libs_ctx;
"main");
rspamd_main->stat = rspamd_mempool_alloc0_shared (rspamd_main->server_pool,
sizeof (struct rspamd_stat));
- rspamd_main->cfg = rspamd_config_new ();
+ rspamd_main->cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_DEFAULT);
rspamd_main->spairs = g_hash_table_new_full (rspamd_spair_hash,
rspamd_spair_equal, g_free, rspamd_spair_close);
rspamd_main->start_mtx = rspamd_mempool_get_mutex (rspamd_main->server_pool);
rspamd_main = (struct rspamd_main *)g_malloc (sizeof (struct rspamd_main));
memset (rspamd_main, 0, sizeof (struct rspamd_main));
rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
- cfg = rspamd_config_new ();
+ cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_DEFAULT);
rspamd_main->cfg = cfg;
cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
cfg->log_type = RSPAMD_LOG_CONSOLE;
struct timeval tv;
rspamd_inet_addr_t *addr, *next_addr, *paddr;
- cfg = rspamd_config_new ();
+ cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_SKIP_LUA);
cfg->dns_retransmits = 2;
cfg->dns_timeout = 0.5;
cfg->upstream_max_errors = 1;