diff options
author | George Hazan <george.hazan@gmail.com> | 2023-06-15 13:08:02 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-06-15 13:08:02 +0300 |
commit | d85347f1f2028afb685142a776f2af4473de8273 (patch) | |
tree | d0480a13ed726f11612e04bf8e23435008b0efce /protocols | |
parent | 110b291bce427209d629cdb9688a8e785a66ef47 (diff) |
memory buffer unzip function moved to core
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/WhatsApp/src/message.cpp | 2 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.h | 3 | ||||
-rw-r--r-- | protocols/WhatsApp/src/server.cpp | 2 | ||||
-rw-r--r-- | protocols/WhatsApp/src/utils.cpp | 38 |
4 files changed, 2 insertions, 43 deletions
diff --git a/protocols/WhatsApp/src/message.cpp b/protocols/WhatsApp/src/message.cpp index cc6e9d8ff9..985728208d 100644 --- a/protocols/WhatsApp/src/message.cpp +++ b/protocols/WhatsApp/src/message.cpp @@ -254,7 +254,7 @@ void WhatsAppProto::ProcessMessage(WAMSG type, const Wa__WebMessageInfo &msg) if (auto *pHist = protoMsg->historysyncnotification) {
MBinBuffer buf(DownloadEncryptedFile(directPath2url(pHist->directpath), pHist->mediakey, "History"));
if (!buf.isEmpty()) {
- MBinBuffer inflate(unzip(unpadBuffer16(buf)));
+ MBinBuffer inflate(Utils_Unzip(unpadBuffer16(buf)));
proto::HistorySync sync(inflate);
if (sync)
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h index 0ec03e5313..ef3bb4f408 100644 --- a/protocols/WhatsApp/src/proto.h +++ b/protocols/WhatsApp/src/proto.h @@ -435,9 +435,6 @@ class WhatsAppProto : public PROTO<WhatsAppProto> // Binary packets
void ProcessBinaryPacket(const uint8_t *pData, size_t cbLen);
- // unzip operations
- MBinBuffer unzip(const MBinBuffer &src);
-
/// Avatars ////////////////////////////////////////////////////////////////////////////
CMStringW GetAvatarFileName(MCONTACT hContact);
void ServerFetchAvatar(const char *jid);
diff --git a/protocols/WhatsApp/src/server.cpp b/protocols/WhatsApp/src/server.cpp index 24d64e5aa7..857666b2e4 100644 --- a/protocols/WhatsApp/src/server.cpp +++ b/protocols/WhatsApp/src/server.cpp @@ -191,7 +191,7 @@ void WhatsAppProto::ProcessBinaryPacket(const uint8_t *pData, size_t cbDataLen) auto b = rdr.readInt8();
if (b & 2) {
buf.remove(1);
- buf = unzip(buf);
+ buf = Utils_Unzip(buf);
rdr = WAReader(buf.data(), buf.length());
}
diff --git a/protocols/WhatsApp/src/utils.cpp b/protocols/WhatsApp/src/utils.cpp index a1d234e405..c49821e21e 100644 --- a/protocols/WhatsApp/src/utils.cpp +++ b/protocols/WhatsApp/src/utils.cpp @@ -362,44 +362,6 @@ void WhatsAppProto::Popup(MCONTACT hContact, const wchar_t *szMsg, const wchar_t /////////////////////////////////////////////////////////////////////////////////////////
-MBinBuffer WhatsAppProto::unzip(const MBinBuffer &src)
-{
- z_stream strm = {};
- inflateInit(&strm);
-
- strm.avail_in = (uInt)src.length();
- strm.next_in = (Bytef *)src.data();
-
- MBinBuffer res;
- 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;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
void bin2file(const MBinBuffer &buf, const wchar_t *pwszFileName)
{
int fileId = _wopen(pwszFileName, _O_WRONLY | _O_TRUNC | _O_BINARY | _O_CREAT, _S_IREAD | _S_IWRITE);
|