From: Aurelien DARRAGON Date: Mon, 3 Apr 2023 12:00:58 +0000 (+0200) Subject: MINOR: hlua_fcn: add Server.get_proxy() X-Git-Tag: v2.8-dev10~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3889efa8e4611bf9c6336cd882ee8473236ad489;p=thirdparty%2Fhaproxy.git MINOR: hlua_fcn: add Server.get_proxy() Server.get_proxy(): get the proxy to which the server belongs (or nil if not available) --- diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index 042f231988..fd3d47c77f 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -1233,6 +1233,14 @@ Server class server. :returns: a key/value table containing stats +.. js:function:: Server.get_proxy(sv) + + Returns the parent proxy to which the server belongs. + + :param class_server sv: A :ref:`server_class` which indicates the manipulated + server. + :returns: a :ref:`proxy_class` or nil if not available + .. js:function:: Server.shut_sess(sv) Shutdown all the sessions attached to the server. See the management socket diff --git a/include/haproxy/hlua_fcn.h b/include/haproxy/hlua_fcn.h index 8516514feb..ff9250afe3 100644 --- a/include/haproxy/hlua_fcn.h +++ b/include/haproxy/hlua_fcn.h @@ -34,6 +34,7 @@ void *hlua_checkudata(lua_State *L, int ud, int class_ref); int hlua_register_metatable(struct lua_State *L, char *name); void hlua_fcn_reg_core_fcn(lua_State *L); int hlua_dump_object(lua_State *L); +int hlua_fcn_new_proxy(lua_State *L, struct proxy *px); int hlua_fcn_new_server(lua_State *L, struct server *srv); int hlua_fcn_new_event_sub(lua_State *L, struct event_hdl_sub *sub); diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c index 308e1d8219..7150b0ca34 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -941,6 +941,25 @@ int hlua_server_get_stats(lua_State *L) } +int hlua_server_get_proxy(lua_State *L) +{ + struct server *srv; + + srv = hlua_check_server(L, 1); + if (srv == NULL) { + lua_pushnil(L); + return 1; + } + + if (!srv->proxy) { + lua_pushnil(L); + return 1; + } + + hlua_fcn_new_proxy(L, srv->proxy); + return 1; +} + int hlua_server_get_addr(lua_State *L) { struct server *srv; @@ -1503,6 +1522,7 @@ int hlua_fcn_new_server(lua_State *L, struct server *srv) hlua_class_function(L, "set_addr", hlua_server_set_addr); hlua_class_function(L, "get_addr", hlua_server_get_addr); hlua_class_function(L, "get_stats", hlua_server_get_stats); + hlua_class_function(L, "get_proxy", hlua_server_get_proxy); hlua_class_function(L, "shut_sess", hlua_server_shut_sess); hlua_class_function(L, "set_drain", hlua_server_set_drain); hlua_class_function(L, "set_maint", hlua_server_set_maint);