]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua: add patref class
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 7 Nov 2024 16:26:32 +0000 (17:26 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 29 Nov 2024 06:22:32 +0000 (07:22 +0100)
Implement patref class to expose pat_ref struct internal pattern struct
in lua. This is some prerequisite work needed to be able to manipulate
exisiting generic pattern object lists (acl/map) from Lua, because the Map
class can only be used to perform matching ops on Map files.

include/haproxy/hlua-t.h
include/haproxy/hlua_fcn.h
src/hlua_fcn.c

index bbbc61f287584b4687fc9e6c5da9faf212bdce23..ce1bc50969f8c1133ef182f101aab612fe703c0d 100644 (file)
@@ -36,6 +36,7 @@
 #include <haproxy/stick_table-t.h>
 #include <haproxy/xref-t.h>
 #include <haproxy/event_hdl-t.h>
+#include <haproxy/pattern-t.h>
 
 #define CLASS_CORE         "Core"
 #define CLASS_TXN          "TXN"
@@ -53,6 +54,7 @@
 #define CLASS_SERVER       "Server"
 #define CLASS_LISTENER     "Listener"
 #define CLASS_EVENT_SUB    "EventSub"
+#define CLASS_PATREF       "Patref"
 #define CLASS_REGEX        "Regex"
 #define CLASS_STKTABLE     "StickTable"
 #define CLASS_CERTCACHE    "CertCache"
index ff9250afe3f09758caadb04061fb91e4e3f64d29..9d5fe184bc4cb2ce78e20295fb9557addad3cbce 100644 (file)
@@ -37,5 +37,6 @@ 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);
+void hlua_fcn_new_patref(lua_State *L, struct pat_ref *ref);
 
 #endif /* _HAPROXY_HLUA_FCN_H */
index afb5cf07ec1a26b8f2ed9ad4bb9f03079b9d87ef..5acb0664a946cc01e8f46b118d8bb3c3e42671f9 100644 (file)
@@ -49,6 +49,7 @@ static int class_proxy_ref;
 static int class_server_ref;
 static int class_listener_ref;
 static int class_event_sub_ref;
+static int class_patref_ref;
 static int class_regex_ref;
 static int class_stktable_ref;
 static int class_proxy_list_ref;
@@ -2617,6 +2618,36 @@ static int hlua_regex_free(struct lua_State *L)
        return 0;
 }
 
+int hlua_patref_get_name(lua_State *L)
+{
+       struct pat_ref *ref;
+
+       ref = hlua_checkudata(L, 1, class_patref_ref);
+       BUG_ON(!ref);
+
+       lua_pushstring(L, ref->reference);
+       return 1;
+}
+
+void hlua_fcn_new_patref(lua_State *L, struct pat_ref *ref)
+{
+       lua_newtable(L);
+
+       /* Pop a class patref metatable and affect it to the userdata
+        * (if provided)
+        */
+       lua_rawgeti(L, LUA_REGISTRYINDEX, class_patref_ref);
+       lua_setmetatable(L, -2);
+
+       if (ref) {
+               lua_pushlightuserdata(L, ref);
+               lua_rawseti(L, -2, 0);
+       }
+
+       /* set public methods */
+       hlua_class_function(L, "get_name", hlua_patref_get_name);
+}
+
 void hlua_fcn_reg_core_fcn(lua_State *L)
 {
        hlua_concat_init(L);
@@ -2675,6 +2706,10 @@ void hlua_fcn_reg_core_fcn(lua_State *L)
        hlua_class_function(L, "__gc", hlua_event_sub_gc);
        class_event_sub_ref = hlua_register_metatable(L, CLASS_EVENT_SUB);
 
+       /* Create patref object. */
+       lua_newtable(L);
+       class_patref_ref = hlua_register_metatable(L, CLASS_PATREF);
+
        /* Create server object. */
        lua_newtable(L);
        hlua_class_function(L, "__gc", hlua_server_gc);