aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_buffer.c19
-rw-r--r--src/lua/lua_cdb.c15
-rw-r--r--src/lua/lua_classifier.c12
-rw-r--r--src/lua/lua_common.c85
-rw-r--r--src/lua/lua_common.h56
-rw-r--r--src/lua/lua_config.c25
-rw-r--r--src/lua/lua_dns.c18
-rw-r--r--src/lua/lua_http.c14
-rw-r--r--src/lua/lua_ip.c15
-rw-r--r--src/lua/lua_mempool.c17
-rw-r--r--src/lua/lua_message.c6
-rw-r--r--src/lua/lua_redis.c15
-rw-r--r--src/lua/lua_regexp.c17
-rw-r--r--src/lua/lua_rsa.c59
-rw-r--r--src/lua/lua_session.c18
-rw-r--r--src/lua/lua_task.c39
-rw-r--r--src/lua/lua_upstream.c25
-rw-r--r--src/lua/lua_xmlrpc.c14
18 files changed, 288 insertions, 181 deletions
diff --git a/src/lua/lua_buffer.c b/src/lua/lua_buffer.c
index 97598e606..ee64a84ab 100644
--- a/src/lua/lua_buffer.c
+++ b/src/lua/lua_buffer.c
@@ -26,7 +26,7 @@
/* Public prototypes */
struct rspamd_io_dispatcher_s * lua_check_io_dispatcher (lua_State * L);
-gint luaopen_io_dispatcher (lua_State * L);
+void luaopen_io_dispatcher (lua_State * L);
/* Lua bindings */
LUA_FUNCTION_DEF (io_dispatcher, create);
@@ -344,8 +344,17 @@ lua_io_dispatcher_destroy (lua_State *L)
return 1;
}
+static gint
+lua_load_dispatcher (lua_State *L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, io_dispatcherlib_f);
+
+ return 1;
+}
-gint
+
+void
luaopen_io_dispatcher (lua_State * L)
{
luaL_newmetatable (L, "rspamd{io_dispatcher}");
@@ -358,14 +367,11 @@ luaopen_io_dispatcher (lua_State * L)
lua_rawset (L, -3);
luaL_register (L, NULL, io_dispatcherlib_m);
- luaL_register (L, "rspamd_io_dispatcher", io_dispatcherlib_f);
-
lua_pop (L, 1); /* remove metatable from stack */
+ rspamd_lua_add_preload (L, "rspamd_io_dispatcher", lua_load_dispatcher);
/* Simple event class */
rspamd_lua_new_class (L, "rspamd{ev_base}", null_reg);
- luaL_register (L, "rspamd_ev_base", null_reg);
-
lua_pop (L, 1); /* remove metatable from stack */
/* Set buffer types globals */
@@ -375,5 +381,4 @@ luaopen_io_dispatcher (lua_State * L)
lua_setglobal (L, "IO_BUFFER_CHARACTER");
lua_pushnumber (L, BUFFER_ANY);
lua_setglobal (L, "IO_BUFFER_ANY");
- return 1;
}
diff --git a/src/lua/lua_cdb.c b/src/lua/lua_cdb.c
index 2ede3c24c..48b091254 100644
--- a/src/lua/lua_cdb.c
+++ b/src/lua/lua_cdb.c
@@ -146,7 +146,16 @@ lua_cdb_destroy (lua_State *L)
return 0;
}
-gint
+static gint
+lua_load_cdb (lua_State *L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, cdblib_f);
+
+ return 1;
+}
+
+void
luaopen_cdb (lua_State * L)
{
luaL_newmetatable (L, "rspamd{cdb}");
@@ -159,9 +168,7 @@ luaopen_cdb (lua_State * L)
lua_rawset (L, -3);
luaL_register (L, NULL, cdblib_m);
- luaL_register (L, "cdb", cdblib_f);
-
lua_pop (L, 1); /* remove metatable from stack */
- return 1;
+ rspamd_lua_add_preload (L, "rspamd_cdb", lua_load_cdb);
}
diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c
index 869bca865..1edca4857 100644
--- a/src/lua/lua_classifier.c
+++ b/src/lua/lua_classifier.c
@@ -428,25 +428,17 @@ lua_check_statfile (lua_State * L)
/* Open functions */
-gint
+void
luaopen_classifier (lua_State * L)
{
rspamd_lua_new_class (L, "rspamd{classifier}", classifierlib_m);
- luaL_register (L, "rspamd_classifier", null_reg);
-
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
-gint
+void
luaopen_statfile (lua_State * L)
{
rspamd_lua_new_class (L, "rspamd{statfile}", statfilelib_m);
- luaL_register (L, "rspamd_statfile", null_reg);
-
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 0d68a364e..17b284e0c 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -249,24 +249,19 @@ lua_logger_debug (lua_State * L)
/*** Init functions ***/
-gint
-luaopen_rspamd (lua_State * L)
+static gint
+lua_load_logger (lua_State *L)
{
- luaL_register (L, "rspamd", null_reg);
- /* make version string available to scripts */
- lua_pushstring (L, "_VERSION");
- lua_pushstring (L, RVERSION);
- lua_rawset (L, -3);
+ lua_newtable (L);
+ luaL_register (L, NULL, loggerlib_f);
return 1;
}
-static gint
+static void
luaopen_logger (lua_State * L)
{
-
- luaL_register (L, "rspamd_logger", loggerlib_f);
- return 1;
+ rspamd_lua_add_preload (L, "rspamd_logger", lua_load_logger);
}
@@ -294,34 +289,34 @@ rspamd_lua_init (struct rspamd_config *cfg)
L = luaL_newstate ();
luaL_openlibs (L);
- (void)luaopen_rspamd (L);
- (void)luaopen_logger (L);
- (void)luaopen_mempool (L);
- (void)luaopen_config (L);
- (void)luaopen_radix (L);
- (void)luaopen_hash_table (L);
- (void)luaopen_trie (L);
- (void)luaopen_task (L);
- (void)luaopen_textpart (L);
- (void)luaopen_mimepart (L);
- (void)luaopen_image (L);
- (void)luaopen_url (L);
- (void)luaopen_message (L);
- (void)luaopen_classifier (L);
- (void)luaopen_statfile (L);
- (void)luaopen_glib_regexp (L);
- (void)luaopen_cdb (L);
- (void)luaopen_xmlrpc (L);
- (void)luaopen_http (L);
- (void)luaopen_redis (L);
- (void)luaopen_upstream (L);
- (void)lua_add_actions_global (L);
- (void)luaopen_session (L);
- (void)luaopen_io_dispatcher (L);
- (void)luaopen_dns_resolver (L);
- (void)luaopen_rsa (L);
- (void)luaopen_ip (L);
- (void)luaopen_ucl (L);
+ luaopen_logger (L);
+ luaopen_mempool (L);
+ luaopen_config (L);
+ luaopen_radix (L);
+ luaopen_hash_table (L);
+ luaopen_trie (L);
+ luaopen_task (L);
+ luaopen_textpart (L);
+ luaopen_mimepart (L);
+ luaopen_image (L);
+ luaopen_url (L);
+ luaopen_message (L);
+ luaopen_classifier (L);
+ luaopen_statfile (L);
+ luaopen_glib_regexp (L);
+ luaopen_cdb (L);
+ luaopen_xmlrpc (L);
+ luaopen_http (L);
+ luaopen_redis (L);
+ luaopen_upstream (L);
+ lua_add_actions_global (L);
+ luaopen_session (L);
+ luaopen_io_dispatcher (L);
+ luaopen_dns_resolver (L);
+ luaopen_rsa (L);
+ luaopen_ip (L);
+
+ rspamd_lua_add_preload (L, "ucl", luaopen_ucl);
return L;
}
@@ -702,3 +697,15 @@ rspamd_lua_typerror (lua_State *L, int narg, const char *tname)
luaL_typename (L, narg));
return luaL_argerror (L, narg, msg);
}
+
+
+void
+rspamd_lua_add_preload (lua_State *L, const gchar *name, lua_CFunction func)
+{
+ lua_getglobal (L, "package");
+ lua_pushstring (L, "preload");
+ lua_gettable (L, -2);
+ lua_pushcfunction (L, func);
+ lua_setfield (L, -2, name);
+ lua_pop (L, 1);
+}
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index 78bf80fdb..6594cdc2b 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -143,31 +143,37 @@ struct rspamd_lua_ip {
/**
* Open libraries functions
*/
-gint luaopen_message (lua_State *L);
-gint luaopen_task (lua_State *L);
-gint luaopen_config (lua_State *L);
-gint luaopen_metric (lua_State *L);
-gint luaopen_radix (lua_State *L);
-gint luaopen_hash_table (lua_State *L);
-gint luaopen_trie (lua_State * L);
-gint luaopen_textpart (lua_State *L);
-gint luaopen_mimepart (lua_State *L);
-gint luaopen_image (lua_State *L);
-gint luaopen_url (lua_State *L);
-gint luaopen_classifier (lua_State *L);
-gint luaopen_statfile (lua_State * L);
-gint luaopen_glib_regexp (lua_State *L);
-gint luaopen_cdb (lua_State *L);
-gint luaopen_xmlrpc (lua_State * L);
-gint luaopen_http (lua_State * L);
-gint luaopen_redis (lua_State * L);
-gint luaopen_upstream (lua_State * L);
-gint luaopen_mempool (lua_State * L);
-gint luaopen_session (lua_State * L);
-gint luaopen_io_dispatcher (lua_State * L);
-gint luaopen_dns_resolver (lua_State * L);
-gint luaopen_rsa (lua_State * L);
-gint luaopen_ip (lua_State * L);
+
+/**
+ * Add preload function
+ */
+void rspamd_lua_add_preload (lua_State *L, const gchar *name, lua_CFunction func);
+
+void luaopen_message (lua_State *L);
+void luaopen_task (lua_State *L);
+void luaopen_config (lua_State *L);
+void luaopen_metric (lua_State *L);
+void luaopen_radix (lua_State *L);
+void luaopen_hash_table (lua_State *L);
+void luaopen_trie (lua_State * L);
+void luaopen_textpart (lua_State *L);
+void luaopen_mimepart (lua_State *L);
+void luaopen_image (lua_State *L);
+void luaopen_url (lua_State *L);
+void luaopen_classifier (lua_State *L);
+void luaopen_statfile (lua_State * L);
+void luaopen_glib_regexp (lua_State *L);
+void luaopen_cdb (lua_State *L);
+void luaopen_xmlrpc (lua_State * L);
+void luaopen_http (lua_State * L);
+void luaopen_redis (lua_State * L);
+void luaopen_upstream (lua_State * L);
+void luaopen_mempool (lua_State * L);
+void luaopen_session (lua_State * L);
+void luaopen_io_dispatcher (lua_State * L);
+void luaopen_dns_resolver (lua_State * L);
+void luaopen_rsa (lua_State * L);
+void luaopen_ip (lua_State * L);
gint rspamd_lua_call_filter (const gchar *function, struct rspamd_task *task);
gint rspamd_lua_call_chain_filter (const gchar *function,
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 777ed33fd..d0bc53d99 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -1234,40 +1234,41 @@ lua_trie_search_task (lua_State *L)
}
/* Init functions */
-gint
+void
luaopen_config (lua_State * L)
{
rspamd_lua_new_class (L, "rspamd{config}", configlib_m);
- luaL_register (L, "rspamd_config", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
-gint
+void
luaopen_radix (lua_State * L)
{
rspamd_lua_new_class (L, "rspamd{radix}", radixlib_m);
- luaL_register (L, "rspamd_radix", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
-gint
+void
luaopen_hash_table (lua_State * L)
{
rspamd_lua_new_class (L, "rspamd{hash_table}", hashlib_m);
luaL_register (L, "rspamd_hash_table", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
+}
+
+static gint
+lua_load_trie (lua_State *L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, trielib_f);
return 1;
}
-gint
+void
luaopen_trie (lua_State * L)
{
luaL_newmetatable (L, "rspamd{trie}");
@@ -1280,9 +1281,7 @@ luaopen_trie (lua_State * L)
lua_rawset (L, -3);
luaL_register (L, NULL, trielib_m);
- luaL_register (L, "rspamd_trie", trielib_f);
+ rspamd_lua_add_preload (L, "rspamd_trie", lua_load_trie);
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c
index bd1306947..17620a289 100644
--- a/src/lua/lua_dns.c
+++ b/src/lua/lua_dns.c
@@ -27,7 +27,7 @@
/* Public prototypes */
struct rspamd_dns_resolver * lua_check_dns_resolver (lua_State * L);
-gint luaopen_dns_resolver (lua_State * L);
+void luaopen_dns_resolver (lua_State * L);
/* Lua bindings */
LUA_FUNCTION_DEF (dns_resolver, init);
@@ -356,7 +356,16 @@ lua_dns_resolver_resolve (lua_State *L)
return 1;
}
-gint
+static gint
+lua_load_dns (lua_State * L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, dns_resolverlib_f);
+
+ return 1;
+}
+
+void
luaopen_dns_resolver (lua_State * L)
{
@@ -379,9 +388,8 @@ luaopen_dns_resolver (lua_State * L)
LUA_ENUM (L, RDNS_REQUEST_AAA, RDNS_REQUEST_SRV);
}
- luaL_register (L, NULL, dns_resolverlib_m);
- luaL_register (L, "rspamd_resolver", dns_resolverlib_f);
+ luaL_register (L, NULL, dns_resolverlib_m);
+ rspamd_lua_add_preload (L, "rspamd_resolver", lua_load_dns);
lua_pop (L, 1); /* remove metatable from stack */
- return 1;
}
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index d1a4434c2..8803df80c 100644
--- a/src/lua/lua_http.c
+++ b/src/lua/lua_http.c
@@ -355,11 +355,17 @@ lua_http_request (lua_State *L)
return 1;
}
-gint
-luaopen_http (lua_State * L)
+static gint
+lua_load_http (lua_State * L)
{
-
- luaL_register (L, "rspamd_http", httplib_m);
+ lua_newtable (L);
+ luaL_register (L, NULL, httplib_m);
return 1;
}
+
+void
+luaopen_http (lua_State * L)
+{
+ rspamd_lua_add_preload (L, "rspamd_http", lua_load_http);
+}
diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c
index fba1cd1cb..a2ce26130 100644
--- a/src/lua/lua_ip.c
+++ b/src/lua/lua_ip.c
@@ -460,7 +460,16 @@ rspamd_lua_ip_push_fromstring (lua_State *L, const gchar *ip_str)
}
}
-gint
+static gint
+lua_load_ip (lua_State * L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, iplib_f);
+
+ return 1;
+}
+
+void
luaopen_ip (lua_State * L)
{
luaL_newmetatable (L, "rspamd{ip}");
@@ -473,9 +482,7 @@ luaopen_ip (lua_State * L)
lua_rawset (L, -3);
luaL_register (L, NULL, iplib_m);
- luaL_register (L, "rspamd_ip", iplib_f);
+ rspamd_lua_add_preload (L, "rspamd_ip", lua_load_ip);
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c
index 465378af9..049f8080e 100644
--- a/src/lua/lua_mempool.c
+++ b/src/lua/lua_mempool.c
@@ -26,7 +26,7 @@
/* Public prototypes */
struct memory_pool_s * rspamd_lua_check_mempool (lua_State * L);
-gint luaopen_mempool (lua_State * L);
+void luaopen_mempool (lua_State * L);
/* Lua bindings */
LUA_FUNCTION_DEF (mempool, create);
@@ -221,7 +221,16 @@ lua_mempool_memory_pool_get_variable (lua_State *L)
return 1;
}
-gint
+static gint
+lua_load_mempool (lua_State * L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, mempoollib_f);
+
+ return 1;
+}
+
+void
luaopen_mempool (lua_State * L)
{
luaL_newmetatable (L, "rspamd{mempool}");
@@ -234,9 +243,7 @@ luaopen_mempool (lua_State * L)
lua_rawset (L, -3);
luaL_register (L, NULL, mempoollib_m);
- luaL_register (L, "rspamd_mempool", mempoollib_f);
+ rspamd_lua_add_preload (L, "rspamd_mempool", lua_load_mempool);
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
diff --git a/src/lua/lua_message.c b/src/lua/lua_message.c
index d5a235d2a..f40d64657 100644
--- a/src/lua/lua_message.c
+++ b/src/lua/lua_message.c
@@ -200,13 +200,9 @@ lua_message_get_date (lua_State * L)
return 1;
}
-gint
+void
luaopen_message (lua_State * L)
{
rspamd_lua_new_class (L, "rspamd{message}", msglib_m);
- luaL_register (L, "rspamd_message", null_reg);
-
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c
index bc4ba594b..67c86586e 100644
--- a/src/lua/lua_redis.c
+++ b/src/lua/lua_redis.c
@@ -366,16 +366,21 @@ lua_redis_make_request (lua_State *L)
return 1;
}
+static gint
+lua_load_redis (lua_State * L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, redislib_m);
+
+ return 1;
+}
/**
* Open redis library
* @param L lua stack
* @return
*/
-gint
+void
luaopen_redis (lua_State * L)
{
-
- luaL_register (L, "rspamd_redis", redislib_m);
-
- return 1;
+ rspamd_lua_add_preload (L, "rspamd_redis", lua_load_redis);
}
diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c
index 41703bc04..4e893d81d 100644
--- a/src/lua/lua_regexp.c
+++ b/src/lua/lua_regexp.c
@@ -274,7 +274,16 @@ lua_regexp_destroy (lua_State *L)
return 0;
}
-gint
+static gint
+lua_load_regexp (lua_State * L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, regexplib_f);
+
+ return 1;
+}
+
+void
luaopen_glib_regexp (lua_State * L)
{
luaL_newmetatable (L, "rspamd{regexp}");
@@ -286,10 +295,8 @@ luaopen_glib_regexp (lua_State * L)
lua_pushstring (L, "rspamd{regexp}");
lua_rawset (L, -3);
- luaL_register (L, NULL, regexplib_m);
- luaL_register (L, "regexp", regexplib_f);
+ luaL_register (L, NULL, regexplib_m);
+ rspamd_lua_add_preload (L, "regexp", lua_load_regexp);
regexp_static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
-
- return 1;
}
diff --git a/src/lua/lua_rsa.c b/src/lua/lua_rsa.c
index c06b14f3f..e4dee90b0 100644
--- a/src/lua/lua_rsa.c
+++ b/src/lua/lua_rsa.c
@@ -641,7 +641,43 @@ lua_rsa_sign_file (lua_State *L)
return 1;
}
-gint
+static gint
+lua_load_pubkey (lua_State * L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, rsapubkeylib_f);
+
+ return 1;
+}
+
+static gint
+lua_load_privkey (lua_State * L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, rsaprivkeylib_f);
+
+ return 1;
+}
+
+static gint
+lua_load_signature (lua_State * L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, rsasignlib_f);
+
+ return 1;
+}
+
+static gint
+lua_load_rsa (lua_State * L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, rsalib_f);
+
+ return 1;
+}
+
+void
luaopen_rsa (lua_State * L)
{
luaL_newmetatable (L, "rspamd{rsa_pubkey}");
@@ -653,8 +689,8 @@ luaopen_rsa (lua_State * L)
lua_pushstring (L, "rspamd{rsa_pubkey}");
lua_rawset (L, -3);
- luaL_register (L, NULL, rsapubkeylib_m);
- luaL_register (L, "rsa_pubkey", rsapubkeylib_f);
+ luaL_register (L, NULL, rsapubkeylib_m);
+ rspamd_lua_add_preload (L, "rspamd_rsa_pubkey", lua_load_pubkey);
luaL_newmetatable (L, "rspamd{rsa_privkey}");
lua_pushstring (L, "__index");
@@ -665,8 +701,8 @@ luaopen_rsa (lua_State * L)
lua_pushstring (L, "rspamd{rsa_privkey}");
lua_rawset (L, -3);
- luaL_register (L, NULL, rsaprivkeylib_m);
- luaL_register (L, "rsa_privkey", rsaprivkeylib_f);
+ luaL_register (L, NULL, rsaprivkeylib_m);
+ rspamd_lua_add_preload (L, "rspamd_rsa_privkey", lua_load_privkey);
luaL_newmetatable (L, "rspamd{rsa_signature}");
lua_pushstring (L, "__index");
@@ -677,22 +713,19 @@ luaopen_rsa (lua_State * L)
lua_pushstring (L, "rspamd{rsa_signature}");
lua_rawset (L, -3);
- luaL_register (L, NULL, rsasignlib_m);
- luaL_register (L, "rsa_signature", rsasignlib_f);
+ luaL_register (L, NULL, rsasignlib_m);
+ rspamd_lua_add_preload (L, "rspamd_rsa_signature", lua_load_signature);
- luaL_register (L, "rsa", rsalib_f);
+ rspamd_lua_add_preload (L, "rspamd_rsa", lua_load_rsa);
- return 1;
+ lua_settop (L, 0);
}
#else
-gint
+void
luaopen_rsa (lua_State * L)
{
msg_info ("this rspamd version is not linked against openssl, therefore no "
"RSA support is available");
-
- return 1;
-
}
#endif
diff --git a/src/lua/lua_session.c b/src/lua/lua_session.c
index 5abc3aa36..3fa636a5b 100644
--- a/src/lua/lua_session.c
+++ b/src/lua/lua_session.c
@@ -25,7 +25,7 @@
/* Public prototypes */
struct rspamd_async_session * lua_check_session (lua_State * L);
-gint luaopen_session (lua_State * L);
+void luaopen_session (lua_State * L);
/* Lua bindings */
LUA_FUNCTION_DEF (session, register_async_event);
@@ -302,7 +302,16 @@ lua_session_check_session_pending (lua_State *L)
return 1;
}
-gint
+static gint
+lua_load_session (lua_State * L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, sessionlib_f);
+
+ return 1;
+}
+
+void
luaopen_session (lua_State * L)
{
luaL_newmetatable (L, "rspamd{session}");
@@ -315,15 +324,12 @@ luaopen_session (lua_State * L)
lua_rawset (L, -3);
luaL_register (L, NULL, sessionlib_m);
- luaL_register (L, "rspamd_session", sessionlib_f);
+ rspamd_lua_add_preload (L, "rspamd_session", lua_load_session);
lua_pop (L, 1); /* remove metatable from stack */
/* Simple event class */
rspamd_lua_new_class (L, "rspamd{event}", eventlib_m);
- luaL_register (L, "rspamd_event", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index c58aea556..82996a357 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -1868,57 +1868,52 @@ lua_url_get_phished (lua_State *L)
}
/* Init part */
-gint
-luaopen_task (lua_State * L)
+
+static gint
+lua_load_task (lua_State * L)
{
- rspamd_lua_new_class_full (L, "rspamd{task}", "rspamd_task", tasklib_m, tasklib_f);
+ lua_newtable (L);
+ luaL_register (L, NULL, tasklib_f);
+ return 1;
+}
+
+void
+luaopen_task (lua_State * L)
+{
+ rspamd_lua_new_class (L, "rspamd{task}", tasklib_m);
lua_pop (L, 1); /* remove metatable from stack */
- return 1;
+ rspamd_lua_add_preload (L, "rspamd_task", lua_load_task);
}
-gint
+void
luaopen_textpart (lua_State * L)
{
rspamd_lua_new_class (L, "rspamd{textpart}", textpartlib_m);
luaL_register (L, "rspamd_textpart", null_reg);
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
-gint
+void
luaopen_mimepart (lua_State * L)
{
rspamd_lua_new_class (L, "rspamd{mimepart}", mimepartlib_m);
- luaL_register (L, "rspamd_mimepart", null_reg);
-
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
-gint
+void
luaopen_image (lua_State * L)
{
rspamd_lua_new_class (L, "rspamd{image}", imagelib_m);
- luaL_register (L, "rspamd_image", null_reg);
-
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
-gint
+void
luaopen_url (lua_State * L)
{
rspamd_lua_new_class (L, "rspamd{url}", urllib_m);
- luaL_register (L, "rspamd_url", null_reg);
-
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
diff --git a/src/lua/lua_upstream.c b/src/lua/lua_upstream.c
index 546405126..09a3df516 100644
--- a/src/lua/lua_upstream.c
+++ b/src/lua/lua_upstream.c
@@ -527,8 +527,25 @@ lua_upstream_list_get_upstream_master_slave (lua_State *L)
return 1;
}
+static gint
+lua_load_upstream (lua_State * L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, upstream_f);
-gint
+ return 1;
+}
+
+static gint
+lua_load_upstream_list (lua_State * L)
+{
+ lua_newtable (L);
+ luaL_register (L, NULL, upstream_list_f);
+
+ return 1;
+}
+
+void
luaopen_upstream (lua_State * L)
{
luaL_newmetatable (L, "rspamd{upstream_list}");
@@ -541,7 +558,7 @@ luaopen_upstream (lua_State * L)
lua_rawset (L, -3);
luaL_register (L, NULL, upstream_list_m);
- luaL_register (L, "upstream_list", upstream_list_f);
+ rspamd_lua_add_preload (L, "upstream_list", lua_load_upstream_list);
lua_pop (L, 1); /* remove metatable from stack */
@@ -555,9 +572,7 @@ luaopen_upstream (lua_State * L)
lua_rawset (L, -3);
luaL_register (L, NULL, upstream_m);
- luaL_register (L, "upstream", upstream_f);
+ rspamd_lua_add_preload (L, "upstream", lua_load_upstream);
lua_pop (L, 1); /* remove metatable from stack */
-
- return 1;
}
diff --git a/src/lua/lua_xmlrpc.c b/src/lua/lua_xmlrpc.c
index ebac5bc18..0d489fd1c 100644
--- a/src/lua/lua_xmlrpc.c
+++ b/src/lua/lua_xmlrpc.c
@@ -599,12 +599,18 @@ lua_xmlrpc_make_request (lua_State *L)
return 1;
}
-gint
-luaopen_xmlrpc (lua_State * L)
+static gint
+lua_load_xmlrpc (lua_State * L)
{
-
- luaL_register (L, "rspamd_xmlrpc", xmlrpclib_m);
+ lua_newtable (L);
+ luaL_register (L, NULL, xmlrpclib_m);
return 1;
}
+void
+luaopen_xmlrpc (lua_State * L)
+{
+ rspamd_lua_add_preload (L, "rspamd_xmlrpc", lua_load_xmlrpc);
+}
+