aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-04-20 16:32:23 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-04-20 16:32:23 +0400
commit2d8eebcf7a0951d3d1189ddface7678fea76dd4c (patch)
tree7a1748e4d3633c3b8def3de8f2a08fb370c7e61d /src/lua
parentd4b35de4315753629ac5b107968e6194eac85d24 (diff)
downloadrspamd-2d8eebcf7a0951d3d1189ddface7678fea76dd4c.tar.gz
rspamd-2d8eebcf7a0951d3d1189ddface7678fea76dd4c.zip
* Bugfixes:
- handle '\' characters in lua strings correctly - fix lua initialization - avoid of using global lua state (global L) - fix listen sockets hash to allow multiply workers of same type but on different listen sockets - fix modules options inserting to allow multiply options of the same name - fix parsing of lua options - fix lua rules
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_cfg_file.c2
-rw-r--r--src/lua/lua_common.c54
-rw-r--r--src/lua/lua_common.h2
3 files changed, 24 insertions, 34 deletions
diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c
index e087600fd..799a603c0 100644
--- a/src/lua/lua_cfg_file.c
+++ b/src/lua/lua_cfg_file.c
@@ -57,6 +57,7 @@ lua_check_element (memory_pool_t *pool, const gchar *name, GList **options, stru
/* New option */
*opt = memory_pool_alloc0 (pool, sizeof (struct module_opt));
(*opt)->is_lua = TRUE;
+ (*opt)->param = memory_pool_strdup (pool, name);
*options = g_list_prepend (*options, *opt);
}
}
@@ -76,7 +77,6 @@ lua_process_module (lua_State *L, const gchar *param, struct config_file *cfg)
}
/* Now iterate throught module table */
- lua_gettable (L, -1);
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
/* key - -2, value - -1 */
name = luaL_checkstring (L, -2);
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index dd79d9eab..fc5fe0772 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -28,7 +28,6 @@
/* Lua module init function */
#define MODULE_INIT_FUNC "module_init"
-lua_State *L = NULL;
const luaL_reg null_reg[] = {
{"__tostring", lua_class_tostring},
{NULL, NULL}
@@ -184,24 +183,25 @@ luaopen_logger (lua_State * L)
void
init_lua (struct config_file *cfg)
{
- if (L == NULL) {
- L = lua_open ();
- luaL_openlibs (L);
-
- (void)luaopen_rspamd (L);
- (void)luaopen_logger (L);
- (void)luaopen_config (L);
- (void)luaopen_metric (L);
- (void)luaopen_radix (L);
- (void)luaopen_hash_table (L);
- (void)luaopen_task (L);
- (void)luaopen_textpart (L);
- (void)luaopen_message (L);
- (void)luaopen_classifier (L);
- (void)luaopen_statfile (L);
- cfg->lua_state = L;
- memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)lua_close, L);
- }
+ lua_State *L;
+
+ L = lua_open ();
+ luaL_openlibs (L);
+
+ (void)luaopen_rspamd (L);
+ (void)luaopen_logger (L);
+ (void)luaopen_config (L);
+ (void)luaopen_metric (L);
+ (void)luaopen_radix (L);
+ (void)luaopen_hash_table (L);
+ (void)luaopen_task (L);
+ (void)luaopen_textpart (L);
+ (void)luaopen_message (L);
+ (void)luaopen_classifier (L);
+ (void)luaopen_statfile (L);
+ cfg->lua_state = L;
+ memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)lua_close, L);
+
}
@@ -213,6 +213,7 @@ init_lua_filters (struct config_file *cfg)
GList *cur, *tmp;
struct script_module *module;
struct statfile *st;
+ lua_State *L = cfg->lua_state;
cur = g_list_first (cfg->script_modules);
while (cur) {
@@ -413,23 +414,12 @@ lua_consolidation_func (struct worker_task *task, const char *metric_name, const
return data.score;
}
-void
-add_luabuf (const char *line)
-{
- int error;
-
- error = luaL_loadbuffer (L, line, strlen (line), "config") || lua_pcall (L, 0, 0, 0);
- if (error) {
- yyerror ("lua error: %s", lua_tostring (L, -1));
- lua_pop (L, 1); /* pop error message from the stack */
- }
-}
-
double
-lua_normalizer_func (double score, void *params)
+lua_normalizer_func (struct config_file *cfg, double score, void *params)
{
GList *p = params;
double res = score;
+ lua_State *L = cfg->lua_state;
/* Call specified function and put input score on stack */
if (!p->data) {
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index dd4e75a8f..f89ccaa30 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -44,7 +44,7 @@ void add_luabuf (const char *line);
GList *call_classifier_pre_callbacks (struct classifier_config *ccf, struct worker_task *task);
double call_classifier_post_callbacks (struct classifier_config *ccf, struct worker_task *task, double in);
-double lua_normalizer_func (double score, void *params);
+double lua_normalizer_func (struct config_file *cfg, double score, void *params);
/* Config file functions */
void lua_post_load_config (struct config_file *cfg);