summaryrefslogtreecommitdiff
path: root/plugins/CloudFile
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2018-03-11 21:29:25 +0300
committeraunsane <aunsane@gmail.com>2018-03-11 21:30:54 +0300
commit5532fd4e1374c15c13e203a89b7cd060c7e15499 (patch)
treec96b03c78f6c9be6dd365e8c83f30090c58e6e22 /plugins/CloudFile
parent30b4b861bc47eab24d3236879d50791871d5c90a (diff)
CloudFile should create Miranda NG folder instead of placing files into Yandex Disk root (fixed #1184)
Diffstat (limited to 'plugins/CloudFile')
-rw-r--r--plugins/CloudFile/src/Services/dropbox_service.cpp95
-rw-r--r--plugins/CloudFile/src/Services/dropbox_service.h12
-rw-r--r--plugins/CloudFile/src/Services/google_api.h2
-rw-r--r--plugins/CloudFile/src/Services/google_service.cpp100
-rw-r--r--plugins/CloudFile/src/Services/google_service.h10
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.cpp110
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.h10
-rw-r--r--plugins/CloudFile/src/Services/yandex_api.h8
-rw-r--r--plugins/CloudFile/src/Services/yandex_service.cpp85
-rw-r--r--plugins/CloudFile/src/Services/yandex_service.h10
-rw-r--r--plugins/CloudFile/src/cloud_file.cpp27
-rw-r--r--plugins/CloudFile/src/cloud_file.h2
-rw-r--r--plugins/CloudFile/src/file_transfer.h16
-rw-r--r--plugins/CloudFile/src/stdafx.h1
-rw-r--r--plugins/CloudFile/src/transfers.cpp12
15 files changed, 225 insertions, 275 deletions
diff --git a/plugins/CloudFile/src/Services/dropbox_service.cpp b/plugins/CloudFile/src/Services/dropbox_service.cpp
index a18ba4f32c..dfbdc0f799 100644
--- a/plugins/CloudFile/src/Services/dropbox_service.cpp
+++ b/plugins/CloudFile/src/Services/dropbox_service.cpp
@@ -33,7 +33,7 @@ int CDropboxService::GetIconId() const
bool CDropboxService::IsLoggedIn()
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA token(getStringA("TokenSecret"));
if (!token || token[0] == 0)
return false;
return true;
@@ -98,7 +98,7 @@ unsigned CDropboxService::RevokeAccessTokenThread(void *param)
{
CDropboxService *service = (CDropboxService*)param;
- ptrA token(db_get_sa(NULL, service->GetAccountName(), "TokenSecret"));
+ ptrA token(service->getStringA("TokenSecret"));
DropboxAPI::RevokeAccessTokenRequest request(token);
NLHR_PTR response(request.Send(service->m_hConnection));
@@ -114,53 +114,50 @@ void CDropboxService::HandleJsonError(JSONNode &node)
}
}
-void CDropboxService::UploadFile(const char *data, size_t size, CMStringA &path)
+auto CDropboxService::UploadFile(const char *data, size_t size, const std::string &path)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA token(getStringA("TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
- DropboxAPI::UploadFileRequest request(token, path, data, size, (OnConflict)strategy);
+ DropboxAPI::UploadFileRequest request(token, path.c_str(), data, size, (OnConflict)strategy);
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- if (root)
- path = root["path_lower"].as_string().c_str();
+ return root["path_lower"].as_string();
}
-void CDropboxService::CreateUploadSession(const char *chunk, size_t chunkSize, CMStringA &sessionId)
+auto CDropboxService::CreateUploadSession(const char *chunk, size_t chunkSize)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA token(getStringA("TokenSecret"));
DropboxAPI::CreateUploadSessionRequest request(token, chunk, chunkSize);
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- if (root)
- sessionId = root["session_id"].as_string().c_str();
+ return root["session_id"].as_string();
}
-void CDropboxService::UploadFileChunk(const char *chunk, size_t chunkSize, const char *sessionId, size_t offset)
+void CDropboxService::UploadFileChunk(const std::string &sessionId, const char *chunk, size_t chunkSize, size_t offset)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- DropboxAPI::UploadFileChunkRequest request(token, sessionId, offset, chunk, chunkSize);
+ ptrA token(getStringA("TokenSecret"));
+ DropboxAPI::UploadFileChunkRequest request(token, sessionId.c_str(), offset, chunk, chunkSize);
NLHR_PTR response(request.Send(m_hConnection));
HandleHttpError(response);
}
-void CDropboxService::CommitUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, CMStringA &path)
+auto CDropboxService::CommitUploadSession(const std::string &sessionId, const char *data, size_t size, size_t offset, const std::string &path)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA token(getStringA("TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
- DropboxAPI::CommitUploadSessionRequest request(token, sessionId, offset, path, data, size, (OnConflict)strategy);
+ DropboxAPI::CommitUploadSessionRequest request(token, sessionId.c_str(), offset, path.c_str(), data, size, (OnConflict)strategy);
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- if (root)
- path = root["path_lower"].as_string().c_str();
+ return root["path_lower"].as_string();
}
-void CDropboxService::CreateFolder(const char *path)
+void CDropboxService::CreateFolder(const std::string &path)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- DropboxAPI::CreateFolderRequest request(token, path);
+ ptrA token(getStringA("TokenSecret"));
+ DropboxAPI::CreateFolderRequest request(token, path.c_str());
NLHR_PTR response(request.Send(m_hConnection));
HandleHttpError(response);
@@ -172,10 +169,10 @@ void CDropboxService::CreateFolder(const char *path)
GetJsonResponse(response);
}
-void CDropboxService::CreateSharedLink(const char *path, CMStringA &url)
+auto CDropboxService::CreateSharedLink(const std::string &path)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- DropboxAPI::CreateSharedLinkRequest shareRequest(token, path);
+ ptrA token(getStringA("TokenSecret"));
+ DropboxAPI::CreateSharedLinkRequest shareRequest(token, path.c_str());
NLHR_PTR response(shareRequest.Send(m_hConnection));
if (response == nullptr)
@@ -195,22 +192,21 @@ void CDropboxService::CreateSharedLink(const char *path, CMStringA &url)
JSONNode error = root.at("error");
if (error.isnull()) {
JSONNode link = root.at("url");
- url = link.as_string().c_str();
- return;
+ return link.as_string();
}
json_string tag = error.at(".tag").as_string();
if (tag != "shared_link_already_exists")
throw Exception(tag.c_str());
- DropboxAPI::GetSharedLinkRequest getRequest(token, path);
+ DropboxAPI::GetSharedLinkRequest getRequest(token, path.c_str());
response = getRequest.Send(m_hConnection);
root = GetJsonResponse(response);
JSONNode links = root.at("links").as_array();
JSONNode link = links[(size_t)0].at("url");
- url = link.as_string().c_str();
+ return link.as_string();
}
UINT CDropboxService::Upload(FileTransferParam *ftp)
@@ -222,14 +218,11 @@ UINT CDropboxService::Upload(FileTransferParam *ftp)
if (ftp->IsFolder()) {
T2Utf folderName(ftp->GetFolderName());
- CMStringA path;
- PreparePath(folderName, path);
+ auto path = PreparePath(folderName);
CreateFolder(path);
- CMStringA link;
- CreateSharedLink(path, link);
- ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
- ftp->AddSharedLink(link);
+ auto link = CreateSharedLink(path);
+ ftp->AddSharedLink(link.c_str());
}
ftp->FirstFile();
@@ -241,31 +234,29 @@ UINT CDropboxService::Upload(FileTransferParam *ftp)
size_t chunkSize = ftp->GetCurrentFileChunkSize();
mir_ptr<char>chunk((char*)mir_calloc(chunkSize));
- CMStringA path;
- const wchar_t *serverFolder = ftp->GetServerFolder();
+ std::string path;
+ auto serverFolder = ftp->GetServerFolder();
if (serverFolder) {
char serverPath[MAX_PATH] = { 0 };
mir_snprintf(serverPath, "%s\\%s", T2Utf(serverFolder), fileName);
- PreparePath(serverPath, path);
+ path = PreparePath(serverPath);
}
- else PreparePath(fileName, path);
+ else
+ path = PreparePath(fileName);
- if (chunkSize == fileSize)
- {
+ if (chunkSize == fileSize) {
ftp->CheckCurrentFile();
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
- UploadFile(chunk, size, path);
+ path = UploadFile(chunk, size, path);
ftp->Progress(size);
}
- else
- {
+ else {
ftp->CheckCurrentFile();
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
- CMStringA sessionId;
- CreateUploadSession(chunk, size, sessionId);
+ auto sessionId = CreateUploadSession(chunk, size);
ftp->Progress(size);
@@ -275,7 +266,7 @@ UINT CDropboxService::Upload(FileTransferParam *ftp)
ftp->CheckCurrentFile();
size = ftp->ReadCurrentFile(chunk, chunkSize);
- UploadFileChunk(chunk, size, sessionId, offset);
+ UploadFileChunk(sessionId, chunk, size, offset);
offset += size;
ftp->Progress(size);
@@ -286,21 +277,19 @@ UINT CDropboxService::Upload(FileTransferParam *ftp)
? ftp->ReadCurrentFile(chunk, fileSize - offset)
: 0;
- CommitUploadSession(chunk, size, sessionId, offset, path);
+ path = CommitUploadSession(sessionId, chunk, size, offset, path);
ftp->Progress(size);
}
if (!ftp->IsFolder()) {
- CMStringA link;
- CreateSharedLink(path, link);
- ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
- ftp->AddSharedLink(link);
+ auto link = CreateSharedLink(path);
+ ftp->AddSharedLink(link.c_str());
}
} while (ftp->NextFile());
}
catch (Exception &ex) {
- Netlib_Logf(m_hConnection, "%s: %s", MODULE, ex.what());
+ debugLogA("%s: %s", GetModuleName(), ex.what());
ftp->SetStatus(ACKRESULT_FAILED);
return ACKRESULT_FAILED;
}
diff --git a/plugins/CloudFile/src/Services/dropbox_service.h b/plugins/CloudFile/src/Services/dropbox_service.h
index 6c55bf2bc7..fa481183c3 100644
--- a/plugins/CloudFile/src/Services/dropbox_service.h
+++ b/plugins/CloudFile/src/Services/dropbox_service.h
@@ -9,12 +9,12 @@ private:
void HandleJsonError(JSONNode &node) override;
- void UploadFile(const char *data, size_t size, CMStringA &path);
- void CreateUploadSession(const char *chunk, size_t chunkSize, CMStringA &sessionId);
- void UploadFileChunk(const char *chunk, size_t chunkSize, const char *sessionId, size_t offset);
- void CommitUploadSession(const char *chunk, size_t chunkSize, const char *sessionId, size_t offset, CMStringA &path);
- void CreateFolder(const char *path);
- void CreateSharedLink(const char *path, CMStringA &url);
+ auto UploadFile(const char *data, size_t size, const std::string &path);
+ auto CreateUploadSession(const char *chunk, size_t chunkSize);
+ void UploadFileChunk(const std::string &sessionId, const char *chunk, size_t chunkSize, size_t offset);
+ auto CommitUploadSession(const std::string &sessionId, const char *chunk, size_t chunkSize, size_t offset, const std::string &path);
+ void CreateFolder(const std::string &path);
+ auto CreateSharedLink(const std::string &path);
public:
CDropboxService(const char *protoName, const wchar_t *userName);
diff --git a/plugins/CloudFile/src/Services/google_api.h b/plugins/CloudFile/src/Services/google_api.h
index d67ef82012..2f5baa8eb3 100644
--- a/plugins/CloudFile/src/Services/google_api.h
+++ b/plugins/CloudFile/src/Services/google_api.h
@@ -9,7 +9,7 @@ namespace GDriveAPI
#define GDRIVE_API_VER "/v3"
#define GDRIVE_API GOOGLE_API "/drive" GDRIVE_API_VER "/files"
#define GDRIVE_UPLOAD GOOGLE_API "/upload/drive" GDRIVE_API_VER "/files"
-#define GDRIVE_SHARE "https://drive.google.com/open?id=%s"
+#define GDRIVE_SHARE "https://drive.google.com/open?id="
#define GOOGLE_APP_ID "528761318515-h1etlccvk5vjsbjuuj8i73cud8do4adi.apps.googleusercontent.com"
#include "../../../miranda-private-keys/Google/client_secret.h"
diff --git a/plugins/CloudFile/src/Services/google_service.cpp b/plugins/CloudFile/src/Services/google_service.cpp
index dcf4e0725d..dde5fc4b39 100644
--- a/plugins/CloudFile/src/Services/google_service.cpp
+++ b/plugins/CloudFile/src/Services/google_service.cpp
@@ -33,18 +33,18 @@ int CGDriveService::GetIconId() const
bool CGDriveService::IsLoggedIn()
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA token(getStringA("TokenSecret"));
if (!token || token[0] == 0)
return false;
time_t now = time(nullptr);
- time_t expiresIn = db_get_dw(NULL, GetAccountName(), "ExpiresIn");
+ time_t expiresIn = getDword("ExpiresIn");
return now < expiresIn;
}
void CGDriveService::Login()
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- ptrA refreshToken(db_get_sa(NULL, GetAccountName(), "RefreshToken"));
+ ptrA token(getStringA("TokenSecret"));
+ ptrA refreshToken(getStringA("RefreshToken"));
if (token && refreshToken && refreshToken[0]) {
GDriveAPI::RefreshTokenRequest request(refreshToken);
NLHR_PTR response(request.Send(m_hConnection));
@@ -52,11 +52,11 @@ void CGDriveService::Login()
JSONNode root = GetJsonResponse(response);
JSONNode node = root.at("access_token");
- db_set_s(NULL, GetAccountName(), "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();
- db_set_dw(NULL, GetAccountName(), "ExpiresIn", expiresIn);
+ setDword("ExpiresIn", expiresIn);
return;
}
@@ -146,21 +146,19 @@ void CGDriveService::HandleJsonError(JSONNode &node)
}
}
-void CGDriveService::UploadFile(const char *parentId, const char *name, const char *data, size_t size, CMStringA &fileId)
+auto CGDriveService::UploadFile(const std::string &parentId, const std::string &fileName, const char *data, size_t size)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- GDriveAPI::UploadFileRequest request(token, parentId, name, data, size);
+ ptrA token(getStringA("TokenSecret"));
+ GDriveAPI::UploadFileRequest request(token, parentId.c_str(), fileName.c_str(), data, size);
NLHR_PTR response(request.Send(m_hConnection));
-
JSONNode root = GetJsonResponse(response);
- if (root)
- fileId = root["id"].as_string().c_str();
+ return root["id"].as_string();
}
-void CGDriveService::CreateUploadSession(const char *parentId, const char *name, CMStringA &uploadUri)
+auto CGDriveService::CreateUploadSession(const std::string &parentId, const std::string &fileName)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- GDriveAPI::CreateUploadSessionRequest request(token, parentId, name);
+ ptrA token(getStringA("TokenSecret"));
+ GDriveAPI::CreateUploadSessionRequest request(token, parentId.c_str(), fileName.c_str());
NLHR_PTR response(request.Send(m_hConnection));
HandleHttpError(response);
@@ -169,57 +167,56 @@ void CGDriveService::CreateUploadSession(const char *parentId, const char *name,
for (int i = 0; i < response->headersCount; i++) {
if (mir_strcmpi(response->headers[i].szName, "Location"))
continue;
-
- uploadUri = response->headers[i].szValue;
- return;
+ return std::string(response->headers[i].szValue);
}
}
HttpResponseToError(response);
}
-void CGDriveService::UploadFileChunk(const char *uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize, CMStringA &fileId)
+auto CGDriveService::UploadFileChunk(const std::string &uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize)
{
- GDriveAPI::UploadFileChunkRequest request(uploadUri, chunk, chunkSize, offset, fileSize);
+ GDriveAPI::UploadFileChunkRequest request(uploadUri.c_str(), chunk, chunkSize, offset, fileSize);
NLHR_PTR response(request.Send(m_hConnection));
HandleHttpError(response);
if (response->resultCode == HTTP_CODE_PERMANENT_REDIRECT)
- return;
+ return std::string();
if (HTTP_CODE_SUCCESS(response->resultCode)) {
JSONNode root = GetJsonResponse(response);
- if (root)
- fileId = root["id"].as_string().c_str();
+ return root["id"].as_string();
}
- else HttpResponseToError(response);
+
+ HttpResponseToError(response);
}
-void CGDriveService::CreateFolder(const char *path, CMStringA &folderId)
+auto CGDriveService::CreateFolder(const char *path)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA token(getStringA("TokenSecret"));
GDriveAPI::CreateFolderRequest request(token, path);
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- if (root)
- folderId = root["id"].as_string().c_str();
+ return root["id"].as_string();
}
-void CGDriveService::CreateSharedLink(const char *itemId, CMStringA &url)
+auto CGDriveService::CreateSharedLink(const std::string &itemId)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- GDriveAPI::GrantPermissionsRequest request(token, itemId);
+ ptrA token(getStringA("TokenSecret"));
+ GDriveAPI::GrantPermissionsRequest request(token, itemId.c_str());
NLHR_PTR response(request.Send(m_hConnection));
HandleHttpError(response);
if (HTTP_CODE_SUCCESS(response->resultCode)) {
- CMStringA sharedUrl(CMStringDataFormat::FORMAT, GDRIVE_SHARE, itemId);
- url = sharedUrl;
+ std::string url = GDRIVE_SHARE;
+ url += itemId;
+ return url;
}
- else HttpResponseToError(response);
+
+ HttpResponseToError(response);
}
UINT CGDriveService::Upload(FileTransferParam *ftp)
@@ -233,61 +230,50 @@ UINT CGDriveService::Upload(FileTransferParam *ftp)
return ACKRESULT_FAILED;
}
- CMStringA folderId;
+ std::string folderId;
if (ftp->IsFolder()) {
- CreateFolder(T2Utf(ftp->GetFolderName()), folderId);
-
- CMStringA link;
- CreateSharedLink(folderId, link);
-
- ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
- ftp->AddSharedLink(link);
+ folderId = CreateFolder(T2Utf(ftp->GetFolderName()));
+ auto link = CreateSharedLink(folderId);
+ ftp->AddSharedLink(link.c_str());
}
ftp->FirstFile();
do {
- CMStringA fileName(T2Utf(ftp->GetCurrentRelativeFilePath()).get());
+ std::string fileName = T2Utf(ftp->GetCurrentRelativeFilePath()).get();
uint64_t fileSize = ftp->GetCurrentFileSize();
size_t chunkSize = ftp->GetCurrentFileChunkSize();
mir_ptr<char>chunk((char*)mir_calloc(chunkSize));
- CMStringA fileId;
+ std::string fileId;
if (chunkSize == fileSize) {
ftp->CheckCurrentFile();
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
-
- UploadFile(folderId, fileName, chunk, size, fileId);
-
+ fileId = UploadFile(folderId, fileName, chunk, size);
ftp->Progress(size);
}
else {
- CMStringA uploadUri;
- CreateUploadSession(uploadUri, folderId, fileName);
+ auto uploadUri = CreateUploadSession(folderId, fileName);
uint64_t offset = 0;
double chunkCount = ceil(double(fileSize) / chunkSize);
while (chunkCount > 0) {
ftp->CheckCurrentFile();
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
-
- UploadFileChunk(uploadUri, chunk, size, offset, fileSize, fileId);
-
+ auto fileId = UploadFileChunk(uploadUri, chunk, size, offset, fileSize);
offset += size;
ftp->Progress(size);
}
}
if (!ftp->IsFolder()) {
- CMStringA link;
- CreateSharedLink(fileId, link);
- ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
- ftp->AddSharedLink(link);
+ auto link = CreateSharedLink(fileId);
+ ftp->AddSharedLink(link.c_str());
}
} while (ftp->NextFile());
}
catch (Exception &ex) {
- Netlib_Logf(m_hConnection, "%s: %s", MODULE, ex.what());
+ debugLogA("%s: %s", GetAccountName(), ex.what());
ftp->SetStatus(ACKRESULT_FAILED);
return ACKRESULT_FAILED;
}
diff --git a/plugins/CloudFile/src/Services/google_service.h b/plugins/CloudFile/src/Services/google_service.h
index 3bb4466e57..9da2f14e5f 100644
--- a/plugins/CloudFile/src/Services/google_service.h
+++ b/plugins/CloudFile/src/Services/google_service.h
@@ -9,11 +9,11 @@ private:
void HandleJsonError(JSONNode &node) override;
- void UploadFile(const char *parentId, const char *name, const char *data, size_t size, CMStringA &fileId);
- void CreateUploadSession(const char *parentId, const char *name, CMStringA &uploadUri);
- void UploadFileChunk(const char *uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize, CMStringA &fileId);
- void CreateFolder(const char *path, CMStringA &folderId);
- void CreateSharedLink(const char *itemId, CMStringA &url);
+ auto UploadFile(const std::string &parentId, const std::string &fileName, const char *data, size_t size);
+ auto CreateUploadSession(const std::string &parentId, const std::string &fileName);
+ auto UploadFileChunk(const std::string &uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize);
+ auto CreateFolder(const char *path);
+ auto CreateSharedLink(const std::string &itemId);
public:
CGDriveService(const char *protoName, const wchar_t *userName);
diff --git a/plugins/CloudFile/src/Services/microsoft_service.cpp b/plugins/CloudFile/src/Services/microsoft_service.cpp
index 53b3a8574e..af4ebe2439 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.cpp
+++ b/plugins/CloudFile/src/Services/microsoft_service.cpp
@@ -33,18 +33,18 @@ int COneDriveService::GetIconId() const
bool COneDriveService::IsLoggedIn()
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA token(getStringA("TokenSecret"));
if (!token || token[0] == 0)
return false;
time_t now = time(nullptr);
- time_t expiresIn = db_get_dw(NULL, GetAccountName(), "ExpiresIn");
+ time_t expiresIn = getWord("ExpiresIn");
return now < expiresIn;
}
void COneDriveService::Login()
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- ptrA refreshToken(db_get_sa(NULL, GetAccountName(), "RefreshToken"));
+ ptrA token(getStringA("TokenSecret"));
+ ptrA refreshToken(getStringA("RefreshToken"));
if (token && refreshToken && refreshToken[0]) {
OneDriveAPI::RefreshTokenRequest request(refreshToken);
NLHR_PTR response(request.Send(m_hConnection));
@@ -56,7 +56,7 @@ void COneDriveService::Login()
node = root.at("expires_in");
time_t expiresIn = time(nullptr) + node.as_int();
- db_set_dw(NULL, GetAccountName(), "ExpiresIn", expiresIn);
+ setDword("ExpiresIn", expiresIn);
return;
}
@@ -67,9 +67,9 @@ void COneDriveService::Login()
void COneDriveService::Logout()
{
- db_unset(NULL, GetAccountName(), "TokenSecret");
- db_unset(NULL, GetAccountName(), "ExpiresIn");
- db_unset(NULL, GetAccountName(), "RefreshToken");
+ delSetting("ExpiresIn");
+ delSetting("TokenSecret");
+ delSetting("RefreshToken");
}
unsigned COneDriveService::RequestAccessTokenThread(void *owner, void *param)
@@ -112,14 +112,14 @@ unsigned COneDriveService::RequestAccessTokenThread(void *owner, void *param)
}
node = root.at("access_token");
- db_set_s(NULL, service->GetAccountName(), "TokenSecret", node.as_string().c_str());
+ service->setString("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);
+ service->setDword("ExpiresIn", expiresIn);
node = root.at("refresh_token");
- db_set_s(NULL, service->GetAccountName(), "RefreshToken", node.as_string().c_str());
+ service->setString("RefreshToken", node.as_string().c_str());
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
@@ -137,72 +137,70 @@ void COneDriveService::HandleJsonError(JSONNode &node)
}
}
-void COneDriveService::UploadFile(const char *parentId, const char *name, const char *data, size_t size, CMStringA &fileId)
+auto COneDriveService::UploadFile(const std::string &parentId, const std::string &fileName, const char *data, size_t size)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA token(getStringA("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)
- : new OneDriveAPI::UploadFileRequest(token, name, data, size, (OnConflict)strategy);
+ OneDriveAPI::UploadFileRequest *request = !parentId.empty()
+ ? new OneDriveAPI::UploadFileRequest(token, parentId.c_str(), fileName.c_str(), data, size, (OnConflict)strategy)
+ : new OneDriveAPI::UploadFileRequest(token, fileName.c_str(), data, size, (OnConflict)strategy);
NLHR_PTR response(request->Send(m_hConnection));
delete request;
JSONNode root = GetJsonResponse(response);
- fileId = root["id"].as_string().c_str();
+ return root["id"].as_string();
}
-void COneDriveService::CreateUploadSession(const char *parentId, const char *name, CMStringA &uploadUri)
+auto COneDriveService::CreateUploadSession(const std::string &parentId, const std::string &fileName)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA token(getStringA("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)
- : new OneDriveAPI::CreateUploadSessionRequest(token, name, (OnConflict)strategy);
+ OneDriveAPI::CreateUploadSessionRequest *request = !parentId.empty()
+ ? new OneDriveAPI::CreateUploadSessionRequest(token, parentId.c_str(), fileName.c_str(), (OnConflict)strategy)
+ : new OneDriveAPI::CreateUploadSessionRequest(token, fileName.c_str(), (OnConflict)strategy);
NLHR_PTR response(request->Send(m_hConnection));
delete request;
JSONNode root = GetJsonResponse(response);
- uploadUri = root["uploadUrl"].as_string().c_str();
+ return root["uploadUrl"].as_string();
}
-void COneDriveService::UploadFileChunk(const char *uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize, CMStringA &fileId)
+auto COneDriveService::UploadFileChunk(const std::string &uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize)
{
- OneDriveAPI::UploadFileChunkRequest request(uploadUri, chunk, chunkSize, offset, fileSize);
+ OneDriveAPI::UploadFileChunkRequest request(uploadUri.c_str(), chunk, chunkSize, offset, fileSize);
NLHR_PTR response(request.Send(m_hConnection));
HandleHttpError(response);
if (response->resultCode == HTTP_CODE_ACCEPTED)
- return;
+ return std::string();
if (HTTP_CODE_SUCCESS(response->resultCode)) {
JSONNode root = GetJsonResponse(response);
- if (root)
- fileId = root["id"].as_string().c_str();
+ return root["id"].as_string();
}
- else HttpResponseToError(response);
+
+ HttpResponseToError(response);
}
-void COneDriveService::CreateFolder(const char *path, CMStringA &folderId)
+auto COneDriveService::CreateFolder(const std::string &path)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- OneDriveAPI::CreateFolderRequest request(token, path);
+ ptrA token(getStringA("TokenSecret"));
+ OneDriveAPI::CreateFolderRequest request(token, path.c_str());
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- if (root)
- folderId = root["id"].as_string().c_str();
+ return root["id"].as_string();
}
-void COneDriveService::CreateSharedLink(const char *itemId, CMStringA &url)
+auto COneDriveService::CreateSharedLink(const std::string &itemId)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- OneDriveAPI::CreateSharedLinkRequest request(token, itemId);
+ ptrA token(getStringA("TokenSecret"));
+ OneDriveAPI::CreateSharedLinkRequest request(token, itemId.c_str());
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- if (root)
- url = root["link"]["webUrl"].as_string().c_str();
+ return root["link"]["webUrl"].as_string();
}
UINT COneDriveService::Upload(FileTransferParam *ftp)
@@ -216,40 +214,36 @@ UINT COneDriveService::Upload(FileTransferParam *ftp)
return ACKRESULT_FAILED;
}
- CMStringA folderId;
+ std::string folderId;
if (ftp->IsFolder()) {
- CMStringA folderName(T2Utf(ftp->GetFolderName()).get());
+ T2Utf folderName(ftp->GetFolderName());
- CMStringA path;
- PreparePath(folderName, path);
- CreateFolder(path, folderId);
+ auto path = PreparePath(folderName);
+ folderId = CreateFolder(path);
- CMStringA link;
- CreateSharedLink(path, link);
- ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
- ftp->AddSharedLink(link);
+ auto link = CreateSharedLink(path);
+ ftp->AddSharedLink(link.c_str());
}
ftp->FirstFile();
do {
- T2Utf fileName(ftp->GetCurrentRelativeFilePath());
+ std::string fileName = T2Utf(ftp->GetCurrentRelativeFilePath());
uint64_t fileSize = ftp->GetCurrentFileSize();
size_t chunkSize = ftp->GetCurrentFileChunkSize();
mir_ptr<char>chunk((char*)mir_calloc(chunkSize));
- CMStringA fileId;
+ std::string fileId;
if (chunkSize == fileSize) {
ftp->CheckCurrentFile();
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
- UploadFile(folderId, T2Utf(fileName), chunk, size, fileId);
+ fileId = UploadFile(folderId, fileName, chunk, size);
ftp->Progress(size);
}
else {
- char uploadUri[1024];
- CreateUploadSession(uploadUri, T2Utf(fileName), folderId);
+ auto uploadUri = CreateUploadSession(folderId, fileName);
uint64_t offset = 0;
double chunkCount = ceil(double(fileSize) / chunkSize);
@@ -257,7 +251,7 @@ UINT COneDriveService::Upload(FileTransferParam *ftp)
ftp->CheckCurrentFile();
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
- UploadFileChunk(uploadUri, chunk, size, offset, fileSize, fileId);
+ fileId = UploadFileChunk(uploadUri, chunk, size, offset, fileSize);
offset += size;
ftp->Progress(size);
@@ -265,15 +259,13 @@ UINT COneDriveService::Upload(FileTransferParam *ftp)
}
if (!ftp->IsFolder()) {
- CMStringA link;
- CreateSharedLink(fileId, link);
- ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
- ftp->AddSharedLink(link);
+ auto link = CreateSharedLink(fileId);
+ ftp->AddSharedLink(link.c_str());
}
} while (ftp->NextFile());
}
catch (Exception &ex) {
- Netlib_Logf(m_hConnection, "%s: %s", MODULE, ex.what());
+ debugLogA("%s: %s", GetAccountName(), ex.what());
ftp->SetStatus(ACKRESULT_FAILED);
return ACKRESULT_FAILED;
}
diff --git a/plugins/CloudFile/src/Services/microsoft_service.h b/plugins/CloudFile/src/Services/microsoft_service.h
index 03c3ea2585..f9e41a93c5 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.h
+++ b/plugins/CloudFile/src/Services/microsoft_service.h
@@ -8,11 +8,11 @@ private:
void HandleJsonError(JSONNode &node) override;
- void UploadFile(const char *parentId, const char *name, const char *data, size_t size, CMStringA &fileId);
- void CreateUploadSession(const char *parentId, const char *name, CMStringA &uploadUri);
- void UploadFileChunk(const char *uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize, CMStringA &fileId);
- void CreateFolder(const char *path, CMStringA &folderId);
- void CreateSharedLink(const char *itemId, CMStringA &url);
+ auto UploadFile(const std::string &parentId, const std::string &fileName, const char *data, size_t size);
+ auto CreateUploadSession(const std::string &parentId, const std::string &fileName);
+ auto UploadFileChunk(const std::string &uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize);
+ auto CreateFolder(const std::string &path);
+ auto CreateSharedLink(const std::string &itemId);
public:
COneDriveService(const char *protoName, const wchar_t *userName);
diff --git a/plugins/CloudFile/src/Services/yandex_api.h b/plugins/CloudFile/src/Services/yandex_api.h
index 6c2d97448b..19c76d61f9 100644
--- a/plugins/CloudFile/src/Services/yandex_api.h
+++ b/plugins/CloudFile/src/Services/yandex_api.h
@@ -59,7 +59,7 @@ namespace YandexAPI
HttpRequest(REQUEST_GET, YADISK_API "/upload")
{
AddOAuthHeader(token);
- AddUrlParameter("path=%s", ptrA(mir_urlEncode(path)));
+ AddUrlParameter("path=app:%s", ptrA(mir_urlEncode(path)));
if (strategy == OnConflict::REPLACE)
AddUrlParameter("overwrite=true");
}
@@ -97,7 +97,7 @@ namespace YandexAPI
HttpRequest(REQUEST_PUT, YADISK_API)
{
AddOAuthHeader(token);
- AddUrlParameter("path=%s", ptrA(mir_urlEncode(path)));
+ AddUrlParameter("path=app:%s", ptrA(mir_urlEncode(path)));
}
};
@@ -108,7 +108,7 @@ namespace YandexAPI
HttpRequest(REQUEST_PUT, YADISK_API "/publish")
{
AddOAuthHeader(token);
- AddUrlParameter("path=%s", ptrA(mir_urlEncode(path)));
+ AddUrlParameter("path=app:%s", ptrA(mir_urlEncode(path)));
}
};
@@ -119,7 +119,7 @@ namespace YandexAPI
HttpRequest(REQUEST_GET, YADISK_API)
{
AddOAuthHeader(token);
- AddUrlParameter("path=%s", ptrA(mir_urlEncode(path)));
+ AddUrlParameter("path=app:%s", ptrA(mir_urlEncode(path)));
}
};
};
diff --git a/plugins/CloudFile/src/Services/yandex_service.cpp b/plugins/CloudFile/src/Services/yandex_service.cpp
index a40dd0d862..662659f8c6 100644
--- a/plugins/CloudFile/src/Services/yandex_service.cpp
+++ b/plugins/CloudFile/src/Services/yandex_service.cpp
@@ -33,18 +33,18 @@ int CYandexService::GetIconId() const
bool CYandexService::IsLoggedIn()
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA token(getStringA("TokenSecret"));
if (!token || token[0] == 0)
return false;
time_t now = time(nullptr);
- time_t expiresIn = db_get_dw(NULL, GetAccountName(), "ExpiresIn");
+ time_t expiresIn = getDword("ExpiresIn");
return now < expiresIn;
}
void CYandexService::Login()
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- ptrA refreshToken(db_get_sa(NULL, GetAccountName(), "RefreshToken"));
+ ptrA token(getStringA("TokenSecret"));
+ ptrA refreshToken(getStringA("RefreshToken"));
if (token && refreshToken && refreshToken[0]) {
YandexAPI::RefreshTokenRequest request(refreshToken);
NLHR_PTR response(request.Send(m_hConnection));
@@ -52,14 +52,14 @@ void CYandexService::Login()
JSONNode root = GetJsonResponse(response);
JSONNode node = root.at("access_token");
- db_set_s(NULL, GetAccountName(), "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();
- db_set_dw(NULL, GetAccountName(), "ExpiresIn", expiresIn);
+ setDword("ExpiresIn", expiresIn);
node = root.at("refresh_token");
- db_set_s(NULL, GetAccountName(), "RefreshToken", node.as_string().c_str());
+ setString("RefreshToken", node.as_string().c_str());
return;
}
@@ -113,14 +113,14 @@ unsigned CYandexService::RequestAccessTokenThread(void *owner, void *param)
}
node = root.at("access_token");
- db_set_s(NULL, service->GetAccountName(), "TokenSecret", node.as_string().c_str());
+ service->setString("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);
+ service->setDword("ExpiresIn", expiresIn);
node = root.at("refresh_token");
- db_set_s(NULL, service->GetAccountName(), "RefreshToken", node.as_string().c_str());
+ service->setString("RefreshToken", node.as_string().c_str());
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
@@ -148,21 +148,20 @@ void CYandexService::HandleJsonError(JSONNode &node)
}
}
-void CYandexService::CreateUploadSession(const char *path, CMStringA &uploadUri)
+auto CYandexService::CreateUploadSession(const std::string &path)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA token(getStringA("TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
- YandexAPI::GetUploadUrlRequest request(token, path, (OnConflict)strategy);
+ YandexAPI::GetUploadUrlRequest request(token, path.c_str(), (OnConflict)strategy);
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- if (root)
- uploadUri = root["href"].as_string().c_str();
+ return root["href"].as_string();
}
-void CYandexService::UploadFile(const char *uploadUri, const char *data, size_t size)
+void CYandexService::UploadFile(const std::string &uploadUri, const char *data, size_t size)
{
- YandexAPI::UploadFileRequest request(uploadUri, data, size);
+ YandexAPI::UploadFileRequest request(uploadUri.c_str(), data, size);
NLHR_PTR response(request.Send(m_hConnection));
HandleHttpError(response);
@@ -173,9 +172,9 @@ void CYandexService::UploadFile(const char *uploadUri, const char *data, size_t
HttpResponseToError(response);
}
-void CYandexService::UploadFileChunk(const char *uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize)
+void CYandexService::UploadFileChunk(const std::string &uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize)
{
- YandexAPI::UploadFileChunkRequest request(uploadUri, chunk, chunkSize, offset, fileSize);
+ YandexAPI::UploadFileChunkRequest request(uploadUri.c_str(), chunk, chunkSize, offset, fileSize);
NLHR_PTR response(request.Send(m_hConnection));
HandleHttpError(response);
@@ -187,29 +186,28 @@ void CYandexService::UploadFileChunk(const char *uploadUri, const char *chunk, s
HttpResponseToError(response);
}
-void CYandexService::CreateFolder(const char *path)
+void CYandexService::CreateFolder(const std::string &path)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- YandexAPI::CreateFolderRequest request(token, path);
+ ptrA token(getStringA("TokenSecret"));
+ YandexAPI::CreateFolderRequest request(token, path.c_str());
NLHR_PTR response(request.Send(m_hConnection));
GetJsonResponse(response);
}
-void CYandexService::CreateSharedLink(const char *path, CMStringA &url)
+auto CYandexService::CreateSharedLink(const std::string &path)
{
- ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
- YandexAPI::PublishRequest publishRequest(token, path);
+ ptrA token(getStringA("TokenSecret"));
+ YandexAPI::PublishRequest publishRequest(token, path.c_str());
NLHR_PTR response(publishRequest.Send(m_hConnection));
GetJsonResponse(response);
- YandexAPI::GetResourcesRequest resourcesRequest(token, path);
+ YandexAPI::GetResourcesRequest resourcesRequest(token, path.c_str());
response = resourcesRequest.Send(m_hConnection);
JSONNode root = GetJsonResponse(response);
- if (root)
- url = root["public_url"].as_string().c_str();
+ return root["public_url"].as_string();
}
UINT CYandexService::Upload(FileTransferParam *ftp)
@@ -226,14 +224,11 @@ UINT CYandexService::Upload(FileTransferParam *ftp)
if (ftp->IsFolder()) {
T2Utf folderName(ftp->GetFolderName());
- CMStringA path;
- PreparePath(folderName, path);
+ auto path = PreparePath(folderName);
CreateFolder(path);
- CMStringA link;
- CreateSharedLink(path, link);
- ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
- ftp->AddSharedLink(link);
+ auto link = CreateSharedLink(path);
+ ftp->AddSharedLink(link.c_str());
}
ftp->FirstFile();
@@ -242,11 +237,8 @@ UINT CYandexService::Upload(FileTransferParam *ftp)
T2Utf fileName(ftp->GetCurrentRelativeFilePath());
uint64_t fileSize = ftp->GetCurrentFileSize();
- CMStringA path;
- PreparePath(fileName, path);
-
- CMStringA uploadUri;
- CreateUploadSession(path, uploadUri);
+ auto path = PreparePath(fileName);
+ auto uploadUri = CreateUploadSession(path);
size_t chunkSize = ftp->GetCurrentFileChunkSize();
mir_ptr<char>chunk((char*)mir_calloc(chunkSize));
@@ -254,36 +246,29 @@ UINT CYandexService::Upload(FileTransferParam *ftp)
if (chunkSize == fileSize) {
ftp->CheckCurrentFile();
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
-
UploadFile(uploadUri, chunk, size);
-
ftp->Progress(size);
}
- else
- {
+ else {
uint64_t offset = 0;
double chunkCount = ceil(double(fileSize) / chunkSize);
while (chunkCount > 0) {
ftp->CheckCurrentFile();
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
-
UploadFileChunk(uploadUri, chunk, size, offset, fileSize);
-
offset += size;
ftp->Progress(size);
}
}
if (!ftp->IsFolder()) {
- CMStringA link;
- CreateSharedLink(path, link);
- ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
- ftp->AddSharedLink(link);
+ auto link = CreateSharedLink(path);
+ ftp->AddSharedLink(link.c_str());
}
} while (ftp->NextFile());
}
catch (Exception &ex) {
- Netlib_Logf(m_hConnection, "%s: %s", MODULE, ex.what());
+ debugLogA("%s: %s", GetAccountName(), ex.what());
ftp->SetStatus(ACKRESULT_FAILED);
return ACKRESULT_FAILED;
}
diff --git a/plugins/CloudFile/src/Services/yandex_service.h b/plugins/CloudFile/src/Services/yandex_service.h
index 2971d6beec..76a12feef0 100644
--- a/plugins/CloudFile/src/Services/yandex_service.h
+++ b/plugins/CloudFile/src/Services/yandex_service.h
@@ -9,11 +9,11 @@ private:
void HandleJsonError(JSONNode &node) override;
- void CreateUploadSession(const char *path, CMStringA &uploadUri);
- void UploadFile(const char *uploadUri, const char *data, size_t size);
- void UploadFileChunk(const char *uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize);
- void CreateFolder(const char *path);
- void CreateSharedLink(const char *path, CMStringA &url);
+ auto CreateUploadSession(const std::string &path);
+ void UploadFile(const std::string &uploadUri, const char *data, size_t size);
+ void UploadFileChunk(const std::string &uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize);
+ void CreateFolder(const std::string &path);
+ auto CreateSharedLink(const std::string &path);
public:
CYandexService(const char *protoName, const wchar_t *userName);
diff --git a/plugins/CloudFile/src/cloud_file.cpp b/plugins/CloudFile/src/cloud_file.cpp
index 9e40ac3db0..d4c082148f 100644
--- a/plugins/CloudFile/src/cloud_file.cpp
+++ b/plugins/CloudFile/src/cloud_file.cpp
@@ -70,17 +70,17 @@ void CCloudService::Report(MCONTACT hContact, const wchar_t *data)
PasteToClipboard(data);
}
-const char* CCloudService::PreparePath(const char *oldPath, CMStringA &newPath)
+std::string CCloudService::PreparePath(const char *path)
{
- if (oldPath == nullptr)
- newPath = "";
- else if (*oldPath != '/') {
- newPath = "/";
- newPath.Append(oldPath);
- newPath.Replace("\\", "/");
+ std::string newPath = path;
+ if (newPath[0] != '/')
+ newPath.insert(0, "/");
+ std::replace(newPath.begin(), newPath.end(), '\\', '/');
+ size_t pos = newPath.find("//");
+ while (pos != std::string::npos) {
+ newPath.replace(pos, 2, "/");
+ pos = newPath.find("//", pos + 1);
}
- else newPath = oldPath;
-
return newPath;
}
@@ -120,8 +120,13 @@ void CCloudService::HandleHttpError(NETLIBHTTPREQUEST *response)
if (response == nullptr)
throw Exception(HttpStatusToError());
- if (!HTTP_CODE_SUCCESS(response->resultCode))
- HttpResponseToError(response);
+ if (HTTP_CODE_SUCCESS(response->resultCode))
+ return;
+
+ if (response->resultCode == HTTP_CODE_UNAUTHORIZED)
+ delSetting("TokenSecret");
+
+ HttpResponseToError(response);
}
JSONNode CCloudService::GetJsonResponse(NETLIBHTTPREQUEST *response)
diff --git a/plugins/CloudFile/src/cloud_file.h b/plugins/CloudFile/src/cloud_file.h
index 5aac068aa6..82f034b555 100644
--- a/plugins/CloudFile/src/cloud_file.h
+++ b/plugins/CloudFile/src/cloud_file.h
@@ -15,7 +15,7 @@ protected:
HNETLIBUSER m_hConnection;
// utils
- const char* PreparePath(const char *oldPath, CMStringA &newPath);
+ std::string PreparePath(const char *path);
virtual char* HttpStatusToError(int status = 0);
virtual void HttpResponseToError(NETLIBHTTPREQUEST *response);
diff --git a/plugins/CloudFile/src/file_transfer.h b/plugins/CloudFile/src/file_transfer.h
index 601933e3dc..bf055d737f 100644
--- a/plugins/CloudFile/src/file_transfer.h
+++ b/plugins/CloudFile/src/file_transfer.h
@@ -17,7 +17,6 @@ private:
const wchar_t* folderName;
int relativePathStart;
- CMStringW data;
LIST<char> m_links;
CMStringW m_description;
@@ -79,13 +78,6 @@ public:
return pfts.hContact;
}
- const wchar_t* GetData() const
- {
- if (data.IsEmpty())
- return NULL;
- return data;
- }
-
const wchar_t* GetDescription() const
{
return m_description.GetString();
@@ -153,14 +145,6 @@ public:
}
}
- void AppendFormatData(const wchar_t *format, ...)
- {
- va_list args;
- va_start(args, format);
- data.AppendFormatV(format, args);
- va_end(args);
- }
-
void AddSharedLink(const char *url)
{
m_links.insert(mir_strdup(url));
diff --git a/plugins/CloudFile/src/stdafx.h b/plugins/CloudFile/src/stdafx.h
index e789c57360..d7c3cf2c8e 100644
--- a/plugins/CloudFile/src/stdafx.h
+++ b/plugins/CloudFile/src/stdafx.h
@@ -9,6 +9,7 @@
#include <time.h>
#include <map>
+#include <algorithm>
#include <newpluginapi.h>
diff --git a/plugins/CloudFile/src/transfers.cpp b/plugins/CloudFile/src/transfers.cpp
index c70dbcf33f..28ceede990 100644
--- a/plugins/CloudFile/src/transfers.cpp
+++ b/plugins/CloudFile/src/transfers.cpp
@@ -66,8 +66,16 @@ UINT UploadAndReportProgressThread(void *owner, void *arg)
FileTransferParam *ftp = (FileTransferParam*)arg;
int res = service->Upload(ftp);
- if (res == ACKRESULT_SUCCESS)
- service->Report(ftp->GetContact(), ftp->GetData());
+ if (res == ACKRESULT_SUCCESS) {
+ CMStringW data = ftp->GetDescription();
+ size_t linkCount;
+ auto links = ftp->GetSharedLinks(linkCount);
+ for (size_t i = 0; i < linkCount; i++) {
+ data.Append(ptrW(mir_utf8decodeW(links[i])));
+ data.AppendChar(0x0A);
+ }
+ service->Report(ftp->GetContact(), data);
+ }
Transfers.remove(ftp);
delete ftp;