diff options
Diffstat (limited to 'src/lua/lua_config.c')
-rw-r--r-- | src/lua/lua_config.c | 80 |
1 files changed, 9 insertions, 71 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 1da50ad19..d3b7c6af9 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -153,17 +153,17 @@ static gint lua_config_get_module_opt (lua_State * L) { struct config_file *cfg = lua_check_config (L); - const gchar *mname, *optname, *val; + const gchar *mname, *optname; + rspamd_cl_object_t *obj; if (cfg) { mname = luaL_checkstring (L, 2); optname = luaL_checkstring (L, 3); if (mname && optname) { - val = get_module_opt (cfg, (gchar *)mname, (gchar *)optname); - if (val) { - lua_pushstring (L, val); - return 1; + obj = get_module_opt (cfg, mname, optname); + if (obj) { + return lua_rcl_obj_push (L, obj); } } } @@ -186,82 +186,20 @@ lua_config_get_mempool (lua_State * L) } static gint -opt_compare (gconstpointer a, gconstpointer b) -{ - const struct module_opt *o1 = a, - *o2 = b; - - return g_ascii_strcasecmp (o1->param, o2->param); -} - -static gint lua_config_get_all_opt (lua_State * L) { struct config_file *cfg = lua_check_config (L); const gchar *mname; - GList *cur_opt, *next_opt; - struct module_opt *opt, *tmp; - gint i; + rspamd_cl_object_t *obj; if (cfg) { mname = luaL_checkstring (L, 2); if (mname) { - cur_opt = g_hash_table_lookup (cfg->modules_opts, mname); - if (cur_opt == NULL) { - lua_pushnil (L); - return 1; + obj = rspamd_cl_obj_get_key (cfg->rcl_obj, mname); + if (obj != NULL) { + return lua_rcl_obj_push (L, obj); } - /* Sort options in alphabet order by param name */ - cur_opt = g_list_sort (cur_opt, opt_compare); - g_hash_table_insert (cfg->modules_opts, (gpointer)mname, cur_opt); - - lua_newtable (L); - while (cur_opt) { - opt = cur_opt->data; - next_opt = g_list_next (cur_opt); - if (next_opt) { - tmp = next_opt->data; - if (g_ascii_strcasecmp (tmp->param, opt->param) == 0) { - /* We have some common values */ - lua_pushstring (L, opt->param); - lua_newtable (L); - /* Now stack looks like: - * table - parent associated table of options - * key - string key of this option - * table - array of values, beginig from 1 - */ - - for (i = 1; ; i++) { - lua_pushinteger (L, i); - lua_pushstring (L, opt->value); - lua_settable (L, -3); - - cur_opt = g_list_next (cur_opt); - if (!cur_opt) { - break; - } - tmp = cur_opt->data; - if (g_ascii_strcasecmp (tmp->param, opt->param) != 0) { - break; - } - opt = tmp; - } - /* Now set index in parent table */ - lua_settable (L, -3); - /* Now continue in outter cycle */ - continue; - } - else { - lua_set_table_index (L, opt->param, opt->value); - } - } - else { - lua_set_table_index (L, opt->param, opt->value); - } - cur_opt = next_opt; - } - return 1; } } lua_pushnil (L); |