From d85347f1f2028afb685142a776f2af4473de8273 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 15 Jun 2023 13:08:02 +0300 Subject: memory buffer unzip function moved to core --- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/utils.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) (limited to 'src/mir_app') diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index d0abb0ecb0..0f02928081 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -875,3 +875,4 @@ Clist_RemoveEvent @989 ?Clist_GetEventByMenu@@YGPAUCListEvent@@H@Z @990 NONAME ?Clist_GetEventCount@@YGHXZ @991 NONAME ?Chat_EmptyHistory@@YGXPAUSESSION_INFO@@@Z @992 NONAME +?Utils_Unzip@@YG?AVMBinBuffer@@PBXI@Z @993 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index ce3a55a6fd..9fe2e92c6a 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -875,3 +875,4 @@ Clist_RemoveEvent @989 ?Clist_GetEventByMenu@@YAPEAUCListEvent@@H@Z @990 NONAME ?Clist_GetEventCount@@YAHXZ @991 NONAME ?Chat_EmptyHistory@@YAXPEAUSESSION_INFO@@@Z @992 NONAME +?Utils_Unzip@@YA?AVMBinBuffer@@PEBX_K@Z @993 NONAME diff --git a/src/mir_app/src/utils.cpp b/src/mir_app/src/utils.cpp index 42e916d7d7..1c23ded07a 100644 --- a/src/mir_app/src/utils.cpp +++ b/src/mir_app/src/utils.cpp @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "stdafx.h" +#include "..\..\libs\zlib\src\zlib.h" #define MS_SYSTEM_GET_MD5I "Miranda/System/GetMD5I" @@ -372,6 +373,47 @@ bool ProcessFileDrop(HDROP hDrop, MCONTACT hContact) ///////////////////////////////////////////////////////////////////////////////////////// +MIR_APP_DLL(MBinBuffer) Utils_Unzip(const void *pData, size_t cbLen) +{ + MBinBuffer res; + if (pData == nullptr || cbLen == 0) + return res; + + z_stream strm = {}; + inflateInit(&strm); + + strm.avail_in = (uInt)cbLen; + strm.next_in = (Bytef *)pData; + + Bytef buf[2048]; + + while (strm.avail_in > 0) { + strm.avail_out = sizeof(buf); + strm.next_out = buf; + + int ret = inflate(&strm, Z_NO_FLUSH); + switch (ret) { + case Z_NEED_DICT: + ret = Z_DATA_ERROR; + __fallthrough; + + case Z_DATA_ERROR: + case Z_MEM_ERROR: + inflateEnd(&strm); + return res; + } + + res.append(buf, sizeof(buf) - strm.avail_out); + if (ret == Z_STREAM_END) + break; + } + + inflateEnd(&strm); + return res; +} + +///////////////////////////////////////////////////////////////////////////////////////// + int LoadUtilsModule(void) { CreateServiceFunction(MS_UTILS_GETCOUNTRYBYNUMBER, GetCountryByNumber); -- cgit v1.2.3