From a5f74a2a2db61cda74f346355f9250179d358065 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Tue, 26 Nov 2024 09:20:10 +0100 Subject: [PATCH] MINOR: hlua_fcn: add Patref:del() Just like "del map" and "del acl" on the cli, the Patref:del() method can be used to delete an existing entry in the pattern reference pointed to by the Lua Patref object. The update will target the live pattern reference version, unless Patref:prepare() is ongoing. --- doc/lua-api/index.rst | 12 ++++++++++++ src/hlua_fcn.c | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index 111954446..d932064cf 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -3498,6 +3498,18 @@ Patref class Affects the live pattern reference version, unless :js:func:`Patref.prepare()` was called and is still ongoing (waiting for commit or giveup) +.. js:function:: Patref.del(ref, key) + + Delete all entries matching the input key in the pattern reference. In + case of duplicate keys, all keys are removed. + + :param string key: the string used as a key + :returns: true on success and false on failure. + + .. Note:: + Affects the live pattern reference version, unless :js:func:`Patref.prepare()` + was called and is still ongoing (waiting for commit or giveup) + .. _applethttp_class: AppletHTTP class diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c index d111bc44e..b1db46c34 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -2773,6 +2773,30 @@ int hlua_patref_add(lua_State *L) return 1; } +int hlua_patref_del(lua_State *L) +{ + struct hlua_patref *ref; + const char *key; + int ret; + + ref = hlua_checkudata(L, 1, class_patref_ref); + + BUG_ON(!ref); + + key = luaL_checkstring(L, 2); + + HA_RWLOCK_WRLOCK(PATREF_LOCK, &ref->ptr->lock); + if ((ref->flags & HLUA_PATREF_FL_GEN) && + pat_ref_may_commit(ref->ptr, ref->curr_gen)) + ret = pat_ref_gen_delete(ref->ptr, ref->curr_gen, key); + else + ret = pat_ref_delete(ref->ptr, key); + HA_RWLOCK_WRUNLOCK(PATREF_LOCK, &ref->ptr->lock); + + lua_pushboolean(L, !!ret); + return 1; +} + void hlua_fcn_new_patref(lua_State *L, struct pat_ref *ref) { struct hlua_patref *_ref; @@ -2805,6 +2829,7 @@ void hlua_fcn_new_patref(lua_State *L, struct pat_ref *ref) hlua_class_function(L, "giveup", hlua_patref_giveup); hlua_class_function(L, "purge", hlua_patref_purge); hlua_class_function(L, "add", hlua_patref_add); + hlua_class_function(L, "del", hlua_patref_del); } int hlua_patref_gc(lua_State *L)