From 330096fcf963731b1a525c137f8b33559c8e6a45 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 11 May 2018 16:39:38 +0100 Subject: [PATCH] [Minor] Allow to get list of fstrings from mempool variable --- src/lua/lua_mempool.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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); -- 2.39.5