diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-04-05 21:09:40 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-04-05 21:09:40 +0400 |
commit | 42baae32bc212e9287e11afa685e2de77cdf48e4 (patch) | |
tree | 1bf9ad6eeb94a0bf40e8d60ed1a0777aa23aa69d /src/cfg_utils.c | |
parent | 6be82def714f297d54302953286223b4afb07208 (diff) | |
download | rspamd-42baae32bc212e9287e11afa685e2de77cdf48e4.tar.gz rspamd-42baae32bc212e9287e11afa685e2de77cdf48e4.zip |
* Add initial version of lua configuration system
Diffstat (limited to 'src/cfg_utils.c')
-rw-r--r-- | src/cfg_utils.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/cfg_utils.c b/src/cfg_utils.c index 18677a1ca..9047340fb 100644 --- a/src/cfg_utils.c +++ b/src/cfg_utils.c @@ -243,6 +243,7 @@ get_module_opt (struct config_file *cfg, gchar *module_name, gchar *opt_name) { GList *cur_opt; struct module_opt *cur; + static char numbuf[64]; cur_opt = g_hash_table_lookup (cfg->modules_opts, module_name); if (cur_opt == NULL) { @@ -252,7 +253,31 @@ get_module_opt (struct config_file *cfg, gchar *module_name, gchar *opt_name) while (cur_opt) { cur = cur_opt->data; if (strcmp (cur->param, opt_name) == 0) { - return cur->value; + /* Check if it is lua variable */ + if (! cur->is_lua) { + /* Plain variable */ + return cur->value; + } + else { + /* Check type */ + switch (cur->lua_type) { + case LUA_VAR_NUM: + /* numbuf is static, so it is safe to return it "as is" */ + snprintf (numbuf, sizeof (numbuf), "%f", *(double *)cur->actual_data); + return numbuf; + case LUA_VAR_BOOLEAN: + snprintf (numbuf, sizeof (numbuf), "%s", *(gboolean *)cur->actual_data ? "yes" : "no"); + return numbuf; + case LUA_VAR_STRING: + return (char *)cur->actual_data; + case LUA_VAR_FUNCTION: + msg_info ("option %s is dynamic, so it cannot be aqquired statically", opt_name); + return NULL; + case LUA_VAR_UNKNOWN: + msg_info ("option %s has unknown type, maybe there is error in LUA code", opt_name); + return NULL; + } + } } cur_opt = g_list_next (cur_opt); } @@ -573,7 +598,9 @@ post_load_config (struct config_file *cfg) cfg->metrics_list = g_list_prepend (cfg->metrics_list, def_metric); g_hash_table_insert (cfg->metrics, DEFAULT_METRIC, def_metric); } - + + /* Lua options */ + (void)lua_post_load_config (cfg); } |