* script module list item
*/
struct script_module {
+ char *name; /**< name of module */
char *path; /**< path to module */
};
protocol return PROTOCOL;
memcached return MEMCACHED;
servers return SERVERS;
+
require return REQUIRE;
+module return MODULE;
+
filters return FILTERS;
factors return FACTORS;
metric return METRIC;
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;
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);
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);
{
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 *
{
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 ***/
{
void *ud = luaL_checkudata (L, 1, "Rspamd.message");
luaL_argcheck (L, ud != NULL, 1, "'message' expected");
- return (GMimeMessage *)ud;
+ return *((GMimeMessage **)ud);
}
{
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 *
{
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 ***/