mirror of
https://github.com/rspamd/rspamd.git
synced 2024-07-29 20:17:47 +02:00
[Minor] Allow to get all upstreams from the list in Lua
This commit is contained in:
parent
9e49ecbddd
commit
9d99bef124
@ -52,6 +52,7 @@ end
|
||||
/* Upstream list functions */
|
||||
LUA_FUNCTION_DEF (upstream_list, create);
|
||||
LUA_FUNCTION_DEF (upstream_list, destroy);
|
||||
LUA_FUNCTION_DEF (upstream_list, all_upstreams);
|
||||
LUA_FUNCTION_DEF (upstream_list, get_upstream_by_hash);
|
||||
LUA_FUNCTION_DEF (upstream_list, get_upstream_round_robin);
|
||||
LUA_FUNCTION_DEF (upstream_list, get_upstream_master_slave);
|
||||
@ -61,6 +62,7 @@ static const struct luaL_reg upstream_list_m[] = {
|
||||
LUA_INTERFACE_DEF (upstream_list, get_upstream_by_hash),
|
||||
LUA_INTERFACE_DEF (upstream_list, get_upstream_round_robin),
|
||||
LUA_INTERFACE_DEF (upstream_list, get_upstream_master_slave),
|
||||
LUA_INTERFACE_DEF (upstream_list, all_upstreams),
|
||||
{"__tostring", rspamd_lua_class_tostring},
|
||||
{"__gc", lua_upstream_list_destroy},
|
||||
{NULL, NULL}
|
||||
@ -317,6 +319,39 @@ lua_upstream_list_get_upstream_master_slave (lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void lua_upstream_inserter (struct upstream *up, guint idx, void *ud)
|
||||
{
|
||||
struct upstream **pup;
|
||||
lua_State *L = (lua_State *)ud;
|
||||
|
||||
pup = lua_newuserdata (L, sizeof (struct upstream *));
|
||||
rspamd_lua_setclass (L, "rspamd{upstream}", -1);
|
||||
*pup = up;
|
||||
|
||||
lua_rawseti (L, -2, idx + 1);
|
||||
}
|
||||
/***
|
||||
* @method upstream_list:all_upstreams()
|
||||
* Returns all upstreams for this list
|
||||
* @return {table|upstream} all upstreams defined
|
||||
*/
|
||||
static gint
|
||||
lua_upstream_list_all_upstreams (lua_State *L)
|
||||
{
|
||||
struct upstream_list *upl;
|
||||
|
||||
upl = lua_check_upstream_list (L);
|
||||
if (upl) {
|
||||
lua_createtable (L, rspamd_upstreams_count (upl), 0);
|
||||
rspamd_upstreams_foreach (upl, lua_upstream_inserter, L);
|
||||
}
|
||||
else {
|
||||
lua_pushnil (L);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static gint
|
||||
lua_load_upstream_list (lua_State * L)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user