summaryrefslogtreecommitdiff
path: root/protocols/Twitter/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/Twitter/src
parente688d75e8db7616d7e6d6fb3ed3c892e4fbe8a97 (diff)
code cleaning
Diffstat (limited to 'protocols/Twitter/src')
-rw-r--r--protocols/Twitter/src/connection.cpp11
-rw-r--r--protocols/Twitter/src/utility.cpp29
-rw-r--r--protocols/Twitter/src/utility.h2
3 files changed, 9 insertions, 33 deletions
diff --git a/protocols/Twitter/src/connection.cpp b/protocols/Twitter/src/connection.cpp
index 3cf4673d27..438572eb7e 100644
--- a/protocols/Twitter/src/connection.cpp
+++ b/protocols/Twitter/src/connection.cpp
@@ -164,7 +164,9 @@ void CTwitterProto::UpdateAvatarWorker(void *p)
return;
CMStringA ext = data->url.Mid(data->url.ReverseFind('.')); // finds the filetype of the avatar
- CMStringW filename(FORMAT, L"%s\\%S%S", GetAvatarFolder().c_str(), username.c_str(), ext.c_str()); // local filename and path
+
+ MFilePath filename; // local filename and path
+ filename.Format(L"%s\\%S%S", GetAvatarFolder().c_str(), username.c_str(), ext.c_str());
PROTO_AVATAR_INFORMATION ai = { 0 };
ai.hContact = data->hContact;
@@ -185,7 +187,12 @@ void CTwitterProto::UpdateAvatarWorker(void *p)
return;
}
- if (save_url(hAvatarNetlib_, data->url, filename)) {
+ MHttpRequest req(REQUEST_GET);
+ req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT;
+ req.m_szUrl = data->url;
+
+ NLHR_PTR resp(Netlib_DownloadFile(hAvatarNetlib_, &req, filename));
+ if (resp && resp->resultCode == 200) {
setString(data->hContact, TWITTER_KEY_AV_URL, data->url.c_str());
ProtoBroadcastAck(data->hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &ai);
}
diff --git a/protocols/Twitter/src/utility.cpp b/protocols/Twitter/src/utility.cpp
index c46c146390..09e764f5f6 100644
--- a/protocols/Twitter/src/utility.cpp
+++ b/protocols/Twitter/src/utility.cpp
@@ -66,32 +66,3 @@ void CTwitterProto::ShowPopup(const char *text, int Error)
}
PUAddPopupW(&popup);
}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-bool save_url(HNETLIBUSER hNetlib, const CMStringA &url, const CMStringW &filename)
-{
- MHttpRequest req(REQUEST_GET);
- req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT;
- req.m_szUrl = const_cast<char*>(url.c_str());
-
- NLHR_PTR resp(Netlib_HttpTransaction(hNetlib, &req));
- if (!resp)
- return false;
-
- if (resp->resultCode != 200)
- return false;
-
- // Create folder if necessary
- if (CreatePathToFileW(filename) != ERROR_SUCCESS)
- return false;
-
- // Write to file
- if (FILE *f = _wfopen(filename, L"wb")) {
- fwrite(resp->body, 1, resp->body.GetLength(), f);
- fclose(f);
- }
- else return false;
-
- return true;
-}
diff --git a/protocols/Twitter/src/utility.h b/protocols/Twitter/src/utility.h
index 3a7e32a0e1..aa53df8dc0 100644
--- a/protocols/Twitter/src/utility.h
+++ b/protocols/Twitter/src/utility.h
@@ -24,5 +24,3 @@ StringPairs ParseQueryString(const CMStringA &queryString);
void Split(const CMStringA &str, OBJLIST<CMStringA> &out, char sep, bool includeEmpty = false);
void htmlEntitiesDecode(CMStringA &context);
-
-bool save_url(HNETLIBUSER hNetlib,const CMStringA &url,const CMStringW &filename);