From: Vsevolod Stakhov Date: Sat, 7 Sep 2019 12:59:19 +0000 (+0100) Subject: [Minor] Support unpack for text X-Git-Tag: 2.0~259 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78ca04d46d55fbaee295381aa554b4e88d6c8139;p=thirdparty%2Frspamd.git [Minor] Support unpack for text --- diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index e18912e9a3..c25d204717 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -3715,11 +3715,28 @@ lua_util_unpack (lua_State *L) Header h; const char *fmt = luaL_checkstring(L, 1); size_t ld; - const char *data = luaL_checklstring (L, 2, &ld); - size_t pos = (size_t) posrelat (luaL_optinteger (L, 3, 1), ld) - 1; + const char *data; int n = 0; /* number of results */ + + if (lua_type (L, 2) == LUA_TUSERDATA) { + struct rspamd_lua_text *t = lua_check_text (L, 2); + + if (!t) { + return luaL_error (L, "invalid arguments"); + } + + data = t->start; + ld = t->len; + } + else { + data = luaL_checklstring (L, 2, &ld); + } + + size_t pos = (size_t) posrelat (luaL_optinteger (L, 3, 1), ld) - 1; luaL_argcheck(L, pos <= ld, 3, "initial position out of string"); + initheader (L, &h); + while (*fmt != '\0') { int size, ntoalign; KOption opt = getdetails (&h, pos, &fmt, &size, &ntoalign);