aboutsummaryrefslogtreecommitdiffstats
path: root/src/cfg_rcl.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2013-11-07 22:08:55 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2013-11-07 22:08:55 +0000
commit5f0b3e44efaae6f8c3c2101b5cbde333f129933c (patch)
tree9d5985ef489449e8cecf78c49a66ea839a4bd1e8 /src/cfg_rcl.c
parent8082b0292b52e4cd5dfc229cb6b93b6e1a7d56f2 (diff)
downloadrspamd-5f0b3e44efaae6f8c3c2101b5cbde333f129933c.tar.gz
rspamd-5f0b3e44efaae6f8c3c2101b5cbde333f129933c.zip
Allow 'modules' directive to be a plain string.
Diffstat (limited to 'src/cfg_rcl.c')
-rw-r--r--src/cfg_rcl.c94
1 files changed, 58 insertions, 36 deletions
diff --git a/src/cfg_rcl.c b/src/cfg_rcl.c
index 6cdad1b63..eedcd9ee2 100644
--- a/src/cfg_rcl.c
+++ b/src/cfg_rcl.c
@@ -623,57 +623,79 @@ rspamd_rcl_lua_handler (struct config_file *cfg, ucl_object_t *obj,
}
static gboolean
-rspamd_rcl_modules_handler (struct config_file *cfg, ucl_object_t *obj,
- gpointer ud, struct rspamd_rcl_section *section, GError **err)
+rspamd_rcl_add_module_path (struct config_file *cfg, const gchar *path, GError **err)
{
- ucl_object_t *val, *cur;
struct stat st;
struct script_module *cur_mod;
glob_t globbuf;
gchar *pattern;
- const gchar *data;
size_t len;
guint i;
- val = ucl_object_find_key (obj, "path");
+ if (stat (path, &st) == -1) {
+ g_set_error (err, CFG_RCL_ERROR, errno, "cannot stat path %s, %s", path, strerror (errno));
+ return FALSE;
+ }
- LL_FOREACH (val, cur) {
- if (ucl_object_tostring_safe (cur, &data)) {
- if (stat (data, &st) == -1) {
- g_set_error (err, CFG_RCL_ERROR, errno, "cannot stat path %s, %s", data, strerror (errno));
- return FALSE;
+ /* Handle directory */
+ if (S_ISDIR (st.st_mode)) {
+ globbuf.gl_offs = 0;
+ len = strlen (path) + sizeof ("*.lua");
+ pattern = g_malloc (len);
+ snprintf (pattern, len, "%s%s", path, "*.lua");
+
+ if (glob (pattern, GLOB_DOOFFS, NULL, &globbuf) == 0) {
+ for (i = 0; i < globbuf.gl_pathc; i ++) {
+ cur_mod = memory_pool_alloc (cfg->cfg_pool, sizeof (struct script_module));
+ cur_mod->path = memory_pool_strdup (cfg->cfg_pool, globbuf.gl_pathv[i]);
+ cfg->script_modules = g_list_prepend (cfg->script_modules, cur_mod);
}
+ globfree (&globbuf);
+ g_free (pattern);
+ }
+ else {
+ g_set_error (err, CFG_RCL_ERROR, errno, "glob failed for %s, %s", pattern, strerror (errno));
+ g_free (pattern);
+ return FALSE;
+ }
+ }
+ else {
+ /* Handle single file */
+ cur_mod = memory_pool_alloc (cfg->cfg_pool, sizeof (struct script_module));
+ cur_mod->path = memory_pool_strdup (cfg->cfg_pool, path);
+ cfg->script_modules = g_list_prepend (cfg->script_modules, cur_mod);
+ }
- /* Handle directory */
- if (S_ISDIR (st.st_mode)) {
- globbuf.gl_offs = 0;
- len = strlen (data) + sizeof ("*.lua");
- pattern = g_malloc (len);
- snprintf (pattern, len, "%s%s", data, "*.lua");
-
- if (glob (pattern, GLOB_DOOFFS, NULL, &globbuf) == 0) {
- for (i = 0; i < globbuf.gl_pathc; i ++) {
- cur_mod = memory_pool_alloc (cfg->cfg_pool, sizeof (struct script_module));
- cur_mod->path = memory_pool_strdup (cfg->cfg_pool, globbuf.gl_pathv[i]);
- cfg->script_modules = g_list_prepend (cfg->script_modules, cur_mod);
- }
- globfree (&globbuf);
- g_free (pattern);
- }
- else {
- g_set_error (err, CFG_RCL_ERROR, errno, "glob failed for %s, %s", pattern, strerror (errno));
- g_free (pattern);
+ return TRUE;
+}
+
+static gboolean
+rspamd_rcl_modules_handler (struct config_file *cfg, ucl_object_t *obj,
+ gpointer ud, struct rspamd_rcl_section *section, GError **err)
+{
+ ucl_object_t *val, *cur;
+ const gchar *data;
+
+ if (obj->type == UCL_OBJECT) {
+ val = ucl_object_find_key (obj, "path");
+
+ LL_FOREACH (val, cur) {
+ if (ucl_object_tostring_safe (cur, &data)) {
+ if (!rspamd_rcl_add_module_path (cfg, data, err)) {
return FALSE;
}
}
- else {
- /* Handle single file */
- cur_mod = memory_pool_alloc (cfg->cfg_pool, sizeof (struct script_module));
- cur_mod->path = memory_pool_strdup (cfg->cfg_pool, data);
- cfg->script_modules = g_list_prepend (cfg->script_modules, cur_mod);
- }
}
}
+ else if (ucl_object_tostring_safe (obj, &data)) {
+ if (!rspamd_rcl_add_module_path (cfg, data, err)) {
+ return FALSE;
+ }
+ }
+ else {
+ g_set_error (err, CFG_RCL_ERROR, EINVAL, "module parameter has wrong type (must be an object or a string)");
+ return FALSE;
+ }
return TRUE;
}
@@ -947,7 +969,7 @@ rspamd_rcl_config_init (void)
* Modules handler
*/
sub = rspamd_rcl_add_section (&new, "modules", rspamd_rcl_modules_handler, UCL_OBJECT,
- FALSE, TRUE);
+ FALSE, FALSE);
/**
* Classifiers handler