From: Vsevolod Stakhov Date: Wed, 2 Sep 2009 15:15:51 +0000 (+0400) Subject: * Fix lua API X-Git-Tag: 0.2.7~28 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=563a106f3a57e460b9c5ea06a2eb4e6456f9e080;p=rspamd.git * Fix lua API --- diff --git a/src/cfg_file.h b/src/cfg_file.h index 7e3f035bc..2b67f8c72 100644 --- a/src/cfg_file.h +++ b/src/cfg_file.h @@ -95,6 +95,7 @@ struct memcached_server { * script module list item */ struct script_module { + char *name; /**< name of module */ char *path; /**< path to module */ }; diff --git a/src/cfg_file.l b/src/cfg_file.l index 7f2931ccc..ce207dbf5 100644 --- a/src/cfg_file.l +++ b/src/cfg_file.l @@ -51,7 +51,10 @@ connect_timeout return CONNECT_TIMEOUT; protocol return PROTOCOL; memcached return MEMCACHED; servers return SERVERS; + require return REQUIRE; +module return MODULE; + filters return FILTERS; factors return FACTORS; metric return METRIC; diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 66ae67d58..907f7e6b5 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -146,14 +146,15 @@ init_lua () luaopen_task (L); luaopen_message (L); luaopen_logger (L); + luaopen_config (L); + luaopen_metric (L); + luaopen_textpart (L); } } void init_lua_filters (struct config_file *cfg) { - char *init_func; - size_t funclen; struct config_file **pcfg; GList *cur; struct script_module *module; @@ -163,19 +164,20 @@ init_lua_filters (struct config_file *cfg) while (cur) { module = cur->data; if (module->path) { - luaL_loadfile (L, module->path); + if (luaL_loadfile (L, module->path) != 0) { + msg_info ("lua_init_filters: load of %s failed: %s", module->path, lua_tostring (L, -1)); + cur = g_list_next (cur); + continue; + } /* Call module init function */ - funclen = strlen (module->path) + sizeof (":") + sizeof (MODULE_INIT_FUNC) - 1; - init_func = g_malloc (funclen); - snprintf (init_func, funclen, "%s:%s", module->path, MODULE_INIT_FUNC); - lua_getglobal (L, init_func); pcfg = lua_newuserdata (L, sizeof (struct config_file *)); lua_setclass (L, "Rspamd.config", -1); *pcfg = cfg; + lua_setglobal (L, "rspamd_config"); /* do the call (1 arguments, 1 result) */ - if (lua_pcall (L, 1, 1, 0) != 0) { - msg_info ("lua_init_filters: call to %s failed", init_func); + if (lua_pcall(L, 0, LUA_MULTRET, 0) != 0) { + msg_info ("lua_init_filters: init of %s failed: %s", module->path, lua_tostring (L, -1)); } } cur = g_list_next (cur); diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 6c9152417..bcb69a009 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -19,6 +19,7 @@ int luaopen_message (lua_State *L); int luaopen_task (lua_State *L); int luaopen_config (lua_State *L); int luaopen_metric (lua_State *L); +int luaopen_textpart (lua_State *L); void init_lua_filters (struct config_file *cfg); int lua_call_filter (const char *function, struct worker_task *task); diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 7eb03f871..c385d24f7 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -50,7 +50,7 @@ lua_check_config (lua_State *L) { void *ud = luaL_checkudata (L, 1, "Rspamd.config"); luaL_argcheck (L, ud != NULL, 1, "'config' expected"); - return (struct config_file *)ud; + return *((struct config_file **)ud); } static struct metric * @@ -58,7 +58,7 @@ lua_check_metric (lua_State *L) { void *ud = luaL_checkudata (L, 1, "Rspamd.metric"); luaL_argcheck (L, ud != NULL, 1, "'metric' expected"); - return (struct metric *)ud; + return *((struct metric **)ud); } /*** Config functions ***/ diff --git a/src/lua/lua_message.c b/src/lua/lua_message.c index b178da0d4..60daf357b 100644 --- a/src/lua/lua_message.c +++ b/src/lua/lua_message.c @@ -89,7 +89,7 @@ lua_check_message (lua_State *L) { void *ud = luaL_checkudata (L, 1, "Rspamd.message"); luaL_argcheck (L, ud != NULL, 1, "'message' expected"); - return (GMimeMessage *)ud; + return *((GMimeMessage **)ud); } diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index e3f1e55d6..2f55f0d71 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -60,7 +60,7 @@ lua_check_task (lua_State *L) { void *ud = luaL_checkudata (L, 1, "Rspamd.task"); luaL_argcheck (L, ud != NULL, 1, "'task' expected"); - return (struct worker_task *)ud; + return *((struct worker_task **)ud); } static struct mime_text_part * @@ -68,7 +68,7 @@ lua_check_textpart (lua_State *L) { void *ud = luaL_checkudata (L, 1, "Rspamd.textpart"); luaL_argcheck (L, ud != NULL, 1, "'textpart' expected"); - return (struct mime_text_part *)ud; + return *((struct mime_text_part **)ud); } /*** Task interface ***/