aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_compress.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-08-26 16:08:28 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-08-26 16:08:51 +0100
commitc7bca7a471a4d91ba5b7489ff234f30f92821dac (patch)
tree7655172623aae7d6b69deff173fff900f1e90ba9 /src/lua/lua_compress.c
parent4b22c83c6522476a160cb9ee07d5f21006c2e70b (diff)
downloadrspamd-c7bca7a471a4d91ba5b7489ff234f30f92821dac.tar.gz
rspamd-c7bca7a471a4d91ba5b7489ff234f30f92821dac.zip
[Minor] Lua_compression: Add support of the compression level for gzip
Diffstat (limited to 'src/lua/lua_compress.c')
-rw-r--r--src/lua/lua_compress.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/lua/lua_compress.c b/src/lua/lua_compress.c
index 599a796e0..f383d27c2 100644
--- a/src/lua/lua_compress.c
+++ b/src/lua/lua_compress.c
@@ -323,7 +323,7 @@ lua_compress_zlib_compress (lua_State *L)
struct rspamd_lua_text *t = NULL, *res;
gsize sz;
z_stream strm;
- gint rc;
+ gint rc, comp_level = Z_DEFAULT_COMPRESSION;
guchar *p;
gsize remain;
@@ -333,9 +333,18 @@ lua_compress_zlib_compress (lua_State *L)
return luaL_error (L, "invalid arguments");
}
+ if (lua_isnumber (L, 2)) {
+ comp_level = lua_tointeger (L, 2);
+
+ if (comp_level > Z_BEST_COMPRESSION || comp_level < Z_BEST_SPEED) {
+ return luaL_error (L, "invalid arguments: compression level must be between %d and %d",
+ Z_BEST_SPEED, Z_BEST_COMPRESSION);
+ }
+ }
+
memset (&strm, 0, sizeof (strm));
- rc = deflateInit2 (&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
+ rc = deflateInit2 (&strm, comp_level, Z_DEFLATED,
MAX_WBITS + 16, MAX_MEM_LEVEL - 1, Z_DEFAULT_STRATEGY);
if (rc != Z_OK) {