summaryrefslogtreecommitdiff
path: root/plugins/CloudFile/src/Services
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
parent66c4ae72a70a6e155c4a2a6d14c91c532cdb3974 (diff)
CloudFile: added support for the usual accounts system(#1144)
Diffstat (limited to 'plugins/CloudFile/src/Services')
-rw-r--r--plugins/CloudFile/src/Services/dropbox_service.cpp49
-rw-r--r--plugins/CloudFile/src/Services/dropbox_service.h9
-rw-r--r--plugins/CloudFile/src/Services/google_service.cpp55
-rw-r--r--plugins/CloudFile/src/Services/google_service.h9
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.cpp59
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.h9
-rw-r--r--plugins/CloudFile/src/Services/yandex_service.cpp55
-rw-r--r--plugins/CloudFile/src/Services/yandex_service.h9
8 files changed, 151 insertions, 103 deletions
diff --git a/plugins/CloudFile/src/Services/dropbox_service.cpp b/plugins/CloudFile/src/Services/dropbox_service.cpp
index 1eb184ed5d..72b544a232 100644
--- a/plugins/CloudFile/src/Services/dropbox_service.cpp
+++ b/plugins/CloudFile/src/Services/dropbox_service.cpp
@@ -1,20 +1,29 @@
#include "..\stdafx.h"
#include "dropbox_api.h"
-CDropboxService::CDropboxService(HNETLIBUSER hConnection)
- : CCloudService(hConnection)
+CDropboxService::CDropboxService(const char *protoName, const wchar_t *userName)
+ : CCloudService(protoName, userName)
{
- CreateServiceFunctionObj(MS_DROPBOX_UPLOAD, &CDropboxService::UploadToDropbox, this);
+ //CreateServiceFunctionObj(MS_DROPBOX_UPLOAD, &CDropboxService::UploadToDropbox, this);
}
-const char* CDropboxService::GetModule() const
+CDropboxService* CDropboxService::Init(const char *moduleName, const wchar_t *userName)
{
- return "Dropbox";
+ CDropboxService *proto = new CDropboxService(moduleName, userName);
+ Services.insert(proto);
+ return proto;
+}
+
+int CDropboxService::UnInit(CDropboxService *proto)
+{
+ Services.remove(proto);
+ delete proto;
+ return 0;
}
-const wchar_t* CDropboxService::GetText() const
+const char* CDropboxService::GetModuleName() const
{
- return LPGENW("Dropbox");
+ return "Dropbox";
}
int CDropboxService::GetIconId() const
@@ -24,7 +33,7 @@ int CDropboxService::GetIconId() const
bool CDropboxService::IsLoggedIn()
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
if (!token || token[0] == 0)
return false;
return true;
@@ -55,14 +64,14 @@ unsigned CDropboxService::RequestAccessTokenThread(void *owner, void *param)
NLHR_PTR response(request.Send(service->hConnection));
if (response == nullptr || response->resultCode != HTTP_CODE_OK) {
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError());
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError());
//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((wchar_t*)error_description, MB_ICONERROR);
return 0;
}
@@ -70,14 +79,14 @@ unsigned CDropboxService::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());
- ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, (WPARAM)ID_STATUS_ONLINE);
+ db_set_s(NULL, service->GetAccountName(), "TokenSecret", node.as_string().c_str());
+ //ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, (WPARAM)ID_STATUS_ONLINE);
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
@@ -90,7 +99,7 @@ unsigned CDropboxService::RevokeAccessTokenThread(void *param)
{
CDropboxService *service = (CDropboxService*)param;
- ptrA token(db_get_sa(NULL, service->GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, service->GetAccountName(), "TokenSecret"));
DropboxAPI::RevokeAccessTokenRequest request(token);
NLHR_PTR response(request.Send(service->hConnection));
@@ -108,7 +117,7 @@ void CDropboxService::HandleJsonError(JSONNode &node)
void CDropboxService::UploadFile(const char *data, size_t size, char *path)
{
- 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);
DropboxAPI::UploadFileRequest request(token, path, data, size, (OnConflict)strategy);
NLHR_PTR response(request.Send(hConnection));
@@ -120,7 +129,7 @@ void CDropboxService::UploadFile(const char *data, size_t size, char *path)
void CDropboxService::CreateUploadSession(const char *chunk, size_t chunkSize, char *sessionId)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
DropboxAPI::CreateUploadSessionRequest request(token, chunk, chunkSize);
NLHR_PTR response(request.Send(hConnection));
@@ -131,7 +140,7 @@ void CDropboxService::CreateUploadSession(const char *chunk, size_t chunkSize, c
void CDropboxService::UploadFileChunk(const char *chunk, size_t chunkSize, const char *sessionId, size_t offset)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
DropboxAPI::UploadFileChunkRequest request(token, sessionId, offset, chunk, chunkSize);
NLHR_PTR response(request.Send(hConnection));
@@ -140,7 +149,7 @@ void CDropboxService::UploadFileChunk(const char *chunk, size_t chunkSize, const
void CDropboxService::CommitUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, char *path)
{
- 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);
DropboxAPI::CommitUploadSessionRequest request(token, sessionId, offset, path, data, size, (OnConflict)strategy);
NLHR_PTR response(request.Send(hConnection));
@@ -152,7 +161,7 @@ void CDropboxService::CommitUploadSession(const char *data, size_t size, const c
void CDropboxService::CreateFolder(const char *path)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
DropboxAPI::CreateFolderRequest request(token, path);
NLHR_PTR response(request.Send(hConnection));
@@ -167,7 +176,7 @@ void CDropboxService::CreateFolder(const char *path)
void CDropboxService::CreateSharedLink(const char *path, char *url)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
DropboxAPI::CreateSharedLinkRequest shareRequest(token, path);
NLHR_PTR response(shareRequest.Send(hConnection));
diff --git a/plugins/CloudFile/src/Services/dropbox_service.h b/plugins/CloudFile/src/Services/dropbox_service.h
index 1f123d2d5c..d65db25034 100644
--- a/plugins/CloudFile/src/Services/dropbox_service.h
+++ b/plugins/CloudFile/src/Services/dropbox_service.h
@@ -17,10 +17,13 @@ private:
void CreateSharedLink(const char *path, char *url);
public:
- CDropboxService(HNETLIBUSER hConnection);
+ CDropboxService(const char *protoName, const wchar_t *userName);
+
+ static CDropboxService* Init(const char *szModuleName, const wchar_t *szUserName);
+ static int UnInit(CDropboxService*);
+
+ const char* GetModuleName() const override;
- const char* GetModule() const;
- const wchar_t* GetText() const;
int GetIconId() const;
bool IsLoggedIn();
diff --git a/plugins/CloudFile/src/Services/google_service.cpp b/plugins/CloudFile/src/Services/google_service.cpp
index 5c5b7703d4..a15056b884 100644
--- a/plugins/CloudFile/src/Services/google_service.cpp
+++ b/plugins/CloudFile/src/Services/google_service.cpp
@@ -1,19 +1,28 @@
#include "..\stdafx.h"
#include "google_api.h"
-CGDriveService::CGDriveService(HNETLIBUSER hConnection)
- : CCloudService(hConnection)
+CGDriveService::CGDriveService(const char *protoName, const wchar_t *userName)
+ : CCloudService(protoName, userName)
{
}
-const char* CGDriveService::GetModule() const
+CGDriveService* CGDriveService::Init(const char *moduleName, const wchar_t *userName)
{
- return "Google";
+ CGDriveService *proto = new CGDriveService(moduleName, userName);
+ Services.insert(proto);
+ return proto;
}
-const wchar_t* CGDriveService::GetText() const
+int CGDriveService::UnInit(CGDriveService *proto)
{
- return LPGENW("Google Drive");
+ Services.remove(proto);
+ delete proto;
+ return 0;
+}
+
+const char* CGDriveService::GetModuleName() const
+{
+ return "/Google";
}
int CGDriveService::GetIconId() const
@@ -23,18 +32,18 @@ int CGDriveService::GetIconId() const
bool CGDriveService::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 CGDriveService::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]) {
GDriveAPI::RefreshTokenRequest request(refreshToken);
NLHR_PTR response(request.Send(hConnection));
@@ -42,11 +51,11 @@ void CGDriveService::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;
}
@@ -79,14 +88,14 @@ unsigned CGDriveService::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;
}
@@ -94,20 +103,20 @@ unsigned CGDriveService::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, "");
@@ -120,7 +129,7 @@ unsigned CGDriveService::RevokeAccessTokenThread(void *param)
{
CGDriveService *service = (CGDriveService*)param;
- ptrA token(db_get_sa(NULL, service->GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, service->GetAccountName(), "TokenSecret"));
GDriveAPI::RevokeAccessTokenRequest request(token);
NLHR_PTR response(request.Send(service->hConnection));
@@ -138,7 +147,7 @@ void CGDriveService::HandleJsonError(JSONNode &node)
void CGDriveService::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"));
GDriveAPI::UploadFileRequest request(token, parentId, name, data, size);
NLHR_PTR response(request.Send(hConnection));
@@ -149,7 +158,7 @@ void CGDriveService::UploadFile(const char *parentId, const char *name, const ch
void CGDriveService::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"));
GDriveAPI::CreateUploadSessionRequest request(token, parentId, name);
NLHR_PTR response(request.Send(hConnection));
@@ -191,7 +200,7 @@ void CGDriveService::UploadFileChunk(const char *uploadUri, const char *chunk, s
void CGDriveService::CreateFolder(const char *path, char *folderId)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
GDriveAPI::CreateFolderRequest request(token, path);
NLHR_PTR response(request.Send(hConnection));
@@ -202,7 +211,7 @@ void CGDriveService::CreateFolder(const char *path, char *folderId)
void CGDriveService::CreateSharedLink(const char *itemId, char *url)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
GDriveAPI::GrantPermissionsRequest request(token, itemId);
NLHR_PTR response(request.Send(hConnection));
diff --git a/plugins/CloudFile/src/Services/google_service.h b/plugins/CloudFile/src/Services/google_service.h
index 878fa8f442..3fb4634c4b 100644
--- a/plugins/CloudFile/src/Services/google_service.h
+++ b/plugins/CloudFile/src/Services/google_service.h
@@ -16,10 +16,13 @@ private:
void CreateSharedLink(const char *itemId, char *url);
public:
- CGDriveService(HNETLIBUSER hConnection);
+ CGDriveService(const char *protoName, const wchar_t *userName);
+
+ static CGDriveService* Init(const char *szModuleName, const wchar_t *szUserName);
+ static int UnInit(CGDriveService*);
+
+ const char* GetModuleName() const override;
- const char* GetModule() const;
- const wchar_t* GetText() const;
int GetIconId() const;
bool IsLoggedIn();
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));
diff --git a/plugins/CloudFile/src/Services/microsoft_service.h b/plugins/CloudFile/src/Services/microsoft_service.h
index cdd9d53976..c58bb4e07c 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.h
+++ b/plugins/CloudFile/src/Services/microsoft_service.h
@@ -15,10 +15,13 @@ private:
void CreateSharedLink(const char *itemId, char *url);
public:
- COneDriveService(HNETLIBUSER hConnection);
+ COneDriveService(const char *protoName, const wchar_t *userName);
- const char* GetModule() const;
- const wchar_t* GetText() const;
+ static COneDriveService* Init(const char *szModuleName, const wchar_t *szUserName);
+ static int UnInit(COneDriveService*);
+
+ const char* GetModuleName() const override;
+
int GetIconId() const;
bool IsLoggedIn();
diff --git a/plugins/CloudFile/src/Services/yandex_service.cpp b/plugins/CloudFile/src/Services/yandex_service.cpp
index 1e4d5749cb..8a246fa59f 100644
--- a/plugins/CloudFile/src/Services/yandex_service.cpp
+++ b/plugins/CloudFile/src/Services/yandex_service.cpp
@@ -1,19 +1,28 @@
#include "..\stdafx.h"
#include "yandex_api.h"
-CYandexService::CYandexService(HNETLIBUSER hConnection)
- : CCloudService(hConnection)
+CYandexService::CYandexService(const char *protoName, const wchar_t *userName)
+ : CCloudService(protoName, userName)
{
}
-const char* CYandexService::GetModule() const
+CYandexService* CYandexService::Init(const char *moduleName, const wchar_t *userName)
{
- return "Yandex";
+ CYandexService *proto = new CYandexService(moduleName, userName);
+ Services.insert(proto);
+ return proto;
}
-const wchar_t* CYandexService::GetText() const
+int CYandexService::UnInit(CYandexService *proto)
{
- return LPGENW("Yandex.Disk");
+ Services.remove(proto);
+ delete proto;
+ return 0;
+}
+
+const char* CYandexService::GetModuleName() const
+{
+ return "Yandex.Disk";
}
int CYandexService::GetIconId() const
@@ -23,18 +32,18 @@ int CYandexService::GetIconId() const
bool CYandexService::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 CYandexService::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]) {
YandexAPI::RefreshTokenRequest request(refreshToken);
NLHR_PTR response(request.Send(hConnection));
@@ -42,14 +51,14 @@ void CYandexService::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);
node = root.at("refresh_token");
- db_set_s(NULL, GetModule(), "RefreshToken", node.as_string().c_str());
+ db_set_s(NULL, GetAccountName(), "RefreshToken", node.as_string().c_str());
return;
}
@@ -82,14 +91,14 @@ unsigned CYandexService::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;
}
@@ -97,20 +106,20 @@ unsigned CYandexService::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, "");
@@ -123,7 +132,7 @@ unsigned CYandexService::RevokeAccessTokenThread(void *param)
{
CYandexService *service = (CYandexService*)param;
- ptrA token(db_get_sa(NULL, service->GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, service->GetAccountName(), "TokenSecret"));
YandexAPI::RevokeAccessTokenRequest request(token);
NLHR_PTR response(request.Send(service->hConnection));
@@ -141,7 +150,7 @@ void CYandexService::HandleJsonError(JSONNode &node)
void CYandexService::CreateUploadSession(const char *path, 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);
YandexAPI::GetUploadUrlRequest request(token, path, (OnConflict)strategy);
NLHR_PTR response(request.Send(hConnection));
@@ -180,7 +189,7 @@ void CYandexService::UploadFileChunk(const char *uploadUri, const char *chunk, s
void CYandexService::CreateFolder(const char *path)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
YandexAPI::CreateFolderRequest request(token, path);
NLHR_PTR response(request.Send(hConnection));
@@ -189,7 +198,7 @@ void CYandexService::CreateFolder(const char *path)
void CYandexService::CreateSharedLink(const char *path, char *url)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
YandexAPI::PublishRequest publishRequest(token, path);
NLHR_PTR response(publishRequest.Send(hConnection));
diff --git a/plugins/CloudFile/src/Services/yandex_service.h b/plugins/CloudFile/src/Services/yandex_service.h
index 85c0ad12de..09c06d9a24 100644
--- a/plugins/CloudFile/src/Services/yandex_service.h
+++ b/plugins/CloudFile/src/Services/yandex_service.h
@@ -16,10 +16,13 @@ private:
void CreateSharedLink(const char *path, char *url);
public:
- CYandexService(HNETLIBUSER hConnection);
+ CYandexService(const char *protoName, const wchar_t *userName);
+
+ static CYandexService* Init(const char *szModuleName, const wchar_t *szUserName);
+ static int UnInit(CYandexService*);
+
+ const char* GetModuleName() const override;
- const char* GetModule() const;
- const wchar_t* GetText() const;
int GetIconId() const;
bool IsLoggedIn();