From 51a37928e9cb4be0984a0e3580a79bc2dec0891e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 11 Oct 2021 12:02:30 +0100 Subject: [PATCH] [Minor] Lua_upstream: Add get_name method --- src/lua/lua_upstream.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lua/lua_upstream.c b/src/lua/lua_upstream.c index c259c22db..322b242f8 100644 --- a/src/lua/lua_upstream.c +++ b/src/lua/lua_upstream.c @@ -78,12 +78,14 @@ static const struct luaL_reg upstream_list_f[] = { LUA_FUNCTION_DEF (upstream, ok); LUA_FUNCTION_DEF (upstream, fail); LUA_FUNCTION_DEF (upstream, get_addr); +LUA_FUNCTION_DEF (upstream, get_name); LUA_FUNCTION_DEF (upstream, destroy); static const struct luaL_reg upstream_m[] = { LUA_INTERFACE_DEF (upstream, ok), LUA_INTERFACE_DEF (upstream, fail), LUA_INTERFACE_DEF (upstream, get_addr), + LUA_INTERFACE_DEF (upstream, get_name), {"__tostring", rspamd_lua_class_tostring}, {"__gc", lua_upstream_destroy}, {NULL, NULL} @@ -126,6 +128,27 @@ lua_upstream_get_addr (lua_State *L) return 1; } +/*** + * @method upstream:get_name() + * Get name of upstream + * @return {string} name of the upstream + */ +static gint +lua_upstream_get_name (lua_State *L) +{ + LUA_TRACE_POINT; + struct rspamd_lua_upstream *up = lua_check_upstream (L); + + if (up) { + lua_pushstring (L, rspamd_upstream_name (up->up)); + } + else { + lua_pushnil (L); + } + + return 1; +} + /*** * @method upstream:fail() * Indicate upstream failure. After certain amount of failures during specified time frame, an upstream is marked as down and does not participate in rotations. -- 2.39.5