aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-04-08 17:38:45 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-04-08 17:38:45 +0400
commitb98e24b4b430d185f612281b2c6e5441f108f165 (patch)
tree0fa73efc48051265387e0d97dc9b1d23128ac570
parente47778974acc39511f01ac89281bd32a759aab9f (diff)
downloadrspamd-b98e24b4b430d185f612281b2c6e5441f108f165.tar.gz
rspamd-b98e24b4b430d185f612281b2c6e5441f108f165.zip
* Handle modules configuration
-rw-r--r--src/cfg_xml.c55
-rw-r--r--src/lua/lua_cfg_file.c9
2 files changed, 31 insertions, 33 deletions
diff --git a/src/cfg_xml.c b/src/cfg_xml.c
index 5acba2d49..1c797b668 100644
--- a/src/cfg_xml.c
+++ b/src/cfg_xml.c
@@ -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);
diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c
index 8be11b02b..e087600fd 100644
--- a/src/lua/lua_cfg_file.c
+++ b/src/lua/lua_cfg_file.c
@@ -31,13 +31,13 @@
/* 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);
}
}