diff options
author | George Hazan <ghazan@miranda.im> | 2019-07-24 14:30:13 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-07-24 14:30:13 +0300 |
commit | 103de9c164934b2393dfcba7011625f90c8a2097 (patch) | |
tree | f7a4a09afe29398f3b7605d7d0db264638a18150 /plugins | |
parent | 541eab20530165d10592a9fda590f435c6a8b4be (diff) |
NLHR_PTR - smart pointers make better code
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CrashDumper/src/upload.cpp | 8 | ||||
-rw-r--r-- | plugins/HTTPServer/src/GuiElements.cpp | 3 | ||||
-rw-r--r-- | plugins/PackUpdater/Src/Utils.cpp | 4 | ||||
-rw-r--r-- | plugins/PasteIt/src/PasteToWeb.cpp | 4 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/Utils.cpp | 5 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp | 5 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp | 5 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp | 5 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/download.cpp | 4 |
9 files changed, 10 insertions, 33 deletions
diff --git a/plugins/CrashDumper/src/upload.cpp b/plugins/CrashDumper/src/upload.cpp index 746567bd28..1e212aa391 100644 --- a/plugins/CrashDumper/src/upload.cpp +++ b/plugins/CrashDumper/src/upload.cpp @@ -122,10 +122,8 @@ bool InternetDownloadFile(const char *szUrl, VerTrnsfr* szReq) while (result == 0xBADBAD) {
// download the page
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(hNetlibUser, &nlhr));
if (nlhrReply) {
- int i;
-
// if the recieved code is 200 OK
switch (nlhrReply->resultCode) {
case 200:
@@ -156,7 +154,7 @@ bool InternetDownloadFile(const char *szUrl, VerTrnsfr* szReq) case 307:
// get the url for the new location and save it to szInfo
// look for the reply header "Location"
- for (i = 0; i < nlhrReply->headersCount; i++) {
+ for (int i = 0; i < nlhrReply->headersCount; i++) {
if (!mir_strcmp(nlhrReply->headers[i].szName, "Location")) {
size_t rlen = 0;
if (nlhrReply->headers[i].szValue[0] == '/') {
@@ -188,8 +186,6 @@ bool InternetDownloadFile(const char *szUrl, VerTrnsfr* szReq) result = 1;
ShowMessage(0, TranslateT("Cannot upload Version Info. Host unreachable."));
}
-
- Netlib_FreeHttpRequest(nlhrReply);
}
mir_free(szRedirUrl);
diff --git a/plugins/HTTPServer/src/GuiElements.cpp b/plugins/HTTPServer/src/GuiElements.cpp index 285cc7595f..ebb4f0587f 100644 --- a/plugins/HTTPServer/src/GuiElements.cpp +++ b/plugins/HTTPServer/src/GuiElements.cpp @@ -151,7 +151,7 @@ unsigned long GetExternIP(const char *szURL, const char *szPattern) IN_ADDR externIP;
externIP.s_addr = 0;
- NETLIBHTTPREQUEST *nlreply = Netlib_HttpTransaction(hNetlibUser, &nlhr);
+ NLHR_PTR nlreply(Netlib_HttpTransaction(hNetlibUser, &nlhr));
if (nlreply) {
if (nlreply->resultCode >= 200 && nlreply->resultCode < 300) {
nlreply->pData[nlreply->dataLength] = 0;// make sure its null terminated
@@ -171,7 +171,6 @@ unsigned long GetExternIP(const char *szURL, const char *szPattern) if ((externIP.s_addr = inet_addr(pszIp)) == INADDR_NONE)
externIP.s_addr = 0;
}
- Netlib_FreeHttpRequest(nlreply);
}
::SetCursor(hPrevCursor);
return ntohl(externIP.s_addr);
diff --git a/plugins/PackUpdater/Src/Utils.cpp b/plugins/PackUpdater/Src/Utils.cpp index a65e5073e3..0502abf28b 100644 --- a/plugins/PackUpdater/Src/Utils.cpp +++ b/plugins/PackUpdater/Src/Utils.cpp @@ -125,8 +125,7 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal) nlhr.headers[3].szValue = "no-cache";
bool ret = false;
- NETLIBHTTPREQUEST *pReply = Netlib_HttpTransaction(hNetlibUser, &nlhr);
-
+ NLHR_PTR pReply(Netlib_HttpTransaction(hNetlibUser, &nlhr));
if (pReply) {
if (200 == pReply->resultCode && pReply->dataLength > 0) {
HANDLE hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
@@ -136,7 +135,6 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal) if (hFile)
CloseHandle(hFile);
}
- Netlib_FreeHttpRequest(pReply);
}
mir_free(szUrl);
diff --git a/plugins/PasteIt/src/PasteToWeb.cpp b/plugins/PasteIt/src/PasteToWeb.cpp index 7a98dcf5b8..536bf8001f 100644 --- a/plugins/PasteIt/src/PasteToWeb.cpp +++ b/plugins/PasteIt/src/PasteToWeb.cpp @@ -456,14 +456,12 @@ char* PasteToWeb::SendToWeb(char* url, std::map<std::string, std::string>& heade char *resCont = nullptr;
nlhr.headersCount = nHeaders;
- NETLIBHTTPREQUEST* nlhrReply = Netlib_HttpTransaction(g_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(g_hNetlibUser, &nlhr));
if (nlhrReply != nullptr) {
if (nlhrReply->resultCode == 200) {
resCont = nlhrReply->pData;
nlhrReply->pData = 0;
}
-
- Netlib_FreeHttpRequest(nlhrReply);
}
delete[] httpHeaders;
diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index f6d23f1899..321ce1bd71 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -258,7 +258,7 @@ bool DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc) bool ret = false;
for (int i = 0; !ret && i < MAX_RETRIES; i++) {
Netlib_LogfW(hNetlibUser,L"Downloading file %s to %s (attempt %d)",pFileURL->tszDownloadURL,pFileURL->tszDiskPath, i+1);
- NETLIBHTTPREQUEST *pReply = Netlib_HttpTransaction(hNetlibUser, &nlhr);
+ NLHR_PTR pReply(Netlib_HttpTransaction(hNetlibUser, &nlhr));
if (pReply) {
nlc = pReply->nlc;
if ((200 == pReply->resultCode) && (pReply->dataLength > 0)) {
@@ -269,7 +269,6 @@ bool DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc) if (crc != pFileURL->CRCsum) {
// crc check failed, try again
Netlib_LogfW(hNetlibUser,L"crc check failed for file %s",pFileURL->tszDiskPath);
- Netlib_FreeHttpRequest(pReply);
continue;
}
}
@@ -296,8 +295,6 @@ bool DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc) ret = true;
}
else Netlib_LogfW(hNetlibUser,L"Downloading file %s failed with error %d",pFileURL->tszDownloadURL,pReply->resultCode);
-
- Netlib_FreeHttpRequest(pReply);
}
else {
Netlib_LogfW(hNetlibUser,L"Downloading file %s failed, host is propably temporary down.",pFileURL->tszDownloadURL);
diff --git a/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp b/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp index cff46d50a5..992979f1e5 100644 --- a/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp +++ b/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp @@ -75,7 +75,7 @@ int CSendHost_ImageShack::Send() void CSendHost_ImageShack::SendThread() { // send DATA and wait for m_nlreply - NETLIBHTTPREQUEST* reply = Netlib_HttpTransaction(g_hNetlibUser, &m_nlhr); + NLHR_PTR reply(Netlib_HttpTransaction(g_hNetlibUser, &m_nlhr)); HTTPFormDestroy(&m_nlhr); if (reply) { if (reply->resultCode >= 200 && reply->resultCode < 300 && reply->dataLength) { @@ -92,7 +92,6 @@ void CSendHost_ImageShack::SendThread() m_URLthumb.Empty(); svcSendMsgExit(url); - Netlib_FreeHttpRequest(reply); return; } @@ -107,8 +106,6 @@ void CSendHost_ImageShack::SendThread() mir_free(err); } else Error(SS_ERR_RESPONSE, m_pszSendTyp, reply->resultCode); - - Netlib_FreeHttpRequest(reply); } else Error(SS_ERR_NORESPONSE, m_pszSendTyp, m_nlhr.resultCode); diff --git a/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp b/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp index f4590cdbe5..e6344b5cf3 100644 --- a/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp +++ b/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp @@ -59,7 +59,7 @@ void CSendHost_Imgur::SendThread(void* obj) { CSendHost_Imgur *self = (CSendHost_Imgur*)obj; // send DATA and wait for m_nlreply - NETLIBHTTPREQUEST *reply = Netlib_HttpTransaction(g_hNetlibUser, &self->m_nlhr); + NLHR_PTR reply(Netlib_HttpTransaction(g_hNetlibUser, &self->m_nlhr)); self->HTTPFormDestroy(&self->m_nlhr); if (reply) { if (reply->dataLength) { @@ -72,7 +72,6 @@ void CSendHost_Imgur::SendThread(void* obj) self->m_URLthumb = self->m_URL; self->m_URLthumb.Insert(idx, 'm'); } - Netlib_FreeHttpRequest(reply); self->svcSendMsgExit(self->m_URL); return; } else self->Error(SS_ERR_RESPONSE, self->m_pszSendTyp, (*root)["status"].as_int(), 0); @@ -80,8 +79,6 @@ void CSendHost_Imgur::SendThread(void* obj) else self->Error(SS_ERR_RESPONSE, self->m_pszSendTyp, reply->resultCode); } else self->Error(SS_ERR_RESPONSE, self->m_pszSendTyp, reply->resultCode); - - Netlib_FreeHttpRequest(reply); } else self->Error(SS_ERR_NORESPONSE, self->m_pszSendTyp, self->m_nlhr.resultCode); diff --git a/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp b/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp index da0c5c2707..d750c92554 100644 --- a/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp +++ b/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp @@ -64,7 +64,7 @@ void CSendHost_UploadPie::SendThread(void* obj) { CSendHost_UploadPie* self = (CSendHost_UploadPie*)obj; // send DATA and wait for m_nlreply - NETLIBHTTPREQUEST* reply = Netlib_HttpTransaction(g_hNetlibUser, &self->m_nlhr); + NLHR_PTR reply(Netlib_HttpTransaction(g_hNetlibUser, &self->m_nlhr)); self->HTTPFormDestroy(&self->m_nlhr); if (reply) { if (reply->resultCode >= 200 && reply->resultCode < 300 && reply->dataLength) { @@ -86,7 +86,6 @@ void CSendHost_UploadPie::SendThread(void* obj) if (url) { self->m_URL = url; - Netlib_FreeHttpRequest(reply); self->svcSendMsgExit(url); return; } else { // check error mess from server @@ -99,8 +98,6 @@ void CSendHost_UploadPie::SendThread(void* obj) } } else self->Error(SS_ERR_RESPONSE, self->m_pszSendTyp, reply->resultCode); - - Netlib_FreeHttpRequest(reply); } else self->Error(SS_ERR_NORESPONSE, self->m_pszSendTyp, self->m_nlhr.resultCode); diff --git a/plugins/SmileyAdd/src/download.cpp b/plugins/SmileyAdd/src/download.cpp index 7276ac40dc..ac9cefff92 100644 --- a/plugins/SmileyAdd/src/download.cpp +++ b/plugins/SmileyAdd/src/download.cpp @@ -62,7 +62,7 @@ bool InternetDownloadFile(const char *szUrl, char *szDest, HNETLIBCONN &hHttpDwn while (result == 0xBADBAD) {
// download the page
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(hNetlibUser, &nlhr));
if (nlhrReply) {
hHttpDwnl = nlhrReply->nlc;
// if the recieved code is 200 OK
@@ -113,8 +113,6 @@ bool InternetDownloadFile(const char *szUrl, char *szDest, HNETLIBCONN &hHttpDwn hHttpDwnl = nullptr;
result = 1;
}
-
- Netlib_FreeHttpRequest(nlhrReply);
}
mir_free(szRedirUrl);
|