From c2765b3eb3c3beb3d9f42dc061761df2e300904c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 25 Aug 2014 13:17:21 +0100 Subject: Use modules preload for lua. --- src/lua/lua_rsa.c | 59 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 13 deletions(-) (limited to 'src/lua/lua_rsa.c') 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 -- cgit v1.2.3