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.
This commit is contained in:
Aurelien DARRAGON 2024-11-26 09:20:10 +01:00
parent 6cc2662ce7
commit a5f74a2a2d
2 changed files with 37 additions and 0 deletions

View File

@ -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

View File

@ -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)