diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2014-03-07 19:41:15 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2014-03-07 19:41:15 +0000 |
commit | 3997c1912c9ef57697452f357b02b10b8f5bc6a7 (patch) | |
tree | 06003caf27213aa4bd5ecaf36992b03037c7b1b3 /plugins/Dropbox/src | |
parent | 370996a4a7ced75fe363bc1c3eb34f77f5d7aee1 (diff) |
Dropbox:
- code cleaning and reorganization
- added "/help" command
- more informative authorization request
- version bumped
git-svn-id: http://svn.miranda-ng.org/main/trunk@8456 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox/src')
-rw-r--r-- | plugins/Dropbox/src/common.h | 6 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox.cpp | 149 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox.h | 66 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_commands.cpp | 123 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_dialogs.cpp | 117 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_events.cpp | 102 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_icons.cpp | 2 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_menus.cpp | 53 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_services.cpp | 108 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_transfers.cpp | 28 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_utils.cpp | 28 | ||||
-rw-r--r-- | plugins/Dropbox/src/file_transfer.h | 9 | ||||
-rw-r--r-- | plugins/Dropbox/src/http_request.h | 18 | ||||
-rw-r--r-- | plugins/Dropbox/src/main.cpp | 48 | ||||
-rw-r--r-- | plugins/Dropbox/src/resource.h | bin | 1818 -> 954 bytes | |||
-rw-r--r-- | plugins/Dropbox/src/singleton.h | 29 | ||||
-rw-r--r-- | plugins/Dropbox/src/stdafx.cpp | 59 | ||||
-rw-r--r-- | plugins/Dropbox/src/version.h | 2 |
18 files changed, 481 insertions, 466 deletions
diff --git a/plugins/Dropbox/src/common.h b/plugins/Dropbox/src/common.h index faa1e30302..265ce1765c 100644 --- a/plugins/Dropbox/src/common.h +++ b/plugins/Dropbox/src/common.h @@ -28,10 +28,14 @@ #include "version.h"
#include "resource.h"
-#include "dropbox.h"
+
#define MODULE "Dropbox"
extern HINSTANCE g_hInstance;
+class CDropbox;
+
+#include "dropbox.h"
+
#endif //_COMMON_H_
\ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp index b52e80c166..e7dc92458c 100644 --- a/plugins/Dropbox/src/dropbox.cpp +++ b/plugins/Dropbox/src/dropbox.cpp @@ -1,46 +1,56 @@ #include "common.h"
-std::map<HWND, MCONTACT> CDropbox::dcftp;
-std::map<std::string, pThreadFunc> CDropbox::commands;
-HGENMENU CDropbox::ContactMenuItems[CMI_MAX];
-
-void CDropbox::Init()
+CDropbox::CDropbox()
{
PROTOCOLDESCRIPTOR pd = { PROTOCOLDESCRIPTOR_V3_SIZE };
pd.szName = MODULE;
pd.type = PROTOTYPE_VIRTUAL;
CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM)&pd);
- HookEvent(ME_OPT_INITIALISE, OnOptionsInit);
- HookEvent(ME_SYSTEM_PRESHUTDOWN, OnPreShutdown);
- HookEvent(ME_SYSTEM_MODULESLOADED, CDropbox::OnModulesLoaded);
- HookEvent(ME_DB_CONTACT_DELETED, CDropbox::OnContactDeleted);
- HookEvent(ME_CLIST_PREBUILDCONTACTMENU, CDropbox::OnPrebuildContactMenu);
+ HookEventObj(ME_SYSTEM_PRESHUTDOWN, OnPreShutdown, this);
+ HookEventObj(ME_SYSTEM_MODULESLOADED, OnModulesLoaded, this);
+ HookEventObj(ME_DB_CONTACT_DELETED, OnContactDeleted, this);
+ HookEventObj(ME_OPT_INITIALISE, OnOptionsInitialized, this);
+ HookEventObj(ME_CLIST_PREBUILDCONTACTMENU, OnPrebuildContactMenu, this);
- CreateProtoServiceFunction(MODULE, PS_GETCAPS, CDropbox::ProtoGetCaps);
- CreateProtoServiceFunction(MODULE, PSS_FILE, CDropbox::ProtoSendFile);
- CreateProtoServiceFunction(MODULE, PSS_MESSAGE, CDropbox::ProtoSendMessage);
- CreateProtoServiceFunction(MODULE, PSR_MESSAGE, CDropbox::ProtoReceiveMessage);
+ CreateProtoServiceFunction(MODULE, PS_GETCAPS, ProtoGetCaps);
+ CreateProtoServiceFunctionObj(PSS_FILE, ProtoSendFile, this);
+ CreateProtoServiceFunctionObj(PSS_MESSAGE, ProtoSendMessage, this);
+ CreateProtoServiceFunctionObj(PSR_MESSAGE, ProtoReceiveMessage, this);
- InitIcons();
- InitMenus();
+ InitializeIcons();
+ InitializeMenus();
+ commands["help"] = CDropbox::CommandHelp;
commands["content"] = CDropbox::CommandContent;
commands["share"] = CDropbox::CommandShare;
commands["delete"] = CDropbox::CommandDelete;
- hContactTransfer = 0;
hFileProcess = hMessageProcess = 1;
+ hDefaultContact = hTransferContact = 0;
}
-MCONTACT CDropbox::hContactDefault = 0;
-
MCONTACT CDropbox::GetDefaultContact()
{
- if (!hContactDefault)
- hContactDefault = db_find_first(MODULE);
+ if (!hDefaultContact)
+ hDefaultContact = db_find_first(MODULE);
+
+ if (!hDefaultContact)
+ {
+ hDefaultContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
+ if (!CallService(MS_PROTO_ADDTOCONTACT, hDefaultContact, (LPARAM)MODULE))
+ {
+ db_set_s(NULL, MODULE, "Nick", MODULE);
+ db_set_s(hDefaultContact, MODULE, "Nick", MODULE);
+ db_set_ws(hDefaultContact, "CList", "MyHandle", L"Dropbox");
- return hContactDefault;
+ int status = db_get_w(hDefaultContact, MODULE, "Status", ID_STATUS_OFFLINE);
+ if (HasAccessToken() && status == ID_STATUS_OFFLINE)
+ db_set_w(hDefaultContact, MODULE, "Status", ID_STATUS_ONLINE);
+ }
+ }
+
+ return hDefaultContact;
}
bool CDropbox::HasAccessToken()
@@ -57,7 +67,7 @@ void CDropbox::RequestAcceessToken() if (DialogBoxParam(
g_hInstance,
MAKEINTRESOURCE(IDD_TOKEN_REQUEST),
- NULL,
+ NULL,
CDropbox::TokenRequestProc,
(LPARAM)&request_token) == IDOK)
{
@@ -85,7 +95,7 @@ void CDropbox::RequestAcceessToken() JSONNODE *root = json_parse(response->pData);
if (root)
{
- if (response->resultCode == HTTP_STATUS::OK)
+ if (response->resultCode == HTTP_STATUS_OK)
{
JSONNODE *node = json_get(root, "access_token");
ptrA access_token = ptrA(mir_u2a(json_as_string(node)));
@@ -130,27 +140,82 @@ void CDropbox::DestroyAcceessToken() }
}
-void CDropbox::RequestApiAuthorizationAsync(void *arg)
+UINT CDropbox::RequestAcceessTokenAsync(void *owner, void* param)
{
- if (HasAccessToken() && MessageBox(
- NULL,
- TranslateT("Are you sure you want to request authorization?"),
- TranslateT("Request authorization"),
- MB_YESNO | MB_ICONQUESTION) == IDYES)
+ HWND hwndDlg = (HWND)param;
+ CDropbox *instance = (CDropbox*)owner;
+
+ EnableWindow(GetDlgItem(hwndDlg, IDC_AUTHORIZE), FALSE);
+ SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("in process..."));
+
+ if (instance->HasAccessToken())
+ instance->DestroyAcceessToken();
+
+ char requestToken[128];
+ GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, requestToken, SIZEOF(requestToken));
+
+ char data[1024];
+ mir_snprintf(
+ data,
+ SIZEOF(data),
+ "grant_type=authorization_code&code=%s",
+ requestToken);
+
+ HttpRequest *request = new HttpRequest(instance->hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/oauth2/token");
+ request->AddBasicAuthHeader(DROPBOX_API_KEY, DROPBOX_API_SECRET);
+ request->AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ request->pData = mir_strdup(data);
+ request->dataLength = (int)strlen(data);
+
+ mir_ptr<NETLIBHTTPREQUEST> response(request->Send());
+
+ delete request;
+
+ MCONTACT hContact = instance->GetDefaultContact();
+
+ if (response)
{
- INSTANCE->DestroyAcceessToken();
- INSTANCE->RequestAcceessToken();
+ JSONNODE *root = json_parse(response->pData);
+ if (root)
+ {
+ if (response->resultCode == HTTP_STATUS_OK)
+ {
+ JSONNODE *node = json_get(root, "access_token");
+ ptrA access_token = ptrA(mir_u2a(json_as_string(node)));
+ db_set_s(NULL, MODULE, "TokenSecret", access_token);
+
+ if (hContact)
+ {
+ if (db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
+ db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE);
+ }
+
+ if (hwndDlg)
+ SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you have been authorized"));
+ else
+ ShowNotification(TranslateT("you have been authorized"), MB_ICONINFORMATION);
+ }
+ else
+ {
+ JSONNODE *node = json_get(root, "error_description");
+ ptrW error_description(json_as_string(node));
+
+ if (hwndDlg)
+ SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, error_description);
+ else
+ ShowNotification((wchar_t*)error_description, MB_ICONERROR);
+ }
+ }
}
else
- INSTANCE->RequestAcceessToken();
-}
+ {
+ if (hwndDlg)
+ SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("unknown error"));
+ else
+ HandleFileTransferError(response, hContact);
+ }
-void CDropbox::RevokeApiAuthorizationAsync(void *arg)
-{
- if (HasAccessToken() && MessageBox(
- NULL,
- TranslateT("Are you sure you want to revoke authorization?"),
- TranslateT("Revoke authorization"),
- MB_YESNO | MB_ICONQUESTION) == IDYES)
- INSTANCE->DestroyAcceessToken();
+ SetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, "");
+
+ return 0;
}
\ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h index b10d78edb0..3864dc3548 100644 --- a/plugins/Dropbox/src/dropbox.h +++ b/plugins/Dropbox/src/dropbox.h @@ -3,7 +3,6 @@ #include <map>
#include <string>
-#include "singleton.h"
#include "http_request.h"
#include "file_transfer.h"
@@ -20,18 +19,15 @@ #define BBB_ID_FILE_SEND 10001
-#define INSTANCE Singleton<CDropbox>::GetInstance()
-
enum
{
- CMI_AUTH_REQUEST,
- CMI_AUTH_REVOKE,
CMI_SEND_FILES,
CMI_MAX // this item shall be the last one
};
-struct MessageParam
+struct CommandParam
{
+ CDropbox *instance;
HANDLE hProcess;
MCONTACT hContact;
void *data;
@@ -40,56 +36,54 @@ struct MessageParam class CDropbox
{
public:
- void Init();
- void Uninit() { };
+ CDropbox();
+ virtual ~CDropbox() { }
private:
HANDLE hNetlibUser;
ULONG hFileProcess;
ULONG hMessageProcess;
- MCONTACT hContactTransfer;
+
+ MCONTACT hDefaultContact;
+ MCONTACT hTransferContact;
- static MCONTACT hContactDefault;
- static std::map<HWND, MCONTACT> dcftp;
- static std::map<std::string, pThreadFunc> commands;
+ std::map<HWND, MCONTACT> dcftp;
+ std::map<std::string, pThreadFunc> commands;
- static HGENMENU ContactMenuItems[CMI_MAX];
+ HGENMENU contactMenuItems[CMI_MAX];
// hooks
- static int OnModulesLoaded(WPARAM wParam, LPARAM lParam);
- static int OnPreShutdown(WPARAM wParam, LPARAM lParam);
- static int OnOptionsInit(WPARAM wParam, LPARAM lParam);
- static int OnContactDeleted(WPARAM wParam, LPARAM lParam);
- static int OnPrebuildContactMenu(WPARAM wParam, LPARAM);
- static int OnSrmmWindowOpened(WPARAM wParam, LPARAM);
- static int OnSrmmButtonPressed(WPARAM wParam, LPARAM);
- static int OnFileDoalogCancelled(WPARAM wParam, LPARAM);
- static int OnFileDoalogSuccessed(WPARAM wParam, LPARAM);
+ static int OnModulesLoaded(void *obj, WPARAM wParam, LPARAM lParam);
+ static int OnPreShutdown(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 OnFileDoalogCancelled(void *obj, WPARAM wParam, LPARAM lParam);
+ static int OnFileDoalogSuccessed(void *obj, WPARAM wParam, LPARAM lParam);
// services
static INT_PTR ProtoGetCaps(WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoSendFile(WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoSendMessage(WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoReceiveMessage(WPARAM wParam, LPARAM lParam);
-
- static INT_PTR RequestApiAuthorization(WPARAM wParam, LPARAM lParam);
- static INT_PTR RevokeApiAuthorization(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 SendFilesToDropbox(WPARAM wParam, LPARAM lParam);
+ static INT_PTR SendFilesToDropbox(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
- static bool HasAccessToken();
+ bool HasAccessToken();
void RequestAcceessToken();
void DestroyAcceessToken();
- static void RequestApiAuthorizationAsync(void *arg);
- static void RevokeApiAuthorizationAsync(void *arg);
+ static UINT RequestAcceessTokenAsync(void *owner, void* param);
// transrers
static int HandleFileTransferError(NETLIBHTTPREQUEST *response, MCONTACT hContact);
@@ -103,13 +97,13 @@ private: static void _cdecl SendFileAsync(void *arg);
// contacts
- static MCONTACT GetDefaultContact();
+ MCONTACT GetDefaultContact();
// icons
- static void InitIcons();
+ void InitializeIcons();
// menus
- static void InitMenus();
+ void InitializeMenus();
static void Menu_DisableItem(HGENMENU hMenuItem, BOOL bDisable);
// dialogs
@@ -117,6 +111,8 @@ private: static INT_PTR CALLBACK MainOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
// utils
+ static HANDLE CreateProtoServiceFunctionObj(const char *szService, MIRANDASERVICEOBJ serviceProc, void *obj);
+
static wchar_t *HttpStatusToText(HTTP_STATUS status);
static void ShowNotification(const wchar_t *caption, const wchar_t *message, int flags = 0, MCONTACT hContact = NULL);
diff --git a/plugins/Dropbox/src/dropbox_commands.cpp b/plugins/Dropbox/src/dropbox_commands.cpp index 10b20657d0..ff819ddc2b 100644 --- a/plugins/Dropbox/src/dropbox_commands.cpp +++ b/plugins/Dropbox/src/dropbox_commands.cpp @@ -1,8 +1,21 @@ #include "common.h"
+void CDropbox::CommandHelp(void *arg)
+{
+ CommandParam *param = (CommandParam*)arg;
+
+ CMStringA help = Translate("Dropbox supports the following commands:"); help += "\n";
+ help += "\"/content [dir]\" - "; help += Translate("shows all files in folder \"dir\" (\"dir\" can be omitted for root folder)"); help += "\n";
+ help += "\"/share <path>\" - "; help += Translate("returns download link for file or folder with specified path (\"path\" is relative from root folder)"); help += "\n";
+ help += "\"/delete <path>\" - "; help += Translate("deletes file or folder with specified path (\"path\" is relative from root folder)");
+
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help.GetBuffer());
+}
+
void CDropbox::CommandContent(void *arg)
{
- MessageParam *param = (MessageParam*)arg;
+ CommandParam *param = (CommandParam*)arg;
char *name = (char*)param->data;
@@ -10,14 +23,14 @@ void CDropbox::CommandContent(void *arg) if (name)
url.AppendFormat("/%s", name);
- HttpRequest *request = new HttpRequest(INSTANCE->hNetlibUser, REQUEST_GET, url);
+ HttpRequest *request = new HttpRequest(param->instance->hNetlibUser, REQUEST_GET, url);
request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret"));
mir_ptr<NETLIBHTTPREQUEST> response(request->Send());
delete request;
- if (response && response->resultCode == HTTP_STATUS::OK)
+ if (response && response->resultCode == HTTP_STATUS_OK)
{
CMStringA message;
@@ -25,7 +38,7 @@ void CDropbox::CommandContent(void *arg) if (root)
{
JSONNODE *node = json_get(root, "is_dir");
- bool isDir = json_as_bool(node);
+ bool isDir = json_as_bool(node) > 0;
if (!isDir)
message.AppendFormat("\"%s\" %s", name, Translate("is file"));
else
@@ -47,7 +60,7 @@ void CDropbox::CommandContent(void *arg) }
ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- CallContactService(INSTANCE->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
return;
}
@@ -58,73 +71,91 @@ void CDropbox::CommandContent(void *arg) void CDropbox::CommandShare(void *arg)
{
- MessageParam *param = (MessageParam*)arg;
+ CommandParam *param = (CommandParam*)arg;
char *name = (char*)param->data;
-
- CMStringA url = DROPBOX_API_URL "/shares/" DROPBOX_API_ROOT;
if (name)
- url.AppendFormat("/%s", name);
-
- HttpRequest *request = new HttpRequest(INSTANCE->hNetlibUser, REQUEST_POST, url);
- request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret"));
+ {
+ CMStringA url = DROPBOX_API_URL "/shares/" DROPBOX_API_ROOT;
+ if (name)
+ url.AppendFormat("/%s", name);
- mir_ptr<NETLIBHTTPREQUEST> response(request->Send());
+ HttpRequest *request = new HttpRequest(param->instance->hNetlibUser, REQUEST_POST, url);
+ request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret"));
- delete request;
+ mir_ptr<NETLIBHTTPREQUEST> response(request->Send());
- if (response && response->resultCode == HTTP_STATUS::OK)
- {
- CMStringA link;
+ delete request;
- JSONNODE *root = json_parse(response->pData);
- if (root)
+ if (response && response->resultCode == HTTP_STATUS_OK)
{
- JSONNODE *node = json_get(root, "url");
- link = mir_u2a(json_as_string(node));
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- CallContactService(INSTANCE->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)link.GetBuffer());
+ CMStringA link;
- return;
+ JSONNODE *root = json_parse(response->pData);
+ if (root)
+ {
+ JSONNODE *node = json_get(root, "url");
+ link = mir_u2a(json_as_string(node));
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)link.GetBuffer());
+
+ return;
+ }
}
}
+ else
+ {
+ CMStringA error; error.AppendFormat(Translate("\"%s\"command has invalid parameter.\nUse \"/help\" for more info."), "/share");
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());
+
+ return;
+ }
ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
}
void CDropbox::CommandDelete(void *arg)
{
- MessageParam *param = (MessageParam*)arg;
+ CommandParam *param = (CommandParam*)arg;
char *name = (char*)param->data;
+ if (name)
+ {
+ CMStringA pparam = CMStringA("root=" DROPBOX_API_ROOT "&path=") + name;
- CMStringA pparam = CMStringA("root=" DROPBOX_API_ROOT "&path=") + name;
-
- HttpRequest *request = new HttpRequest(INSTANCE->hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/fileops/delete");
- request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret"));
- request->AddHeader("Content-Type", "application/x-www-form-urlencoded");
- request->pData = mir_strdup(pparam);
- request->dataLength = pparam.GetLength();
+ HttpRequest *request = new HttpRequest(param->instance->hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/fileops/delete");
+ request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret"));
+ request->AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ request->pData = mir_strdup(pparam);
+ request->dataLength = pparam.GetLength();
- mir_ptr<NETLIBHTTPREQUEST> response(request->Send());
+ mir_ptr<NETLIBHTTPREQUEST> response(request->Send());
- delete request;
+ delete request;
- if (response && response->resultCode == HTTP_STATUS::OK)
- {
- JSONNODE *root = json_parse(response->pData);
- if (root)
+ if (response && response->resultCode == HTTP_STATUS_OK)
{
- JSONNODE *node = json_get(root, "is_deleted");
- bool isDeleted = json_as_bool(node);
- CMStringA message;
- message.AppendFormat("%s %s", name, !isDeleted ? Translate("is not deleted") : Translate("is deleted"));
- ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
- CallContactService(INSTANCE->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
-
- return;
+ JSONNODE *root = json_parse(response->pData);
+ if (root)
+ {
+ JSONNODE *node = json_get(root, "is_deleted");
+ bool isDeleted = json_as_bool(node) > 0;
+ CMStringA message;
+ message.AppendFormat("%s %s", name, !isDeleted ? Translate("is not deleted") : Translate("is deleted"));
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
+
+ return;
+ }
}
}
+ else
+ {
+ CMStringA error; error.AppendFormat(Translate("\"%s\"command has invalid parameter.\nUse \"/help\" for more info."), "/delete");
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());
+ }
ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
}
\ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox_dialogs.cpp b/plugins/Dropbox/src/dropbox_dialogs.cpp index 445da14a3f..c649c3e60e 100644 --- a/plugins/Dropbox/src/dropbox_dialogs.cpp +++ b/plugins/Dropbox/src/dropbox_dialogs.cpp @@ -58,94 +58,65 @@ INT_PTR CALLBACK CDropbox::TokenRequestProc(HWND hwndDlg, UINT msg, WPARAM wPara INT_PTR CALLBACK CDropbox::MainOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
+ CDropbox *instance = (CDropbox*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+
switch (msg)
{
case WM_INITDIALOG:
+ {
TranslateDialogDefault(hwndDlg);
- {
- CheckDlgButton(hwndDlg, IDC_USE_SHORT_LINKS, db_get_b(NULL, MODULE, "UseSortLinks", 1));
- }
+
+ instance = (CDropbox*)lParam;
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
+
+ CheckDlgButton(hwndDlg, IDC_USE_SHORT_LINKS, db_get_b(NULL, MODULE, "UseSortLinks", 1));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_AUTHORIZE), FALSE);
+
+ LOGFONT lf;
+ HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_AUTH_STATUS, WM_GETFONT, 0, 0);
+ GetObject(hFont, sizeof(lf), &lf);
+ lf.lfWeight = FW_BOLD;
+ SendDlgItemMessage(hwndDlg, IDC_AUTH_STATUS, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);
+
+ if (instance->HasAccessToken())
+ SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you are already authorized"));
+ else
+ SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you are not authorized yet"));
+ }
return TRUE;
case WM_COMMAND:
- if (HIWORD(wParam) == STN_CLICKED)
+ switch (LOWORD(wParam))
{
- switch (LOWORD(wParam))
- {
- case IDC_GETAUTH:
- CallService(MS_UTILS_OPENURL, 0, (LPARAM)DROPBOX_WWW_URL DROPBOX_API_VER "/oauth2/authorize?response_type=code&client_id=" DROPBOX_API_KEY);
- break;
-
- case IDC_USE_SHORT_LINKS:
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_AUTHORIZE:
- {
- char request_token[128];
- GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, request_token, SIZEOF(request_token));
-
- char data[1024];
- mir_snprintf(
- data,
- SIZEOF(data),
- "grant_type=authorization_code&code=%s",
- request_token);
-
- HttpRequest *request = new HttpRequest(INSTANCE->hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/oauth2/token");
- request->pData = mir_strdup(data);
- request->dataLength = (int)strlen(data);
- request->AddHeader("Content-Type", "application/x-www-form-urlencoded");
- request->AddBasicAuthHeader(DROPBOX_API_KEY, DROPBOX_API_SECRET);
-
- mir_ptr<NETLIBHTTPREQUEST> response(request->Send());
-
- delete request;
-
- MCONTACT hContact = CDropbox::GetDefaultContact();
-
- if (response)
- {
- JSONNODE *root = json_parse(response->pData);
- if (root)
- {
- if (response->resultCode == HTTP_STATUS::OK)
- {
- JSONNODE *node = json_get(root, "access_token");
- ptrA access_token = ptrA(mir_u2a(json_as_string(node)));
- db_set_s(NULL, MODULE, "TokenSecret", access_token);
-
- if (hContact)
- {
- if (db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
- db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE);
- }
-
- ShowNotification(TranslateT("You have been authorized"), MB_ICONINFORMATION);
- }
- else
- {
- JSONNODE *node = json_get(root, "error_description");
- ptrW error_description(json_as_string(node));
-
- ShowNotification((wchar_t*)error_description, MB_ICONERROR);
- }
- }
- }
- else
- HandleFileTransferError(response, hContact);
-
- }
- }
+ case IDC_GETAUTH:
+ CallService(MS_UTILS_OPENURL, 0, (LPARAM)DROPBOX_WWW_URL DROPBOX_API_VER "/oauth2/authorize?response_type=code&client_id=" DROPBOX_API_KEY);
+ SetFocus(GetDlgItem(hwndDlg, IDC_REQUEST_CODE));
break;
+
+ case IDC_REQUEST_CODE:
+ {
+ if ((HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return 0;
+
+ char requestToken[128];
+ GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, requestToken, SIZEOF(requestToken));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_AUTHORIZE), strlen(requestToken) != 0);
+ }
+ break;
+
+ case IDC_AUTHORIZE:
+ mir_forkthreadowner(CDropbox::RequestAcceessTokenAsync, instance, hwndDlg, 0);
+ break;
+
+ case IDC_USE_SHORT_LINKS:
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+
}
break;
case WM_NOTIFY:
if (reinterpret_cast<NMHDR*>(lParam)->code == PSN_APPLY)
- {
db_set_b(NULL, MODULE, "UseSortLinks", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_USE_SHORT_LINKS));
- }
break;
}
return FALSE;
diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp index 0e5472ef0b..325a328152 100644 --- a/plugins/Dropbox/src/dropbox_events.cpp +++ b/plugins/Dropbox/src/dropbox_events.cpp @@ -1,9 +1,11 @@ #include "common.h"
-int CDropbox::OnModulesLoaded(WPARAM wParam, LPARAM lParam)
+int CDropbox::OnModulesLoaded(void *obj, WPARAM wParam, LPARAM lParam)
{
- HookEvent(ME_FILEDLG_CANCELED, CDropbox::OnFileDoalogCancelled);
- HookEvent(ME_FILEDLG_SUCCEEDED, CDropbox::OnFileDoalogSuccessed);
+ CDropbox *instance = (CDropbox*)obj;
+
+ HookEventObj(ME_FILEDLG_CANCELED, OnFileDoalogCancelled, obj);
+ HookEventObj(ME_FILEDLG_SUCCEEDED, OnFileDoalogSuccessed, obj);
NETLIBUSER nlu = { sizeof(nlu) };
nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
@@ -11,30 +13,7 @@ int CDropbox::OnModulesLoaded(WPARAM wParam, LPARAM lParam) nlu.szSettingsModule = MODULE;
nlu.ptszDescriptiveName = L"Dropbox";
- INSTANCE->hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
-
- MCONTACT hContact = GetDefaultContact();
- if (!hContact)
- {
- hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
- if (!CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)MODULE))
- {
- db_set_s(NULL, MODULE, "Nick", MODULE);
- db_set_s(hContact, MODULE, "Nick", MODULE);
- db_set_ws(hContact, "CList", "MyHandle", L"Dropbox");
-
- if (HasAccessToken() && db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
- {
- db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE);
- }
-
- if (!db_get_b(NULL, "FirstRun", MODULE, 0))
- {
- mir_forkthread(CDropbox::RequestApiAuthorizationAsync, 0);
- db_set_b(NULL, "FirstRun", MODULE, 1);
- }
- }
- }
+ instance->hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
if (ServiceExists(MS_BB_ADDBUTTON))
{
@@ -48,14 +27,14 @@ int CDropbox::OnModulesLoaded(WPARAM wParam, LPARAM lParam) bbd.dwDefPos = 100 + bbd.dwButtonID;
CallService(MS_BB_ADDBUTTON, 0, (LPARAM)&bbd);
- HookEvent(ME_MSG_WINDOWEVENT, CDropbox::OnSrmmWindowOpened);
- HookEvent(ME_MSG_BUTTONPRESSED, CDropbox::OnSrmmButtonPressed);
+ HookEventObj(ME_MSG_WINDOWEVENT, OnSrmmWindowOpened, obj);
+ HookEventObj(ME_MSG_BUTTONPRESSED, OnTabSrmmButtonPressed, obj);
}
return 0;
}
-int CDropbox::OnPreShutdown(WPARAM wParam, LPARAM lParam)
+int CDropbox::OnPreShutdown(void *obj, WPARAM wParam, LPARAM lParam)
{
if (ServiceExists(MS_BB_ADDBUTTON))
{
@@ -69,7 +48,20 @@ int CDropbox::OnPreShutdown(WPARAM wParam, LPARAM lParam) return 0;
}
-int CDropbox::OnOptionsInit(WPARAM wParam, LPARAM lParam)
+int CDropbox::OnContactDeleted(void *obj, WPARAM hContact, LPARAM lParam)
+{
+ CDropbox *instance = (CDropbox*)obj;
+
+ if (lstrcmpiA(GetContactProto(hContact), MODULE) == 0)
+ {
+ if (instance->HasAccessToken())
+ instance->DestroyAcceessToken();
+ }
+
+ return 0;
+}
+
+int CDropbox::OnOptionsInitialized(void *obj, WPARAM wParam, LPARAM lParam)
{
OPTIONSDIALOGPAGE odp = { sizeof(odp) };
odp.position = 100000000;
@@ -77,27 +69,19 @@ int CDropbox::OnOptionsInit(WPARAM wParam, LPARAM lParam) odp.flags = ODPF_BOLDGROUPS;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_MAIN);
odp.pszGroup = LPGEN("Network");
- odp.pszTitle = LPGEN("Dropbox");
+ odp.pszTitle = "Dropbox";
odp.pfnDlgProc = MainOptionsProc;
+ odp.dwInitParam = (LPARAM)obj;
Options_AddPage(wParam, &odp);
return 0;
}
-int CDropbox::OnContactDeleted(WPARAM hContact, LPARAM lParam)
+int CDropbox::OnSrmmWindowOpened(void *obj, WPARAM wParam, LPARAM lParam)
{
- if (lstrcmpiA(GetContactProto(hContact), MODULE) == 0)
- {
- if (HasAccessToken())
- INSTANCE->DestroyAcceessToken();
- }
+ CDropbox *instance = (CDropbox*)obj;
- return 0;
-}
-
-int CDropbox::OnSrmmWindowOpened(WPARAM wParam, LPARAM lParam)
-{
MessageWindowEventData *ev = (MessageWindowEventData*)lParam;
if (ev->uType == MSG_WINDOW_EVT_OPENING && ev->hContact)
{
@@ -105,9 +89,9 @@ int CDropbox::OnSrmmWindowOpened(WPARAM wParam, LPARAM lParam) BBButton bbd = { sizeof(bbd) };
bbd.pszModuleName = MODULE;
- if (ev->hContact == GetDefaultContact() || !HasAccessToken() || status == ID_STATUS_OFFLINE)
+ if (ev->hContact == instance->GetDefaultContact() || !instance->HasAccessToken() || status == ID_STATUS_OFFLINE)
bbd.bbbFlags = BBSF_HIDDEN | BBSF_DISABLED;
- else if (INSTANCE->hContactTransfer)
+ else if (instance->hTransferContact)
bbd.bbbFlags = BBSF_DISABLED;
bbd.dwButtonID = BBB_ID_FILE_SEND;
@@ -117,38 +101,44 @@ int CDropbox::OnSrmmWindowOpened(WPARAM wParam, LPARAM lParam) return 0;
}
-int CDropbox::OnSrmmButtonPressed(WPARAM wParam, LPARAM lParam)
+int CDropbox::OnTabSrmmButtonPressed(void *obj, WPARAM wParam, LPARAM lParam)
{
+ CDropbox *instance = (CDropbox*)obj;
+
CustomButtonClickData *cbc = (CustomButtonClickData *)lParam;
if (!strcmp(cbc->pszModule, MODULE) && cbc->dwButtonId == BBB_ID_FILE_SEND && cbc->hContact)
{
- INSTANCE->hContactTransfer = cbc->hContact;
+ instance->hTransferContact = cbc->hContact;
- HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, GetDefaultContact(), 0);
+ HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, instance->GetDefaultContact(), 0);
- dcftp[hwnd] = cbc->hContact;
+ instance->dcftp[hwnd] = cbc->hContact;
}
return 0;
}
-int CDropbox::OnFileDoalogCancelled(WPARAM hContact, LPARAM lParam)
+int CDropbox::OnFileDoalogCancelled(void *obj, WPARAM hContact, LPARAM lParam)
{
+ CDropbox *instance = (CDropbox*)obj;
+
HWND hwnd = (HWND)lParam;
- if (INSTANCE->hContactTransfer == dcftp[hwnd])
+ if (instance->hTransferContact == instance->dcftp[hwnd])
{
- dcftp.erase((HWND)lParam);
- INSTANCE->hContactTransfer = 0;
+ instance->dcftp.erase((HWND)lParam);
+ instance->hTransferContact = 0;
}
return 0;
}
-int CDropbox::OnFileDoalogSuccessed(WPARAM hContact, LPARAM lParam)
+int CDropbox::OnFileDoalogSuccessed(void *obj, WPARAM hContact, LPARAM lParam)
{
+ CDropbox *instance = (CDropbox*)obj;
+
HWND hwnd = (HWND)lParam;
- if (INSTANCE->hContactTransfer == dcftp[hwnd])
- dcftp.erase((HWND)lParam);
+ if (instance->hTransferContact == instance->dcftp[hwnd])
+ instance->dcftp.erase((HWND)lParam);
return 0;
}
\ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox_icons.cpp b/plugins/Dropbox/src/dropbox_icons.cpp index d13ed695f7..114643240c 100644 --- a/plugins/Dropbox/src/dropbox_icons.cpp +++ b/plugins/Dropbox/src/dropbox_icons.cpp @@ -1,6 +1,6 @@ #include "common.h"
-void CDropbox::InitIcons()
+void CDropbox::InitializeIcons()
{
wchar_t filePath[MAX_PATH];
GetModuleFileName(g_hInstance, filePath, MAX_PATH);
diff --git a/plugins/Dropbox/src/dropbox_menus.cpp b/plugins/Dropbox/src/dropbox_menus.cpp index 0dcac861a8..a227bb4bb0 100644 --- a/plugins/Dropbox/src/dropbox_menus.cpp +++ b/plugins/Dropbox/src/dropbox_menus.cpp @@ -1,6 +1,6 @@ #include "common.h"
-void CDropbox::InitMenus()
+void CDropbox::InitializeMenus()
{
CLISTMENUITEM mi = { 0 };
mi.cbSize = sizeof(CLISTMENUITEM);
@@ -10,60 +10,23 @@ void CDropbox::InitMenus() mi.ptszName = LPGENT("Send files to Dropbox");
mi.position = -2000020000 + CMI_SEND_FILES;
mi.icolibItem = LoadSkinnedIconHandle(SKINICON_EVENT_FILE);
- ContactMenuItems[CMI_SEND_FILES] = Menu_AddContactMenuItem(&mi);
- CreateServiceFunction(mi.pszService, SendFilesToDropbox);
-
- mi.pszService = MODULE"/RequestAuthorization";
- mi.ptszName = LPGENT("Request authorization");
- mi.position = 1000030000 + CMI_AUTH_REQUEST;
- mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_REQUEST);
- ContactMenuItems[CMI_AUTH_REQUEST] = Menu_AddContactMenuItem(&mi);
- CreateServiceFunction(mi.pszService, RequestApiAuthorization);
-
- mi.pszService = MODULE"/RevokeAuthorization";
- mi.ptszName = LPGENT("Revoke authorization");
- mi.position = 1000030000 + CMI_AUTH_REVOKE;
- mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_REVOKE);
- ContactMenuItems[CMI_AUTH_REVOKE] = Menu_AddContactMenuItem(&mi);
- CreateServiceFunction(mi.pszService, RevokeApiAuthorization);
+ contactMenuItems[CMI_SEND_FILES] = Menu_AddContactMenuItem(&mi);
+ CreateServiceFunctionObj(mi.pszService, SendFilesToDropbox, this);
}
-void CDropbox::Menu_DisableItem(HGENMENU hMenuItem, BOOL bDisable)
+int CDropbox::OnPrebuildContactMenu(void *obj, WPARAM hContact, LPARAM lParam)
{
- CLISTMENUITEM clmi = { sizeof(clmi) };
- clmi.cbSize = sizeof(CLISTMENUITEM);
- clmi.flags = CMIM_FLAGS;
- if (bDisable)
- clmi.flags |= CMIF_GRAYED;
-
- Menu_ModifyItem(hMenuItem, &clmi);
-}
+ CDropbox *instance = (CDropbox*)obj;
-int CDropbox::OnPrebuildContactMenu(WPARAM hContact, LPARAM lParam)
-{
if (!hContact)
return 0;
- Menu_DisableItem(ContactMenuItems[CMI_SEND_FILES], FALSE);
-
- Menu_ShowItem(ContactMenuItems[CMI_AUTH_REQUEST], FALSE);
- Menu_ShowItem(ContactMenuItems[CMI_AUTH_REVOKE], FALSE);
- Menu_ShowItem(ContactMenuItems[CMI_SEND_FILES], FALSE);
+ Menu_ShowItem(instance->contactMenuItems[CMI_SEND_FILES], FALSE);
WORD status = db_get_w(hContact, GetContactProto(hContact), "Status", ID_STATUS_OFFLINE);
- if (hContact == GetDefaultContact())
- {
- if (!HasAccessToken())
- Menu_ShowItem(ContactMenuItems[CMI_AUTH_REQUEST], TRUE);
- else
- Menu_ShowItem(ContactMenuItems[CMI_AUTH_REVOKE], TRUE);
- }
- else if (status != ID_STATUS_OFFLINE && HasAccessToken())
- Menu_ShowItem(ContactMenuItems[CMI_SEND_FILES], TRUE);
-
- if (INSTANCE->hContactTransfer)
- Menu_DisableItem(ContactMenuItems[CMI_SEND_FILES], TRUE);
+ if (hContact != instance->GetDefaultContact() && status != ID_STATUS_OFFLINE && instance->HasAccessToken() && !instance->hTransferContact)
+ Menu_ShowItem(instance->contactMenuItems[CMI_SEND_FILES], TRUE);
return 0;
}
\ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp index ec556056ff..4a28527423 100644 --- a/plugins/Dropbox/src/dropbox_services.cpp +++ b/plugins/Dropbox/src/dropbox_services.cpp @@ -17,18 +17,20 @@ INT_PTR CDropbox::ProtoGetCaps(WPARAM wParam, LPARAM) return 0;
}
-INT_PTR CDropbox::ProtoSendFile(WPARAM wParam, LPARAM lParam)
+INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM wParam, LPARAM lParam)
{
- if (!HasAccessToken())
+ CDropbox *instance = (CDropbox*)obj;
+
+ if (!instance->HasAccessToken())
return ACKRESULT_FAILED;
CCSDATA *pccsd = (CCSDATA*)lParam;
- FileTransfer *ftp = new FileTransfer();
+ FileTransferParam *ftp = new FileTransferParam(instance);
ftp->pfts.flags = PFTS_SENDING | PFTS_UTF;
ftp->pfts.hContact = pccsd->hContact;
- ftp->hContact = (INSTANCE->hContactTransfer) ? INSTANCE->hContactTransfer : pccsd->hContact;
- INSTANCE->hContactTransfer = 0;
+ ftp->hContact = (instance->hTransferContact) ? instance->hTransferContact : pccsd->hContact;
+ instance->hTransferContact = 0;
char **files = (char**)pccsd->lParam;
@@ -77,7 +79,7 @@ INT_PTR CDropbox::ProtoSendFile(WPARAM wParam, LPARAM lParam) }
}
- ULONG fileId = InterlockedIncrement(&INSTANCE->hFileProcess);
+ ULONG fileId = InterlockedIncrement(&instance->hFileProcess);
ftp->hProcess = (HANDLE)fileId;
mir_forkthread(CDropbox::SendFileAsync, ftp);
@@ -85,50 +87,76 @@ INT_PTR CDropbox::ProtoSendFile(WPARAM wParam, LPARAM lParam) return fileId;
}
-INT_PTR CDropbox::ProtoSendMessage(WPARAM, LPARAM lParam)
+INT_PTR CDropbox::ProtoSendMessage(void *obj, WPARAM, LPARAM lParam)
{
+ CDropbox *instance = (CDropbox*)obj;
+
CCSDATA *pccsd = (CCSDATA*)lParam;
char *message = (char*)pccsd->lParam;
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = MODULE;
+ dbei.timestamp = time(NULL);
+ dbei.eventType = EVENTTYPE_MESSAGE;
+ dbei.cbBlob = strlen(message);
+ dbei.pBlob = (PBYTE)message;
+ dbei.flags = DBEF_SENT | DBEF_UTF;
+ db_event_add(pccsd->hContact, &dbei);
+
+ char help[1024];
+
if (message[0] && message[0] == '/')
{
// parse commands
char *sep = strchr(message, ' ');
int len = strlen(message) - (sep ? strlen(sep) : 0) - 1;
- char *cmd = (char*)mir_alloc(len + 1);
+ ptrA cmd((char*)mir_alloc(len + 1));
strncpy(cmd, message + 1, len);
cmd[len] = 0;
- if (INSTANCE->commands.find(cmd) != INSTANCE->commands.end())
+ if (instance->commands.find((char*)cmd) != instance->commands.end())
{
- ULONG messageId = InterlockedIncrement(&INSTANCE->hMessageProcess);
+ ULONG messageId = InterlockedIncrement(&instance->hMessageProcess);
- MessageParam *param = new MessageParam();
+ CommandParam *param = new CommandParam();
+ param->instance = instance;
param->hContact = pccsd->hContact;
param->hProcess = (HANDLE)messageId;
param->data = (sep ? sep + 1 : NULL);
- mir_forkthread(INSTANCE->commands[cmd], param);
+ mir_forkthread(instance->commands[(char*)cmd], param);
return messageId;
}
- //mir_free(cmd);
+ else
+ {
+ mir_snprintf(
+ help,
+ SIZEOF(help),
+ Translate("Unknown command \"%s\".\nUse \"/help\" for more info."),
+ message);
+
+ CallContactService(instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help);
+
+ return 0;
+ }
}
- DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.szModule = MODULE;
- dbei.timestamp = time(NULL);
- dbei.eventType = EVENTTYPE_MESSAGE;
- dbei.cbBlob = strlen(message);
- dbei.pBlob = (PBYTE)message;
- dbei.flags = DBEF_SENT | DBEF_UTF;
- db_event_add(pccsd->hContact, &dbei);
+ mir_snprintf(
+ help,
+ SIZEOF(help),
+ Translate("\"%s\" is not valid.\nUse \"/help\" for more info."),
+ message);
+
+ CallContactService(instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help);
return 0;
}
-INT_PTR CDropbox::ProtoReceiveMessage(WPARAM, LPARAM lParam)
+INT_PTR CDropbox::ProtoReceiveMessage(void *obj, WPARAM, LPARAM lParam)
{
+ CDropbox *instance = (CDropbox*)obj;
+
CCSDATA *pccsd = (CCSDATA*)lParam;
char *message = (char*)pccsd->lParam;
@@ -144,27 +172,29 @@ INT_PTR CDropbox::ProtoReceiveMessage(WPARAM, LPARAM lParam) return 0;
}
-INT_PTR CDropbox::RequestApiAuthorization(WPARAM, LPARAM)
+//INT_PTR CDropbox::RequestApiAuthorization(WPARAM, LPARAM)
+//{
+// mir_forkthread(CDropbox::RequestApiAuthorizationAsync, 0);
+//
+// return 0;
+//}
+//
+//INT_PTR CDropbox::RevokeApiAuthorization(WPARAM, LPARAM)
+//{
+// mir_forkthread(CDropbox::RevokeApiAuthorizationAsync, 0);
+//
+// return 0;
+//}
+
+INT_PTR CDropbox::SendFilesToDropbox(void *obj, WPARAM hContact, LPARAM)
{
- mir_forkthread(CDropbox::RequestApiAuthorizationAsync, 0);
+ CDropbox *instance = (CDropbox*)obj;
- return 0;
-}
-
-INT_PTR CDropbox::RevokeApiAuthorization(WPARAM, LPARAM)
-{
- mir_forkthread(CDropbox::RevokeApiAuthorizationAsync, 0);
-
- return 0;
-}
-
-INT_PTR CDropbox::SendFilesToDropbox(WPARAM hContact, LPARAM)
-{
- INSTANCE->hContactTransfer = hContact;
+ instance->hTransferContact = hContact;
- HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, INSTANCE->GetDefaultContact(), 0);
+ HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, instance->GetDefaultContact(), 0);
- dcftp[hwnd] = hContact;
+ instance->dcftp[hwnd] = hContact;
return 0;
}
\ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp index 2abdaa588c..c764ff9081 100644 --- a/plugins/Dropbox/src/dropbox_transfers.cpp +++ b/plugins/Dropbox/src/dropbox_transfers.cpp @@ -8,7 +8,7 @@ int CDropbox::HandleFileTransferError(NETLIBHTTPREQUEST *response, MCONTACT hCon return ACKRESULT_FAILED;
}
- if (response->resultCode != HTTP_STATUS::OK)
+ if (response->resultCode != HTTP_STATUS_OK)
{
CDropbox::ShowNotification(HttpStatusToText((HTTP_STATUS)response->resultCode), MB_ICONERROR, hContact);
return response->resultCode;
@@ -30,7 +30,7 @@ int CDropbox::SendFileChunkedFirst(const char *data, int length, char *uploadId, delete request;
- if (response && response->resultCode == HTTP_STATUS::OK)
+ if (response && response->resultCode == HTTP_STATUS_OK)
{
JSONNODE *root = json_parse(response->pData);
if (root)
@@ -66,7 +66,7 @@ int CDropbox::SendFileChunkedNext(const char *data, int length, const char *uplo delete request;
- if (response && response->resultCode == HTTP_STATUS::OK)
+ if (response && response->resultCode == HTTP_STATUS_OK)
{
JSONNODE *root = json_parse(response->pData);
if (root)
@@ -109,7 +109,7 @@ int CDropbox::SendFileChunkedLast(const char *fileName, const char *uploadId, MC delete request;
- if (response && response->resultCode == HTTP_STATUS::OK)
+ if (response && response->resultCode == HTTP_STATUS_OK)
{
if (!strchr(fileName, '\\'))
{
@@ -128,7 +128,7 @@ int CDropbox::SendFileChunkedLast(const char *fileName, const char *uploadId, MC delete request;
- if (response &&response->resultCode == HTTP_STATUS::OK)
+ if (response &&response->resultCode == HTTP_STATUS_OK)
{
JSONNODE *root = json_parse(response->pData);
if (root)
@@ -206,7 +206,7 @@ int CDropbox::CreateFolder(const char *folderName, MCONTACT hContact) delete request;
- if (response && (response->resultCode == HTTP_STATUS::OK || response->resultCode == HTTP_STATUS::FORBIDDEN))
+ if (response && (response->resultCode == HTTP_STATUS_OK || response->resultCode == HTTP_STATUS_FORBIDDEN))
{
if (!strchr(folderName, '\\'))
{
@@ -227,7 +227,7 @@ int CDropbox::CreateFolder(const char *folderName, MCONTACT hContact) response = request->Send();
- if (response && response->resultCode == HTTP_STATUS::OK)
+ if (response && response->resultCode == HTTP_STATUS_OK)
{
JSONNODE *root = json_parse(response->pData);
if (root != NULL)
@@ -283,13 +283,13 @@ int CDropbox::CreateFolder(const char *folderName, MCONTACT hContact) void _cdecl CDropbox::SendFileAsync(void *arg)
{
bool error = false;
- FileTransfer *ftp = (FileTransfer*)arg;
+ FileTransferParam *ftp = (FileTransferParam*)arg;
ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ftp->hProcess, 0);
for (int i = 0; ftp->pszFolders[i]; i++)
{
- if (INSTANCE->CreateFolder(ftp->pszFolders[i], ftp->hContact))
+ if (ftp->instance->CreateFolder(ftp->pszFolders[i], ftp->hContact))
{
error = true;
break;
@@ -336,7 +336,7 @@ void _cdecl CDropbox::SendFileAsync(void *arg) if (!offset)
{
- if (INSTANCE->SendFileChunkedFirst(data, count, uploadId, offset, ftp->hContact))
+ if (ftp->instance->SendFileChunkedFirst(data, count, uploadId, offset, ftp->hContact))
{
error = true;
break;
@@ -344,7 +344,7 @@ void _cdecl CDropbox::SendFileAsync(void *arg) }
else
{
- if (INSTANCE->SendFileChunkedNext(data, count, uploadId, offset, ftp->hContact))
+ if (ftp->instance->SendFileChunkedNext(data, count, uploadId, offset, ftp->hContact))
{
error = true;
break;
@@ -361,7 +361,7 @@ void _cdecl CDropbox::SendFileAsync(void *arg) if (!error)
{
- if (INSTANCE->SendFileChunkedLast(fileName, uploadId, ftp->hContact))
+ if (ftp->instance->SendFileChunkedLast(fileName, uploadId, ftp->hContact))
{
error = true;
}
@@ -377,8 +377,8 @@ void _cdecl CDropbox::SendFileAsync(void *arg) }
}
- if (INSTANCE->hContactTransfer)
- INSTANCE->hContactTransfer = 0;
+ if (ftp->instance->hTransferContact)
+ ftp->instance->hTransferContact = 0;
if (!error)
ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ftp->hProcess, 0);
diff --git a/plugins/Dropbox/src/dropbox_utils.cpp b/plugins/Dropbox/src/dropbox_utils.cpp index 43bef5ca61..e3a05093df 100644 --- a/plugins/Dropbox/src/dropbox_utils.cpp +++ b/plugins/Dropbox/src/dropbox_utils.cpp @@ -1,26 +1,34 @@ #include "common.h"
+HANDLE CDropbox::CreateProtoServiceFunctionObj(const char *szService, MIRANDASERVICEOBJ serviceProc, void *obj)
+{
+ char str[MAXMODULELABELLENGTH];
+ mir_snprintf(str, sizeof(str), "%s%s", MODULE, szService);
+ str[MAXMODULELABELLENGTH - 1] = 0;
+ return CreateServiceFunctionObj(str, serviceProc, obj);
+}
+
wchar_t *CDropbox::HttpStatusToText(HTTP_STATUS status)
{
switch (status)
{
- case OK:
- return TranslateT("OK");
- case BAD_REQUEST:
+ case HTTP_STATUS_OK:
+ return TranslateT("Ok");
+ case HTTP_STATUS_BAD_REQUEST:
return TranslateT("Bad input parameter. Error message should indicate which one and why");
- case UNAUTHORIZED:
+ case HTTP_STATUS_UNAUTHORIZED:
return TranslateT("Bad or expired token. This can happen if the user or Dropbox revoked or expired an access token. To fix, you should re-authenticate the user");
- case FORBIDDEN:
+ case HTTP_STATUS_FORBIDDEN:
return TranslateT("Bad OAuth request (wrong consumer key, bad nonce, expired timestamp...). Unfortunately, re-authenticating the user won't help here");
- case NOT_FOUND:
+ case HTTP_STATUS_NOT_FOUND:
return TranslateT("File or folder not found at the specified path");
- case METHOD_NOT_ALLOWED:
+ case HTTP_STATUS_METHOD_NOT_ALLOWED:
return TranslateT("Request method not expected (generally should be GET or POST)");
- case TOO_MANY_REQUESTS:
+ case HTTP_STATUS_TOO_MANY_REQUESTS:
return TranslateT("Your app is making too many requests and is being rate limited. 429s can trigger on a per-app or per-user basis");
- case SERVICE_UNAVAILABLE:
+ case HTTP_STATUS_SERVICE_UNAVAILABLE:
return TranslateT("If the response includes the Retry-After header, this means your OAuth 1.0 app is being rate limited. Otherwise, this indicates a transient server error, and your app should retry its request.");
- case INSUFICIENTE_STORAGE:
+ case HTTP_STATUS_INSUFICIENTE_STORAGE:
return TranslateT("User is over Dropbox storage quota");
}
diff --git a/plugins/Dropbox/src/file_transfer.h b/plugins/Dropbox/src/file_transfer.h index 1c0a511e47..a4d76b548b 100644 --- a/plugins/Dropbox/src/file_transfer.h +++ b/plugins/Dropbox/src/file_transfer.h @@ -3,18 +3,21 @@ #include "common.h"
-struct FileTransfer
+struct FileTransferParam
{
HANDLE hProcess;
MCONTACT hContact;
+ CDropbox *instance;
PROTOFILETRANSFERSTATUS pfts;
int totalFolders;
char **pszFolders;
int relativePathStart;
- FileTransfer()
+ FileTransferParam(CDropbox *instance)
{
+ this->instance = instance;
+
totalFolders = 0;
pszFolders = NULL;
relativePathStart = 0;
@@ -32,7 +35,7 @@ struct FileTransfer pfts.wszCurrentFile = NULL;
}
- ~FileTransfer()
+ ~FileTransferParam()
{
if (pfts.pszFiles)
{
diff --git a/plugins/Dropbox/src/http_request.h b/plugins/Dropbox/src/http_request.h index 3af4929720..30fce9d7b6 100644 --- a/plugins/Dropbox/src/http_request.h +++ b/plugins/Dropbox/src/http_request.h @@ -5,15 +5,15 @@ enum HTTP_STATUS
{
- OK = 200,
- BAD_REQUEST = 400,
- UNAUTHORIZED = 401,
- FORBIDDEN = 403,
- NOT_FOUND = 404,
- METHOD_NOT_ALLOWED = 405,
- TOO_MANY_REQUESTS = 429,
- SERVICE_UNAVAILABLE = 503,
- INSUFICIENTE_STORAGE = 507
+ HTTP_STATUS_OK = 200,
+ HTTP_STATUS_BAD_REQUEST = 400,
+ HTTP_STATUS_UNAUTHORIZED = 401,
+ HTTP_STATUS_FORBIDDEN = 403,
+ HTTP_STATUS_NOT_FOUND = 404,
+ HTTP_STATUS_METHOD_NOT_ALLOWED = 405,
+ HTTP_STATUS_TOO_MANY_REQUESTS = 429,
+ HTTP_STATUS_SERVICE_UNAVAILABLE = 503,
+ HTTP_STATUS_INSUFICIENTE_STORAGE = 507
};
class HttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject
diff --git a/plugins/Dropbox/src/main.cpp b/plugins/Dropbox/src/main.cpp deleted file mode 100644 index 30ce75dc2a..0000000000 --- a/plugins/Dropbox/src/main.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "common.h"
-
-int hLangpack;
-HINSTANCE g_hInstance;
-
-PLUGININFOEX pluginInfo =
-{
- sizeof(PLUGININFOEX),
- __PLUGIN_NAME,
- PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
- __DESCRIPTION,
- __AUTHOR,
- __AUTHOREMAIL,
- __COPYRIGHT,
- __AUTHORWEB,
- UNICODE_AWARE,
- // {B908773A-86F7-4A91-8674-6A20BA0E67D1}
- {0xb908773a, 0x86f7, 0x4a91, {0x86, 0x74, 0x6a, 0x20, 0xba, 0xe, 0x67, 0xd1}}
-
-};
-
-DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID)
-{
- g_hInstance = hInstance;
-
- return TRUE;
-}
-
-extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
-{
- return &pluginInfo;
-}
-
-extern "C" int __declspec(dllexport) Load(void)
-{
- mir_getLP(&pluginInfo);
-
- Singleton<CDropbox>::GetInstance()->Init();
-
- return 0;
-}
-
-extern "C" int __declspec(dllexport) Unload(void)
-{
- Singleton<CDropbox>::GetInstance()->Uninit();
-
- return 0;
-}
\ No newline at end of file diff --git a/plugins/Dropbox/src/resource.h b/plugins/Dropbox/src/resource.h Binary files differindex 51c6dfb265..6f36825cec 100644 --- a/plugins/Dropbox/src/resource.h +++ b/plugins/Dropbox/src/resource.h diff --git a/plugins/Dropbox/src/singleton.h b/plugins/Dropbox/src/singleton.h deleted file mode 100644 index 432e2ed7f0..0000000000 --- a/plugins/Dropbox/src/singleton.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _SINGLETON_H_
-#define _SINGLETON_H_
-
-template<typename T>
-class Singleton
-{
-public:
- static T *GetInstance()
- {
- if (!instance)
- instance = new T;
- return instance;
- }
-
-private:
- static T* instance;
-
- Singleton();
- Singleton(Singleton const&);
-
- ~Singleton();
-
- Singleton &operator=(Singleton const&);
-};
-
-template <typename T> T *Singleton<T>::instance = 0;
-
-
-#endif //_SINGLETON_H_
\ No newline at end of file diff --git a/plugins/Dropbox/src/stdafx.cpp b/plugins/Dropbox/src/stdafx.cpp index 2aa7ce281e..1c648a0dbd 100644 --- a/plugins/Dropbox/src/stdafx.cpp +++ b/plugins/Dropbox/src/stdafx.cpp @@ -1,18 +1,49 @@ -/*
-Copyright (C) 2012-14 Miranda NG project (http://miranda-ng.org)
+#include "common.h"
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation version 2
-of the License.
+int hLangpack;
+CDropbox *dropbox;
+HINSTANCE g_hInstance;
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+PLUGININFOEX pluginInfo =
+{
+ sizeof(PLUGININFOEX),
+ __PLUGIN_NAME,
+ PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
+ __DESCRIPTION,
+ __AUTHOR,
+ __AUTHOREMAIL,
+ __COPYRIGHT,
+ __AUTHORWEB,
+ UNICODE_AWARE,
+ // {B908773A-86F7-4A91-8674-6A20BA0E67D1}
+ {0xb908773a, 0x86f7, 0x4a91, {0x86, 0x74, 0x6a, 0x20, 0xba, 0xe, 0x67, 0xd1}}
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
+};
-#include "common.h"
\ No newline at end of file +DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID)
+{
+ g_hInstance = hInstance;
+
+ return TRUE;
+}
+
+extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+{
+ return &pluginInfo;
+}
+
+extern "C" int __declspec(dllexport) Load(void)
+{
+ mir_getLP(&pluginInfo);
+
+ dropbox = new CDropbox();
+
+ return 0;
+}
+
+extern "C" int __declspec(dllexport) Unload(void)
+{
+ delete dropbox;
+
+ return 0;
+}
\ No newline at end of file diff --git a/plugins/Dropbox/src/version.h b/plugins/Dropbox/src/version.h index 178ef67ee7..c15caf348c 100644 --- a/plugins/Dropbox/src/version.h +++ b/plugins/Dropbox/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>
|