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;
}
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 {
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);
/* 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;
/* 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);
}
}
/* 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);
}
}