summaryrefslogtreecommitdiff
path: root/protocols/WhatsAppWeb/src/utils.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-10-04 13:08:04 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-10-04 13:08:04 +0300
commitead9c198a915b217ed1f4034ea91581ea4500a42 (patch)
treec0a533601a04ac79ba17594ecf63695c14454569 /protocols/WhatsAppWeb/src/utils.cpp
parente244c307f2e1fec282a097a991fbfc1c8272d603 (diff)
WhatsApp: zipped nodes support
Diffstat (limited to 'protocols/WhatsAppWeb/src/utils.cpp')
-rw-r--r--protocols/WhatsAppWeb/src/utils.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/protocols/WhatsAppWeb/src/utils.cpp b/protocols/WhatsAppWeb/src/utils.cpp
index 4c8fb5d8ca..509f277f49 100644
--- a/protocols/WhatsAppWeb/src/utils.cpp
+++ b/protocols/WhatsAppWeb/src/utils.cpp
@@ -344,3 +344,37 @@ void WhatsAppProto::Popup(MCONTACT hContact, const wchar_t *szMsg, const wchar_t
ppd.hContact = hContact;
Popup_AddClass(&ppd);
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+MBinBuffer WhatsAppProto::unzip(const MBinBuffer &src)
+{
+ z_stream strm = {};
+ inflateInit(&strm);
+
+ strm.avail_in = 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; /* and fall through */
+ case Z_DATA_ERROR:
+ case Z_MEM_ERROR:
+ inflateEnd(&strm);
+ return ret;
+ }
+
+ res.append(buf, sizeof(buf) - strm.avail_out);
+ }
+
+ inflateEnd(&strm);
+ return res;
+} \ No newline at end of file