summaryrefslogtreecommitdiff
path: root/plugins/Dropbox/src/dropbox.h
blob: 6da80d85f44d6dafad64cb14e2705d5ebcd2d0a7 (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
#ifndef _DROPBOX_PROTO_H_
#define _DROPBOX_PROTO_H_

#include "http_request.h"
#include "file_transfer.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 "..\..\..\miranda-private-keys\Dropbox\secret_key.h"

#define DROPBOX_FILE_CHUNK_SIZE 4 * 1024 * 1024 //4 MB

#define BBB_ID_FILE_SEND 10001

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

class CDropbox : public MZeroedObject
{
	struct CommandParam
	{
		CDropbox *instance;
		HANDLE hProcess;
		MCONTACT hContact;
		void *data;
	};

public:
	CDropbox();
	virtual ~CDropbox();

private:
	HANDLE hNetlibConnection;
	ULONG  hFileProcess;
	ULONG  hMessageProcess;

	HANDLE hFileSentEventHook;

	MCONTACT hDefaultContact;
	MCONTACT hTransferContact;
	HWND     hTransferWindow;

	HGENMENU contactMenuItems[CMI_MAX];

	// hooks
	static int OnProtoAck(void *obj, WPARAM wParam, LPARAM lParam);
	static int OnPreShutdown(void *obj, WPARAM wParam, LPARAM lParam);
	static int OnModulesLoaded(void *obj, WPARAM wParam, LPARAM lParam);
	static int OnContactDeleted(void *obj, WPARAM wParam, LPARAM lParam);
	static int OnOptionsInitialized(void *obj, WPARAM wParam, LPARAM lParam);
	static int OnPrebuildContactMenu(void *obj, WPARAM wParam, LPARAM lParam);
	static int OnSrmmWindowOpened(void *obj, WPARAM wParam, LPARAM lParam);
	static int OnTabSrmmButtonPressed(void *obj, WPARAM wParam, LPARAM lParam);
	static int OnFileDialogCancelled(void *obj, WPARAM wParam, LPARAM lParam);
	static int OnFileDialogSuccessed(void *obj, WPARAM wParam, LPARAM lParam);

	// services
	static HANDLE CreateProtoServiceFunctionObj(const char *szService, MIRANDASERVICEOBJ serviceProc, void *obj);

	static INT_PTR ProtoGetCaps(WPARAM wParam, LPARAM lParam);
	static INT_PTR ProtoGetName(WPARAM wParam, LPARAM lParam);
	static INT_PTR ProtoLoadIcon(WPARAM wParam, LPARAM lParam);
	static INT_PTR ProtoGetStatus(WPARAM wParam, LPARAM lParam);
	static INT_PTR ProtoSetStatus(void *obj, WPARAM wParam, LPARAM lParam);
	static INT_PTR ProtoSendFile(void *obj, WPARAM wParam, LPARAM lParam);
	static INT_PTR ProtoSendMessage(void *obj, WPARAM wParam, LPARAM lParam);
	static INT_PTR ProtoReceiveMessage(void *obj, WPARAM wParam, LPARAM lParam);

	static INT_PTR SendFileToDropbox(void *obj, WPARAM wParam, LPARAM lParam);

	// commands
	static void CommandHelp(void *arg);
	static void CommandContent(void *arg);
	static void CommandShare(void *arg);
	static void CommandDelete(void *arg);

	// access token
	bool HasAccessToken();

	void RequestAccessToken();
	void DestroyAccessToken();

	static UINT RequestAccessTokenAsync(void *owner, void *param);

	// account info
	void RequestAccountInfo();

	// transfers
	void SendFile(const char *fileName, const char *data, int length);
	void SendFileChunkedFirst(const char *data, int length, char *uploadId, size_t &offset);
	void SendFileChunkedNext(const char *data, int length, const char *uploadId, size_t &offset);
	void SendFileChunkedLast(const char *fileName, const char *uploadId);

	void CreateFolder(const char *folderName);

	void CreateDownloadUrl(const char *path, char *url);

	static UINT SendFilesAsync(void *owner, void *arg);
	static UINT SendFilesAndEventAsync(void *owner, void *arg);
	static UINT SendFilesAndReportAsync(void *owner, void *arg);

	// contacts
	MCONTACT GetDefaultContact();

	// menus
	void InitializeMenus();
	static void Menu_DisableItem(HGENMENU hMenuItem, BOOL bDisable);

	static INT_PTR SendFilesToDropboxCommand(void *obj, WPARAM wParam, LPARAM lParam);

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

	// SRMM
	static void DisableSrmmButton(MCONTACT hContact);

	// utils
	static char* HttpStatusToText(HTTP_STATUS status);
	static void HandleHttpResponseError(NETLIBHTTPREQUEST *response);
};

#endif //_DROPBOX_PROTO_H_