summaryrefslogtreecommitdiff
path: root/plugins/PluginUpdater
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-01-05 15:54:03 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-01-05 15:54:03 +0300
commit14c4e44a0a91e1ad701d4ae3c58185d25118e64e (patch)
tree50f36035466f355c74373e757bc00b6610ce6267 /plugins/PluginUpdater
parent94667140aeb3886d22e4c1301423fe99aaf3fba4 (diff)
Netlib:
- NETLIBHTTPHEADER & NETLIBHTTPREQUEST obsoleted; - NETLIBHTTPREQUEST divided into MHttpRequest & MHttpResponse; - MHttpHeaders now manager headers both for MHttpRequest & MHttpResponse;
Diffstat (limited to 'plugins/PluginUpdater')
-rw-r--r--plugins/PluginUpdater/src/Utils.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp
index 9a30007c66..4cc80eaec1 100644
--- a/plugins/PluginUpdater/src/Utils.cpp
+++ b/plugins/PluginUpdater/src/Utils.cpp
@@ -143,22 +143,17 @@ int DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc)
#endif
szUserAgent.Append(")");
- NETLIBHTTPHEADER headers[4] = {
- { "User-Agent", szUserAgent.GetBuffer() },
- { "Connection", "close" },
- { "Cache-Control", "no-cache" },
- { "Pragma", "no-cache" }
- };
-
ptrA szUrl(mir_u2a(pFileURL->wszDownloadURL));
- NETLIBHTTPREQUEST nlhr = {};
+ MHttpRequest nlhr;
nlhr.flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11 | NLHRF_PERSISTENT;
nlhr.requestType = REQUEST_GET;
nlhr.nlc = nlc;
- nlhr.szUrl = szUrl;
- nlhr.headersCount = _countof(headers);
- nlhr.headers = headers;
+ nlhr.m_szUrl = szUrl;
+ nlhr.AddHeader("User-Agent", szUserAgent);
+ nlhr.AddHeader("Connection", "close");
+ nlhr.AddHeader("Cache-Control", "no-cache");
+ nlhr.AddHeader("Pragma", "no-cache");
for (int i = 0; i < MAX_RETRIES; i++) {
Netlib_LogfW(g_hNetlibUser, L"Downloading file %s to %s (attempt %d)", pFileURL->wszDownloadURL, pFileURL->wszDiskPath, i + 1);
@@ -170,14 +165,14 @@ int DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc)
}
nlc = pReply->nlc;
- if (pReply->resultCode != 200 || pReply->dataLength <= 0) {
+ if (pReply->resultCode != 200 || pReply->body.IsEmpty()) {
Netlib_LogfW(g_hNetlibUser, L"Downloading file %s failed with error %d", pFileURL->wszDownloadURL, pReply->resultCode);
return pReply->resultCode;
}
// Check CRC sum
if (pFileURL->CRCsum) {
- int crc = crc32(0, (unsigned char *)pReply->pData, pReply->dataLength);
+ int crc = crc32(0, (unsigned char *)pReply->body.c_str(), pReply->body.GetLength());
if (crc != pFileURL->CRCsum) {
// crc check failed, try again
Netlib_LogfW(g_hNetlibUser, L"crc check failed for file %s", pFileURL->wszDiskPath);
@@ -190,7 +185,7 @@ int DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc)
HANDLE hFile = CreateFile(pFileURL->wszDiskPath, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile != INVALID_HANDLE_VALUE) {
// write the downloaded file directly
- WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, nullptr);
+ WriteFile(hFile, pReply->body, pReply->body.GetLength(), &dwBytes, nullptr);
CloseHandle(hFile);
}
else {
@@ -199,7 +194,7 @@ int DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc)
mir_snwprintf(wszTempFile, L"%s\\pulocal.tmp", g_wszTempPath);
hFile = CreateFile(wszTempFile, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile != INVALID_HANDLE_VALUE) {
- WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, nullptr);
+ WriteFile(hFile, pReply->body, pReply->body.GetLength(), &dwBytes, nullptr);
CloseHandle(hFile);
PU::SafeMoveFile(wszTempFile, pFileURL->wszDiskPath);
}