return TRUE;
}
-static gboolean
-rspamd_rcl_add_module_path (struct rspamd_config *cfg,
- const gchar *path,
- GError **err)
+gboolean
+rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
+ const gchar *path,
+ GError **err)
{
struct stat st;
struct script_module *cur_mod;
LL_FOREACH (val, cur)
{
if (ucl_object_tostring_safe (cur, &data)) {
- if (!rspamd_rcl_add_module_path (cfg,
- rspamd_mempool_strdup (cfg->cfg_pool, data), err)) {
+ if (!rspamd_rcl_add_lua_plugins_path (cfg,
+ rspamd_mempool_strdup (cfg->cfg_pool, data), err)) {
return FALSE;
}
}
}
}
else if (ucl_object_tostring_safe (obj, &data)) {
- if (!rspamd_rcl_add_module_path (cfg,
- rspamd_mempool_strdup (cfg->cfg_pool, data), err)) {
+ if (!rspamd_rcl_add_lua_plugins_path (cfg,
+ rspamd_mempool_strdup (cfg->cfg_pool, data), err)) {
return FALSE;
}
}
ucl_object_t *top_doc, const ucl_object_t *obj,
const ucl_object_t *comments, gboolean is_top)
{
- ucl_object_iter_t it;
+ ucl_object_iter_t it = NULL;
const ucl_object_t *cur, *cmt;
ucl_object_t *cur_doc;
top_doc = rspamd_rcl_add_doc_by_path (cfg, root_path, doc_string,
doc_name, ucl_object_type (top), NULL, 0, NULL, FALSE);
ucl_object_insert_key (top_doc,
- ucl_object_fromlstring (example_data, example_len),
+ ucl_object_fromstring_common (example_data, example_len, 0),
"example", 0, false);
rspamd_rcl_add_doc_from_comments (cfg, top_doc, top, comments, TRUE);
const gchar *doc_string,
const gchar *doc_name,
const gchar *example_data, gsize example_len);
+
+/**
+ * Add lua modules path
+ * @param cfg
+ * @param path
+ * @param err
+ * @return
+ */
+gboolean rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
+ const gchar *path,
+ GError **err);
#endif /* CFG_RCL_H_ */
cur = g_list_next (cur);
}
- return rspamd_init_lua_filters (cfg);
+ return rspamd_init_lua_filters (cfg, 0);
}
static void
}
gboolean
-rspamd_init_lua_filters (struct rspamd_config *cfg)
+rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load)
{
struct rspamd_config **pcfg;
GList *cur;
while (cur) {
module = cur->data;
if (module->path) {
- if (!rspamd_config_is_module_enabled (cfg, module->name)) {
- cur = g_list_next (cur);
- continue;
+ if (!force_load) {
+ if (!rspamd_config_is_module_enabled (cfg, module->name)) {
+ cur = g_list_next (cur);
+ continue;
+ }
}
lua_pushcfunction (L, &rspamd_lua_traceback);
/**
* Load and initialize lua plugins
*/
-gboolean rspamd_init_lua_filters (struct rspamd_config *cfg);
+gboolean
+rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load);
/**
* Initialize new locked lua_State structure
lua_config_add_doc (lua_State *L)
{
struct rspamd_config *cfg;
- const gchar *path, *option, *doc_string;
+ const gchar *path = NULL, *option, *doc_string;
const gchar *type_str = NULL, *default_value = NULL;
ucl_type_t type = UCL_NULL;
gboolean required = FALSE;
GError *err = NULL;
cfg = lua_check_config (L, 1);
- path = luaL_checkstring (L, 2);
+
+ if (lua_type (L, 2 ) == LUA_TSTRING) {
+ path = luaL_checkstring (L, 2);
+ }
+
option = luaL_checkstring (L, 3);
doc_string = luaL_checkstring (L, 4);
- if (cfg && path && option && doc_string) {
+ if (cfg && option && doc_string) {
if (lua_type (L, 5) == LUA_TTABLE) {
if (!rspamd_lua_parse_table_arguments (L, 2, &err,
"type=S;default=S;required=B",
lua_config_add_example (lua_State *L)
{
struct rspamd_config *cfg;
- const gchar *path, *option, *doc_string, *example;
+ const gchar *path = NULL, *option, *doc_string, *example;
gsize example_len;
cfg = lua_check_config (L, 1);
- path = luaL_checkstring (L, 2);
+
+ if (lua_type (L, 2 ) == LUA_TSTRING) {
+ path = luaL_checkstring (L, 2);
+ }
+
option = luaL_checkstring (L, 3);
doc_string = luaL_checkstring (L, 4);
example = luaL_checklstring (L, 5, &example_len);
- if (cfg && path && option && doc_string && example) {
+ if (cfg && option && doc_string && example) {
rspamd_rcl_add_doc_by_example (cfg, path, doc_string, option,
example, example_len);
else
logger.infox('DCC module not configured');
end
+
+rspamd_config:add_example(nil, 'dcc',
+ "Check messages for 'bulkiness' using DCC",
+[[
+dcc {
+ host = "/var/dcc/dccifd"; # Unix socket or hostname
+ port = 1234 # Port to use (needed for TCP socket)
+ timeout = 2s; # Timeout to wait for checks
+}
+]])
\ No newline at end of file
static gboolean json = FALSE;
static gboolean compact = FALSE;
static gboolean keyword = FALSE;
+static const gchar *plugins_path = RSPAMD_PLUGINSDIR;
extern struct rspamd_main *rspamd_main;
/* Defined in modules.c */
extern module_t *modules[];
"Output compacted", NULL},
{"keyword", 'k', 0, G_OPTION_ARG_NONE, &keyword,
"Search by keyword", NULL},
+ {"plugins", 'P', 0, G_OPTION_ARG_STRING, &plugins_path,
+ "Use the following plugin path (" RSPAMD_PLUGINSDIR ")", NULL},
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
};
"-c: output compacted JSON\n"
"-j: output pretty formatted JSON\n"
"-k: search by keyword in doc string\n"
- "--color: show colored output\n"
+ "-P: use specific Lua plugins path\n"
+ "--no-color: show colored output\n"
"--short: show only option names\n"
"--no-examples: do not show examples (impied by --short)\n"
"--help: shows available options and commands";
cfg->compiled_workers = workers;
rspamd_rcl_config_init (cfg);
+ lua_pushboolean (cfg->lua_state, true);
+ lua_setglobal (cfg->lua_state, "confighelp");
+ rspamd_rcl_add_lua_plugins_path (cfg, plugins_path, NULL);
/* Init modules to get documentation strings */
for (pmod = cfg->compiled_modules; pmod != NULL && *pmod != NULL; pmod++) {
(*pworker)->worker_init_func (cfg);
}
+ /* Init lua modules */
+ rspamd_init_lua_filters (cfg, TRUE);
+
if (argc > 1) {
for (i = 1; i < argc; i ++) {
if (argv[i][0] != '-') {
local function maybe_print_color(key)
- if opts['color'] then
+ if not opts['no-color'] then
return ansicolors.white .. key .. ansicolors.reset
else
return key