aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-12-16 15:02:28 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-12-16 15:02:28 +0000
commit9d99bef1243389742c3071801192e16fb90d8995 (patch)
tree4d73126dfd32b722a5c3805feebc0ff053ac766e /src/lua
parent9e49ecbddd34b13c5319171229623916a86d0a23 (diff)
downloadrspamd-9d99bef1243389742c3071801192e16fb90d8995.tar.gz
rspamd-9d99bef1243389742c3071801192e16fb90d8995.zip
[Minor] Allow to get all upstreams from the list in Lua
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_upstream.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lua/lua_upstream.c b/src/lua/lua_upstream.c
index 84d112ef1..066183187 100644
--- a/src/lua/lua_upstream.c
+++ b/src/lua/lua_upstream.c
@@ -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)
{