summaryrefslogtreecommitdiff
path: root/plugins/CloudFile
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-05-03 12:31:44 +0200
committerGeorge Hazan <ghazan@miranda.im>2018-05-03 12:32:36 +0200
commit48cb59cb5687303a608903259bb10eb9e6a9ee36 (patch)
treee7ef1bda96cac9fb9ed59ce7a29477a3d262c50e /plugins/CloudFile
parent89a1dbcab6947a68d81dd048e5d91cebdb0c2510 (diff)
CloudFile: thread functions rewritten using PROTO::ForkThread
Diffstat (limited to 'plugins/CloudFile')
-rw-r--r--plugins/CloudFile/src/Services/dropbox_service.cpp44
-rw-r--r--plugins/CloudFile/src/Services/dropbox_service.h4
-rw-r--r--plugins/CloudFile/src/Services/google_service.cpp51
-rw-r--r--plugins/CloudFile/src/Services/google_service.h4
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.cpp33
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.h2
-rw-r--r--plugins/CloudFile/src/Services/yandex_service.cpp50
-rw-r--r--plugins/CloudFile/src/Services/yandex_service.h4
-rw-r--r--plugins/CloudFile/src/oauth.cpp4
-rw-r--r--plugins/CloudFile/src/oauth.h5
-rw-r--r--plugins/CloudFile/src/version.h2
11 files changed, 90 insertions, 113 deletions
diff --git a/plugins/CloudFile/src/Services/dropbox_service.cpp b/plugins/CloudFile/src/Services/dropbox_service.cpp
index 8eadbc4e4c..e7be5f4157 100644
--- a/plugins/CloudFile/src/Services/dropbox_service.cpp
+++ b/plugins/CloudFile/src/Services/dropbox_service.cpp
@@ -41,76 +41,70 @@ bool CDropboxService::IsLoggedIn()
void CDropboxService::Login(HWND owner)
{
- COAuthDlg dlg(this, DROPBOX_API_AUTH, RequestAccessTokenThread);
+ COAuthDlg dlg(this, DROPBOX_API_AUTH, (MyThreadFunc)&CDropboxService::RequestAccessTokenThread);
dlg.SetParent(owner);
dlg.DoModal();
}
void CDropboxService::Logout()
{
- mir_forkthreadex(RevokeAccessTokenThread, this);
+ ForkThread((MyThreadFunc)&CDropboxService::RevokeAccessTokenThread);
}
-unsigned CDropboxService::RequestAccessTokenThread(void *owner, void *param)
+void CDropboxService::RequestAccessTokenThread(void *param)
{
HWND hwndDlg = (HWND)param;
- CDropboxService *service = (CDropboxService*)owner;
- if (service->IsLoggedIn())
- service->Logout();
+ if (IsLoggedIn())
+ Logout();
char requestToken[128];
GetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, requestToken, _countof(requestToken));
DropboxAPI::GetAccessTokenRequest request(requestToken);
- NLHR_PTR response(request.Send(service->m_hConnection));
+ NLHR_PTR response(request.Send(m_hConnection));
if (response == nullptr || response->resultCode != HTTP_CODE_OK) {
- Netlib_Logf(service->m_hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError());
+ Netlib_Logf(m_hConnection, "%s: %s", GetAccountName(), HttpStatusToError());
ShowNotification(TranslateT("Server does not respond"), MB_ICONERROR);
EndDialog(hwndDlg, 0);
- return 0;
+ return;
}
JSONNode root = JSONNode::parse(response->pData);
if (root.empty()) {
- Netlib_Logf(service->m_hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(m_hConnection, "%s: %s", GetAccountName(), HttpStatusToError(response->resultCode));
ShowNotification(TranslateT("Server does not respond"), MB_ICONERROR);
EndDialog(hwndDlg, 0);
- return 0;
+ return;
}
JSONNode node = root.at("error_description");
if (!node.isnull()) {
CMStringW error_description = node.as_mstring();
- Netlib_Logf(service->m_hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(m_hConnection, "%s: %s", GetAccountName(), HttpStatusToError(response->resultCode));
ShowNotification(error_description, MB_ICONERROR);
EndDialog(hwndDlg, 0);
- return 0;
+ return;
}
node = root.at("access_token");
- db_set_s(NULL, service->GetAccountName(), "TokenSecret", node.as_string().c_str());
+ db_set_s(NULL, GetAccountName(), "TokenSecret", node.as_string().c_str());
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
EndDialog(hwndDlg, 1);
- return 0;
}
-unsigned CDropboxService::RevokeAccessTokenThread(void *param)
+void CDropboxService::RevokeAccessTokenThread(void *)
{
- CDropboxService *service = (CDropboxService*)param;
-
- ptrA token(service->getStringA("TokenSecret"));
+ ptrA token(getStringA("TokenSecret"));
DropboxAPI::RevokeAccessTokenRequest request(token);
- NLHR_PTR response(request.Send(service->m_hConnection));
-
- service->delSetting("ExpiresIn");
- service->delSetting("TokenSecret");
- service->delSetting("RefreshToken");
+ NLHR_PTR response(request.Send(m_hConnection));
- return 0;
+ delSetting("ExpiresIn");
+ delSetting("TokenSecret");
+ delSetting("RefreshToken");
}
void CDropboxService::HandleJsonError(JSONNode &node)
diff --git a/plugins/CloudFile/src/Services/dropbox_service.h b/plugins/CloudFile/src/Services/dropbox_service.h
index 793a27d52b..b6c5a7dfcd 100644
--- a/plugins/CloudFile/src/Services/dropbox_service.h
+++ b/plugins/CloudFile/src/Services/dropbox_service.h
@@ -4,8 +4,8 @@
class CDropboxService : public CCloudService
{
private:
- static unsigned RequestAccessTokenThread(void *owner, void *param);
- static unsigned __stdcall RevokeAccessTokenThread(void *param);
+ void __cdecl RequestAccessTokenThread(void *);
+ void __cdecl RevokeAccessTokenThread(void *);
void HandleJsonError(JSONNode &node) override;
diff --git a/plugins/CloudFile/src/Services/google_service.cpp b/plugins/CloudFile/src/Services/google_service.cpp
index c9fbb45c1c..cd1d252c11 100644
--- a/plugins/CloudFile/src/Services/google_service.cpp
+++ b/plugins/CloudFile/src/Services/google_service.cpp
@@ -61,88 +61,81 @@ void CGDriveService::Login(HWND owner)
return;
}
- COAuthDlg dlg(this, GOOGLE_AUTH, RequestAccessTokenThread);
+ COAuthDlg dlg(this, GOOGLE_AUTH, (MyThreadFunc)&CGDriveService::RequestAccessTokenThread);
dlg.SetParent(owner);
dlg.DoModal();
}
void CGDriveService::Logout()
{
- mir_forkthreadex(RevokeAccessTokenThread, this);
+ ForkThread((MyThreadFunc)&CGDriveService::RevokeAccessTokenThread);
}
-unsigned CGDriveService::RequestAccessTokenThread(void *owner, void *param)
+void CGDriveService::RequestAccessTokenThread(void *param)
{
HWND hwndDlg = (HWND)param;
- CGDriveService *service = (CGDriveService*)owner;
- if (service->IsLoggedIn())
- service->Logout();
+ if (IsLoggedIn())
+ Logout();
char requestToken[128];
GetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, requestToken, _countof(requestToken));
GDriveAPI::GetAccessTokenRequest request(requestToken);
- NLHR_PTR response(request.Send(service->m_hConnection));
+ NLHR_PTR response(request.Send(m_hConnection));
if (response == nullptr || response->resultCode != HTTP_CODE_OK) {
const char *error = response && response->dataLength
? response->pData
- : service->HttpStatusToError(response ? response->resultCode : 0);
+ : HttpStatusToError(response ? response->resultCode : 0);
- Netlib_Logf(service->m_hConnection, "%s: %s", service->GetAccountName(), error);
+ Netlib_Logf(m_hConnection, "%s: %s", GetAccountName(), error);
ShowNotification(TranslateT("Server does not respond"), MB_ICONERROR);
EndDialog(hwndDlg, 0);
- return 0;
+ return;
}
JSONNode root = JSONNode::parse(response->pData);
if (root.empty()) {
- Netlib_Logf(service->m_hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(m_hConnection, "%s: %s", GetAccountName(), HttpStatusToError(response->resultCode));
ShowNotification(TranslateT("Server does not respond"), MB_ICONERROR);
EndDialog(hwndDlg, 0);
- return 0;
+ return;
}
JSONNode node = root.at("error_description");
if (!node.isnull()) {
CMStringW error_description = node.as_mstring();
- Netlib_Logf(service->m_hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(m_hConnection, "%s: %s", GetAccountName(), HttpStatusToError(response->resultCode));
ShowNotification(error_description, MB_ICONERROR);
EndDialog(hwndDlg, 0);
- return 0;
+ return;
}
node = root.at("access_token");
- db_set_s(NULL, service->GetAccountName(), "TokenSecret", node.as_string().c_str());
+ db_set_s(NULL, GetAccountName(), "TokenSecret", node.as_string().c_str());
node = root.at("expires_in");
time_t expiresIn = time(nullptr) + node.as_int();
- db_set_dw(NULL, service->GetAccountName(), "ExpiresIn", expiresIn);
+ db_set_dw(NULL, GetAccountName(), "ExpiresIn", expiresIn);
node = root.at("refresh_token");
- db_set_s(NULL, service->GetAccountName(), "RefreshToken", node.as_string().c_str());
+ db_set_s(NULL, GetAccountName(), "RefreshToken", node.as_string().c_str());
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
EndDialog(hwndDlg, 1);
-
- return 0;
}
-unsigned CGDriveService::RevokeAccessTokenThread(void *param)
+void CGDriveService::RevokeAccessTokenThread(void*)
{
- CGDriveService *service = (CGDriveService*)param;
-
- ptrA token(db_get_sa(NULL, service->GetAccountName(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
GDriveAPI::RevokeAccessTokenRequest request(token);
- NLHR_PTR response(request.Send(service->m_hConnection));
-
- service->delSetting("ExpiresIn");
- service->delSetting("TokenSecret");
- service->delSetting("RefreshToken");
+ NLHR_PTR response(request.Send(m_hConnection));
- return 0;
+ delSetting("ExpiresIn");
+ delSetting("TokenSecret");
+ delSetting("RefreshToken");
}
void CGDriveService::HandleJsonError(JSONNode &node)
diff --git a/plugins/CloudFile/src/Services/google_service.h b/plugins/CloudFile/src/Services/google_service.h
index 35d5f528fb..919babb86f 100644
--- a/plugins/CloudFile/src/Services/google_service.h
+++ b/plugins/CloudFile/src/Services/google_service.h
@@ -4,8 +4,8 @@
class CGDriveService : public CCloudService
{
private:
- static unsigned RequestAccessTokenThread(void *owner, void *param);
- static unsigned __stdcall RevokeAccessTokenThread(void *param);
+ void __cdecl RequestAccessTokenThread(void *param);
+ void __cdecl RevokeAccessTokenThread(void *param);
void HandleJsonError(JSONNode &node) override;
diff --git a/plugins/CloudFile/src/Services/microsoft_service.cpp b/plugins/CloudFile/src/Services/microsoft_service.cpp
index 2843e66d0f..2a3f3c19b4 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.cpp
+++ b/plugins/CloudFile/src/Services/microsoft_service.cpp
@@ -60,7 +60,7 @@ void COneDriveService::Login(HWND owner)
return;
}
- COAuthDlg dlg(this, MICROSOFT_AUTH, RequestAccessTokenThread);
+ COAuthDlg dlg(this, MICROSOFT_AUTH, (MyThreadFunc)&COneDriveService::RequestAccessTokenThread);
dlg.SetParent(owner);
dlg.DoModal();
}
@@ -72,63 +72,60 @@ void COneDriveService::Logout()
delSetting("RefreshToken");
}
-unsigned COneDriveService::RequestAccessTokenThread(void *owner, void *param)
+void COneDriveService::RequestAccessTokenThread(void *param)
{
HWND hwndDlg = (HWND)param;
- COneDriveService *service = (COneDriveService*)owner;
- if (service->IsLoggedIn())
- service->Logout();
+ if (IsLoggedIn())
+ Logout();
char requestToken[128];
GetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, requestToken, _countof(requestToken));
OneDriveAPI::GetAccessTokenRequest request(requestToken);
- NLHR_PTR response(request.Send(service->m_hConnection));
+ NLHR_PTR response(request.Send(m_hConnection));
if (response == nullptr || response->resultCode != HTTP_CODE_OK) {
const char *error = response->dataLength
? response->pData
- : service->HttpStatusToError(response->resultCode);
+ : HttpStatusToError(response->resultCode);
- Netlib_Logf(service->m_hConnection, "%s: %s", service->GetAccountName(), error);
+ Netlib_Logf(m_hConnection, "%s: %s", GetAccountName(), error);
ShowNotification(TranslateT("Server does not respond"), MB_ICONERROR);
EndDialog(hwndDlg, 0);
- return 0;
+ return;
}
JSONNode root = JSONNode::parse(response->pData);
if (root.empty()) {
- Netlib_Logf(service->m_hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(m_hConnection, "%s: %s", GetAccountName(), HttpStatusToError(response->resultCode));
ShowNotification(TranslateT("Server does not respond"), MB_ICONERROR);
EndDialog(hwndDlg, 0);
- return 0;
+ return;
}
JSONNode node = root.at("error_description");
if (!node.isnull()) {
CMStringW error_description = node.as_mstring();
- Netlib_Logf(service->m_hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(m_hConnection, "%s: %s", GetAccountName(), HttpStatusToError(response->resultCode));
ShowNotification(error_description, MB_ICONERROR);
EndDialog(hwndDlg, 0);
- return 0;
+ return;
}
node = root.at("access_token");
- service->setString("TokenSecret", node.as_string().c_str());
+ setString("TokenSecret", node.as_string().c_str());
node = root.at("expires_in");
time_t expiresIn = time(nullptr) + node.as_int();
- service->setDword("ExpiresIn", expiresIn);
+ setDword("ExpiresIn", expiresIn);
node = root.at("refresh_token");
- service->setString("RefreshToken", node.as_string().c_str());
+ setString("RefreshToken", node.as_string().c_str());
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
EndDialog(hwndDlg, 1);
-
- return 0;
}
void COneDriveService::HandleJsonError(JSONNode &node)
diff --git a/plugins/CloudFile/src/Services/microsoft_service.h b/plugins/CloudFile/src/Services/microsoft_service.h
index 895e39ed45..d993410003 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.h
+++ b/plugins/CloudFile/src/Services/microsoft_service.h
@@ -4,7 +4,7 @@
class COneDriveService : public CCloudService
{
private:
- static unsigned RequestAccessTokenThread(void *owner, void *param);
+ void __cdecl RequestAccessTokenThread(void *param);
void HandleJsonError(JSONNode &node) override;
diff --git a/plugins/CloudFile/src/Services/yandex_service.cpp b/plugins/CloudFile/src/Services/yandex_service.cpp
index f1082a6899..acc9fb0315 100644
--- a/plugins/CloudFile/src/Services/yandex_service.cpp
+++ b/plugins/CloudFile/src/Services/yandex_service.cpp
@@ -64,87 +64,81 @@ void CYandexService::Login(HWND owner)
return;
}
- COAuthDlg dlg(this, YANDEX_AUTH, RequestAccessTokenThread);
+ COAuthDlg dlg(this, YANDEX_AUTH, (MyThreadFunc)&CYandexService::RequestAccessTokenThread);
dlg.SetParent(owner);
dlg.DoModal();
}
void CYandexService::Logout()
{
- mir_forkthreadex(RevokeAccessTokenThread, this);
+ ForkThread((MyThreadFunc)&CYandexService::RevokeAccessTokenThread);
}
-unsigned CYandexService::RequestAccessTokenThread(void *owner, void *param)
+void CYandexService::RequestAccessTokenThread(void *param)
{
HWND hwndDlg = (HWND)param;
- CYandexService *service = (CYandexService*)owner;
- if (service->IsLoggedIn())
- service->Logout();
+ if (IsLoggedIn())
+ Logout();
char requestToken[128];
GetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, requestToken, _countof(requestToken));
YandexAPI::GetAccessTokenRequest request(requestToken);
- NLHR_PTR response(request.Send(service->m_hConnection));
+ NLHR_PTR response(request.Send(m_hConnection));
if (response == nullptr || response->resultCode != HTTP_CODE_OK) {
const char *error = response->dataLength
? response->pData
- : service->HttpStatusToError(response->resultCode);
+ : HttpStatusToError(response->resultCode);
- Netlib_Logf(service->m_hConnection, "%s: %s", service->GetAccountName(), error);
+ Netlib_Logf(m_hConnection, "%s: %s", GetAccountName(), error);
ShowNotification(TranslateT("Server does not respond"), MB_ICONERROR);
EndDialog(hwndDlg, 0);
- return 0;
+ return;
}
JSONNode root = JSONNode::parse(response->pData);
if (root.empty()) {
- Netlib_Logf(service->m_hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(m_hConnection, "%s: %s", GetAccountName(), HttpStatusToError(response->resultCode));
ShowNotification(TranslateT("Server does not respond"), MB_ICONERROR);
EndDialog(hwndDlg, 0);
- return 0;
+ return;
}
JSONNode node = root.at("error_description");
if (!node.isnull()) {
CMStringW error_description = node.as_mstring();
- Netlib_Logf(service->m_hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(m_hConnection, "%s: %s", GetAccountName(), HttpStatusToError(response->resultCode));
ShowNotification(error_description, MB_ICONERROR);
EndDialog(hwndDlg, 0);
- return 0;
+ return;
}
node = root.at("access_token");
- service->setString("TokenSecret", node.as_string().c_str());
+ setString("TokenSecret", node.as_string().c_str());
node = root.at("expires_in");
time_t expiresIn = time(nullptr) + node.as_int();
- service->setDword("ExpiresIn", expiresIn);
+ setDword("ExpiresIn", expiresIn);
node = root.at("refresh_token");
- service->setString("RefreshToken", node.as_string().c_str());
+ setString("RefreshToken", node.as_string().c_str());
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
EndDialog(hwndDlg, 1);
- return 0;
}
-unsigned CYandexService::RevokeAccessTokenThread(void *param)
+void CYandexService::RevokeAccessTokenThread(void*)
{
- CYandexService *service = (CYandexService*)param;
-
- ptrA token(db_get_sa(NULL, service->GetAccountName(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
YandexAPI::RevokeAccessTokenRequest request(token);
- NLHR_PTR response(request.Send(service->m_hConnection));
-
- service->delSetting("ExpiresIn");
- service->delSetting("TokenSecret");
- service->delSetting("RefreshToken");
+ NLHR_PTR response(request.Send(m_hConnection));
- return 0;
+ delSetting("ExpiresIn");
+ delSetting("TokenSecret");
+ delSetting("RefreshToken");
}
void CYandexService::HandleJsonError(JSONNode &node)
diff --git a/plugins/CloudFile/src/Services/yandex_service.h b/plugins/CloudFile/src/Services/yandex_service.h
index d384ad0a53..0fdcdf679a 100644
--- a/plugins/CloudFile/src/Services/yandex_service.h
+++ b/plugins/CloudFile/src/Services/yandex_service.h
@@ -4,8 +4,8 @@
class CYandexService : public CCloudService
{
private:
- static unsigned RequestAccessTokenThread(void *owner, void *param);
- static unsigned __stdcall RevokeAccessTokenThread(void *param);
+ void __cdecl RequestAccessTokenThread(void *param);
+ void __cdecl RevokeAccessTokenThread(void *param);
void HandleJsonError(JSONNode &node) override;
diff --git a/plugins/CloudFile/src/oauth.cpp b/plugins/CloudFile/src/oauth.cpp
index cad2bd8651..9516ef4139 100644
--- a/plugins/CloudFile/src/oauth.cpp
+++ b/plugins/CloudFile/src/oauth.cpp
@@ -1,6 +1,6 @@
#include "stdafx.h"
-COAuthDlg::COAuthDlg(CCloudService *service, const char *authUrl, pThreadFuncOwner requestAccessTokenThread)
+COAuthDlg::COAuthDlg(CCloudService *service, const char *authUrl, CCloudService::MyThreadFunc requestAccessTokenThread)
: CDlgBase(g_plugin.getInst(), IDD_OAUTH), m_service(service),
m_requestAccessTokenThread(requestAccessTokenThread),
m_authorize(this, IDC_OAUTH_AUTHORIZE, authUrl),
@@ -28,5 +28,5 @@ void COAuthDlg::Code_OnChange(CCtrlBase*)
void COAuthDlg::Ok_OnClick(CCtrlButton*)
{
- mir_forkthreadowner(m_requestAccessTokenThread, m_service, m_hwnd);
+ m_service->ForkThread(m_requestAccessTokenThread, m_hwnd);
} \ No newline at end of file
diff --git a/plugins/CloudFile/src/oauth.h b/plugins/CloudFile/src/oauth.h
index 5107047749..7c71cf005c 100644
--- a/plugins/CloudFile/src/oauth.h
+++ b/plugins/CloudFile/src/oauth.h
@@ -3,9 +3,8 @@
class COAuthDlg : public CDlgBase
{
-private:
CCloudService *m_service;
- pThreadFuncOwner m_requestAccessTokenThread;
+ CCloudService::MyThreadFunc m_requestAccessTokenThread;
CCtrlHyperlink m_authorize;
CCtrlEdit m_code;
@@ -18,7 +17,7 @@ protected:
void Ok_OnClick(CCtrlButton*);
public:
- COAuthDlg(CCloudService *service, const char *authUrl, pThreadFuncOwner requestAccessTokenThread);
+ COAuthDlg(CCloudService *service, const char *authUrl, CCloudService::MyThreadFunc requestAccessTokenThread);
};
#endif //_OAUTH_H_ \ No newline at end of file
diff --git a/plugins/CloudFile/src/version.h b/plugins/CloudFile/src/version.h
index 28e640d870..ee97e77eac 100644
--- a/plugins/CloudFile/src/version.h
+++ b/plugins/CloudFile/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 0
-#define __BUILD_NUM 5
+#define __BUILD_NUM 6
#include <stdver.h>