summaryrefslogtreecommitdiff
path: root/plugins/CloudFile/src/services.cpp
blob: d95b2aee94f8f8ac594e342ac2a4d8add79e0f54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "stdafx.h"

static int CompareServices(const CCloudService *p1, const CCloudService *p2)
{
	return mir_strcmp(p1->GetAccountName(), p2->GetAccountName());
}

LIST<CCloudService> Services(10, CompareServices);

static INT_PTR GetServiceCount(WPARAM, LPARAM)
{
	return Services.getCount();
}

static INT_PTR GetService(WPARAM wParam, LPARAM lParam)
{
	ptrA accountName(mir_strdup((char*)wParam));
	if (!accountName || !mir_strlen(accountName))
		accountName = db_get_sa(NULL, MODULE, "DefaultService");
	if (accountName == nullptr)
		return 1;
	CCloudServiceSearch search(accountName);
	CCloudService *service = Services.find(&search);
	if (service == nullptr)
		return 2;
	CFSERVICEINFO *info = (CFSERVICEINFO*)lParam;
	if (info != nullptr) {
		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;
}

void InitServices()
{
	PROTOCOLDESCRIPTOR pd = { sizeof(pd) };
	pd.type = PROTOTYPE_PROTOCOL;

	pd.szName = MODULE "/Dropbox";
	pd.fnInit = (pfnInitProto)CDropboxService::Init;
	pd.fnUninit = (pfnUninitProto)CDropboxService::UnInit;
	Proto_RegisterModule(&pd);

	pd.szName = MODULE "/GDrive";
	pd.fnInit = (pfnInitProto)CGDriveService::Init;
	pd.fnUninit = (pfnUninitProto)CGDriveService::UnInit;
	Proto_RegisterModule(&pd);

	pd.szName = MODULE "/OneDrivre";
	pd.fnInit = (pfnInitProto)COneDriveService::Init;
	pd.fnUninit = (pfnUninitProto)COneDriveService::UnInit;
	Proto_RegisterModule(&pd);

	pd.szName = MODULE "/YandexDisk";
	pd.fnInit = (pfnInitProto)CYandexService::Init;
	pd.fnUninit = (pfnUninitProto)CYandexService::UnInit;
	Proto_RegisterModule(&pd);

	pd.szName = MODULE;
	pd.type = PROTOTYPE_FILTER;
	Proto_RegisterModule(&pd);

	CreateServiceFunction(MODULE PSS_FILE, &CCloudService::SendFileInterceptor);

	CreateServiceFunction(MS_CLOUDFILE_GETSERVICE, GetService);
	CreateServiceFunction(MS_CLOUDFILE_ENUMSERVICES, EnumServices);
}