]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lua: Add dlua_var_expand() allow var_expand() from lua
authorMarkus Valentin <markus.valentin@open-xchange.com>
Thu, 26 Jun 2025 08:42:39 +0000 (10:42 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 16 Jul 2025 10:16:26 +0000 (10:16 +0000)
src/lib-lua/dlua-dovecot.c

index 05433a82c31a44720e351b5328dbb08f02af3bbb..d3bc2457d664e7a7961705990379ad5992211fdd 100644 (file)
@@ -10,6 +10,7 @@
 #include "dict-lua.h"
 #include "doveadm-client-lua.h"
 #include "strescape.h"
+#include "var-expand.h"
 
 #define LUA_SCRIPT_DOVECOT "dovecot"
 #define LUA_SCRIPT_DOVECOT_BASE64 "base64"
@@ -736,6 +737,20 @@ static int dlua_split_tabescaped(lua_State *L)
        return 1;
 }
 
+static int dlua_var_expand(lua_State *L)
+{
+       DLUA_REQUIRE_ARGS(L, 1);
+       string_t *output = t_str_new(128);
+       const char *error;
+       const char *input = luaL_checkstring(L, 1);
+
+       if (var_expand(output, input, NULL, &error) != 0)
+               return luaL_error(L, "failed to expand '%s': %s", input, error);
+
+       lua_pushlstring(L, str_c(output), str_len(output));
+       return 1;
+}
+
 static int dlua_base64_encode(lua_State *L)
 {
        DLUA_REQUIRE_ARGS(L, 1);
@@ -775,6 +790,7 @@ static luaL_Reg lua_dovecot_methods[] = {
        { "tabescape", dlua_tabescape},
        { "tabunescape", dlua_tabunescape},
        { "split_tabescaped", dlua_split_tabescaped},
+       { "var_expand", dlua_var_expand },
        { NULL, NULL }
 };