]> source.dussan.org Git - rspamd.git/commitdiff
* Handle modules configuration
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 8 Apr 2010 13:38:45 +0000 (17:38 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 8 Apr 2010 13:38:45 +0000 (17:38 +0400)
src/cfg_xml.c
src/lua/lua_cfg_file.c

index 5acba2d4963d1dcaf296dcf312e8841885753aee..1c797b66852c08ff683f83eb6686bafc992d39e8 100644 (file)
@@ -702,36 +702,24 @@ handle_module_opt (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GHa
                        is_lua = TRUE;
                }
        }
-       cur_opt = g_hash_table_lookup (cfg->modules_opts, ctx->section_pointer);
-       if (cur_opt == NULL) {
-               /* Insert new option structure */
-               cur = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct module_opt));
-               cur->param = name;
-               cur->value = data;
-               cur->is_lua = is_lua;
-               cur_opt = g_list_prepend (NULL, cur);
-               g_hash_table_insert (cfg->modules_opts, memory_pool_strdup (cfg->cfg_pool, ctx->section_pointer), cur_opt);
-       }
-       else {
-               /* First try to find option with this name */
-               while (cur_opt) {
-                       cur = cur_opt->data;
-                       if (strcmp (cur->param, name) == 0) {
-                               /* cur->value is in pool */
-                               cur->value = data;
-                               cur->is_lua = is_lua;
-                               return TRUE;
-                       }
-                       cur_opt = g_list_next (cur_opt);
+       cur_opt = ctx->section_pointer;
+       /* First try to find option with this name */
+       while (cur_opt) {
+               cur = cur_opt->data;
+               if (strcmp (cur->param, name) == 0) {
+                       /* cur->value is in pool */
+                       cur->value = data;
+                       cur->is_lua = is_lua;
+                       return TRUE;
                }
-               /* Not found, insert */
-               cur = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct module_opt));
-               cur->param = name;
-               cur->value = data;
-               cur->is_lua = is_lua;
-               /* Slow way, but we cannot prepend here as we need to modify pointer inside module_options hash */
-               cur_opt = g_list_append (cur_opt, cur);
+               cur_opt = g_list_next (cur_opt);
        }
+       /* Not found, insert */
+       cur = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct module_opt));
+       cur->param = name;
+       cur->value = data;
+       cur->is_lua = is_lua;
+       ctx->section_pointer = g_list_prepend (ctx->section_pointer, cur);
 
        return TRUE;
 }
@@ -1157,7 +1145,9 @@ rspamd_xml_start_element (GMarkupParseContext *context, const gchar *element_nam
                        if (g_ascii_strcasecmp (element_name, "module") == 0) {
                                /* Read module data */
                                if (extract_attr ("name", attribute_names, attribute_values, &res)) {
-                                       ud->section_pointer = res;
+                                       ud->parent_pointer = memory_pool_strdup (ud->cfg->cfg_pool, res);
+                                       /* Empty list */
+                                       ud->section_pointer = NULL;
                                        ud->state = XML_READ_MODULE;
                                }
                                else {
@@ -1274,6 +1264,13 @@ rspamd_xml_end_element (GMarkupParseContext      *context, const gchar *element_name,
        switch (ud->state) {
                case XML_READ_MODULE:
                        CHECK_TAG ("module", FALSE);
+                       if (res) {
+                               if (ud->section_pointer != NULL) {
+                                       g_hash_table_insert (ud->cfg->modules_opts, ud->parent_pointer, ud->section_pointer);
+                                       ud->parent_pointer = NULL;
+                                       ud->section_pointer = NULL;
+                               }
+                       }
                        break;
                case XML_READ_CLASSIFIER:
                        CHECK_TAG ("classifier", FALSE);
index 8be11b02bc6c8860ce7c52846b35aebd6e55358e..e087600fde3593623cc7a9d62493ad1fcf308915 100644 (file)
 
 /* Check element with specified name in list, and append it to list if no element with such name was found */
 static void
-lua_check_element (memory_pool_t *pool, const gchar *name, GList *options, struct module_opt **opt) 
+lua_check_element (memory_pool_t *pool, const gchar *name, GList **options, struct module_opt **opt) 
 {
        struct module_opt                   *cur;
        GList                               *cur_opt;
        gboolean                             found = FALSE;
 
-       cur_opt = options;
+       cur_opt = *options;
 
        while (cur_opt) {
                cur = cur_opt->data;
@@ -57,7 +57,7 @@ lua_check_element (memory_pool_t *pool, const gchar *name, GList *options, struc
                /* New option */
                *opt = memory_pool_alloc0 (pool, sizeof (struct module_opt));
                (*opt)->is_lua = TRUE;
-               (void)g_list_append (options, *opt);
+               *options = g_list_prepend (*options, *opt);
        }
 }
 
@@ -81,8 +81,9 @@ lua_process_module (lua_State *L, const gchar *param, struct config_file *cfg)
                /* key - -2, value - -1 */
                name = luaL_checkstring (L, -2);
                if (name != NULL) {
-                       lua_check_element (cfg->cfg_pool, name, cur_opt, &cur);
+                       lua_check_element (cfg->cfg_pool, name, &cur_opt, &cur);
                        lua_process_element (cfg, name, cur, -1);
+                       g_hash_table_insert (cfg->modules_opts, (gpointer)param, cur_opt);
                }
        }