From 8d0758286e5d0220647355a218a4c94f70591e6f Mon Sep 17 00:00:00 2001 From: aunsane Date: Sun, 11 Mar 2018 22:59:22 +0300 Subject: CloudFile: Dropbox OAuth with miranda-ng redirect uri --- plugins/CloudFile/src/Services/dropbox_api.h | 10 ++--- plugins/CloudFile/src/cloud_file.cpp | 51 +++++++++++++++++++------ plugins/CloudFile/src/cloud_file.h | 4 -- plugins/CloudFile/src/events.cpp | 56 ++++++++++++++-------------- plugins/CloudFile/src/main.cpp | 1 - plugins/CloudFile/src/menus.cpp | 2 +- plugins/CloudFile/src/services.cpp | 30 ++++++--------- plugins/CloudFile/src/stdafx.h | 5 ++- plugins/CloudFile/src/transfers.cpp | 49 +----------------------- plugins/CloudFile/src/utils.cpp | 12 ++++++ 10 files changed, 100 insertions(+), 120 deletions(-) (limited to 'plugins') diff --git a/plugins/CloudFile/src/Services/dropbox_api.h b/plugins/CloudFile/src/Services/dropbox_api.h index 50e5d44cab..a4ebe5910d 100644 --- a/plugins/CloudFile/src/Services/dropbox_api.h +++ b/plugins/CloudFile/src/Services/dropbox_api.h @@ -13,19 +13,19 @@ namespace DropboxAPI #define DROPBOX_APP_KEY "fa8du7gkf2q8xzg" #include "../../../miranda-private-keys/Dropbox/secret_key.h" -#define DROPBOX_API_AUTH "https://www.dropbox.com/oauth2/authorize?response_type=code&client_id=" DROPBOX_APP_KEY +#define DROPBOX_API_AUTH "https://www.dropbox.com/oauth2/authorize?response_type=code&redirect_uri=https%3A%2F%2Foauth.miranda-ng.org%2Fverification&client_id=" DROPBOX_APP_KEY class GetAccessTokenRequest : public HttpRequest { public: - GetAccessTokenRequest(const char *requestToken) : + GetAccessTokenRequest(const char *code) : HttpRequest(REQUEST_POST, DROPBOX_API_OAUTH "/token") { AddHeader("Content-Type", "application/x-www-form-urlencoded"); - CMStringA data(CMStringDataFormat::FORMAT, - "client_id=%s&client_secret=%s&grant_type=authorization_code&code=%s", - DROPBOX_APP_KEY, DROPBOX_API_SECRET, requestToken); + CMStringA data = "redirect_uri=https://oauth.miranda-ng.org/verification"; + data.AppendFormat("&client_id=%s&client_secret=%s", DROPBOX_APP_KEY, DROPBOX_API_SECRET); + data.AppendFormat("&grant_type=authorization_code&code=%s", code); SetData(data.GetBuffer(), data.GetLength()); } }; diff --git a/plugins/CloudFile/src/cloud_file.cpp b/plugins/CloudFile/src/cloud_file.cpp index d4c082148f..331d4d426c 100644 --- a/plugins/CloudFile/src/cloud_file.cpp +++ b/plugins/CloudFile/src/cloud_file.cpp @@ -44,6 +44,45 @@ DWORD_PTR CCloudService::GetCaps(int type, MCONTACT) } } +int CCloudService::FileCancel(MCONTACT, HANDLE hTransfer) +{ + FileTransferParam *ftp = Transfers.find((FileTransferParam*)&hTransfer); + if (ftp) + ftp->Terminate(); + + return 0; +} + +HANDLE CCloudService::SendFile(MCONTACT hContact, const wchar_t *description, wchar_t **paths) +{ + FileTransferParam *ftp = new FileTransferParam(hContact); + ftp->SetDescription(description); + ftp->SetWorkingDirectory(paths[0]); + for (int i = 0; paths[i]; i++) { + if (PathIsDirectory(paths[i])) + continue; + ftp->AddFile(paths[i]); + } + Transfers.insert(ftp); + mir_forkthreadowner(UploadAndReportProgressThread, this, ftp); + return (HANDLE)ftp->GetId(); +} + +void CCloudService::OpenUploadDialog(MCONTACT hContact) +{ + char *proto = GetContactProto(hContact); + if (!mir_strcmpi(proto, META_PROTO)) + hContact = CallService(MS_MC_GETMOSTONLINECONTACT, hContact); + + auto it = InterceptedContacts.find(hContact); + if (it == InterceptedContacts.end()) { + HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, hContact, 0); + InterceptedContacts[hContact] = hwnd; + } + else + SetActiveWindow(it->second); +} + int CCloudService::OnEvent(PROTOEVENTTYPE iEventType, WPARAM, LPARAM) { switch (iEventType) { @@ -58,18 +97,6 @@ int CCloudService::OnEvent(PROTOEVENTTYPE iEventType, WPARAM, LPARAM) return 1; } -void CCloudService::Report(MCONTACT hContact, const wchar_t *data) -{ - if (db_get_b(NULL, MODULE, "UrlAutoSend", 1)) - SendToContact(hContact, data); - - if (db_get_b(NULL, MODULE, "UrlPasteToMessageInputArea", 0)) - PasteToInputArea(hContact, data); - - if (db_get_b(NULL, MODULE, "UrlCopyToClipboard", 0)) - PasteToClipboard(data); -} - std::string CCloudService::PreparePath(const char *path) { std::string newPath = path; diff --git a/plugins/CloudFile/src/cloud_file.h b/plugins/CloudFile/src/cloud_file.h index 82f034b555..3c6ba9b7ac 100644 --- a/plugins/CloudFile/src/cloud_file.h +++ b/plugins/CloudFile/src/cloud_file.h @@ -36,8 +36,6 @@ public: int __cdecl FileCancel(MCONTACT hContact, HANDLE hTransfer) override; HANDLE __cdecl SendFile(MCONTACT hContact, const wchar_t *msg, wchar_t **ppszFiles) override; - static INT_PTR SendFileInterceptor(WPARAM wParam, LPARAM lParam); - int GetId() const; virtual const char* GetModuleName() const = 0; const char* GetAccountName() const; @@ -52,8 +50,6 @@ public: void OpenUploadDialog(MCONTACT hContact); virtual UINT Upload(FileTransferParam *ftp) = 0; - - void Report(MCONTACT hContact, const wchar_t *data); }; class CCloudServiceSearch : public CCloudService diff --git a/plugins/CloudFile/src/events.cpp b/plugins/CloudFile/src/events.cpp index 0812f3f5cf..869413978c 100644 --- a/plugins/CloudFile/src/events.cpp +++ b/plugins/CloudFile/src/events.cpp @@ -1,28 +1,6 @@ #include "stdafx.h" -int OnModulesLoaded(WPARAM, LPARAM) -{ - - //InitializeMenus(); - - // options - HookEvent(ME_OPT_INITIALISE, OnOptionsInitialized); - - // srfile - for (auto &service : Services) - HookEventObj(ME_FILEDLG_CANCELED, OnFileDialogCanceled, service); - - HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPrebuildContactMenu); - - HookEvent(ME_MSG_WINDOWEVENT, OnSrmmWindowOpened); - HookEvent(ME_MSG_BUTTONPRESSED, OnSrmmButtonPressed); - - HookTemporaryEvent(ME_MSG_TOOLBARLOADED, OnSrmmToolbarLoaded); - - return 0; -} - -int OnProtoAck(WPARAM, LPARAM lParam) +static int OnProtoAck(WPARAM, LPARAM lParam) { ACKDATA *ack = (ACKDATA*)lParam; @@ -46,13 +24,33 @@ int OnProtoAck(WPARAM, LPARAM lParam) return 0; } -int OnFileDialogCanceled(void* obj, WPARAM hContact, LPARAM) +static int OnFileDialogCanceled(WPARAM hContact, LPARAM) { - CCloudService *service = (CCloudService*)obj; + for (auto &service : Services) { + auto it = service->InterceptedContacts.find(hContact); + if (it != service->InterceptedContacts.end()) + service->InterceptedContacts.erase(it); + } + return 0; +} + +int OnModulesLoaded(WPARAM, LPARAM) +{ + + HookEvent(ME_PROTO_ACK, OnProtoAck); - auto it = service->InterceptedContacts.find(hContact); - if (it != service->InterceptedContacts.end()) - service->InterceptedContacts.erase(it); + // options + HookEvent(ME_OPT_INITIALISE, OnOptionsInitialized); + + // srfile + HookEvent(ME_FILEDLG_CANCELED, OnFileDialogCanceled); + + HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPrebuildContactMenu); + + HookEvent(ME_MSG_WINDOWEVENT, OnSrmmWindowOpened); + HookEvent(ME_MSG_BUTTONPRESSED, OnSrmmButtonPressed); + + HookTemporaryEvent(ME_MSG_TOOLBARLOADED, OnSrmmToolbarLoaded); return 0; -} +} \ No newline at end of file diff --git a/plugins/CloudFile/src/main.cpp b/plugins/CloudFile/src/main.cpp index 6ca530e9ce..28627c612e 100644 --- a/plugins/CloudFile/src/main.cpp +++ b/plugins/CloudFile/src/main.cpp @@ -32,7 +32,6 @@ extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); - HookEvent(ME_PROTO_ACK, OnProtoAck); HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); InitializeIcons(); diff --git a/plugins/CloudFile/src/menus.cpp b/plugins/CloudFile/src/menus.cpp index 17d421b008..311b17b7e6 100644 --- a/plugins/CloudFile/src/menus.cpp +++ b/plugins/CloudFile/src/menus.cpp @@ -2,7 +2,7 @@ HGENMENU hContactMenu; -INT_PTR UploadMenuCommand(void *obj, WPARAM hContact, LPARAM) +static INT_PTR UploadMenuCommand(void *obj, WPARAM hContact, LPARAM) { CCloudService *service = (CCloudService*)obj; service->OpenUploadDialog(hContact); diff --git a/plugins/CloudFile/src/services.cpp b/plugins/CloudFile/src/services.cpp index 2921296434..80fc88a852 100644 --- a/plugins/CloudFile/src/services.cpp +++ b/plugins/CloudFile/src/services.cpp @@ -63,34 +63,26 @@ INT_PTR Upload(WPARAM wParam, LPARAM lParam) if (service == nullptr) return 3; - FileTransferParam *ftp = new FileTransferParam(0); - ftp->SetWorkingDirectory(uploadData->localPath); - ftp->SetServerFolder(uploadData->serverFolder); - - if (PathIsDirectory(uploadData->localPath)) - { + if (PathIsDirectory(uploadData->localPath)) { // temporary unsupported - Transfers.remove(ftp); - delete ftp; - - return ACKRESULT_FAILED; + return 4; } - else - ftp->AddFile(uploadData->localPath); - int res = service->Upload(ftp); + FileTransferParam ftp(0); + ftp.SetWorkingDirectory(uploadData->localPath); + ftp.SetServerFolder(uploadData->serverFolder); + ftp.AddFile(uploadData->localPath); + + int res = service->Upload(&ftp); if (res == ACKRESULT_SUCCESS && lParam) { CFUPLOADRESULT *result = (CFUPLOADRESULT*)lParam; - const char **links = ftp->GetSharedLinks(result->linkCount); + const char **links = ftp.GetSharedLinks(result->linkCount); result->links = (char**)mir_calloc(sizeof(char*) * result->linkCount); for (size_t i = 0; i < result->linkCount; i++) result->links[i] = mir_strdup(links[i]); - result->description = mir_wstrdup(ftp->GetDescription()); + result->description = mir_wstrdup(ftp.GetDescription()); } - Transfers.remove(ftp); - delete ftp; - return res; } @@ -123,7 +115,7 @@ void InitializeServices() pd.type = PROTOTYPE_FILTER; Proto_RegisterModule(&pd); - CreateServiceFunction(MODULE PSS_FILE, &CCloudService::SendFileInterceptor); + CreateServiceFunction(MODULE PSS_FILE, SendFileInterceptor); CreateServiceFunction(MS_CLOUDFILE_GETSERVICE, GetService); CreateServiceFunction(MS_CLOUDFILE_ENUMSERVICES, EnumServices); diff --git a/plugins/CloudFile/src/stdafx.h b/plugins/CloudFile/src/stdafx.h index d7c3cf2c8e..61d86ce5fa 100644 --- a/plugins/CloudFile/src/stdafx.h +++ b/plugins/CloudFile/src/stdafx.h @@ -75,8 +75,6 @@ void InitializeServices(); // events int OnModulesLoaded(WPARAM, LPARAM); -int OnProtoAck(WPARAM, LPARAM); -int OnFileDialogCanceled(void* obj, WPARAM hContact, LPARAM); // icons void InitializeIcons(); @@ -101,6 +99,8 @@ int OnOptionsInitialized(WPARAM wParam, LPARAM); // transfers extern LIST Transfers; + +INT_PTR SendFileInterceptor(WPARAM wParam, LPARAM lParam); UINT UploadAndReportProgressThread(void *owner, void *arg); // utils @@ -110,5 +110,6 @@ bool CanSendToContact(MCONTACT hContact); void SendToContact(MCONTACT hContact, const wchar_t *data); void PasteToInputArea(MCONTACT hContact, const wchar_t *data); void PasteToClipboard(const wchar_t *data); +void Report(MCONTACT hContact, const wchar_t *data); #endif //_COMMON_H_ \ No newline at end of file diff --git a/plugins/CloudFile/src/transfers.cpp b/plugins/CloudFile/src/transfers.cpp index 28ceede990..ca067399ca 100644 --- a/plugins/CloudFile/src/transfers.cpp +++ b/plugins/CloudFile/src/transfers.cpp @@ -2,7 +2,7 @@ LIST Transfers(1, HandleKeySortT); -INT_PTR CCloudService::SendFileInterceptor(WPARAM, LPARAM lParam) +INT_PTR SendFileInterceptor(WPARAM, LPARAM lParam) { CCSDATA *pccsd = (CCSDATA*)lParam; for (auto &service : Services) { @@ -15,51 +15,6 @@ INT_PTR CCloudService::SendFileInterceptor(WPARAM, LPARAM lParam) return CALLSERVICE_NOTFOUND; } -int CCloudService::FileCancel(MCONTACT, HANDLE hTransfer) -{ - FileTransferParam *ftp = Transfers.find((FileTransferParam*)&hTransfer); - if (ftp) - ftp->Terminate(); - - return 0; -} - -HANDLE CCloudService::SendFile(MCONTACT hContact, const wchar_t *description, wchar_t **paths) -{ - FileTransferParam *ftp = new FileTransferParam(hContact); - - ftp->SetDescription(description); - - ftp->SetWorkingDirectory(paths[0]); - for (int i = 0; paths[i]; i++) { - if (PathIsDirectory(paths[i])) - continue; - ftp->AddFile(paths[i]); - } - - Transfers.insert(ftp); - - mir_forkthreadowner(UploadAndReportProgressThread, this, ftp); - - return (HANDLE)ftp->GetId(); -} - -void CCloudService::OpenUploadDialog(MCONTACT hContact) -{ - char *proto = GetContactProto(hContact); - if (!mir_strcmpi(proto, META_PROTO)) - hContact = CallService(MS_MC_GETMOSTONLINECONTACT, hContact); - - auto it = InterceptedContacts.find(hContact); - if (it == InterceptedContacts.end()) - { - HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, hContact, 0); - InterceptedContacts[hContact] = hwnd; - } - else - SetActiveWindow(it->second); -} - UINT UploadAndReportProgressThread(void *owner, void *arg) { CCloudService *service = (CCloudService*)owner; @@ -74,7 +29,7 @@ UINT UploadAndReportProgressThread(void *owner, void *arg) data.Append(ptrW(mir_utf8decodeW(links[i]))); data.AppendChar(0x0A); } - service->Report(ftp->GetContact(), data); + Report(ftp->GetContact(), data); } Transfers.remove(ftp); diff --git a/plugins/CloudFile/src/utils.cpp b/plugins/CloudFile/src/utils.cpp index 24559827ef..b2a515fe94 100644 --- a/plugins/CloudFile/src/utils.cpp +++ b/plugins/CloudFile/src/utils.cpp @@ -95,3 +95,15 @@ void PasteToClipboard(const wchar_t *data) CloseClipboard(); } } + +void Report(MCONTACT hContact, const wchar_t *data) +{ + if (db_get_b(NULL, MODULE, "UrlAutoSend", 1)) + SendToContact(hContact, data); + + if (db_get_b(NULL, MODULE, "UrlPasteToMessageInputArea", 0)) + PasteToInputArea(hContact, data); + + if (db_get_b(NULL, MODULE, "UrlCopyToClipboard", 0)) + PasteToClipboard(data); +} -- cgit v1.2.3