summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-01-10 12:11:16 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-01-10 12:11:16 +0300
commit730c132f369842cd219388905cf981c2e90f98b3 (patch)
treee347546e613854070cfd3da32eb0e2e8d30b3b91 /protocols/WhatsApp/src
parente688d75e8db7616d7e6d6fb3ed3c892e4fbe8a97 (diff)
code cleaning
Diffstat (limited to 'protocols/WhatsApp/src')
-rw-r--r--protocols/WhatsApp/src/avatars.cpp23
1 files changed, 5 insertions, 18 deletions
diff --git a/protocols/WhatsApp/src/avatars.cpp b/protocols/WhatsApp/src/avatars.cpp
index 32e57706a4..f1b0709c34 100644
--- a/protocols/WhatsApp/src/avatars.cpp
+++ b/protocols/WhatsApp/src/avatars.cpp
@@ -135,7 +135,7 @@ bool CMPlugin::SaveFile(const char *pszUrl, PROTO_AVATAR_INFORMATION &ai)
req.m_szUrl = pszUrl;
req.nlc = hAvatarConn;
- NLHR_PTR pReply(Netlib_HttpTransaction(hAvatarUser, &req));
+ NLHR_PTR pReply(Netlib_DownloadFile(hAvatarUser, &req, ai.filename));
if (pReply == nullptr) {
hAvatarConn = nullptr;
debugLogA("Failed to retrieve avatar from url: %s", pszUrl);
@@ -144,23 +144,10 @@ bool CMPlugin::SaveFile(const char *pszUrl, PROTO_AVATAR_INFORMATION &ai)
hAvatarConn = pReply->nlc;
- bool bSuccess = false;
- if (pReply->resultCode == 200 && !pReply->body.IsEmpty()) {
- if (auto *pszHdr = pReply->FindHeader("Content-Type"))
- ai.format = ProtoGetAvatarFormatByMimeType(pszHdr);
-
- if (ai.format != PA_FORMAT_UNKNOWN) {
- FILE *fout = _wfopen(ai.filename, L"wb");
- if (fout) {
- fwrite(pReply->body, 1, pReply->body.GetLength(), fout);
- fclose(fout);
- bSuccess = true;
- }
- else debugLogA("Error saving avatar to file %S", ai.filename);
- }
- else debugLogA("unknown avatar mime type");
+ if (pReply->resultCode != 200) {
+ debugLogA("Error %d reading avatar from url: %s", pReply->resultCode, pszUrl);
+ return false;
}
- else debugLogA("Error %d reading avatar from url: %s", pReply->resultCode, pszUrl);
- return bSuccess;
+ return true;
}