aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_mempool.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-11 16:39:38 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-11 16:39:38 +0100
commit330096fcf963731b1a525c137f8b33559c8e6a45 (patch)
tree793ecdb0ef6d4d01ba0d0885bb1ed25e7d979ede /src/lua/lua_mempool.c
parentfb466004e675ffd30c438ce5e3fc37c9a686eeaa (diff)
downloadrspamd-330096fcf963731b1a525c137f8b33559c8e6a45.tar.gz
rspamd-330096fcf963731b1a525c137f8b33559c8e6a45.zip
[Minor] Allow to get list of fstrings from mempool variable
Diffstat (limited to 'src/lua/lua_mempool.c')
-rw-r--r--src/lua/lua_mempool.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c
index 77fc249fc..58630904f 100644
--- a/src/lua/lua_mempool.c
+++ b/src/lua/lua_mempool.c
@@ -87,7 +87,8 @@ LUA_FUNCTION_DEF (mempool, set_bucket);
* - `int`: unpack a single integer
* - `int64`: unpack 64-bits integer
* - `boolean`: unpack boolean
- * - `bucket`: bucket of numbers represented as a table
+ * - `bucket`: bucket of numbers represented as a Lua table
+ * - `fstrings`: list of rspamd_fstring_t (GList) represented as a Lua table
* @param {string} name variable's name to get
* @param {string} type list of types to be extracted
* @return {variable list} list of variables extracted (but **not** a table)
@@ -466,6 +467,25 @@ lua_mempool_get_variable (lua_State *L)
pv += sizeof (struct lua_numbers_bucket) +
bucket->nelts * sizeof (gdouble);
}
+ else if (len == sizeof ("fstrings") - 1 &&
+ g_ascii_strncasecmp (pt, "fstrings", len) == 0) {
+ GList *cur;
+ rspamd_fstring_t *fstr;
+
+ cur = (GList *)pv;
+ lua_newtable (L);
+
+ i = 1;
+ while (cur != NULL) {
+ fstr = cur->data;
+ lua_pushlstring (L, fstr->str, fstr->len);
+ lua_rawseti (L, -1, i);
+ i ++;
+ cur = g_list_next (cur);
+ }
+
+ pv += sizeof (GList *);
+ }
else {
msg_err ("unknown type for get_variable: %s", pt);
lua_pushnil (L);