aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_mempool.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-10-07 12:34:00 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-10-07 12:34:00 +0100
commit096b420d859408cf02b2bca729d4fd99a07f991c (patch)
tree1f8a79ebab7774bba0b0ceb1ebcaa9b15e2f0d43 /src/lua/lua_mempool.c
parent7d21da8f21e07a207169cf47f3e90548e4bb0ea2 (diff)
downloadrspamd-096b420d859408cf02b2bca729d4fd99a07f991c.tar.gz
rspamd-096b420d859408cf02b2bca729d4fd99a07f991c.zip
[Minor] Accept tables in lua_set_mempool_variable
Diffstat (limited to 'src/lua/lua_mempool.c')
-rw-r--r--src/lua/lua_mempool.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c
index a6ef9f2c2..77fc249fc 100644
--- a/src/lua/lua_mempool.c
+++ b/src/lua/lua_mempool.c
@@ -303,6 +303,7 @@ lua_mempool_set_variable (lua_State *L)
struct memory_pool_s *mempool = rspamd_lua_check_mempool (L, 1);
const gchar *var = luaL_checkstring (L, 2);
gpointer value;
+ struct lua_numbers_bucket *bucket;
gchar *vp;
union {
gdouble d;
@@ -310,7 +311,7 @@ lua_mempool_set_variable (lua_State *L)
gboolean b;
} val;
gsize slen;
- gint i, len = 0, type;
+ gint i, j, len = 0, type;
if (mempool && var) {
@@ -330,7 +331,8 @@ lua_mempool_set_variable (lua_State *L)
}
else if (type == LUA_TTABLE) {
/* We assume it as a bucket of numbers so far */
-
+ slen = rspamd_lua_table_size (L, i);
+ len += sizeof (gdouble) * slen + sizeof (*bucket);
}
else {
msg_err ("cannot handle lua type %s", lua_typename (L, type));
@@ -362,6 +364,20 @@ lua_mempool_set_variable (lua_State *L)
memcpy (vp, val.s, slen + 1);
vp += slen + 1;
}
+ else if (type == LUA_TTABLE) {
+ slen = rspamd_lua_table_size (L, i);
+ /* XXX: Ret, ret, ret: alignment issues */
+ bucket = (struct lua_numbers_bucket *)vp;
+ bucket->nelts = slen;
+
+ for (j = 0; j < slen; j ++) {
+ lua_rawgeti (L, i, j + 1);
+ bucket->elts[j] = lua_tonumber (L, -1);
+ lua_pop (L, 1);
+ }
+
+ vp += sizeof (gdouble) * slen + sizeof (*bucket);
+ }
else {
msg_err ("cannot handle lua type %s", lua_typename (L, type));
}