]> source.dussan.org Git - rspamd.git/commitdiff
Parse modules in ucl.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 27 Oct 2013 21:27:37 +0000 (21:27 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 27 Oct 2013 21:27:37 +0000 (21:27 +0000)
src/cfg_rcl.c
src/cfg_xml.c

index 8cd6d2217a7d58f955cb9dfe30c33f5431b5f382..2190f648a91250d3fb715ee45067d6156ff50508 100644 (file)
@@ -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;
 }
 
index 4e3757bad221af463609587cdac1b08af4f853d6..7c019acffd2afff034bfb9a44973f77dfd17142c 100644 (file)
@@ -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)
 {