]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Lua_upstream: Add get_name method
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 11 Oct 2021 11:02:30 +0000 (12:02 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 11 Oct 2021 11:02:30 +0000 (12:02 +0100)
src/lua/lua_upstream.c

index c259c22db4e61f87533e87856347923d310a69b2..322b242f870225b3459f3994b7fdc4fe9ac0ddaf 100644 (file)
@@ -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.