]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua_fcn: add Patref:prepare() method
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 21 Nov 2024 15:32:05 +0000 (16:32 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 29 Nov 2024 06:23:14 +0000 (07:23 +0100)
Just like the "prepare map" or "prepare acl" on the cli, but for Lua:
it leverages the pattern API to create a subset (ie: a new generation id)
that will automatically be used as target for following Patref operations
(add/set/del...) until the "commit" method is invoked to atomically push
the pending updates.

doc/lua-api/index.rst
src/hlua_fcn.c

index f9d629d0f6fe5972e6eef6fcd500e642d6382c3a..c903fe1de6f2b59bd61048fa9d6632ef9b8609d3 100644 (file)
@@ -3456,6 +3456,12 @@ Patref class
   :returns: true if the pattern reference is used to handle maps instead
    of acl, false otherwise.
 
+.. js:function:: Patref.prepare(ref)
+
+  Create a new empty version for Patref Object. It can be used to manipulate
+  the Patref object with update methods without applying the updates until the
+  commit() method is called.
+
 .. js:function:: Patref.commit(ref)
 
   Tries to commit pending Patref object updates, that is updates made to the
@@ -3467,6 +3473,8 @@ Patref class
 
   :returns: true on success and nil on failure (followed by an error message).
 
+  See :js:func:`Patref.prepare()`
+
 .. _applethttp_class:
 
 AppletHTTP class
index 573f18ec24978bb732e28148cc7189cba72a2fb1..f2336bd1e675c917a8e59c33284d041b50c1ff09 100644 (file)
@@ -2694,6 +2694,17 @@ int hlua_patref_commit(lua_State *L)
        return _hlua_patref_clear(L, LUA_OK, 0);
 }
 
+int hlua_patref_prepare(lua_State *L)
+{
+       struct hlua_patref *ref;
+
+       ref = hlua_checkudata(L, 1, class_patref_ref);
+       BUG_ON(!ref);
+       ref->curr_gen = pat_ref_newgen(ref->ptr);
+       ref->flags |= HLUA_PATREF_FL_GEN;
+       return 0;
+}
+
 void hlua_fcn_new_patref(lua_State *L, struct pat_ref *ref)
 {
        struct hlua_patref *_ref;
@@ -2721,6 +2732,7 @@ void hlua_fcn_new_patref(lua_State *L, struct pat_ref *ref)
        /* set public methods */
        hlua_class_function(L, "get_name", hlua_patref_get_name);
        hlua_class_function(L, "is_map", hlua_patref_is_map);
+       hlua_class_function(L, "prepare", hlua_patref_prepare);
        hlua_class_function(L, "commit", hlua_patref_commit);
 }