Beispiel #1
0
static void
process_regexp_item (struct rspamd_task *task, void *user_data)
{
	struct regexp_module_item *item = user_data;
	gint res = FALSE;

	/* Non-threaded version */
	if (item->lua_function) {
		/* Just call function */
		res = FALSE;
		if (!rspamd_lua_call_expression_func (item->lua_function, task, NULL,
				&res)) {
			msg_err_task ("error occurred when checking symbol %s",
					item->symbol);
		}
	}
	else {
		/* Process expression */
		if (item->expr) {
			res = rspamd_process_expression (item->expr, 0, task);
		}
		else {
			msg_warn_task ("FIXME: %s symbol is broken with new expressions",
					item->symbol);
		}
	}

	if (res) {
		rspamd_task_insert_result (task, item->symbol, res, NULL);
	}
}
Beispiel #2
0
static gint
lua_expr_process (lua_State *L)
{
	LUA_TRACE_POINT;
	struct lua_expression *e = rspamd_lua_expression (L, 1);
	struct lua_atom_process_data pd;
	gdouble res;
	gint flags = 0, old_top;

	pd.L = L;
	pd.e = e;
	old_top = lua_gettop (L);

	if (e->process_idx == -1) {
		if (!lua_isfunction (L, 2)) {
			return luaL_error (L, "expression process is called with no callback function");
		}

		pd.process_cb_pos = 2;

		if (lua_type (L, 3) != LUA_TNONE && lua_type (L, 3) != LUA_TNIL) {
			pd.stack_item = 3;
		}
		else {
			pd.stack_item = -1;
		}

		if (lua_isnumber (L, 4)) {
			flags = lua_tointeger (L, 4);
		}
	}
	else {
		lua_rawgeti (L, LUA_REGISTRYINDEX, e->process_idx);
		pd.process_cb_pos = lua_gettop (L);

		if (lua_type (L, 2) != LUA_TNONE && lua_type (L, 2) != LUA_TNIL) {
			pd.stack_item = 2;
		}
		else {
			pd.stack_item = -1;
		}

		if (lua_isnumber (L, 3)) {
			flags = lua_tointeger (L, 3);
		}
	}

	res = rspamd_process_expression (e->expr, flags, &pd);

	lua_settop (L, old_top);
	lua_pushnumber (L, res);

	return 1;
}
Beispiel #3
0
static gint
lua_expr_process (lua_State *L)
{
    struct lua_expression *e = rspamd_lua_expression (L, 1);
    gint res;
    gint flags = 0;

    if (lua_gettop (L) >= 3) {
        flags = lua_tonumber (L, 3);
    }

    res = rspamd_process_expression (e->expr, flags, GINT_TO_POINTER (2));

    lua_pushnumber (L, res);

    return 1;
}