]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Allow to get list of fstrings from mempool variable
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 11 May 2018 15:39:38 +0000 (16:39 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 11 May 2018 15:39:38 +0000 (16:39 +0100)
src/lua/lua_mempool.c

index 77fc249fc18fe477ccbe8e155441c1fd3a0f4436..58630904fde48da08d0c018129b0d60d76939638 100644 (file)
@@ -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);