aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-06-28 18:07:11 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-06-28 18:07:11 +0100
commita014c2274bf178774697ce2a2b83a02bf6a3ac1c (patch)
tree84e6a626206973162fc8a633d98d510ea4d59c37
parent90fa147ca70698661da0cce271d6ac0982a92c37 (diff)
downloadrspamd-a014c2274bf178774697ce2a2b83a02bf6a3ac1c.tar.gz
rspamd-a014c2274bf178774697ce2a2b83a02bf6a3ac1c.zip
[Minor] Fix various cases in Lua API
-rw-r--r--src/lua/CMakeLists.txt3
-rw-r--r--src/lua/lua_common.c15
-rw-r--r--src/lua/lua_common.h5
-rw-r--r--src/lua/lua_cryptobox.c4
4 files changed, 17 insertions, 10 deletions
diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt
index 4a2003605..2730702b2 100644
--- a/src/lua/CMakeLists.txt
+++ b/src/lua/CMakeLists.txt
@@ -29,6 +29,7 @@ SET(LUASRC ${CMAKE_CURRENT_SOURCE_DIR}/lua_common.c
${CMAKE_CURRENT_SOURCE_DIR}/lua_dns.c
${CMAKE_CURRENT_SOURCE_DIR}/lua_udp.c
${CMAKE_CURRENT_SOURCE_DIR}/lua_text.c
- ${CMAKE_CURRENT_SOURCE_DIR}/lua_worker.c)
+ ${CMAKE_CURRENT_SOURCE_DIR}/lua_worker.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/lua_kann.c)
SET(RSPAMD_LUA ${LUASRC} PARENT_SCOPE) \ No newline at end of file
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index a33f33791..785042b8e 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -47,7 +47,7 @@ lua_error_quark (void)
/* Util functions */
/**
- * Create new class and store metatable on top of the stack
+ * Create new class and store metatable on top of the stack (must be popped if not needed)
* @param L
* @param classname name of class
* @param func table of class methods
@@ -62,10 +62,14 @@ rspamd_lua_new_class (lua_State * L,
lua_pushvalue (L, -2); /* pushes the metatable */
lua_settable (L, -3); /* metatable.__index = metatable */
- lua_pushstring (L, "class"); /* mt,"__index",it,"class" */
- lua_pushstring (L, classname); /* mt,"__index",it,"class",classname */
- lua_rawset (L, -3); /* mt,"__index",it */
- luaL_register (L, NULL, methods);
+ lua_pushstring (L, "class"); /* mt,"class" */
+ lua_pushstring (L, classname); /* mt,"class",classname */
+ lua_rawset (L, -3); /* mt */
+
+ if (methods) {
+ luaL_register (L, NULL, methods); /* pushes all methods as MT fields */
+ }
+ /* MT is left on stack ! */
}
/**
@@ -915,6 +919,7 @@ rspamd_lua_init (bool wipe_mem)
luaopen_dns (L);
luaopen_udp (L);
luaopen_worker (L);
+ luaopen_kann (L);
luaL_newmetatable (L, "rspamd{ev_base}");
lua_pushstring (L, "class");
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index 8919a46fd..4c0605782 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -42,9 +42,9 @@ luaL_register (lua_State *L, const gchar *name, const struct luaL_reg *methods)
#endif
/* Interface definitions */
-#define LUA_FUNCTION_DEF(class, name) static gint lua_ ## class ## _ ## name ( \
+#define LUA_FUNCTION_DEF(class, name) static int lua_ ## class ## _ ## name ( \
lua_State * L)
-#define LUA_PUBLIC_FUNCTION_DEF(class, name) gint lua_ ## class ## _ ## name ( \
+#define LUA_PUBLIC_FUNCTION_DEF(class, name) int lua_ ## class ## _ ## name ( \
lua_State * L)
#define LUA_INTERFACE_DEF(class, name) { # name, lua_ ## class ## _ ## name }
@@ -286,6 +286,7 @@ void luaopen_cryptobox (lua_State *L);
void luaopen_dns (lua_State *L);
void luaopen_udp (lua_State * L);
void luaopen_worker (lua_State * L);
+void luaopen_kann (lua_State * L);
void rspamd_lua_dostring (const gchar *line);
diff --git a/src/lua/lua_cryptobox.c b/src/lua/lua_cryptobox.c
index 300c33793..63608ed9a 100644
--- a/src/lua/lua_cryptobox.c
+++ b/src/lua/lua_cryptobox.c
@@ -1075,8 +1075,8 @@ lua_cryptobox_hash_create (lua_State *L)
/***
* @function rspamd_cryptobox_hash.create_specific(type, [string])
* Creates new hash context
- * @param {string} type type of signature
- * @param {string} data raw signature data
+ * @param {string} type type of hash (blake2, sha256, md5, sha512, mum, xxh64, xxh32, t1ha)
+ * @param {string} string initial data
* @return {cryptobox_hash} hash object
*/
static gint