]> source.dussan.org Git - rspamd.git/commitdiff
* Fix lua API
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 2 Sep 2009 15:15:51 +0000 (19:15 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 2 Sep 2009 15:15:51 +0000 (19:15 +0400)
src/cfg_file.h
src/cfg_file.l
src/lua/lua_common.c
src/lua/lua_common.h
src/lua/lua_config.c
src/lua/lua_message.c
src/lua/lua_task.c

index 7e3f035bca25d815dcf9d4d38454df3d76350565..2b67f8c72490652a48ad410abe9cda8824d69d91 100644 (file)
@@ -95,6 +95,7 @@ struct memcached_server {
  * script module list item
  */
 struct script_module {
+    char *name;                                     /**< name of module                                     */
        char *path;                                                                             /**< path to module                                                                             */
 };
 
index 7f2931ccc54a7dc1ba3e573ab0b1d817f74acc0f..ce207dbf52108505817bd260693beefa937e077a 100644 (file)
@@ -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;
index 66ae67d5852fc8db1b036c497c2da1d51562db39..907f7e6b58cb4f47b8915142f8364cdbc7055e24 100644 (file)
@@ -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);
index 6c915241721e0c5c637e4ff0b24836377c504aa0..bcb69a009856fb697a7a6d8bb827702654835c40 100644 (file)
@@ -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);
index 7eb03f871a9b84a8e5bd4b5343b018c95aa915f2..c385d24f74501ac1731eb28f733e8f9b78bb1805 100644 (file)
@@ -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 ***/
index b178da0d437d1702436d45ab1951583af31d063f..60daf357bf4ac25147b913a83b0c235b3eab6c33 100644 (file)
@@ -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);
 }
 
 
index e3f1e55d6ac21eeb3acc0febe3229df4453d0907..2f55f0d718f4949123e227604559df0734f013dc 100644 (file)
@@ -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    ***/