lua_gettable (L, -2);
if (lua_type (L, -1) == LUA_TTABLE) {
+ gint old_top;
+
+ old_top = lua_gettop (L);
lua_pushstring (L, "callback");
lua_gettable (L, -2);
rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
- if (lua_pcall (L, 1, 1, 0) != 0) {
+ if (lua_pcall (L, 1, LUA_MULTRET, 0) != 0) {
msg_err_task ("stat_metatokens failed: %s",
lua_tostring (L, -1));
lua_pop (L, 1);
} else {
- /* Iterate over table of tables */
- for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
- elt.flags |= RSPAMD_STAT_TOKEN_FLAG_LUA_META;
-
- if (lua_isnumber (L, -1)) {
- gdouble num = lua_tonumber (L, -1);
- guint8 *pnum = rspamd_mempool_alloc (
- task->task_pool,
- sizeof (num));
-
- msg_debug_task ("got metatoken number: %.2f", num);
- memcpy (pnum, &num, sizeof (num));
- elt.begin = (gchar *) pnum;
- elt.len = sizeof (num);
- g_array_append_val (ar, elt);
- } else if (lua_isstring (L, -1)) {
- const gchar *str;
- gsize tlen;
-
- str = lua_tolstring (L, -1, &tlen);
- guint8 *pstr = rspamd_mempool_alloc (
- task->task_pool,
- tlen);
- memcpy (pstr, str, tlen);
-
- msg_debug_task ("got metatoken string: %*s",
- (gint) tlen, str);
- elt.begin = (gchar *) pstr;
- elt.len = tlen;
- g_array_append_val (ar, elt);
+ if (lua_gettop (L) > old_top &&
+ lua_istable (L, old_top + 1)) {
+ lua_pushvalue (L, old_top + 1);
+ /* Iterate over table of tables */
+ for (lua_pushnil (L); lua_next (L, -2);
+ lua_pop (L, 1)) {
+ elt.flags |= RSPAMD_STAT_TOKEN_FLAG_LUA_META;
+
+ if (lua_isnumber (L, -1)) {
+ gdouble num = lua_tonumber (L, -1);
+ guint8 *pnum = rspamd_mempool_alloc (
+ task->task_pool,
+ sizeof (num));
+
+ msg_debug_task ("got metatoken number: %.2f",
+ num);
+ memcpy (pnum, &num, sizeof (num));
+ elt.begin = (gchar *) pnum;
+ elt.len = sizeof (num);
+ g_array_append_val (ar, elt);
+ } else if (lua_isstring (L, -1)) {
+ const gchar *str;
+ gsize tlen;
+
+ str = lua_tolstring (L, -1, &tlen);
+ guint8 *pstr = rspamd_mempool_alloc (
+ task->task_pool,
+ tlen);
+ memcpy (pstr, str, tlen);
+
+ msg_debug_task ("got metatoken string: %*s",
+ (gint) tlen, str);
+ elt.begin = (gchar *) pstr;
+ elt.len = tlen;
+ g_array_append_val (ar, elt);
+ }
}
}
}
struct rspamd_lua_regexp *re = NULL;
GList *cur;
struct rspamd_mime_header *hdr;
+ gint old_top;
if (part && lua_isfunction (L, 2)) {
if (lua_istable (L, 3)) {
}
}
+ old_top = lua_gettop (L);
lua_pushvalue (L, 2);
lua_pushstring (L, hdr->name);
rspamd_lua_push_header (L, hdr, full, raw);
- if (lua_pcall (L, 2, 1, 0) != 0) {
+ if (lua_pcall (L, 2, LUA_MULTRET, 0) != 0) {
msg_err ("call to header_foreach failed: %s",
lua_tostring (L, -1));
- lua_pop (L, 1);
+ lua_settop (L, old_top);
break;
}
else {
- if (lua_isboolean (L, -1)) {
- if (lua_toboolean (L, -1)) {
- lua_pop (L, 1);
- break;
+ if (lua_gettop (L) > old_top) {
+ if (lua_isboolean (L, old_top + 1)) {
+ if (lua_toboolean (L, old_top + 1)) {
+ lua_settop (L, old_top);
+ break;
+ }
}
}
}
- lua_pop (L, 1);
+ lua_settop (L, old_top);
cur = g_list_next (cur);
}
}
struct rspamd_lua_regexp *re = NULL;
GList *cur;
struct rspamd_mime_header *hdr;
+ gint old_top;
if (task && lua_isfunction (L, 2)) {
if (lua_istable (L, 3)) {
}
}
+ old_top = lua_gettop (L);
lua_pushvalue (L, 2);
lua_pushstring (L, hdr->name);
rspamd_lua_push_header (L, hdr, full, raw);
- if (lua_pcall (L, 2, 1, 0) != 0) {
- msg_err_task ("call to header_foreach failed: %s",
- lua_tostring (L, -1));
- lua_pop (L, 1);
+ if (lua_pcall (L, 2, LUA_MULTRET, 0) != 0) {
+ msg_err ("call to header_foreach failed: %s",
+ lua_tostring (L, -1));
+ lua_settop (L, old_top);
break;
}
else {
- if (lua_isboolean (L, -1)) {
- if (lua_toboolean (L, -1)) {
- lua_pop (L, 1);
- break;
+ if (lua_gettop (L) > old_top) {
+ if (lua_isboolean (L, old_top + 1)) {
+ if (lua_toboolean (L, old_top + 1)) {
+ lua_settop (L, old_top);
+ break;
+ }
}
}
}
- lua_pop (L, 1);
+ lua_settop (L, old_top);
cur = g_list_next (cur);
}
}