summaryrefslogtreecommitdiff
path: root/protocols/CloudFile/src/services.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-03-02 12:32:44 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-03-02 12:32:55 +0300
commit931a7dc1ac0dbc7e6c1083583ced915e572f5b47 (patch)
tree9fe9a6448d44030e26aa7107ce16044ed413e0d0 /protocols/CloudFile/src/services.cpp
parentdd7d9954042254e66e3bbbec7195c6be8b1a0663 (diff)
all protocols (even virtual ones) moved to the Protocols folder
Diffstat (limited to 'protocols/CloudFile/src/services.cpp')
-rw-r--r--protocols/CloudFile/src/services.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/protocols/CloudFile/src/services.cpp b/protocols/CloudFile/src/services.cpp
new file mode 100644
index 0000000000..e0a01fbfba
--- /dev/null
+++ b/protocols/CloudFile/src/services.cpp
@@ -0,0 +1,106 @@
+#include "stdafx.h"
+
+static int CompareServices(const CCloudService *p1, const CCloudService *p2)
+{
+ return mir_strcmp(p1->GetAccountName(), p2->GetAccountName());
+}
+
+LIST<CCloudService> Services(10, CompareServices);
+
+CCloudService* FindService(const char *szProto)
+{
+ for (auto &it : Services)
+ if (!mir_strcmp(it->GetAccountName(), szProto))
+ return it;
+
+ return nullptr;
+}
+
+static INT_PTR GetService(WPARAM wParam, LPARAM lParam)
+{
+ CFSERVICEINFO *info = (CFSERVICEINFO*)lParam;
+ if (info == nullptr)
+ return 1;
+
+ ptrA accountName(mir_strdup((char*)wParam));
+ if (!accountName || !mir_strlen(accountName))
+ accountName = g_plugin.getStringA("DefaultService");
+ if (accountName == nullptr)
+ return 2;
+
+ CCloudService *service = FindService(accountName);
+ if (service == nullptr)
+ return 3;
+
+ info->accountName = service->GetAccountName();
+ info->userName = service->GetUserName();
+
+ return 0;
+}
+
+static INT_PTR EnumServices(WPARAM wParam, LPARAM lParam)
+{
+ CFSERVICEINFO info = {};
+ enumCFServiceFunc enumFunc = (enumCFServiceFunc)wParam;
+ void *param = (void*)lParam;
+
+ for (auto &service : Services) {
+ info.accountName = service->GetAccountName();
+ info.userName = service->GetUserName();
+ int res = enumFunc(&info, param);
+ if (res != 0)
+ return res;
+ }
+
+ return 0;
+}
+
+INT_PTR Upload(WPARAM wParam, LPARAM lParam)
+{
+ CFUPLOADDATA *uploadData = (CFUPLOADDATA*)wParam;
+ if (uploadData == nullptr)
+ return 1;
+
+ ptrA accountName(mir_strdup(uploadData->accountName));
+ if (!mir_strlen(accountName))
+ accountName = g_plugin.getStringA("DefaultService");
+ if (accountName == nullptr)
+ return 2;
+
+ CCloudService *service = FindService(uploadData->accountName);
+ if (service == nullptr)
+ return 3;
+
+ if (PathIsDirectory(uploadData->localPath)) {
+ // temporary unsupported
+ return 4;
+ }
+
+ FileTransferParam ftp(0);
+ ftp.SetWorkingDirectory(uploadData->localPath);
+ ftp.SetServerDirectory(uploadData->serverFolder);
+ ftp.AddFile(uploadData->localPath);
+
+ int res = CCloudService::Upload(service, &ftp);
+ if (res == ACKRESULT_SUCCESS && lParam) {
+ size_t linkCount = 0;
+ const char **links = ftp.GetSharedLinks(linkCount);
+ if (linkCount > 0) {
+ CFUPLOADRESULT *result = (CFUPLOADRESULT*)lParam;
+ result->link = mir_strdup(links[linkCount - 1]);
+ }
+ }
+
+ return res;
+}
+
+void InitializeServices()
+{
+ Proto_RegisterModule(PROTOTYPE_FILTER, MODULENAME);
+
+ CreateServiceFunction(MODULENAME PSS_FILE, SendFileInterceptor);
+
+ CreateServiceFunction(MS_CLOUDFILE_GETSERVICE, GetService);
+ CreateServiceFunction(MS_CLOUDFILE_ENUMSERVICES, EnumServices);
+ CreateServiceFunction(MS_CLOUDFILE_UPLOAD, Upload);
+}