summaryrefslogtreecommitdiff
path: root/plugins/CloudFile/src/Services/microsoft_service.cpp
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2018-02-19 00:00:03 +0300
committeraunsane <aunsane@gmail.com>2018-02-19 00:00:20 +0300
commit46e398c0d295f3d33fe4c0450c36e1fc45a95616 (patch)
tree727617421cce4e6cc7f0863b4c4fcf367e135a10 /plugins/CloudFile/src/Services/microsoft_service.cpp
parent66c4ae72a70a6e155c4a2a6d14c91c532cdb3974 (diff)
CloudFile: added support for the usual accounts system(#1144)
Diffstat (limited to 'plugins/CloudFile/src/Services/microsoft_service.cpp')
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.cpp59
1 files changed, 34 insertions, 25 deletions
diff --git a/plugins/CloudFile/src/Services/microsoft_service.cpp b/plugins/CloudFile/src/Services/microsoft_service.cpp
index 38519e6d55..3b2f52a073 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.cpp
+++ b/plugins/CloudFile/src/Services/microsoft_service.cpp
@@ -1,19 +1,28 @@
#include "..\stdafx.h"
#include "microsoft_api.h"
-COneDriveService::COneDriveService(HNETLIBUSER hConnection)
- : CCloudService(hConnection)
+COneDriveService::COneDriveService(const char *protoName, const wchar_t *userName)
+ : CCloudService(protoName, userName)
{
}
-const char* COneDriveService::GetModule() const
+COneDriveService* COneDriveService::Init(const char *moduleName, const wchar_t *userName)
{
- return "Microsoft";
+ COneDriveService *proto = new COneDriveService(moduleName, userName);
+ Services.insert(proto);
+ return proto;
}
-const wchar_t* COneDriveService::GetText() const
+int COneDriveService::UnInit(COneDriveService *proto)
{
- return LPGENW("OneDrive");
+ Services.remove(proto);
+ delete proto;
+ return 0;
+}
+
+const char* COneDriveService::GetModuleName() const
+{
+ return "/OneDrive";
}
int COneDriveService::GetIconId() const
@@ -23,18 +32,18 @@ int COneDriveService::GetIconId() const
bool COneDriveService::IsLoggedIn()
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
if (!token || token[0] == 0)
return false;
time_t now = time(nullptr);
- time_t expiresIn = db_get_dw(NULL, GetModule(), "ExpiresIn");
+ time_t expiresIn = db_get_dw(NULL, GetAccountName(), "ExpiresIn");
return now < expiresIn;
}
void COneDriveService::Login()
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
- ptrA refreshToken(db_get_sa(NULL, GetModule(), "RefreshToken"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA refreshToken(db_get_sa(NULL, GetAccountName(), "RefreshToken"));
if (token && refreshToken && refreshToken[0]) {
OneDriveAPI::RefreshTokenRequest request(refreshToken);
NLHR_PTR response(request.Send(hConnection));
@@ -42,11 +51,11 @@ void COneDriveService::Login()
JSONNode root = GetJsonResponse(response);
JSONNode node = root.at("access_token");
- db_set_s(NULL, GetModule(), "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, GetModule(), "ExpiresIn", expiresIn);
+ db_set_dw(NULL, GetAccountName(), "ExpiresIn", expiresIn);
return;
}
@@ -57,9 +66,9 @@ void COneDriveService::Login()
void COneDriveService::Logout()
{
- db_unset(NULL, GetModule(), "TokenSecret");
- db_unset(NULL, GetModule(), "ExpiresIn");
- db_unset(NULL, GetModule(), "RefreshToken");
+ db_unset(NULL, GetAccountName(), "TokenSecret");
+ db_unset(NULL, GetAccountName(), "ExpiresIn");
+ db_unset(NULL, GetAccountName(), "RefreshToken");
}
unsigned COneDriveService::RequestAccessTokenThread(void *owner, void *param)
@@ -81,14 +90,14 @@ unsigned COneDriveService::RequestAccessTokenThread(void *owner, void *param)
? response->pData
: service->HttpStatusToError(response->resultCode);
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), error);
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), error);
//ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);
return 0;
}
JSONNode root = JSONNode::parse(response->pData);
if (root.empty()) {
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
//ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);
return 0;
}
@@ -96,20 +105,20 @@ unsigned COneDriveService::RequestAccessTokenThread(void *owner, void *param)
JSONNode node = root.at("error_description");
if (!node.isnull()) {
ptrW error_description(mir_a2u_cp(node.as_string().c_str(), CP_UTF8));
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
//ShowNotification((wchar_t*)error_description, MB_ICONERROR);
return 0;
}
node = root.at("access_token");
- db_set_s(NULL, service->GetModule(), "TokenSecret", node.as_string().c_str());
+ db_set_s(NULL, service->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->GetModule(), "ExpiresIn", expiresIn);
+ db_set_dw(NULL, service->GetAccountName(), "ExpiresIn", expiresIn);
node = root.at("refresh_token");
- db_set_s(NULL, service->GetModule(), "RefreshToken", node.as_string().c_str());
+ db_set_s(NULL, service->GetAccountName(), "RefreshToken", node.as_string().c_str());
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
@@ -129,7 +138,7 @@ void COneDriveService::HandleJsonError(JSONNode &node)
void COneDriveService::UploadFile(const char *parentId, const char *name, const char *data, size_t size, char *fileId)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
OneDriveAPI::UploadFileRequest *request = mir_strlen(parentId)
? new OneDriveAPI::UploadFileRequest(token, parentId, name, data, size, (OnConflict)strategy)
@@ -144,7 +153,7 @@ void COneDriveService::UploadFile(const char *parentId, const char *name, const
void COneDriveService::CreateUploadSession(const char *parentId, const char *name, char *uploadUri)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
OneDriveAPI::CreateUploadSessionRequest *request = mir_strlen(parentId)
? new OneDriveAPI::CreateUploadSessionRequest(token, parentId, name, (OnConflict)strategy)
@@ -179,7 +188,7 @@ void COneDriveService::UploadFileChunk(const char *uploadUri, const char *chunk,
void COneDriveService::CreateFolder(const char *path, char *folderId)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
OneDriveAPI::CreateFolderRequest request(token, path);
NLHR_PTR response(request.Send(hConnection));
@@ -190,7 +199,7 @@ void COneDriveService::CreateFolder(const char *path, char *folderId)
void COneDriveService::CreateSharedLink(const char *itemId, char *url)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
OneDriveAPI::CreateSharedLinkRequest request(token, itemId);
NLHR_PTR response(request.Send(hConnection));