summaryrefslogtreecommitdiff
path: root/plugins/Dropbox/src/dropbox.h
blob: c2aed06ec814fafba5cdf16823e3494bf152c9c3 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#ifndef _DROPBOX_PROTO_H_
#define _DROPBOX_PROTO_H_

#include "singleton.h"
#include "http_request.h"

#define DROPBOX_API_VER "1"
#define DROPBOX_API_ROOT "sandbox"
#define DROPBOX_WWW_URL "https://www.dropbox.com/"
#define DROPBOX_API_URL "https://api.dropbox.com/" DROPBOX_API_VER
#define DROPBOX_APICONTENT_URL "https://api-content.dropbox.com/" DROPBOX_API_VER

#define DROPBOX_API_KEY "fa8du7gkf2q8xzg"
#include "..\..\..\Dropbox\secret_key.h"

#define DROPBOX_FILE_CHUNK_SIZE 1024 * 1024 //1 MB

enum
{
	CMI_API_ACCESS_REQUERIED,
	CMI_MAX   // this item shall be the last one
};

struct FileTransferParam
{
	HANDLE hProcess;
	PROTOFILETRANSFERSTATUS pfts;

	int totalFolders;
	char **pszFolders;
	int relativePathStart;

	FileTransferParam()
	{
		totalFolders = 0;
		pszFolders = NULL;
		relativePathStart = 0;

		pfts.cbSize = sizeof(this->pfts);
		pfts.flags = PFTS_UTF;
		pfts.currentFileNumber = 0;
		pfts.currentFileProgress = 0;
		pfts.currentFileSize = 0;
		pfts.totalBytes = 0;
		pfts.totalFiles = 0;
		pfts.totalProgress = 0;
		pfts.pszFiles = NULL;
		pfts.tszWorkingDir = NULL;
		pfts.wszCurrentFile = NULL;
	}

	~FileTransferParam()
	{
		if (pfts.pszFiles)
		{
			for (int i = 0; pfts.pszFiles[i]; i++)
			{
				if (pfts.pszFiles[i]) mir_free(pfts.pszFiles[i]);
			}
			delete pfts.pszFiles;
		}

		if (pszFolders)
		{
			for (int i = 0; pszFolders[i]; i++)
			{
				if (pszFolders[i]) mir_free(pszFolders[i]);
			}
			delete pszFolders;
		}
	}
};

class CDropbox
{
public:
	void Init();
	void Uninit() { };

private:
	HANDLE hNetlibUser;
	ULONG  hFileProcess;

	static HGENMENU ContactMenuItems[CMI_MAX];

	// hooks
	static int OnModulesLoaded(WPARAM wParam, LPARAM lParam);
	static int OnOptionsInit(WPARAM wParam, LPARAM lParam);

	// services
	static INT_PTR GetCaps(WPARAM wParam, LPARAM lParam);
	static INT_PTR SendFile(WPARAM wParam, LPARAM lParam);
	static INT_PTR SendMessage(WPARAM wParam, LPARAM lParam);

	static INT_PTR RequeriedApiAccess(WPARAM wParam, LPARAM lParam);

	// access token
	static bool HasAccessToken();

	void RequestAcceessToken(MCONTACT hContact);
	void DestroyAcceessToken(MCONTACT hContact);

	static void RequeriedAccessAsync(void *arg);

	// transrers
	HttpRequest *CreateFileSendChunkedRequest(const char *data, int length);
	void SendFileChunkedFirst(const char *data, int length, char *uploadId, int &offset);
	void SendFileChunkedNext(const char *data, int length, const char *uploadId, int &offset);
	void SendFileChunkedLast(const char *fileName, const char *uploadId, MCONTACT hContact);

	void CreateFolder(const char *folderName, MCONTACT hContact);

	static void _cdecl SendFileAsync(void *arg);

	// contacts
	static MCONTACT GetDefaultContact();

	// icons
	static void InitIcons();

	// menus
	static void InitMenus();

	// dialogs
	static INT_PTR CALLBACK TokenRequestProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
	static INT_PTR CALLBACK MainOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);

	// utils
	void ShowNotification(const wchar_t *caption, const wchar_t *message, int flags = 0, MCONTACT hContact = NULL);
	void ShowNotification(const wchar_t *message, int flags = 0, MCONTACT hContact = NULL);
};

#endif //_DROPBOX_PROTO_H_