aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_expression.c
diff options
context:
space:
mode:
authorMikhail Galanin <mgalanin@mimecast.com>2018-08-13 12:06:30 +0100
committerMikhail Galanin <mgalanin@mimecast.com>2018-08-13 12:06:30 +0100
commita9bc3d63a38ab46217303b09f8b03d0215c2f5ea (patch)
treede01b01d314e914e8f949145ae6931c59396913c /src/lua/lua_expression.c
parentff3053a983825f2a6c1dc8799f6ec9b337eed224 (diff)
downloadrspamd-a9bc3d63a38ab46217303b09f8b03d0215c2f5ea.tar.gz
rspamd-a9bc3d63a38ab46217303b09f8b03d0215c2f5ea.zip
[Minor] Use struct to pass parameters to process_atom() functions
Diffstat (limited to 'src/lua/lua_expression.c')
-rw-r--r--src/lua/lua_expression.c56
1 files changed, 34 insertions, 22 deletions
diff --git a/src/lua/lua_expression.c b/src/lua/lua_expression.c
index 03a667b8d..0d57a3bd8 100644
--- a/src/lua/lua_expression.c
+++ b/src/lua/lua_expression.c
@@ -98,7 +98,7 @@ static const struct luaL_reg exprlib_f[] = {
static rspamd_expression_atom_t * lua_atom_parse (const gchar *line, gsize len,
rspamd_mempool_t *pool, gpointer ud, GError **err);
-static gdouble lua_atom_process (gpointer input, rspamd_expression_atom_t *atom);
+static gdouble lua_atom_process (struct rspamd_expr_process_data *process_data, rspamd_expression_atom_t *atom);
static const struct rspamd_atom_subr lua_atom_subr = {
.parse = lua_atom_parse,
@@ -166,22 +166,22 @@ lua_atom_parse (const gchar *line, gsize len,
}
static gdouble
-lua_atom_process (gpointer input, rspamd_expression_atom_t *atom)
+lua_atom_process (struct rspamd_expr_process_data *process_data, rspamd_expression_atom_t *atom)
{
struct lua_expression *e = (struct lua_expression *)atom->data;
gdouble ret = 0;
- lua_rawgeti (e->L, LUA_REGISTRYINDEX, e->process_idx);
- lua_pushlstring (e->L, atom->str, atom->len);
- lua_pushvalue (e->L, GPOINTER_TO_INT (input));
+ lua_rawgeti (process_data->L, LUA_REGISTRYINDEX, e->process_idx);
+ lua_pushlstring (process_data->L, atom->str, atom->len);
+ lua_pushvalue (process_data->L, process_data->stack_item);
- if (lua_pcall (e->L, 2, 1, 0) != 0) {
- msg_info ("callback call failed: %s", lua_tostring (e->L, -1));
- lua_pop (e->L, 1);
+ if (lua_pcall (process_data->L, 2, 1, 0) != 0) {
+ msg_info ("callback call failed: %s", lua_tostring (process_data->L, -1));
+ lua_pop (process_data->L, 1);
}
else {
- ret = lua_tonumber (e->L, -1);
- lua_pop (e->L, 1);
+ ret = lua_tonumber (process_data->L, -1);
+ lua_pop (process_data->L, 1);
}
return ret;
@@ -195,11 +195,16 @@ lua_expr_process (lua_State *L)
gdouble res;
gint flags = 0;
+ struct rspamd_expr_process_data process_data;
+ memset (&process_data, 0, sizeof process_data);
+ process_data.L = L;
+ process_data.stack_item = 2;
+
if (lua_gettop (L) >= 3) {
- flags = lua_tonumber (L, 3);
+ process_data.flags = flags;
}
- res = rspamd_process_expression (e->expr, flags, GINT_TO_POINTER (2));
+ res = rspamd_process_expression (e->expr, &process_data);
lua_pushnumber (L, res);
@@ -214,29 +219,36 @@ lua_expr_process_traced (lua_State *L)
rspamd_expression_atom_t *atom;
gint res;
guint i;
- gint flags = 0;
- GPtrArray *trace;
+ struct rspamd_expr_process_data process_data;
+ memset (&process_data, 0, sizeof process_data);
+
+ process_data.L = L;
+ /*
+ * stack:1 - self
+ * stack:2 - data, see process_traced() definition for details
+ */
+ process_data.stack_item = 2;
if (lua_gettop (L) >= 3) {
- flags = lua_tonumber (L, 3);
+ process_data.flags = lua_tonumber (L, 3);
}
- trace = g_ptr_array_sized_new (32);
- res = rspamd_process_expression_track (e->expr, flags, GINT_TO_POINTER (2),
- trace);
+ process_data.trace = g_ptr_array_sized_new (32);
+
+ res = rspamd_process_expression_track (e->expr, &process_data);
lua_pushnumber (L, res);
- lua_createtable (L, trace->len, 0);
+ lua_createtable (L, process_data.trace->len, 0);
- for (i = 0; i < trace->len; i ++) {
- atom = g_ptr_array_index (trace, i);
+ for (i = 0; i < process_data.trace->len; i ++) {
+ atom = g_ptr_array_index (process_data.trace, i);
lua_pushlstring (L, atom->str, atom->len);
lua_rawseti (L, -2, i + 1);
}
- g_ptr_array_free (trace, TRUE);
+ g_ptr_array_free (process_data.trace, TRUE);
return 2;
}