aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-01-03 15:02:45 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-01-03 15:02:45 +0000
commit8a2b528566e9f6e09ab0febb62fa2fe6487ed784 (patch)
tree33f01d39eb8f944490f9f1f5eb9eb92ebc722eb0 /src/lua
parent70116523047683084cac89b619419b12a802906f (diff)
downloadrspamd-8a2b528566e9f6e09ab0febb62fa2fe6487ed784.tar.gz
rspamd-8a2b528566e9f6e09ab0febb62fa2fe6487ed784.zip
[Project] Add inflate utility
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_util.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index e04f82160..d915085fc 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -388,11 +388,21 @@ LUA_FUNCTION_DEF (util, zstd_decompress);
*
* @param {string/rspamd_text} data compressed data
* @param {integer} size_limit optional size limit
- * @return {error,rspamd_text} pair of error + decompressed text
+ * @return {rspamd_text} decompressed text
*/
LUA_FUNCTION_DEF (util, gzip_decompress);
/***
+ * @function util.inflate(data, [size_limit])
+ * Decompresses input using inflate algorithm
+ *
+ * @param {string/rspamd_text} data compressed data
+ * @param {integer} size_limit optional size limit
+ * @return {rspamd_text} decompressed text
+ */
+LUA_FUNCTION_DEF (util, inflate);
+
+/***
* @function util.gzip_compress(data)
* Compresses input using gzip compression
*
@@ -663,6 +673,7 @@ static const struct luaL_reg utillib_f[] = {
LUA_INTERFACE_DEF (util, zstd_decompress),
LUA_INTERFACE_DEF (util, gzip_compress),
LUA_INTERFACE_DEF (util, gzip_decompress),
+ LUA_INTERFACE_DEF (util, inflate),
LUA_INTERFACE_DEF (util, normalize_prob),
LUA_INTERFACE_DEF (util, caseless_hash),
LUA_INTERFACE_DEF (util, caseless_hash_fast),
@@ -2319,7 +2330,7 @@ lua_util_gzip_compress (lua_State *L)
static gint
-lua_util_gzip_decompress (lua_State *L)
+lua_util_zlib_inflate (lua_State *L, int windowBits)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t = NULL, *res, tmp;
@@ -2351,7 +2362,7 @@ lua_util_gzip_decompress (lua_State *L)
memset (&strm, 0, sizeof (strm));
/* windowBits +16 to decode gzip, zlib 1.2.0.4+ */
- rc = inflateInit2 (&strm, MAX_WBITS + 16);
+ rc = inflateInit2 (&strm, windowBits);
if (rc != Z_OK) {
return luaL_error (L, "cannot init zlib");
@@ -2372,7 +2383,7 @@ lua_util_gzip_decompress (lua_State *L)
strm.avail_out = remain;
strm.next_out = p;
- rc = inflate (&strm, Z_FINISH);
+ rc = inflate (&strm, Z_NO_FLUSH);
if (rc != Z_OK && rc != Z_BUF_ERROR) {
if (rc == Z_STREAM_END) {
@@ -2414,9 +2425,19 @@ lua_util_gzip_decompress (lua_State *L)
inflateEnd (&strm);
res->len = strm.total_out;
- return 2;
+ return 1;
+}
+static gint
+lua_util_gzip_decompress (lua_State *L)
+{
+ return lua_util_zlib_inflate (L, MAX_WBITS + 16);
}
+static gint
+lua_util_inflate (lua_State *L)
+{
+ return lua_util_zlib_inflate (L, 0);
+}
static gint
lua_util_normalize_prob (lua_State *L)