summaryrefslogtreecommitdiff
path: root/plugins/CloudFile/src/Services/google_service.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/CloudFile/src/Services/google_service.cpp')
-rw-r--r--plugins/CloudFile/src/Services/google_service.cpp51
1 files changed, 22 insertions, 29 deletions
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)