]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua_fcn: add Patref:del()
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 26 Nov 2024 08:20:10 +0000 (09:20 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 29 Nov 2024 06:23:37 +0000 (07:23 +0100)
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
src/hlua_fcn.c

index 111954446d3ba4b99f5d18823ba234a750315b58..d932064cf2de4420b276ef5903a4615e1d703efe 100644 (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
index d111bc44e39440b5a770791e6c7b6e74e258b3b7..b1db46c34c6ff6ca80217ff7db3bb05fa3280d85 100644 (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)