summaryrefslogtreecommitdiff
path: root/plugins/CloudFile
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-11 12:44:23 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-11 12:44:23 +0300
commit05da7a15de40291b2135d8e089e24ec20babb065 (patch)
tree4be6dad7f3cb2a5ab7a31f9a5123893ed72cf20d /plugins/CloudFile
parentbb583302ec9f478eebd3b57d06a476a5d82730c6 (diff)
CloudFile: war agains static buffers & buffer overruns
Diffstat (limited to 'plugins/CloudFile')
-rw-r--r--plugins/CloudFile/src/Services/dropbox_service.cpp41
-rw-r--r--plugins/CloudFile/src/Services/dropbox_service.h8
-rw-r--r--plugins/CloudFile/src/Services/google_service.cpp75
-rw-r--r--plugins/CloudFile/src/Services/google_service.h10
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.cpp63
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.h10
-rw-r--r--plugins/CloudFile/src/Services/yandex_service.cpp24
-rw-r--r--plugins/CloudFile/src/Services/yandex_service.h4
-rw-r--r--plugins/CloudFile/src/cloud_file.cpp18
-rw-r--r--plugins/CloudFile/src/cloud_file.h2
10 files changed, 114 insertions, 141 deletions
diff --git a/plugins/CloudFile/src/Services/dropbox_service.cpp b/plugins/CloudFile/src/Services/dropbox_service.cpp
index bec549dc2c..52cb094986 100644
--- a/plugins/CloudFile/src/Services/dropbox_service.cpp
+++ b/plugins/CloudFile/src/Services/dropbox_service.cpp
@@ -90,7 +90,6 @@ unsigned CDropboxService::RequestAccessTokenThread(void *owner, void *param)
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
EndDialog(hwndDlg, 1);
-
return 0;
}
@@ -114,7 +113,7 @@ void CDropboxService::HandleJsonError(JSONNode &node)
}
}
-void CDropboxService::UploadFile(const char *data, size_t size, char *path)
+void CDropboxService::UploadFile(const char *data, size_t size, CMStringA &path)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
@@ -122,19 +121,19 @@ void CDropboxService::UploadFile(const char *data, size_t size, char *path)
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("path_lower");
- mir_strcpy(path, node.as_string().c_str());
+ if (root)
+ path = root["path_lower"].as_string().c_str();
}
-void CDropboxService::CreateUploadSession(const char *chunk, size_t chunkSize, char *sessionId)
+void CDropboxService::CreateUploadSession(const char *chunk, size_t chunkSize, CMStringA &sessionId)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
DropboxAPI::CreateUploadSessionRequest request(token, chunk, chunkSize);
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("session_id");
- mir_strcpy(sessionId, node.as_string().c_str());
+ if (root)
+ sessionId = root["session_id"].as_string().c_str();
}
void CDropboxService::UploadFileChunk(const char *chunk, size_t chunkSize, const char *sessionId, size_t offset)
@@ -142,11 +141,10 @@ void CDropboxService::UploadFileChunk(const char *chunk, size_t chunkSize, const
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
DropboxAPI::UploadFileChunkRequest request(token, sessionId, 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, char *path)
+void CDropboxService::CommitUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, CMStringA &path)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
@@ -154,8 +152,8 @@ void CDropboxService::CommitUploadSession(const char *data, size_t size, const c
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("path_lower");
- mir_strcpy(path, node.as_string().c_str());
+ if (root)
+ path = root["path_lower"].as_string().c_str();
}
void CDropboxService::CreateFolder(const char *path)
@@ -173,7 +171,7 @@ void CDropboxService::CreateFolder(const char *path)
GetJsonResponse(response);
}
-void CDropboxService::CreateSharedLink(const char *path, char *url)
+void CDropboxService::CreateSharedLink(const char *path, CMStringA &url)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
DropboxAPI::CreateSharedLinkRequest shareRequest(token, path);
@@ -196,7 +194,7 @@ void CDropboxService::CreateSharedLink(const char *path, char *url)
JSONNode error = root.at("error");
if (error.isnull()) {
JSONNode link = root.at("url");
- mir_strcpy(url, link.as_string().c_str());
+ url = link.as_string().c_str();
return;
}
@@ -211,7 +209,7 @@ void CDropboxService::CreateSharedLink(const char *path, char *url)
JSONNode links = root.at("links").as_array();
JSONNode link = links[(size_t)0].at("url");
- mir_strcpy(url, link.as_string().c_str());
+ url = link.as_string().c_str();
}
UINT CDropboxService::Upload(FileTransferParam *ftp)
@@ -223,11 +221,11 @@ UINT CDropboxService::Upload(FileTransferParam *ftp)
if (ftp->IsFolder()) {
T2Utf folderName(ftp->GetFolderName());
- char path[MAX_PATH];
+ CMStringA path;
PreparePath(folderName, path);
CreateFolder(path);
- char link[MAX_PATH];
+ CMStringA link;
CreateSharedLink(path, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
ftp->AddSharedLink(link);
@@ -239,18 +237,17 @@ UINT CDropboxService::Upload(FileTransferParam *ftp)
T2Utf fileName(ftp->GetCurrentRelativeFilePath());
uint64_t fileSize = ftp->GetCurrentFileSize();
- int chunkSize = ftp->GetCurrentFileChunkSize();
+ size_t chunkSize = ftp->GetCurrentFileChunkSize();
mir_ptr<char>chunk((char*)mir_calloc(chunkSize));
- char path[MAX_PATH];
+ CMStringA path;
const wchar_t *serverFolder = ftp->GetServerFolder();
if (serverFolder) {
char serverPath[MAX_PATH] = { 0 };
mir_snprintf(serverPath, "%s\\%s", T2Utf(serverFolder), fileName);
PreparePath(serverPath, path);
}
- else
- PreparePath(fileName, path);
+ else PreparePath(fileName, path);
if (chunkSize == fileSize)
{
@@ -266,7 +263,7 @@ UINT CDropboxService::Upload(FileTransferParam *ftp)
ftp->CheckCurrentFile();
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
- char sessionId[64];
+ CMStringA sessionId;
CreateUploadSession(chunk, size, sessionId);
ftp->Progress(size);
@@ -294,7 +291,7 @@ UINT CDropboxService::Upload(FileTransferParam *ftp)
}
if (!ftp->IsFolder()) {
- char link[MAX_PATH];
+ CMStringA link;
CreateSharedLink(path, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
ftp->AddSharedLink(link);
diff --git a/plugins/CloudFile/src/Services/dropbox_service.h b/plugins/CloudFile/src/Services/dropbox_service.h
index 1010779229..6c55bf2bc7 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, char *path);
- void CreateUploadSession(const char *chunk, size_t chunkSize, char *sessionId);
+ 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, char *path);
+ 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, char *url);
+ void CreateSharedLink(const char *path, CMStringA &url);
public:
CDropboxService(const char *protoName, const wchar_t *userName);
diff --git a/plugins/CloudFile/src/Services/google_service.cpp b/plugins/CloudFile/src/Services/google_service.cpp
index 0fafdbaf01..5298945e7a 100644
--- a/plugins/CloudFile/src/Services/google_service.cpp
+++ b/plugins/CloudFile/src/Services/google_service.cpp
@@ -3,8 +3,7 @@
CGDriveService::CGDriveService(const char *protoName, const wchar_t *userName)
: CCloudService(protoName, userName)
-{
-}
+{}
CGDriveService* CGDriveService::Init(const char *moduleName, const wchar_t *userName)
{
@@ -44,10 +43,10 @@ void CGDriveService::Login()
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
ptrA refreshToken(db_get_sa(NULL, GetAccountName(), "RefreshToken"));
- if (token && refreshToken && refreshToken[0]) {
+ if (token && refreshToken && refreshToken[0]) {
GDriveAPI::RefreshTokenRequest request(refreshToken);
NLHR_PTR response(request.Send(m_hConnection));
-
+
JSONNode root = GetJsonResponse(response);
JSONNode node = root.at("access_token");
@@ -56,10 +55,10 @@ void CGDriveService::Login()
node = root.at("expires_in");
time_t expiresIn = time(nullptr) + node.as_int();
db_set_dw(NULL, GetAccountName(), "ExpiresIn", expiresIn);
-
+
return;
}
-
+
COAuthDlg dlg(this, GOOGLE_AUTH, RequestAccessTokenThread);
dlg.DoModal();
}
@@ -145,18 +144,18 @@ void CGDriveService::HandleJsonError(JSONNode &node)
}
}
-void CGDriveService::UploadFile(const char *parentId, const char *name, const char *data, size_t size, char *fileId)
+void CGDriveService::UploadFile(const char *parentId, const char *name, const char *data, size_t size, CMStringA &fileId)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
GDriveAPI::UploadFileRequest request(token, parentId, name, data, size);
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("id");
- mir_strcpy(fileId, node.as_string().c_str());
+ if (root)
+ fileId = root["id"].as_string().c_str();
}
-void CGDriveService::CreateUploadSession(const char *parentId, const char *name, char *uploadUri)
+void CGDriveService::CreateUploadSession(const char *parentId, const char *name, CMStringA &uploadUri)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
GDriveAPI::CreateUploadSessionRequest request(token, parentId, name);
@@ -165,12 +164,11 @@ void CGDriveService::CreateUploadSession(const char *parentId, const char *name,
HandleHttpError(response);
if (HTTP_CODE_SUCCESS(response->resultCode)) {
- for (int i = 0; i < response->headersCount; i++)
- {
+ for (int i = 0; i < response->headersCount; i++) {
if (mir_strcmpi(response->headers[i].szName, "Location"))
continue;
- mir_strcpy(uploadUri, response->headers[i].szValue);
+ uploadUri = response->headers[i].szValue;
return;
}
}
@@ -178,7 +176,7 @@ void CGDriveService::CreateUploadSession(const char *parentId, const char *name,
HttpResponseToError(response);
}
-void CGDriveService::UploadFileChunk(const char *uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize, char *fileId)
+void CGDriveService::UploadFileChunk(const char *uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize, CMStringA &fileId)
{
GDriveAPI::UploadFileChunkRequest request(uploadUri, chunk, chunkSize, offset, fileSize);
NLHR_PTR response(request.Send(m_hConnection));
@@ -190,26 +188,24 @@ void CGDriveService::UploadFileChunk(const char *uploadUri, const char *chunk, s
if (HTTP_CODE_SUCCESS(response->resultCode)) {
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("id");
- mir_strcpy(fileId, node.as_string().c_str());
- return;
+ if (root)
+ fileId = root["id"].as_string().c_str();
}
-
- HttpResponseToError(response);
+ else HttpResponseToError(response);
}
-void CGDriveService::CreateFolder(const char *path, char *folderId)
+void CGDriveService::CreateFolder(const char *path, CMStringA &folderId)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
GDriveAPI::CreateFolderRequest request(token, path);
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("id");
- mir_strcpy(folderId, node.as_string().c_str());
+ if (root)
+ folderId = root["id"].as_string().c_str();
}
-void CGDriveService::CreateSharedLink(const char *itemId, char *url)
+void CGDriveService::CreateSharedLink(const char *itemId, CMStringA &url)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
GDriveAPI::GrantPermissionsRequest request(token, itemId);
@@ -219,11 +215,9 @@ void CGDriveService::CreateSharedLink(const char *itemId, char *url)
if (HTTP_CODE_SUCCESS(response->resultCode)) {
CMStringA sharedUrl(CMStringDataFormat::FORMAT, GDRIVE_SHARE, itemId);
- mir_strcpy(url, sharedUrl);
- return;
+ url = sharedUrl;
}
-
- HttpResponseToError(response);
+ else HttpResponseToError(response);
}
UINT CGDriveService::Upload(FileTransferParam *ftp)
@@ -237,31 +231,27 @@ UINT CGDriveService::Upload(FileTransferParam *ftp)
return ACKRESULT_FAILED;
}
- char folderId[32] = { 0 };
+ CMStringA folderId;
if (ftp->IsFolder()) {
- T2Utf folderName(ftp->GetFolderName());
-
- CreateFolder(folderName, folderId);
- char link[MAX_PATH];
+ CreateFolder(T2Utf(ftp->GetFolderName()), folderId);
+ CMStringA link;
CreateSharedLink(folderId, link);
+
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
ftp->AddSharedLink(link);
}
ftp->FirstFile();
- do
- {
- T2Utf fileName(ftp->GetCurrentRelativeFilePath());
+ do {
+ CMStringA fileName(T2Utf(ftp->GetCurrentRelativeFilePath()).get());
uint64_t fileSize = ftp->GetCurrentFileSize();
- char fileId[32];
-
size_t chunkSize = ftp->GetCurrentFileChunkSize();
mir_ptr<char>chunk((char*)mir_calloc(chunkSize));
- if (chunkSize == fileSize)
- {
+ CMStringA fileId;
+ if (chunkSize == fileSize) {
ftp->CheckCurrentFile();
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
@@ -269,9 +259,8 @@ UINT CGDriveService::Upload(FileTransferParam *ftp)
ftp->Progress(size);
}
- else
- {
- char uploadUri[1024];
+ else {
+ CMStringA uploadUri;
CreateUploadSession(uploadUri, folderId, fileName);
uint64_t offset = 0;
@@ -288,7 +277,7 @@ UINT CGDriveService::Upload(FileTransferParam *ftp)
}
if (!ftp->IsFolder()) {
- char link[MAX_PATH];
+ CMStringA link;
CreateSharedLink(fileId, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
ftp->AddSharedLink(link);
diff --git a/plugins/CloudFile/src/Services/google_service.h b/plugins/CloudFile/src/Services/google_service.h
index cef71c8a45..3bb4466e57 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, char *fileId);
- void CreateUploadSession(const char *parentId, const char *name, char *uploadUri);
- void UploadFileChunk(const char *uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize, char *fileId);
- void CreateFolder(const char *path, char *folderId);
- void CreateSharedLink(const char *itemId, char *url);
+ 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);
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 015979191d..0a272a4e80 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.cpp
+++ b/plugins/CloudFile/src/Services/microsoft_service.cpp
@@ -47,7 +47,7 @@ void COneDriveService::Login()
if (token && refreshToken && refreshToken[0]) {
OneDriveAPI::RefreshTokenRequest request(refreshToken);
NLHR_PTR response(request.Send(m_hConnection));
-
+
JSONNode root = GetJsonResponse(response);
JSONNode node = root.at("access_token");
@@ -56,10 +56,10 @@ void COneDriveService::Login()
node = root.at("expires_in");
time_t expiresIn = time(nullptr) + node.as_int();
db_set_dw(NULL, GetAccountName(), "ExpiresIn", expiresIn);
-
+
return;
}
-
+
COAuthDlg dlg(this, MICROSOFT_AUTH, RequestAccessTokenThread);
dlg.DoModal();
}
@@ -136,7 +136,7 @@ void COneDriveService::HandleJsonError(JSONNode &node)
}
}
-void COneDriveService::UploadFile(const char *parentId, const char *name, const char *data, size_t size, char *fileId)
+void COneDriveService::UploadFile(const char *parentId, const char *name, const char *data, size_t size, CMStringA &fileId)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
@@ -147,11 +147,10 @@ void COneDriveService::UploadFile(const char *parentId, const char *name, const
delete request;
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("id");
- mir_strcpy(fileId, node.as_string().c_str());
+ fileId = root["id"].as_string().c_str();
}
-void COneDriveService::CreateUploadSession(const char *parentId, const char *name, char *uploadUri)
+void COneDriveService::CreateUploadSession(const char *parentId, const char *name, CMStringA &uploadUri)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
@@ -162,11 +161,10 @@ void COneDriveService::CreateUploadSession(const char *parentId, const char *nam
delete request;
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("uploadUrl");
- mir_strcpy(uploadUri, node.as_string().c_str());
+ uploadUri = root["uploadUrl"].as_string().c_str();
}
-void COneDriveService::UploadFileChunk(const char *uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize, char *fileId)
+void COneDriveService::UploadFileChunk(const char *uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize, CMStringA &fileId)
{
OneDriveAPI::UploadFileChunkRequest request(uploadUri, chunk, chunkSize, offset, fileSize);
NLHR_PTR response(request.Send(m_hConnection));
@@ -178,35 +176,32 @@ void COneDriveService::UploadFileChunk(const char *uploadUri, const char *chunk,
if (HTTP_CODE_SUCCESS(response->resultCode)) {
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("id");
- mir_strcpy(fileId, node.as_string().c_str());
- return;
+ if (root)
+ fileId = root["id"].as_string().c_str();
}
-
- HttpResponseToError(response);
+ else HttpResponseToError(response);
}
-void COneDriveService::CreateFolder(const char *path, char *folderId)
+void COneDriveService::CreateFolder(const char *path, CMStringA &folderId)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
OneDriveAPI::CreateFolderRequest request(token, path);
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("id");
- mir_strcpy(folderId, node.as_string().c_str());
+ if (root)
+ folderId = root["id"].as_string().c_str();
}
-void COneDriveService::CreateSharedLink(const char *itemId, char *url)
+void COneDriveService::CreateSharedLink(const char *itemId, CMStringA &url)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
OneDriveAPI::CreateSharedLinkRequest request(token, itemId);
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("link");
- JSONNode webUrl = node.at("webUrl");
- mir_strcpy(url, webUrl.as_string().c_str());
+ if (root)
+ url = root["link"]["webUrl"].as_string().c_str();
}
UINT COneDriveService::Upload(FileTransferParam *ftp)
@@ -220,33 +215,30 @@ UINT COneDriveService::Upload(FileTransferParam *ftp)
return ACKRESULT_FAILED;
}
- char folderId[32] = { 0 };
+ CMStringA folderId;
if (ftp->IsFolder()) {
- T2Utf folderName(ftp->GetFolderName());
+ CMStringA folderName(T2Utf(ftp->GetFolderName()).get());
- char path[MAX_PATH];
+ CMStringA path;
PreparePath(folderName, path);
CreateFolder(path, folderId);
- char link[MAX_PATH];
+ CMStringA link;
CreateSharedLink(path, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
ftp->AddSharedLink(link);
}
ftp->FirstFile();
- do
- {
+ do {
T2Utf fileName(ftp->GetCurrentRelativeFilePath());
uint64_t fileSize = ftp->GetCurrentFileSize();
- char fileId[32];
-
size_t chunkSize = ftp->GetCurrentFileChunkSize();
mir_ptr<char>chunk((char*)mir_calloc(chunkSize));
-
- if (chunkSize == fileSize)
- {
+
+ CMStringA fileId;
+ if (chunkSize == fileSize) {
ftp->CheckCurrentFile();
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
@@ -254,8 +246,7 @@ UINT COneDriveService::Upload(FileTransferParam *ftp)
ftp->Progress(size);
}
- else
- {
+ else {
char uploadUri[1024];
CreateUploadSession(uploadUri, T2Utf(fileName), folderId);
@@ -273,7 +264,7 @@ UINT COneDriveService::Upload(FileTransferParam *ftp)
}
if (!ftp->IsFolder()) {
- char link[MAX_PATH];
+ CMStringA link;
CreateSharedLink(fileId, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
ftp->AddSharedLink(link);
diff --git a/plugins/CloudFile/src/Services/microsoft_service.h b/plugins/CloudFile/src/Services/microsoft_service.h
index 32df62c451..03c3ea2585 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, char *fileId);
- void CreateUploadSession(const char *parentId, const char *name, char *uploadUri);
- void UploadFileChunk(const char *uploadUri, const char *chunk, size_t chunkSize, uint64_t offset, uint64_t fileSize, char *fileId);
- void CreateFolder(const char *path, char *folderId);
- void CreateSharedLink(const char *itemId, char *url);
+ 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);
public:
COneDriveService(const char *protoName, const wchar_t *userName);
diff --git a/plugins/CloudFile/src/Services/yandex_service.cpp b/plugins/CloudFile/src/Services/yandex_service.cpp
index 0709419cdd..b87cfaff5c 100644
--- a/plugins/CloudFile/src/Services/yandex_service.cpp
+++ b/plugins/CloudFile/src/Services/yandex_service.cpp
@@ -124,7 +124,6 @@ unsigned CYandexService::RequestAccessTokenThread(void *owner, void *param)
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
EndDialog(hwndDlg, 1);
-
return 0;
}
@@ -148,7 +147,7 @@ void CYandexService::HandleJsonError(JSONNode &node)
}
}
-void CYandexService::CreateUploadSession(const char *path, char *uploadUri)
+void CYandexService::CreateUploadSession(const char *path, CMStringA &uploadUri)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
@@ -156,8 +155,8 @@ void CYandexService::CreateUploadSession(const char *path, char *uploadUri)
NLHR_PTR response(request.Send(m_hConnection));
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("href");
- mir_strcpy(uploadUri, node.as_string().c_str());
+ if (root)
+ uploadUri = root["href"].as_string().c_str();
}
void CYandexService::UploadFile(const char *uploadUri, const char *data, size_t size)
@@ -196,7 +195,7 @@ void CYandexService::CreateFolder(const char *path)
GetJsonResponse(response);
}
-void CYandexService::CreateSharedLink(const char *path, char *url)
+void CYandexService::CreateSharedLink(const char *path, CMStringA &url)
{
ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
YandexAPI::PublishRequest publishRequest(token, path);
@@ -208,9 +207,8 @@ void CYandexService::CreateSharedLink(const char *path, char *url)
response = resourcesRequest.Send(m_hConnection);
JSONNode root = GetJsonResponse(response);
- JSONNode link = root.at("public_url");
-
- mir_strcpy(url, link.as_string().c_str());
+ if (root)
+ url = root["public_url"].as_string().c_str();
}
UINT CYandexService::Upload(FileTransferParam *ftp)
@@ -227,11 +225,11 @@ UINT CYandexService::Upload(FileTransferParam *ftp)
if (ftp->IsFolder()) {
T2Utf folderName(ftp->GetFolderName());
- char path[MAX_PATH];
+ CMStringA path;
PreparePath(folderName, path);
CreateFolder(path);
- char link[MAX_PATH];
+ CMStringA link;
CreateSharedLink(path, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
ftp->AddSharedLink(link);
@@ -243,10 +241,10 @@ UINT CYandexService::Upload(FileTransferParam *ftp)
T2Utf fileName(ftp->GetCurrentRelativeFilePath());
uint64_t fileSize = ftp->GetCurrentFileSize();
- char path[MAX_PATH];
+ CMStringA path;
PreparePath(fileName, path);
- char uploadUri[1024];
+ CMStringA uploadUri;
CreateUploadSession(path, uploadUri);
size_t chunkSize = ftp->GetCurrentFileChunkSize();
@@ -276,7 +274,7 @@ UINT CYandexService::Upload(FileTransferParam *ftp)
}
if (!ftp->IsFolder()) {
- char link[MAX_PATH];
+ CMStringA link;
CreateSharedLink(path, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
ftp->AddSharedLink(link);
diff --git a/plugins/CloudFile/src/Services/yandex_service.h b/plugins/CloudFile/src/Services/yandex_service.h
index 9c40408d5b..2971d6beec 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, char *uploadUri);
+ 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, char *url);
+ void CreateSharedLink(const char *path, CMStringA &url);
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 ed265f71aa..9e40ac3db0 100644
--- a/plugins/CloudFile/src/cloud_file.cpp
+++ b/plugins/CloudFile/src/cloud_file.cpp
@@ -70,19 +70,17 @@ void CCloudService::Report(MCONTACT hContact, const wchar_t *data)
PasteToClipboard(data);
}
-char* CCloudService::PreparePath(const char *oldPath, char *newPath)
+const char* CCloudService::PreparePath(const char *oldPath, CMStringA &newPath)
{
if (oldPath == nullptr)
- mir_strcpy(newPath, "");
- else if (*oldPath != '/')
- {
- CMStringA result("/");
- result.Append(oldPath);
- result.Replace("\\", "/");
- mir_strcpy(newPath, result);
+ newPath = "";
+ else if (*oldPath != '/') {
+ newPath = "/";
+ newPath.Append(oldPath);
+ newPath.Replace("\\", "/");
}
- else
- mir_strcpy(newPath, oldPath);
+ else newPath = oldPath;
+
return newPath;
}
diff --git a/plugins/CloudFile/src/cloud_file.h b/plugins/CloudFile/src/cloud_file.h
index ebf6a6c6fe..5aac068aa6 100644
--- a/plugins/CloudFile/src/cloud_file.h
+++ b/plugins/CloudFile/src/cloud_file.h
@@ -15,7 +15,7 @@ protected:
HNETLIBUSER m_hConnection;
// utils
- char* PreparePath(const char *oldPath, char *newPath);
+ const char* PreparePath(const char *oldPath, CMStringA &newPath);
virtual char* HttpStatusToError(int status = 0);
virtual void HttpResponseToError(NETLIBHTTPREQUEST *response);