summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2018-02-24 01:15:27 +0300
committeraunsane <aunsane@gmail.com>2018-02-24 01:15:27 +0300
commit1785dc55c0a4cdcbc5f9788e0196e7d3a38fe53c (patch)
tree3c9fb0a2d27504f14e1ef9ffe43e2d58f4ea1085 /plugins
parent3f343c22a352462660a71806303c1f8957a85702 (diff)
CloudFile: Implement new upload services (#1144)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/CloudFile/src/Services/dropbox_service.cpp10
-rw-r--r--plugins/CloudFile/src/Services/google_service.cpp2
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.cpp2
-rw-r--r--plugins/CloudFile/src/Services/yandex_service.cpp8
-rw-r--r--plugins/CloudFile/src/file_transfer.h35
-rw-r--r--plugins/CloudFile/src/services.cpp61
-rw-r--r--plugins/CloudFile/src/transfers.cpp5
-rw-r--r--plugins/CloudFile/src/utils.cpp13
-rw-r--r--plugins/ExternalAPI/m_cloudfile.h33
9 files changed, 131 insertions, 38 deletions
diff --git a/plugins/CloudFile/src/Services/dropbox_service.cpp b/plugins/CloudFile/src/Services/dropbox_service.cpp
index 72b544a232..16a9ee659f 100644
--- a/plugins/CloudFile/src/Services/dropbox_service.cpp
+++ b/plugins/CloudFile/src/Services/dropbox_service.cpp
@@ -231,6 +231,7 @@ UINT CDropboxService::Upload(FileTransferParam *ftp)
char link[MAX_PATH];
CreateSharedLink(path, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
+ ftp->AddSharedLink(link);
}
ftp->FirstFile();
@@ -294,9 +295,10 @@ UINT CDropboxService::Upload(FileTransferParam *ftp)
}
if (!ftp->IsFolder()) {
- char url[MAX_PATH];
- CreateSharedLink(path, url);
- ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(url)));
+ char link[MAX_PATH];
+ CreateSharedLink(path, link);
+ ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
+ ftp->AddSharedLink(link);
}
} while (ftp->NextFile());
}
@@ -340,4 +342,4 @@ INT_PTR CDropboxService::UploadToDropbox(void *obj, WPARAM wParam, LPARAM lParam
delete ftp;
return res;
-}
+} \ No newline at end of file
diff --git a/plugins/CloudFile/src/Services/google_service.cpp b/plugins/CloudFile/src/Services/google_service.cpp
index a15056b884..3877506b0f 100644
--- a/plugins/CloudFile/src/Services/google_service.cpp
+++ b/plugins/CloudFile/src/Services/google_service.cpp
@@ -246,6 +246,7 @@ UINT CGDriveService::Upload(FileTransferParam *ftp)
CreateSharedLink(folderId, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
+ ftp->AddSharedLink(link);
}
ftp->FirstFile();
@@ -290,6 +291,7 @@ UINT CGDriveService::Upload(FileTransferParam *ftp)
char link[MAX_PATH];
CreateSharedLink(fileId, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
+ ftp->AddSharedLink(link);
}
} while (ftp->NextFile());
}
diff --git a/plugins/CloudFile/src/Services/microsoft_service.cpp b/plugins/CloudFile/src/Services/microsoft_service.cpp
index 3b2f52a073..ec211f1244 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.cpp
+++ b/plugins/CloudFile/src/Services/microsoft_service.cpp
@@ -231,6 +231,7 @@ UINT COneDriveService::Upload(FileTransferParam *ftp)
char link[MAX_PATH];
CreateSharedLink(path, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
+ ftp->AddSharedLink(link);
}
ftp->FirstFile();
@@ -275,6 +276,7 @@ UINT COneDriveService::Upload(FileTransferParam *ftp)
char link[MAX_PATH];
CreateSharedLink(fileId, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
+ ftp->AddSharedLink(link);
}
} while (ftp->NextFile());
}
diff --git a/plugins/CloudFile/src/Services/yandex_service.cpp b/plugins/CloudFile/src/Services/yandex_service.cpp
index 8a246fa59f..cf4c5786e0 100644
--- a/plugins/CloudFile/src/Services/yandex_service.cpp
+++ b/plugins/CloudFile/src/Services/yandex_service.cpp
@@ -234,6 +234,7 @@ UINT CYandexService::Upload(FileTransferParam *ftp)
char link[MAX_PATH];
CreateSharedLink(path, link);
ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
+ ftp->AddSharedLink(link);
}
ftp->FirstFile();
@@ -275,9 +276,10 @@ UINT CYandexService::Upload(FileTransferParam *ftp)
}
if (!ftp->IsFolder()) {
- char url[MAX_PATH];
- CreateSharedLink(path, url);
- ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(url)));
+ char link[MAX_PATH];
+ CreateSharedLink(path, link);
+ ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(link)));
+ ftp->AddSharedLink(link);
}
} while (ftp->NextFile());
}
diff --git a/plugins/CloudFile/src/file_transfer.h b/plugins/CloudFile/src/file_transfer.h
index cbe928eda9..ab83d7db2e 100644
--- a/plugins/CloudFile/src/file_transfer.h
+++ b/plugins/CloudFile/src/file_transfer.h
@@ -18,9 +18,12 @@ private:
int relativePathStart;
CMStringW data;
+ LIST<char> m_links;
+ CMStringW m_description;
public:
FileTransferParam(MCONTACT hContact)
+ : m_links(1)
{
hFile = NULL;
id = InterlockedIncrement(&hFileProcess);
@@ -55,14 +58,15 @@ public:
if (pfts.tszWorkingDir)
mir_free(pfts.tszWorkingDir);
- if (pfts.pszFiles)
- {
+ if (pfts.pszFiles) {
for (int i = 0; pfts.pszFiles[i]; i++)
- {
if (pfts.pszFiles[i]) mir_free(pfts.pszFiles[i]);
- }
mir_free(pfts.pszFiles);
}
+
+ for (auto &link : m_links)
+ mir_free(link);
+ m_links.destroy();
}
ULONG GetId() const
@@ -70,7 +74,7 @@ public:
return id;
}
- MCONTACT GetHContact() const
+ MCONTACT GetContact() const
{
return pfts.hContact;
}
@@ -82,6 +86,17 @@ public:
return data;
}
+ const wchar_t* GetDescription() const
+ {
+ return m_description.GetString();
+ }
+
+ const int GetSharedLinks(const char **result) const
+ {
+ result = (const char**)m_links.getArray();
+ return m_links.getCount();
+ }
+
void Terminate()
{
isTerminated = true;
@@ -100,6 +115,11 @@ public:
return serverFolder;
}
+ void SetDescription(const wchar_t *description)
+ {
+ m_description = description;
+ }
+
void SetWorkingDirectory(const wchar_t *path)
{
relativePathStart = wcsrchr(path, '\\') - path + 1;
@@ -141,6 +161,11 @@ public:
va_end(args);
}
+ void AddSharedLink(const char *url)
+ {
+ m_links.insert(mir_strdup(url));
+ }
+
const wchar_t* GetCurrentFilePath() const
{
return pfts.ptszFiles[pfts.currentFileNumber];
diff --git a/plugins/CloudFile/src/services.cpp b/plugins/CloudFile/src/services.cpp
index d95b2aee94..76f35938b4 100644
--- a/plugins/CloudFile/src/services.cpp
+++ b/plugins/CloudFile/src/services.cpp
@@ -18,15 +18,15 @@ static INT_PTR GetService(WPARAM wParam, LPARAM lParam)
if (!accountName || !mir_strlen(accountName))
accountName = db_get_sa(NULL, MODULE, "DefaultService");
if (accountName == nullptr)
- return 1;
+ return 2;
CCloudServiceSearch search(accountName);
CCloudService *service = Services.find(&search);
if (service == nullptr)
- return 2;
+ return 3;
CFSERVICEINFO *info = (CFSERVICEINFO*)lParam;
if (info != nullptr) {
- info->AccountName = service->GetAccountName();
- info->UserName = service->GetUserName();
+ info->accountName = service->GetAccountName();
+ info->userName = service->GetUserName();
}
return 0;
}
@@ -37,8 +37,8 @@ static INT_PTR EnumServices(WPARAM wParam, LPARAM lParam)
enumCFServiceFunc enumFunc = (enumCFServiceFunc)wParam;
void *param = (void*)lParam;
for (auto &service : Services) {
- info.AccountName = service->GetAccountName();
- info.UserName = service->GetUserName();
+ info.accountName = service->GetAccountName();
+ info.userName = service->GetUserName();
int res = enumFunc(&info, param);
if (res != 0)
return res;
@@ -46,6 +46,54 @@ static INT_PTR EnumServices(WPARAM wParam, LPARAM lParam)
return 0;
}
+INT_PTR Upload(WPARAM wParam, LPARAM lParam)
+{
+ CFUPLOADDATA *uploadData = (CFUPLOADDATA*)wParam;
+ if (uploadData == nullptr)
+ return 1;
+
+ ptrA accountName(mir_strdup((char*)wParam));
+ if (!accountName || !mir_strlen(uploadData->accountName))
+ accountName = db_get_sa(NULL, MODULE, "DefaultService");
+ if (accountName == nullptr)
+ return 2;
+ CCloudServiceSearch search(uploadData->accountName);
+ CCloudService *service = Services.find(&search);
+ if (service == nullptr)
+ return 3;
+
+ FileTransferParam *ftp = new FileTransferParam(0);
+ ftp->SetWorkingDirectory(uploadData->localPath);
+ ftp->SetServerFolder(uploadData->serverFolder);
+
+ if (PathIsDirectory(uploadData->localPath))
+ {
+ // temporary unsupported
+ Transfers.remove(ftp);
+ delete ftp;
+
+ return ACKRESULT_FAILED;
+ }
+ else
+ ftp->AddFile(uploadData->localPath);
+
+ int res = service->Upload(ftp);
+ if (res == ACKRESULT_SUCCESS && lParam) {
+ CFUPLOADRESULT *result = (CFUPLOADRESULT*)lParam;
+ const char **links = nullptr;
+ int linkCount = ftp->GetSharedLinks(links);
+ result->links = (char**)mir_calloc(sizeof(char*) * linkCount);
+ for (int i = 0; i < linkCount; i++)
+ result->links[i] = mir_strdup(links[i]);
+ result->description = mir_wstrdup(ftp->GetDescription());
+ }
+
+ Transfers.remove(ftp);
+ delete ftp;
+
+ return res;
+}
+
void InitServices()
{
PROTOCOLDESCRIPTOR pd = { sizeof(pd) };
@@ -79,4 +127,5 @@ void InitServices()
CreateServiceFunction(MS_CLOUDFILE_GETSERVICE, GetService);
CreateServiceFunction(MS_CLOUDFILE_ENUMSERVICES, EnumServices);
+ CreateServiceFunction(MS_CLOUDFILE_UPLOAD, Upload);
} \ No newline at end of file
diff --git a/plugins/CloudFile/src/transfers.cpp b/plugins/CloudFile/src/transfers.cpp
index 7ffcc4e7ef..b72c934abb 100644
--- a/plugins/CloudFile/src/transfers.cpp
+++ b/plugins/CloudFile/src/transfers.cpp
@@ -28,8 +28,7 @@ HANDLE CCloudService::SendFile(MCONTACT hContact, const wchar_t *description, wc
{
FileTransferParam *ftp = new FileTransferParam(hContact);
- if (description && description[0])
- ftp->AppendFormatData(L"%s\r\n", description);
+ ftp->SetDescription(description);
ftp->SetWorkingDirectory(paths[0]);
for (int i = 0; paths[i]; i++) {
@@ -68,7 +67,7 @@ UINT UploadAndReportProgressThread(void *owner, void *arg)
int res = service->Upload(ftp);
if (res == ACKRESULT_SUCCESS)
- service->Report(ftp->GetHContact(), ftp->GetData());
+ service->Report(ftp->GetContact(), ftp->GetData());
Transfers.remove(ftp);
delete ftp;
diff --git a/plugins/CloudFile/src/utils.cpp b/plugins/CloudFile/src/utils.cpp
index 44a3149a25..24559827ef 100644
--- a/plugins/CloudFile/src/utils.cpp
+++ b/plugins/CloudFile/src/utils.cpp
@@ -3,12 +3,9 @@
void ShowNotification(const wchar_t *caption, const wchar_t *message, int flags, MCONTACT hContact)
{
if (Miranda_IsTerminated())
- {
return;
- }
- if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1))
- {
+ if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) {
POPUPDATAT ppd = { 0 };
ppd.lchContact = hContact;
wcsncpy(ppd.lpwzContactName, caption, MAX_CONTACTNAME);
@@ -91,11 +88,9 @@ void PasteToClipboard(const wchar_t *data)
HGLOBAL hClipboardData = GlobalAlloc(NULL, size);
if (hClipboardData) {
wchar_t *pchData = (wchar_t*)GlobalLock(hClipboardData);
- if (pchData) {
- memcpy(pchData, (wchar_t*)data, size);
- GlobalUnlock(hClipboardData);
- SetClipboardData(CF_UNICODETEXT, hClipboardData);
- }
+ mir_wstrcpy(pchData, data);
+ GlobalUnlock(hClipboardData);
+ SetClipboardData(CF_UNICODETEXT, hClipboardData);
}
CloseClipboard();
}
diff --git a/plugins/ExternalAPI/m_cloudfile.h b/plugins/ExternalAPI/m_cloudfile.h
index 8824227e3a..9207546c23 100644
--- a/plugins/ExternalAPI/m_cloudfile.h
+++ b/plugins/ExternalAPI/m_cloudfile.h
@@ -1,17 +1,15 @@
#ifndef M_CLOUDFILE_H_
#define M_CLOUDFILE_H_
-#define MIID_DROPBOX {0x9649d8e2, 0x7326, 0x4ec1, {0xb4, 0xa3, 0xf2, 0xec, 0x1a, 0x39, 0x84, 0x94}}
-
struct CFSERVICEINFO
{
- const char *AccountName;
- const wchar_t *UserName;
+ const char *accountName;
+ const wchar_t *userName;
};
// get cloud file service info by account name
-// wParam = (WPARAM)(const char*)accountName
-// lParam = (LPARAM)(CFSERVICEINFO*)serviceInfo
+// wParam = (WPARAM)(const char*)accountName (can be NULL)
+// lParam = (LPARAM)(CFSERVICEINFO*)serviceInfo (can be NULL)
// returns 0 on success, nonzero on failure
#define MS_CLOUDFILE_GETSERVICE "CloudFile/GetService"
@@ -19,9 +17,28 @@ struct CFSERVICEINFO
typedef int(*enumCFServiceFunc)(const CFSERVICEINFO *serviceInfo, void *param);
// get list of cloud file services
-// wParam = (WPARAM)(void*)param
-// lParam = (LPARAM)(enumCFServiceFunc)enumFunc
+// wParam = (WPARAM)(enumCFServiceFunc)enumFunc
+// lParam = (LPARAM)(void*)param (can be NULL)
// returns 0 on success, nonzero on failure
#define MS_CLOUDFILE_ENUMSERVICES "CloudFile/EnumServices"
+struct CFUPLOADDATA
+{
+ const char *accountName; // cloud service to upload (can be NULL)
+ const wchar_t *localPath; // local path
+ const wchar_t *serverFolder; // server folder in witch file will be placed (can be NULL)
+};
+
+struct CFUPLOADRESULT
+{
+ char **links;
+ wchar_t *description;
+};
+
+// upload file on cloud service
+// wParam = (WPARAM)(const CFUPLOADDATA*)uploadData
+// lParam = (LPARAM)(char CFUPLOADRESULT*)uploadResult (can be NULL)
+// returns 0 on success, nonzero on failure
+#define MS_CLOUDFILE_UPLOAD "CloudFile/Upload"
+
#endif //M_CLOUDFILE_H_ \ No newline at end of file