aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2013-10-27 21:27:37 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2013-10-27 21:27:37 +0000
commitf4453c68aecb0f09b2cc8faf0abdd119fe7d1dd2 (patch)
treea0f6a80f9ca6063904f0397223af0c82762e0686 /src
parentdac24787dff6273cc2b6c1584cb255f6b24a0238 (diff)
downloadrspamd-f4453c68aecb0f09b2cc8faf0abdd119fe7d1dd2.tar.gz
rspamd-f4453c68aecb0f09b2cc8faf0abdd119fe7d1dd2.zip
Parse modules in ucl.
Diffstat (limited to 'src')
-rw-r--r--src/cfg_rcl.c62
-rw-r--r--src/cfg_xml.c51
2 files changed, 62 insertions, 51 deletions
diff --git a/src/cfg_rcl.c b/src/cfg_rcl.c
index 8cd6d2217..2190f648a 100644
--- a/src/cfg_rcl.c
+++ b/src/cfg_rcl.c
@@ -616,6 +616,62 @@ rspamd_rcl_lua_handler (struct config_file *cfg, ucl_object_t *obj,
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;
+ 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");
+
+ 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 (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 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);
+ }
+ }
+ }
+
+ return TRUE;
+}
+
/**
* Fake handler to parse default options only, uses struct cfg_file as pointer
* for default handlers
@@ -769,6 +825,12 @@ rspamd_rcl_config_init (void)
sub = rspamd_rcl_add_section (&new, "lua", rspamd_rcl_lua_handler, UCL_STRING,
FALSE, TRUE);
+ /**
+ * Modules handler
+ */
+ sub = rspamd_rcl_add_section (&new, "modules", rspamd_rcl_modules_handler, UCL_OBJECT,
+ FALSE, TRUE);
+
return new;
}
diff --git a/src/cfg_xml.c b/src/cfg_xml.c
index 4e3757bad..7c019acff 100644
--- a/src/cfg_xml.c
+++ b/src/cfg_xml.c
@@ -754,57 +754,6 @@ process_attrs (const gchar **attribute_names, const gchar **attribute_values, uc
/* Handlers */
-
-
-/* Modules section */
-gboolean
-handle_module_path (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GHashTable *attrs, gchar *data, gpointer user_data, gpointer dest_struct, gint offset)
-{
- struct stat st;
- struct script_module *cur;
- glob_t globbuf;
- gchar *pattern;
- size_t len;
- guint i;
-
- if (stat (data, &st) == -1) {
- msg_err ("cannot stat path %s, %s", data, strerror (errno));
- return FALSE;
- }
-
- /* 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 = memory_pool_alloc (cfg->cfg_pool, sizeof (struct script_module));
- cur->path = memory_pool_strdup (cfg->cfg_pool, globbuf.gl_pathv[i]);
- cfg->script_modules = g_list_prepend (cfg->script_modules, cur);
- }
- globfree (&globbuf);
- g_free (pattern);
- }
- else {
- msg_err ("glob failed: %s", strerror (errno));
- g_free (pattern);
- return FALSE;
- }
- }
- else {
- /* Handle single file */
- cur = memory_pool_alloc (cfg->cfg_pool, sizeof (struct script_module));
- cur->path = memory_pool_strdup (cfg->cfg_pool, data);
- cfg->script_modules = g_list_prepend (cfg->script_modules, cur);
- }
-
-
- return TRUE;
-}
-
gboolean
handle_composite (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GHashTable *attrs, gchar *data, gpointer user_data, gpointer dest_struct, gint offset)
{