aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_mempool.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-20 16:28:39 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-20 16:28:39 +0100
commitcad17efeebbfa1bfda7da74e27518dfe07083c8a (patch)
tree9a903f1bf75baf89a042154d4fa6ebf593e4fa47 /src/lua/lua_mempool.c
parent2869225b681c55c97870b9a58ee3527470e5055b (diff)
downloadrspamd-cad17efeebbfa1bfda7da74e27518dfe07083c8a.tar.gz
rspamd-cad17efeebbfa1bfda7da74e27518dfe07083c8a.zip
Allow to get complex variables from mempool.
Diffstat (limited to 'src/lua/lua_mempool.c')
-rw-r--r--src/lua/lua_mempool.c64
1 files changed, 43 insertions, 21 deletions
diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c
index af19c64b5..69b153046 100644
--- a/src/lua/lua_mempool.c
+++ b/src/lua/lua_mempool.c
@@ -199,8 +199,9 @@ lua_mempool_get_variable (lua_State *L)
{
struct memory_pool_s *mempool = rspamd_lua_check_mempool (L, 1);
const gchar *var = luaL_checkstring (L, 2);
- const gchar *type = NULL;
- gchar *value;
+ const gchar *type = NULL, *pt;
+ gchar *value, *pv;
+ guint len, nvar;
if (mempool && var) {
value = rspamd_mempool_get_variable (mempool, var);
@@ -212,27 +213,48 @@ lua_mempool_get_variable (lua_State *L)
if (value) {
if (type) {
- if (g_ascii_strcasecmp (type, "double") == 0) {
- lua_pushnumber (L, *(gdouble *)value);
- }
- else if (g_ascii_strcasecmp (type, "int") == 0) {
- lua_pushnumber (L, *(gint *)value);
- }
- else if (g_ascii_strcasecmp (type, "int64") == 0) {
- lua_pushnumber (L, *(gint64 *)value);
- }
- else if (g_ascii_strcasecmp (type, "bool") == 0) {
- lua_pushboolean (L, *(gboolean *)value);
- }
- else if (g_ascii_strcasecmp (type, "string") == 0) {
- lua_pushstring (L, (const gchar *)value);
- }
- else {
- msg_err ("unknown type for get_variable: %s", type);
- lua_pushnil (L);
+ pt = type;
+ pv = value;
+ nvar = 0;
+
+ while ((len = strcspn (pt, ",")) > 0) {
+ if (len == sizeof ("double") - 1 &&
+ g_ascii_strncasecmp (pt, "double", len) == 0) {
+ lua_pushnumber (L, *(gdouble *)pv);
+ pv += sizeof (gdouble);
+ }
+ else if (len == sizeof ("int") - 1 &&
+ g_ascii_strncasecmp (pt, "int", len) == 0) {
+ lua_pushnumber (L, *(gint *)pv);
+ pv += sizeof (gint);
+ }
+ else if (len == sizeof ("int64") - 1 &&
+ g_ascii_strncasecmp (pt, "int64", len) == 0) {
+ lua_pushnumber (L, *(gint64 *)pv);
+ pv += sizeof (gint64);
+ }
+ else if (len == sizeof ("bool") - 1 &&
+ g_ascii_strncasecmp (pt, "bool", len) == 0) {
+ lua_pushboolean (L, *(gboolean *)pv);
+ pv += sizeof (gboolean);
+ }
+ else if (len == sizeof ("string") - 1 &&
+ g_ascii_strncasecmp (pt, "string", len) == 0) {
+ lua_pushstring (L, (const gchar *)pv);
+ pv += sizeof (gchar *);
+ }
+ else {
+ msg_err ("unknown type for get_variable: %s", type);
+ lua_pushnil (L);
+ }
+
+ pt += len;
+ pt += strspn (pt, ",");
+
+ nvar ++;
}
- return 1;
+ return nvar;
}
lua_pushstring (L, value);