From 0a95d1c9e2791898c03eab04a06932ec65f3a934 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Thu, 30 Nov 2017 08:28:00 +0300 Subject: Dropbox moved to deprecated (use CloudFile) --- plugins/Dropbox/Dropbox.vcxproj | 45 ---- plugins/Dropbox/Dropbox.vcxproj.filters | 4 - .../Dropbox/proto_dropbox/Proto_Dropbox.vcxproj | 28 --- .../proto_dropbox/Proto_Dropbox.vcxproj.filters | 4 - plugins/Dropbox/proto_dropbox/res/Offline.ico | Bin 5430 -> 0 bytes plugins/Dropbox/proto_dropbox/res/Online.ico | Bin 5430 -> 0 bytes plugins/Dropbox/proto_dropbox/res/Proto_Dropbox.rc | 70 ------ plugins/Dropbox/proto_dropbox/src/resource.h | 17 -- plugins/Dropbox/res/dropbox.ico | Bin 5430 -> 0 bytes plugins/Dropbox/res/resource.rc | 175 --------------- plugins/Dropbox/res/upload.ico | Bin 5430 -> 0 bytes plugins/Dropbox/res/version.rc | 55 ----- plugins/Dropbox/src/api/account.h | 38 ---- plugins/Dropbox/src/api/operations.h | 143 ------------ plugins/Dropbox/src/api/upload.h | 94 -------- plugins/Dropbox/src/dropbox.cpp | 219 ------------------ plugins/Dropbox/src/dropbox.h | 142 ------------ plugins/Dropbox/src/dropbox_commands.cpp | 176 --------------- plugins/Dropbox/src/dropbox_events.cpp | 129 ----------- plugins/Dropbox/src/dropbox_icons.cpp | 30 --- plugins/Dropbox/src/dropbox_menus.cpp | 51 ----- plugins/Dropbox/src/dropbox_options.cpp | 160 -------------- plugins/Dropbox/src/dropbox_options.h | 50 ----- plugins/Dropbox/src/dropbox_services.cpp | 227 ------------------- plugins/Dropbox/src/dropbox_transfers.cpp | 217 ------------------ plugins/Dropbox/src/dropbox_utils.cpp | 156 ------------- plugins/Dropbox/src/file_transfer.h | 245 --------------------- plugins/Dropbox/src/http_request.h | 166 -------------- plugins/Dropbox/src/main.cpp | 55 ----- plugins/Dropbox/src/resource.h | 34 --- plugins/Dropbox/src/stdafx.cxx | 20 -- plugins/Dropbox/src/stdafx.h | 87 -------- plugins/Dropbox/src/version.h | 14 -- 33 files changed, 2851 deletions(-) delete mode 100644 plugins/Dropbox/Dropbox.vcxproj delete mode 100644 plugins/Dropbox/Dropbox.vcxproj.filters delete mode 100644 plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj delete mode 100644 plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj.filters delete mode 100644 plugins/Dropbox/proto_dropbox/res/Offline.ico delete mode 100644 plugins/Dropbox/proto_dropbox/res/Online.ico delete mode 100644 plugins/Dropbox/proto_dropbox/res/Proto_Dropbox.rc delete mode 100644 plugins/Dropbox/proto_dropbox/src/resource.h delete mode 100644 plugins/Dropbox/res/dropbox.ico delete mode 100644 plugins/Dropbox/res/resource.rc delete mode 100644 plugins/Dropbox/res/upload.ico delete mode 100644 plugins/Dropbox/res/version.rc delete mode 100644 plugins/Dropbox/src/api/account.h delete mode 100644 plugins/Dropbox/src/api/operations.h delete mode 100644 plugins/Dropbox/src/api/upload.h delete mode 100644 plugins/Dropbox/src/dropbox.cpp delete mode 100644 plugins/Dropbox/src/dropbox.h delete mode 100644 plugins/Dropbox/src/dropbox_commands.cpp delete mode 100644 plugins/Dropbox/src/dropbox_events.cpp delete mode 100644 plugins/Dropbox/src/dropbox_icons.cpp delete mode 100644 plugins/Dropbox/src/dropbox_menus.cpp delete mode 100644 plugins/Dropbox/src/dropbox_options.cpp delete mode 100644 plugins/Dropbox/src/dropbox_options.h delete mode 100644 plugins/Dropbox/src/dropbox_services.cpp delete mode 100644 plugins/Dropbox/src/dropbox_transfers.cpp delete mode 100644 plugins/Dropbox/src/dropbox_utils.cpp delete mode 100644 plugins/Dropbox/src/file_transfer.h delete mode 100644 plugins/Dropbox/src/http_request.h delete mode 100644 plugins/Dropbox/src/main.cpp delete mode 100644 plugins/Dropbox/src/resource.h delete mode 100644 plugins/Dropbox/src/stdafx.cxx delete mode 100644 plugins/Dropbox/src/stdafx.h delete mode 100644 plugins/Dropbox/src/version.h (limited to 'plugins') diff --git a/plugins/Dropbox/Dropbox.vcxproj b/plugins/Dropbox/Dropbox.vcxproj deleted file mode 100644 index a2df21bfb9..0000000000 --- a/plugins/Dropbox/Dropbox.vcxproj +++ /dev/null @@ -1,45 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - Dropbox - {CBA58126-3E02-4159-9BD3-059AF9DBC84E} - - - - - - - - - - - comctl32.lib;shlwapi.lib;%(AdditionalDependencies) - - - Sync - - - - - {f6a9340e-b8d9-4c75-be30-47dc66d0abc7} - - - diff --git a/plugins/Dropbox/Dropbox.vcxproj.filters b/plugins/Dropbox/Dropbox.vcxproj.filters deleted file mode 100644 index a8ab01c0e5..0000000000 --- a/plugins/Dropbox/Dropbox.vcxproj.filters +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj b/plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj deleted file mode 100644 index cb1d058dc4..0000000000 --- a/plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - Proto_Dropbox - {16D1337A-C442-4D3E-857C-E0269BA1CCF0} - - - - - \ No newline at end of file diff --git a/plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj.filters b/plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj.filters deleted file mode 100644 index e39f86d5d6..0000000000 --- a/plugins/Dropbox/proto_dropbox/Proto_Dropbox.vcxproj.filters +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/plugins/Dropbox/proto_dropbox/res/Offline.ico b/plugins/Dropbox/proto_dropbox/res/Offline.ico deleted file mode 100644 index 8f24010392..0000000000 Binary files a/plugins/Dropbox/proto_dropbox/res/Offline.ico and /dev/null differ diff --git a/plugins/Dropbox/proto_dropbox/res/Online.ico b/plugins/Dropbox/proto_dropbox/res/Online.ico deleted file mode 100644 index 915cc776c7..0000000000 Binary files a/plugins/Dropbox/proto_dropbox/res/Online.ico and /dev/null differ diff --git a/plugins/Dropbox/proto_dropbox/res/Proto_Dropbox.rc b/plugins/Dropbox/proto_dropbox/res/Proto_Dropbox.rc deleted file mode 100644 index 22339493ab..0000000000 --- a/plugins/Dropbox/proto_dropbox/res/Proto_Dropbox.rc +++ /dev/null @@ -1,70 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "..\src\resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// Russian (Russia) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) -LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "..\\src\\resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_ICON1 ICON "Offline.ico" -IDI_ICON2 ICON "Online.ico" -#endif // Russian (Russia) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/plugins/Dropbox/proto_dropbox/src/resource.h b/plugins/Dropbox/proto_dropbox/src/resource.h deleted file mode 100644 index f234a1cbb7..0000000000 --- a/plugins/Dropbox/proto_dropbox/src/resource.h +++ /dev/null @@ -1,17 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by Proto_NewsAggr.rc -// -#define IDI_ICON1 105 -#define IDI_ICON2 104 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 103 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/plugins/Dropbox/res/dropbox.ico b/plugins/Dropbox/res/dropbox.ico deleted file mode 100644 index 915cc776c7..0000000000 Binary files a/plugins/Dropbox/res/dropbox.ico and /dev/null differ diff --git a/plugins/Dropbox/res/resource.rc b/plugins/Dropbox/res/resource.rc deleted file mode 100644 index f9a41025a3..0000000000 --- a/plugins/Dropbox/res/resource.rc +++ /dev/null @@ -1,175 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "..\src\resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "winres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// Russian (Russia) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) -LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT -#pragma code_page(1251) - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "..\\src\\resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""winres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - -#endif // Russian (Russia) resources -///////////////////////////////////////////////////////////////////////////// - - -///////////////////////////////////////////////////////////////////////////// -// English resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL -#pragma code_page(1252) - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_OPTIONS_MAIN DIALOGEX 0, 0, 307, 234 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - GROUPBOX "Authorization",IDC_STATIC,5,5,297,103 - LTEXT "To allow Miranda NG access in your Dropbox account:",IDC_STATIC,15,18,270,10 - CONTROL "Go to this link",IDC_GETAUTH,"Hyperlink",WS_GROUP | WS_TABSTOP | 0x1,144,35,153,8 - LTEXT "1.",IDC_STATIC,21,35,8,8 - LTEXT "Allow access to app folder",IDC_STATIC,29,35,109,16 - LTEXT "2.",IDC_STATIC,21,53,8,8 - LTEXT "Enter authorization code",IDC_STATIC,29,53,109,16 - EDITTEXT IDC_REQUEST_CODE,144,51,153,13,ES_AUTOHSCROLL - LTEXT "3.",IDC_STATIC,21,71,8,8 - LTEXT "Initiate authorization",IDC_STATIC,29,71,109,16 - PUSHBUTTON "Authorize",IDC_AUTHORIZE,144,68,153,14,BS_CENTER | WS_DISABLED - GROUPBOX "Download link",IDC_STATIC,5,111,297,70 - CONTROL "Generate temporary link",IDC_URL_ISTEMPORARY,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,15,125,282,10 - LTEXT "4.",IDC_STATIC,22,89,8,8 - LTEXT "Check status of authorization",IDC_STATIC,30,89,108,17 - CTEXT "",IDC_AUTH_STATUS,144,89,153,8 - CONTROL "Autosend download link to contact",IDC_URL_AUTOSEND, - "Button",BS_AUTORADIOBUTTON,15,138,282,10 - CONTROL "Paste download link into message input area",IDC_URL_COPYTOMIA, - "Button",BS_AUTORADIOBUTTON,15,151,282,10 - CONTROL "Copy download link to clipboard",IDC_URL_COPYTOCB, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,164,282,10 -END - -IDD_OPTIONS_INTERCEPTION DIALOGEX 0, 0, 308, 234 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - CONTROL "",IDC_ACCOUNTS,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,5,34,298,195 - LTEXT "Here you can choose the protocols in which Dropbox will be used instead of regular file transfers (sending), used by this protocol.",IDC_STATIC,5,5,298,24 -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_OPTIONS_MAIN, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 302 - VERTGUIDE, 15 - VERTGUIDE, 21 - VERTGUIDE, 29 - VERTGUIDE, 90 - VERTGUIDE, 96 - VERTGUIDE, 138 - VERTGUIDE, 144 - VERTGUIDE, 297 - TOPMARGIN, 5 - BOTTOMMARGIN, 229 - END - - IDD_OPTIONS_INTERCEPTION, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 303 - TOPMARGIN, 5 - BOTTOMMARGIN, 229 - HORZGUIDE, 29 - HORZGUIDE, 34 - END -END -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_DROPBOX ICON "dropbox.ico" - -IDI_UPLOAD ICON "upload.ico" - - -///////////////////////////////////////////////////////////////////////////// -// -// AFX_DIALOG_LAYOUT -// - -IDD_OPTIONS_MAIN AFX_DIALOG_LAYOUT -BEGIN - 0 -END - -#endif // English resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/plugins/Dropbox/res/upload.ico b/plugins/Dropbox/res/upload.ico deleted file mode 100644 index e4d86ec109..0000000000 Binary files a/plugins/Dropbox/res/upload.ico and /dev/null differ diff --git a/plugins/Dropbox/res/version.rc b/plugins/Dropbox/res/version.rc deleted file mode 100644 index fdeb14668c..0000000000 --- a/plugins/Dropbox/res/version.rc +++ /dev/null @@ -1,55 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#ifdef APSTUDIO_INVOKED -#error this file is not editable by Microsoft Visual C++ -#endif //APSTUDIO_INVOKED - -#include "..\src\version.h" - -#define APSTUDIO_READONLY_SYMBOLS -#include "afxres.h" -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -VS_VERSION_INFO VERSIONINFO - FILEVERSION __FILEVERSION_STRING - PRODUCTVERSION __FILEVERSION_STRING - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004b0" - BEGIN - VALUE "Author", __AUTHOR - VALUE "FileDescription", __DESCRIPTION - VALUE "FileVersion", __VERSION_STRING - VALUE "InternalName", __PLUGIN_NAME - VALUE "LegalCopyright", __COPYRIGHT - VALUE "OriginalFilename", __FILENAME - VALUE "ProductName", __PLUGIN_NAME - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0, 1200 - END -END - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// diff --git a/plugins/Dropbox/src/api/account.h b/plugins/Dropbox/src/api/account.h deleted file mode 100644 index 6943bd29c3..0000000000 --- a/plugins/Dropbox/src/api/account.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _DROPBOX_API_ACCOUNT_H_ -#define _DROPBOX_API_ACCOUNT_H_ - -class GetAccessTokenRequest : public HttpRequest -{ -public: - GetAccessTokenRequest(const char *requestToken) : - HttpRequest(REQUEST_POST, DROPBOX_API "/oauth2/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); - SetData(data.GetBuffer(), data.GetLength()); - } -}; - -class RevokeAccessTokenRequest : public HttpRequest -{ -public: - RevokeAccessTokenRequest() : - HttpRequest(REQUEST_POST, DROPBOX_API "/oauth2/token/revoke") - { - } -}; - -class GetCurrentAccountRequest : public HttpRequest -{ -public: - GetCurrentAccountRequest(const char *token) : - HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/users/get_current_account") - { - AddBearerAuthHeader(token); - } -}; - -#endif //_DROPBOX_API_ACCOUNT_H_ diff --git a/plugins/Dropbox/src/api/operations.h b/plugins/Dropbox/src/api/operations.h deleted file mode 100644 index d97dec731e..0000000000 --- a/plugins/Dropbox/src/api/operations.h +++ /dev/null @@ -1,143 +0,0 @@ -#ifndef _DROPBOX_API_OPERATIONS_H_ -#define _DROPBOX_API_OPERATIONS_H_ - -class GetTemporaryLinkRequest : public HttpRequest -{ -public: - GetTemporaryLinkRequest(const char *token, const char *path) : - HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/get_temporary_link") - { - AddBearerAuthHeader(token); - AddHeader("Content-Type", "application/json"); - - JSONNode root(JSON_NODE); - root << JSONNode("path", path); - - json_string data = root.write(); - SetData(data.c_str(), data.length()); - } -}; - -class CreateSharedLinkRequest : public HttpRequest -{ -public: - CreateSharedLinkRequest(const char *token, const char *path) : - HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/sharing/create_shared_link_with_settings") - { - AddBearerAuthHeader(token); - AddHeader("Content-Type", "application/json"); - - JSONNode root(JSON_NODE); - root << JSONNode("path", path); - - json_string data = root.write(); - SetData(data.c_str(), data.length()); - } -}; - -class GetSharedLinkRequest : public HttpRequest -{ -public: - GetSharedLinkRequest(const char *token, const char *path) : - HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/sharing/list_shared_links") - { - AddBearerAuthHeader(token); - AddHeader("Content-Type", "application/json"); - - JSONNode root(JSON_NODE); - root << JSONNode("path", path); - - json_string data = root.write(); - SetData(data.c_str(), data.length()); - } -}; - -class SearchRequest : public HttpRequest -{ -public: - SearchRequest(const char *token, const char *query) : - HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/search") - { - AddBearerAuthHeader(token); - AddHeader("Content-Type", "application/json"); - - JSONNode params(JSON_NODE); - params - << JSONNode("path", "") - << JSONNode("query", query) - << JSONNode("max_results", 10); - - json_string data = params.write(); - SetData(data.c_str(), data.length()); - } -}; - -class DeleteRequest : public HttpRequest -{ -public: - DeleteRequest(const char *token, const char *path) : - HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/delete") - { - AddBearerAuthHeader(token); - AddHeader("Content-Type", "application/json"); - - JSONNode root(JSON_NODE); - root << JSONNode("path", path); - - json_string data = root.write(); - SetData(data.c_str(), data.length()); - } -}; - -class CreateFolderRequest : public HttpRequest -{ -public: - CreateFolderRequest(const char *token, const char *path) : - HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/create_folder") - { - AddBearerAuthHeader(token); - AddHeader("Content-Type", "application/json"); - - JSONNode root(JSON_NODE); - root << JSONNode("path", path); - - json_string data = root.write(); - SetData(data.c_str(), data.length()); - } -}; - -class GetMetadataRequest : public HttpRequest -{ -public: - GetMetadataRequest(const char *token, const char *path) : - HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/get_metadata") - { - AddBearerAuthHeader(token); - AddHeader("Content-Type", "application/json"); - - JSONNode root(JSON_NODE); - root << JSONNode("path", path); - - json_string data = root.write(); - SetData(data.c_str(), data.length()); - } -}; - -class ListFolderRequest : public HttpRequest -{ -public: - ListFolderRequest(const char *token, const char *path) : - HttpRequest(REQUEST_POST, DROPBOX_API_RPC "/files/list_folder") - { - AddBearerAuthHeader(token); - AddHeader("Content-Type", "application/json"); - - JSONNode root(JSON_NODE); - root << JSONNode("path", path); - - json_string data = root.write(); - SetData(data.c_str(), data.length()); - } -}; - -#endif //_DROPBOX_API_OPERATIONS_H_ diff --git a/plugins/Dropbox/src/api/upload.h b/plugins/Dropbox/src/api/upload.h deleted file mode 100644 index 98841e9b98..0000000000 --- a/plugins/Dropbox/src/api/upload.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef _DROPBOX_API_UPLOAD_H_ -#define _DROPBOX_API_UPLOAD_H_ - -class UploadFileRequest : public HttpRequest -{ -public: - UploadFileRequest(const char *token, const char *path, const char *data, size_t size) : - HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload") - { - AddBearerAuthHeader(token); - AddHeader("Content-Type", "application/octet-stream"); - - JSONNode params(JSON_NODE); - params - << JSONNode("path", path) - << JSONNode("mode", "overwrite"); - - AddHeader("Dropbox-API-Arg", params.write().c_str()); - - SetData(data, size); - } -}; - -class StartUploadSessionRequest : public HttpRequest -{ -public: - StartUploadSessionRequest(const char *token, const char *data, size_t size) : - HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/start") - { - AddBearerAuthHeader(token); - AddHeader("Content-Type", "application/octet-stream"); - - SetData(data, size); - } -}; - -class AppendToUploadSessionRequest : public HttpRequest -{ -public: - AppendToUploadSessionRequest(const char *token, const char *sessionId, size_t offset, const char *data, size_t size) : - HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/append_v2") - { - AddBearerAuthHeader(token); - AddHeader("Content-Type", "application/octet-stream"); - - - JSONNode cursor; - cursor.set_name("cursor"); - cursor - << JSONNode("session_id", sessionId) - << JSONNode("offset", (unsigned long)offset); - - JSONNode param; - param << cursor; - - AddHeader("Dropbox-API-Arg", param.write().c_str()); - - SetData(data, size); - } -}; - -class FinishUploadSessionRequest : public HttpRequest -{ -public: - FinishUploadSessionRequest(const char *token, const char *sessionId, size_t offset, const char *path, const char *data, size_t size) : - HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/finish") - { - AddBearerAuthHeader(token); - AddHeader("Content-Type", "application/octet-stream"); - - JSONNode cursor(JSON_NODE); - cursor.set_name("cursor"); - cursor - << JSONNode("session_id", sessionId) - << JSONNode("offset", (unsigned long)offset); - - JSONNode commit(JSON_NODE); - commit.set_name("commit"); - commit - << JSONNode("path", path) - << JSONNode("mode", "overwrite"); - - JSONNode params(JSON_NODE); - params - << cursor - << commit; - - AddHeader("Dropbox-API-Arg", params.write().c_str()); - - SetData(data, size); - } -}; - -#endif //_DROPBOX_API_UPLOAD_H_ diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp deleted file mode 100644 index e19cd22b9c..0000000000 --- a/plugins/Dropbox/src/dropbox.cpp +++ /dev/null @@ -1,219 +0,0 @@ -#include "stdafx.h" - -CDropbox::CDropbox() : transfers(1, HandleKeySortT) -{ - HookEvent(ME_PROTO_ACK, OnProtoAck); - HookEventObj(ME_SYSTEM_MODULESLOADED, GlobalEvent<&CDropbox::OnModulesLoaded>, this); - - hUploadedEventHook = CreateHookableEvent(ME_DROPBOX_UPLOADED); - - CreateServiceFunctionObj(MS_DROPBOX_UPLOAD, GlobalService<&CDropbox::UploadToDropbox>, this); - CreateServiceFunctionObj(MS_DROPBOX_UPLOADASYNC, GlobalService<&CDropbox::UploadToDropboxAsync>, this); - - PROTOCOLDESCRIPTOR pd = { 0 }; - pd.cbSize = sizeof(pd); - pd.szName = MODULE; - pd.type = PROTOTYPE_VIRTUAL; - Proto_RegisterModule(&pd); - - CreateServiceFunction(MODULE PS_GETCAPS, ProtoGetCaps); - CreateServiceFunction(MODULE PS_GETNAME, ProtoGetName); - CreateServiceFunction(MODULE PS_LOADICON, ProtoLoadIcon); - CreateServiceFunctionObj(MODULE PS_GETSTATUS, GlobalService<&CDropbox::ProtoGetStatus>, this); - CreateServiceFunctionObj(MODULE PSS_FILE, GlobalService<&CDropbox::ProtoSendFile>, this); - CreateServiceFunctionObj(MODULE PSS_FILECANCEL, GlobalService<&CDropbox::ProtoCancelFile>, this); - CreateServiceFunctionObj(MODULE PSS_MESSAGE, GlobalService<&CDropbox::ProtoSendMessage>, this); - CreateServiceFunction(MODULE PSR_MESSAGE, ProtoReceiveMessage); - - pd.szName = MODULE"Inteceptor"; - pd.type = PROTOTYPE_FILTER; - Proto_RegisterModule(&pd); - - CreateServiceFunctionObj(MODULE "Inteceptor" PSS_FILE, GlobalService<&CDropbox::ProtoSendFileInterceptor>, this); - - InitializeMenus(); - - hMessageProcess = 1; -} - -CDropbox::~CDropbox() -{ - DestroyHookableEvent(hUploadedEventHook); -} - -MCONTACT CDropbox::GetDefaultContact() -{ - if (!hDefaultContact) - hDefaultContact = db_find_first(MODULE); - - if (!hDefaultContact) { - hDefaultContact = db_add_contact(); - if (!Proto_AddToContact(hDefaultContact, MODULE)) { - db_set_s(NULL, MODULE, "Nick", MODULE); - db_set_s(hDefaultContact, MODULE, "Nick", MODULE); - db_set_ws(hDefaultContact, "CList", "MyHandle", L"Dropbox"); - } - db_set_w(hDefaultContact, MODULE, "Status", HasAccessToken() ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE); - } - - return hDefaultContact; -} - -bool CDropbox::HasAccessToken() -{ - ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - return token != NULL; -} - -void CDropbox::RequestAccountInfo(void *p) -{ - CDropbox *instance = (CDropbox*)p; - - MCONTACT hContact = instance->GetDefaultContact(); - - ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - GetCurrentAccountRequest request(token); - NLHR_PTR response(request.Send(instance->hNetlibConnection)); - - try - { - HandleHttpResponse(response); - } - catch (DropboxException &ex) - { - Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, ex.what()); - return; - } - - JSONNode root = JSONNode::parse(response->pData); - if (root.empty()) - return; - - JSONNode referral_link = root.at("referral_link"); - if (!referral_link.empty()) - db_set_s(hContact, MODULE, "Homepage", referral_link.as_string().c_str()); - - JSONNode email = root.at("email"); - if (!email.empty()) - db_set_s(hContact, MODULE, "e-mail", email.as_string().c_str()); - - JSONNode name = root.at("name"); - if (!name.empty()) { - db_set_utf(hContact, MODULE, "FirstName", name.at("given_name").as_string().c_str()); - db_set_utf(hContact, MODULE, "LastName", name.at("surname").as_string().c_str()); - } - - JSONNode country = root.at("country"); - if (!country.empty()) { - std::string isocode = country.as_string(); - - if (isocode.empty()) - db_unset(hContact, MODULE, "Country"); - else { - char *szCountry = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode.c_str(), 0); - db_set_s(hContact, MODULE, "Country", szCountry); - } - } - - /*JSONNode quota_info = root.at("quota_info"); - if (!quota_info.empty()) { - ULONG lTotalQuota = quota_info.at("quota").as_int(); - ULONG lNormalQuota = quota_info.at("normal").as_int(); - ULONG lSharedQuota = quota_info.at("shared").as_int(); - - db_set_dw(hContact, MODULE, "SharedQuota", lSharedQuota); - db_set_dw(hContact, MODULE, "NormalQuota", lNormalQuota); - db_set_dw(hContact, MODULE, "TotalQuota", lTotalQuota); - - db_set_s(hContact, "CList", "StatusMsg", CMStringA(FORMAT, Translate("Free %ld of %ld MB"), (lTotalQuota - lNormalQuota) / (1024 * 1024), lTotalQuota / (1024 * 1024))); - }*/ -} - -void CDropbox::DestroyAccessToken() -{ - RevokeAccessTokenRequest request; - NLHR_PTR response(request.Send(hNetlibConnection)); - - db_unset(NULL, MODULE, "TokenSecret"); - MCONTACT hContact = CDropbox::GetDefaultContact(); - if (hContact) - if (db_get_w(hContact, MODULE, "Status", ID_STATUS_ONLINE) != ID_STATUS_OFFLINE) - db_set_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE); - - ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_ONLINE, (WPARAM)ID_STATUS_OFFLINE); -} - -UINT CDropbox::RequestAccessTokenAsync(void *owner, void *param) -{ - 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->DestroyAccessToken(); - - char requestToken[128]; - GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, requestToken, _countof(requestToken)); - - GetAccessTokenRequest request(requestToken); - NLHR_PTR response(request.Send(instance->hNetlibConnection)); - - if (response == nullptr || response->resultCode != HTTP_STATUS_OK) { - Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, HttpStatusToText(HTTP_STATUS_ERROR)); - if (hwndDlg) - SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("server does not respond")); - /*else - ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);*/ - return 0; - } - - JSONNode root = JSONNode::parse(response->pData); - if (root.empty()) { - Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, HttpStatusToText((HTTP_STATUS)response->resultCode)); - if (hwndDlg) - SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("server does not respond")); - /*else - ShowNotification((wchar_t*)error_description, MB_ICONERROR);*/ - return 0; - } - - JSONNode node = root.at("error_description"); - if (node != JSONNULL) { - ptrW error_description(mir_a2u_cp(node.as_string().c_str(), CP_UTF8)); - Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, HttpStatusToText((HTTP_STATUS)response->resultCode)); - if (hwndDlg) - SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, error_description); - /*else - ShowNotification((wchar_t*)error_description, MB_ICONERROR);*/ - return 0; - } - - node = root.at("access_token"); - db_set_s(NULL, MODULE, "TokenSecret", node.as_string().c_str()); - ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, (WPARAM)ID_STATUS_ONLINE); - - MCONTACT hContact = instance->GetDefaultContact(); - if (hContact) { - if (db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) != ID_STATUS_ONLINE) - db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE); - } - - try { - RequestAccountInfo(instance); - } - catch (DropboxException &ex) { - Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, ex.what()); - return 0; - } - - if (hwndDlg) - SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you have been authorized")); - /*else - ShowNotification(TranslateT("you have been authorized"), MB_ICONINFORMATION);*/ - - SetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, ""); - - return 0; -} diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h deleted file mode 100644 index f9957cc5b3..0000000000 --- a/plugins/Dropbox/src/dropbox.h +++ /dev/null @@ -1,142 +0,0 @@ -#ifndef _DROPBOX_PROTO_H_ -#define _DROPBOX_PROTO_H_ - -enum -{ - CMI_SEND_FILES, - CMI_MAX // this item shall be the last one -}; - -#define JSONNULL JSONNode(JSON_NULL) - -class CDropbox : public MZeroedObject -{ - friend CDropboxOptionsMain; - - struct CommandParam - { - CDropbox *instance; - HANDLE hProcess; - MCONTACT hContact; - void *data; - }; - -public: - CDropbox(); - virtual ~CDropbox(); - -private: - HNETLIBUSER hNetlibConnection; - ULONG hMessageProcess; - - HANDLE hUploadedEventHook; - - MCONTACT hDefaultContact; - - HGENMENU contactMenuItems[CMI_MAX]; - - std::map interceptedContacts; - - LIST transfers; - - // hooks - static int OnProtoAck(WPARAM wParam, LPARAM lParam); - int OnToolbarLoaded(WPARAM wParam, LPARAM lParam); - int OnModulesLoaded(WPARAM wParam, LPARAM lParam); - int OnContactDeleted(WPARAM wParam, LPARAM lParam); - int OnOptionsInitialized(WPARAM wParam, LPARAM lParam); - int OnPrebuildContactMenu(WPARAM wParam, LPARAM lParam); - int OnSrmmWindowOpened(WPARAM wParam, LPARAM lParam); - int OnTabSrmmButtonPressed(WPARAM wParam, LPARAM lParam); - int OnFileDialogCancelled(WPARAM wParam, LPARAM lParam); - - // services - static INT_PTR ProtoGetCaps(WPARAM wParam, LPARAM lParam); - static INT_PTR ProtoGetName(WPARAM wParam, LPARAM lParam); - static INT_PTR ProtoLoadIcon(WPARAM wParam, LPARAM lParam); - INT_PTR ProtoGetStatus(WPARAM wParam, LPARAM lParam); - INT_PTR ProtoSendFile(WPARAM wParam, LPARAM lParam); - INT_PTR ProtoCancelFile(WPARAM wParam, LPARAM lParam); - INT_PTR ProtoSendMessage(WPARAM wParam, LPARAM lParam); - static INT_PTR ProtoReceiveMessage(WPARAM wParam, LPARAM lParam); - - INT_PTR ProtoSendFileInterceptor(WPARAM wParam, LPARAM lParam); - - INT_PTR UploadToDropbox(WPARAM wParam, LPARAM lParam); - INT_PTR UploadToDropboxAsync(WPARAM wParam, LPARAM lParam); - - // commands - static void CommandHelp(void *arg); - static void CommandList(void *arg); - static void CommandShare(void *arg); - static void CommandSearch(void *arg); - static void CommandDelete(void *arg); - - // access token - bool HasAccessToken(); - - void RequestAccessToken(); - void DestroyAccessToken(); - - static UINT RequestAccessTokenAsync(void *owner, void *param); - - // account info - static void __cdecl RequestAccountInfo(void*); - - // transfers - char* UploadFile(const char *data, size_t size, char *path); - void StartUploadSession(const char *data, size_t size, char *sessionId); - void AppendToUploadSession(const char *data, size_t size, const char *sessionId, size_t offset); - char* FinishUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, char *path); - - void CreateFolder(const char *path); - - void CreateDownloadUrl(const char *path, char *url); - - static UINT UploadToDropbox(void *owner, void *arg); - - static UINT UploadAndRaiseEvent(void *owner, void *arg); - static UINT UploadAndReportProgress(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); - - // utils - static char* PreparePath(const char *oldPath, char *newPath); - static char* PreparePath(const wchar_t *oldPath, char *newPath); - - static bool IsAccountIntercepted(const char *module); - - static char* HttpStatusToText(HTTP_STATUS status); - static void HandleHttpResponse(NETLIBHTTPREQUEST *response); - static JSONNode HandleJsonResponse(NETLIBHTTPREQUEST *response); - - static MEVENT AddEventToDb(MCONTACT hContact, WORD type, DWORD flags, DWORD cbBlob, PBYTE pBlob); - - 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); - - template - static int GlobalEvent(void *obj, WPARAM wParam, LPARAM lParam) - { - CDropbox *instance = (CDropbox*)obj; - return instance ? (instance->*Event)(wParam, lParam) : 0; - } - - template - static INT_PTR GlobalService(void *obj, WPARAM wParam, LPARAM lParam) - { - CDropbox *instance = (CDropbox*)obj; - return instance ? (instance->*Service)(wParam, lParam) : 0; - } -}; - -#endif //_DROPBOX_PROTO_H_ \ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox_commands.cpp b/plugins/Dropbox/src/dropbox_commands.cpp deleted file mode 100644 index 0d6c5e4391..0000000000 --- a/plugins/Dropbox/src/dropbox_commands.cpp +++ /dev/null @@ -1,176 +0,0 @@ -#include "stdafx.h" - -void CDropbox::CommandHelp(void *arg) -{ - CommandParam *param = (CommandParam*)arg; - - CMStringA help = (char*)T2Utf(TranslateT("Dropbox supports the following commands:")); - help += "\n"; - help += "\"/list [path]\" \t- "; help += T2Utf(TranslateT("shows all files in folder \"path\" (\"path\" is relative from root and can be omitted for root folder)")); - help += "\n"; - help += "\"/share \" \t- "; help += T2Utf(TranslateT("returns download link for file or folder with specified path (\"path\" is relative from root folder)")); - help += "\n"; - help += "\"/search \" \t- "; help += T2Utf(TranslateT("searches for file or folder matched by query (\"query\" is split on spaces into multiple tokens)")); - help += "\n"; - help += "\"/delete \" \t- "; help += T2Utf(TranslateT("deletes file or folder with specified path (\"path\" is relative from root folder)")); - - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); - ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help.GetBuffer()); -} - -void CDropbox::CommandList(void *arg) -{ - CommandParam *param = (CommandParam*)arg; - - char path[MAX_PATH]; - PreparePath((char*)param->data, path); - if (path[0] == NULL) { - CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/list"); - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); - ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer()); - return; - } - - ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - ListFolderRequest request(token, path); - NLHR_PTR response(request.Send(param->instance->hNetlibConnection)); - - if (response == nullptr || response->resultCode != HTTP_STATUS_OK) { - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); - return; - } - - JSONNode root = JSONNode::parse(response->pData); - if (root.empty()) { - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); - return; - } - - CMStringA message; - JSONNode entries = root.at("entries").as_array(); - if (entries.empty()) - message.AppendFormat("\"%s\" %s", path, T2Utf(TranslateT("is empty"))); - else - { - for (size_t i = 0; i < entries.size(); i++) { - JSONNode entry = entries[i]; - CMStringA subName(entry.at("path_lower").as_string().c_str()); - message.Append((subName[0] == '/') ? subName.Mid(1) : subName); - message.AppendChar('\n'); - } - } - - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); - ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer()); -} - -void CDropbox::CommandShare(void *arg) -{ - CommandParam *param = (CommandParam*)arg; - - char path[MAX_PATH]; - PreparePath((char*)param->data, path); - if (path[0] == NULL) { - CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/share"); - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); - ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer()); - return; - } - - ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - GetTemporaryLinkRequest request(token, path); - NLHR_PTR response(request.Send(param->instance->hNetlibConnection)); - - if (response == nullptr || response->resultCode != HTTP_STATUS_OK) { - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); - return; - } - - JSONNode root = JSONNode::parse(response->pData); - if (root.empty()) { - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); - return; - } - - CMStringA link = root.at("link").as_string().c_str(); - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); - ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)link.GetBuffer()); -} - -void CDropbox::CommandSearch(void *arg) -{ - CommandParam *param = (CommandParam*)arg; - - char *query = (char*)param->data; - if (query == nullptr) { - CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/search"); - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); - ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer()); - return; - } - - ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - //bool useShortUrl = db_get_b(NULL, MODULE, "UseSortLinks", 1) > 0; - SearchRequest request(token, query); - NLHR_PTR response(request.Send(param->instance->hNetlibConnection)); - - if (response == nullptr || response->resultCode != HTTP_STATUS_OK) { - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); - return; - } - - JSONNode root = JSONNode::parse(response->pData); - if (root.empty()) { - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); - return; - } - - CMStringA message; - JSONNode matches = root.at("matches").as_array(); - if (matches.empty()) - message.AppendFormat("\"%s\" %s", query, T2Utf(TranslateT("is not found"))); - else - { - for (size_t i = 0; i < matches.size(); i++) { - JSONNode metadata = matches[i].at("metadata").as_node(); - message.AppendFormat("%s\n", metadata.at("path_lower").as_string().c_str()); - } - } - - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); - ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer()); -} - -void CDropbox::CommandDelete(void *arg) -{ - CommandParam *param = (CommandParam*)arg; - - char path[MAX_PATH]; - PreparePath((char*)param->data, path); - if (path[0] == NULL) { - CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/delete"); - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); - ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer()); - return; - } - - ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - DeleteRequest request(token, path); - NLHR_PTR response(request.Send(param->instance->hNetlibConnection)); - - try - { - HandleJsonResponse(response); - - CMStringA message(FORMAT, "%s %s", path, T2Utf(TranslateT("is deleted"))); - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); - ProtoChainSend(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer()); - } - catch (DropboxException &ex) - { - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, (LPARAM)ex.what()); - return; - } - - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); -} diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp deleted file mode 100644 index f06b4514e3..0000000000 --- a/plugins/Dropbox/src/dropbox_events.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include "stdafx.h" - -int CDropbox::OnToolbarLoaded(WPARAM, LPARAM) -{ - BBButton bbd = {}; - bbd.pszModuleName = MODULE; - bbd.bbbFlags = BBBF_ISIMBUTTON | BBBF_ISCHATBUTTON | BBBF_ISRSIDEBUTTON; - bbd.pwszTooltip = TranslateT("Upload files to Dropbox"); - bbd.hIcon = GetIconHandleByName("upload"); - bbd.dwButtonID = BBB_ID_FILE_SEND; - bbd.dwDefPos = 100 + bbd.dwButtonID; - Srmm_AddButton(&bbd); - return 0; -} - -int CDropbox::OnModulesLoaded(WPARAM, LPARAM) -{ - HookEventObj(ME_DB_CONTACT_DELETED, GlobalEvent<&CDropbox::OnContactDeleted>, this); - HookEventObj(ME_OPT_INITIALISE, GlobalEvent<&CDropbox::OnOptionsInitialized>, this); - HookEventObj(ME_CLIST_PREBUILDCONTACTMENU, GlobalEvent<&CDropbox::OnPrebuildContactMenu>, this); - HookEventObj(ME_MSG_TOOLBARLOADED, GlobalEvent<&CDropbox::OnToolbarLoaded>, this); - - HookEventObj(ME_MSG_WINDOWEVENT, GlobalEvent<&CDropbox::OnSrmmWindowOpened>, this); - HookEventObj(ME_FILEDLG_CANCELED, GlobalEvent<&CDropbox::OnFileDialogCancelled>, this); - - NETLIBUSER nlu = {}; - nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_UNICODE; - nlu.szSettingsModule = MODULE; - nlu.szDescriptiveName.w = L"Dropbox"; - hNetlibConnection = Netlib_RegisterUser(&nlu); - - GetDefaultContact(); - - WORD status = ProtoGetStatus(0, 0); - ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, status); - - HookEventObj(ME_MSG_BUTTONPRESSED, GlobalEvent<&CDropbox::OnTabSrmmButtonPressed>, this); - return 0; -} - -int CDropbox::OnContactDeleted(WPARAM hContact, LPARAM) -{ - if (mir_strcmpi(GetContactProto(hContact), MODULE) == 0) { - if (HasAccessToken()) - DestroyAccessToken(); - hDefaultContact = NULL; - } - return 0; -} - -int CDropbox::OnSrmmWindowOpened(WPARAM, LPARAM lParam) -{ - MessageWindowEventData *ev = (MessageWindowEventData*)lParam; - if (ev->uType == MSG_WINDOW_EVT_OPENING && ev->hContact) { - char *proto = GetContactProto(ev->hContact); - bool isProtoOnline = CallProtoService(proto, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE; - WORD status = db_get_w(ev->hContact, proto, "Status", ID_STATUS_OFFLINE); - bool canSendOffline = (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDOFFLINE) > 0; - - BBButton bbd = {}; - bbd.pszModuleName = MODULE; - bbd.dwButtonID = BBB_ID_FILE_SEND; - bbd.bbbFlags = BBSF_RELEASED; - if (!HasAccessToken() || ev->hContact == GetDefaultContact() || IsAccountIntercepted(proto)) - bbd.bbbFlags = BBSF_HIDDEN | BBSF_DISABLED; - else if (!isProtoOnline || (status == ID_STATUS_OFFLINE && !canSendOffline)) - bbd.bbbFlags = BBSF_DISABLED; - - Srmm_SetButtonState(ev->hContact, &bbd); - } - - return 0; -} - -int CDropbox::OnTabSrmmButtonPressed(WPARAM, LPARAM lParam) -{ - CustomButtonClickData *cbc = (CustomButtonClickData *)lParam; - if (!mir_strcmp(cbc->pszModule, MODULE) && cbc->dwButtonId == BBB_ID_FILE_SEND && cbc->hContact) { - auto it = interceptedContacts.find(cbc->hContact); - if (it == interceptedContacts.end()) - { - HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, cbc->hContact, 0); - interceptedContacts[cbc->hContact] = hwnd; - } - else - FlashWindow(it->second, FALSE); - } - - return 0; -} - -int CDropbox::OnFileDialogCancelled(WPARAM hContact, LPARAM) -{ - auto it = interceptedContacts.find(hContact); - if (it != interceptedContacts.end()) - interceptedContacts.erase(it); - - return 0; -} - -int CDropbox::OnProtoAck(WPARAM, LPARAM lParam) -{ - ACKDATA *ack = (ACKDATA*)lParam; - - if (!mir_strcmp(ack->szModule, MODULE)) - return 0; // don't rebroadcast our own acks - - if (ack->type == ACKTYPE_STATUS) { - WORD status = ack->lParam; - bool canSendOffline = (CallProtoService(ack->szModule, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDOFFLINE) > 0; - - for (MCONTACT hContact = db_find_first(ack->szModule); hContact; hContact = db_find_next(hContact, ack->szModule)) { - MessageWindowData msgw; - if (!Srmm_GetWindowData(hContact, msgw) && msgw.uState & MSG_WINDOW_STATE_EXISTS) { - BBButton bbd = {}; - bbd.pszModuleName = MODULE; - bbd.dwButtonID = BBB_ID_FILE_SEND; - bbd.bbbFlags = BBSF_RELEASED; - - if (status == ID_STATUS_OFFLINE && !canSendOffline) - bbd.bbbFlags = BBSF_DISABLED; - - Srmm_SetButtonState(hContact, &bbd); - } - } - } - - return 0; -} diff --git a/plugins/Dropbox/src/dropbox_icons.cpp b/plugins/Dropbox/src/dropbox_icons.cpp deleted file mode 100644 index 33cc167117..0000000000 --- a/plugins/Dropbox/src/dropbox_icons.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "stdafx.h" - -static IconItem iconList[] = -{ - { LPGEN("Protocol icon"), "main", IDI_DROPBOX }, - { LPGEN("Upload file(s)"), "upload", IDI_UPLOAD } -}; - -void InitializeIcons() -{ - Icon_Register(g_hInstance, "Protocols/" MODULE, iconList, _countof(iconList), MODULE); -} - -HANDLE GetIconHandleByName(const char *name) -{ - for (size_t i = 0; i < _countof(iconList); i++) - if (mir_strcmpi(iconList[i].szName, name) == 0) - return iconList[i].hIcolib; - - return nullptr; -} - -HICON LoadIconEx(int iconId, bool big) -{ - for (int i = 0; i < _countof(iconList); i++) - if (iconList[i].defIconID == iconId) - return IcoLib_GetIconByHandle(iconList[i].hIcolib, big); - - return nullptr; -} diff --git a/plugins/Dropbox/src/dropbox_menus.cpp b/plugins/Dropbox/src/dropbox_menus.cpp deleted file mode 100644 index 1a96848edd..0000000000 --- a/plugins/Dropbox/src/dropbox_menus.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "stdafx.h" - -INT_PTR CDropbox::SendFilesToDropboxCommand(void *obj, WPARAM hContact, LPARAM) -{ - CDropbox *instance = (CDropbox*)obj; - if (!instance->HasAccessToken()) - return 1; - - auto it = instance->interceptedContacts.find(hContact); - if (it == instance->interceptedContacts.end()) - { - HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, hContact, 0); - instance->interceptedContacts[hContact] = hwnd; - } - else - SetActiveWindow(it->second); - - return 0; -} - -void CDropbox::InitializeMenus() -{ - CMenuItem mi; - SET_UID(mi, 0x19af0aaf, 0x37d0, 0x4b88, 0xa5, 0x92, 0xf1, 0x6f, 0x54, 0xfd, 0x67, 0xb5); - mi.pszService = MODULE"/SendFilesToDropbox"; - mi.name.a = LPGEN("Upload files to Dropbox"); - mi.position = -2000020000 + CMI_SEND_FILES; - mi.hIcolibItem = GetIconHandleByName("upload"); - contactMenuItems[CMI_SEND_FILES] = Menu_AddContactMenuItem(&mi); - CreateServiceFunctionObj(mi.pszService, SendFilesToDropboxCommand, this); -} - -int CDropbox::OnPrebuildContactMenu(WPARAM hContact, LPARAM) -{ - bool bShow = false; - - char *proto = GetContactProto(hContact); - if (proto != nullptr) { - bool bHasIM = (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND) != 0; - if (bHasIM && HasAccessToken() && hContact != GetDefaultContact() && !IsAccountIntercepted(proto)) { - bool isProtoOnline = CallProtoService(proto, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE; - WORD status = db_get_w(hContact, proto, "Status", ID_STATUS_OFFLINE); - bool canSendOffline = (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDOFFLINE) > 0; - if (isProtoOnline && (status != ID_STATUS_OFFLINE || canSendOffline)) - bShow = true; - } - } - - Menu_ShowItem(contactMenuItems[CMI_SEND_FILES], bShow); - return 0; -} diff --git a/plugins/Dropbox/src/dropbox_options.cpp b/plugins/Dropbox/src/dropbox_options.cpp deleted file mode 100644 index 65722da497..0000000000 --- a/plugins/Dropbox/src/dropbox_options.cpp +++ /dev/null @@ -1,160 +0,0 @@ -#include "stdafx.h" - -CDropboxOptionsMain::CDropboxOptionsMain(CDropbox *instance) - : CPluginDlgBase(g_hInstance, IDD_OPTIONS_MAIN, MODULE), - m_instance(instance), - m_auth(this, IDC_GETAUTH, DROPBOX_WWW_URL "/oauth2/authorize?response_type=code&client_id=" DROPBOX_APP_KEY), - m_requestCode(this, IDC_REQUEST_CODE), m_authorize(this, IDC_AUTHORIZE), m_authStatus(this, IDC_AUTH_STATUS), - m_urlIsTemporary(this, IDC_URL_ISTEMPORARY), m_urlAutoSend(this, IDC_URL_AUTOSEND), - m_urlPasteToMessageInputArea(this, IDC_URL_COPYTOMIA), m_urlCopyToClipboard(this, IDC_URL_COPYTOCB) -{ - CreateLink(m_urlIsTemporary, "UrlIsTemporary", DBVT_BYTE, 0); - CreateLink(m_urlAutoSend, "UrlAutoSend", DBVT_BYTE, 1); - CreateLink(m_urlPasteToMessageInputArea, "UrlPasteToMessageInputArea", DBVT_BYTE, 0); - CreateLink(m_urlCopyToClipboard, "UrlCopyToClipboard", DBVT_BYTE, 0); - - //m_auth.OnClick = Callback(this, &CDropboxOptionsMain::Auth_OnClick); - m_requestCode.OnChange = Callback(this, &CDropboxOptionsMain::RequestCode_OnChange); - m_authorize.OnClick = Callback(this, &CDropboxOptionsMain::Authorize_OnClick); -} - -void CDropboxOptionsMain::OnInitDialog() -{ - CDlgBase::OnInitDialog(); - - LOGFONT lf; - HFONT hFont = (HFONT)m_authStatus.SendMsg(WM_GETFONT, 0, 0); - GetObject(hFont, sizeof(lf), &lf); - lf.lfWeight = FW_BOLD; - m_authStatus.SendMsg(WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0); - - if (m_instance->HasAccessToken()) - m_authStatus.SetText(TranslateT("you are already authorized")); - else - m_authStatus.SetText(TranslateT("you are not authorized yet")); -} - -void CDropboxOptionsMain::Auth_OnClick(CCtrlBase*) -{ - SetFocus(m_requestCode.GetHwnd()); -} - -void CDropboxOptionsMain::RequestCode_OnChange(CCtrlBase*) -{ - ptrA requestToken(m_requestCode.GetTextA()); - EnableWindow(m_authorize.GetHwnd(), mir_strlen(requestToken) != 0); -} - -void CDropboxOptionsMain::Authorize_OnClick(CCtrlBase*) -{ - mir_forkthreadowner(CDropbox::RequestAccessTokenAsync, m_instance, m_hwnd, nullptr); -} - -///////////////////////////////////////////////////////////////////////////////// - -CDropboxOptionsInterception::CDropboxOptionsInterception(CDropbox*) - : CPluginDlgBase(g_hInstance, IDD_OPTIONS_INTERCEPTION, MODULE), - m_accounts(this, IDC_ACCOUNTS), isAccountListInit(false) -{ -} - -void CDropboxOptionsInterception::OnInitDialog() -{ - CDlgBase::OnInitDialog(); - - m_accounts.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES | LVS_EX_INFOTIP); - - m_accounts.AddColumn(0, TranslateT("Account name"), 50); - m_accounts.AddColumn(1, TranslateT("Protocol"), 50); - - int count; - PROTOACCOUNT** accounts; - Proto_EnumAccounts(&count, &accounts); - const char *interceptedAccounts = db_get_sa(NULL, MODULE, "InterceptedAccounts"); - if (interceptedAccounts == nullptr) - interceptedAccounts = db_get_sa(NULL, MODULE, "InterceptedProtos"); - for (int i = 0; i < count; i++) { - PROTOACCOUNT *acc = accounts[i]; - if (strstr(acc->szProtoName, MODULE) || strstr(acc->szProtoName, "Meta")) - continue; - int iItem = m_accounts.AddItem(mir_wstrdup(acc->tszAccountName), -1, (LPARAM)acc); - m_accounts.SetItem(iItem, 1, mir_a2u(acc->szProtoName)); - if (interceptedAccounts && strstr(interceptedAccounts, acc->szModuleName)) - m_accounts.SetCheckState(iItem, TRUE); - } - - m_accounts.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER); - m_accounts.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER); - - isAccountListInit = true; -} - -INT_PTR CDropboxOptionsInterception::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch (msg) - { - case WM_NOTIFY: - { - LPNMHDR lpnmHdr = (LPNMHDR)lParam; - if (lpnmHdr->idFrom == (UINT_PTR)m_accounts.GetCtrlId() && lpnmHdr->code == LVN_ITEMCHANGED) - { - LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam; - if (pnmv->uChanged & LVIF_STATE && pnmv->uNewState & LVIS_STATEIMAGEMASK) - { - if (isAccountListInit) - NotifyChange(); - } - } - } - break; - } - - return CDlgBase::DlgProc(msg, wParam, lParam); -} - -void CDropboxOptionsInterception::OnApply() -{ - CMStringA interceptedProtos; - int count = m_accounts.GetItemCount(); - for (int iItem = 0; iItem < count; iItem++) - { - PROTOACCOUNT *acc = (PROTOACCOUNT*)m_accounts.GetItemData(iItem); - if (m_accounts.GetCheckState(iItem)) - interceptedProtos.AppendFormat("%s\t", acc->szModuleName); - - // hide tabsrmm button for intercepted accounts - for (MCONTACT hContact = db_find_first(acc->szModuleName); hContact; hContact = db_find_next(hContact, acc->szModuleName)) { - MessageWindowData msgw; - if (!Srmm_GetWindowData(hContact, msgw) && msgw.uState & MSG_WINDOW_STATE_EXISTS) { - BBButton bbd = {}; - bbd.pszModuleName = MODULE; - bbd.dwButtonID = BBB_ID_FILE_SEND; - bbd.bbbFlags = BBSF_HIDDEN | BBSF_DISABLED; - Srmm_SetButtonState(hContact, &bbd); - } - } - } - interceptedProtos.TrimRight(); - db_set_s(NULL, MODULE, "InterceptedAccounts", interceptedProtos); - db_unset(NULL, MODULE, "InterceptedProtos"); -} - -///////////////////////////////////////////////////////////////////////////////// - -int CDropbox::OnOptionsInitialized(WPARAM wParam, LPARAM) -{ - OPTIONSDIALOGPAGE odp = { 0 }; - odp.szTitle.w = _A2W(MODULE); - odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE | ODPF_DONTTRANSLATE; - odp.szGroup.w = LPGENW("Network"); - - odp.szTab.w = LPGENW("General"); - odp.pDialog = CDropboxOptionsMain::CreateOptionsPage(this); - Options_AddPage(wParam, &odp); - - odp.szTab.w = LPGENW("Interception"); - odp.pDialog = CDropboxOptionsInterception::CreateOptionsPage(this); - Options_AddPage(wParam, &odp); - - return 0; -} diff --git a/plugins/Dropbox/src/dropbox_options.h b/plugins/Dropbox/src/dropbox_options.h deleted file mode 100644 index 9f5ffa1607..0000000000 --- a/plugins/Dropbox/src/dropbox_options.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef _DROPBOX_OPTIONS_H_ -#define _DROPBOX_OPTIONS_H_ - -class CDropboxOptionsMain : public CPluginDlgBase -{ -private: - CDropbox *m_instance; - - - CCtrlHyperlink m_auth; - CCtrlEdit m_requestCode; - CCtrlButton m_authorize; - CCtrlBase m_authStatus; - - CCtrlCheck m_urlIsTemporary; - CCtrlCheck m_urlAutoSend; - CCtrlCheck m_urlPasteToMessageInputArea; - CCtrlCheck m_urlCopyToClipboard; - -protected: - void OnInitDialog(); - - void Auth_OnClick(CCtrlBase*); - void RequestCode_OnChange(CCtrlBase*); - void Authorize_OnClick(CCtrlBase*); - -public: - CDropboxOptionsMain(CDropbox *instance); - - static CDlgBase *CreateOptionsPage(void *param) { return new CDropboxOptionsMain((CDropbox*)param); } -}; - -class CDropboxOptionsInterception : public CPluginDlgBase -{ -private: - bool isAccountListInit; - CCtrlListView m_accounts; - -protected: - void OnInitDialog(); - INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam); - void OnApply(); - -public: - CDropboxOptionsInterception(CDropbox *instance); - - static CDlgBase *CreateOptionsPage(void *param) { return new CDropboxOptionsInterception((CDropbox*)param); } -}; - -#endif //_DROPBOX_OPTIONS_H_ \ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp deleted file mode 100644 index 5457883d60..0000000000 --- a/plugins/Dropbox/src/dropbox_services.cpp +++ /dev/null @@ -1,227 +0,0 @@ -#include "stdafx.h" - -INT_PTR CDropbox::ProtoGetCaps(WPARAM wParam, LPARAM) -{ - switch (wParam) { - case PFLAGNUM_1: - return PF1_IM | PF1_FILESEND; - case PFLAGNUM_2: - return PF2_ONLINE; - case PFLAGNUM_4: - return PF4_OFFLINEFILES; - } - - return 0; -} - -INT_PTR CDropbox::ProtoGetName(WPARAM wParam, LPARAM lParam) -{ - if (lParam) { - mir_strncpy((char *)lParam, MODULE, wParam); - return 0; - } - - return 1; -} - -INT_PTR CDropbox::ProtoLoadIcon(WPARAM wParam, LPARAM) -{ - return (LOWORD(wParam) == PLI_PROTOCOL) ? (INT_PTR)CopyIcon(LoadIconEx(IDI_DROPBOX)) : 0; -} - -INT_PTR CDropbox::ProtoGetStatus(WPARAM, LPARAM) -{ - return HasAccessToken() ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE; -} - -INT_PTR CDropbox::ProtoSendFile(WPARAM, LPARAM lParam) -{ - CCSDATA *pccsd = (CCSDATA*)lParam; - - if (!HasAccessToken()) { - ProtoBroadcastAck(MODULE, pccsd->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, nullptr, (LPARAM)"You cannot send files when you are not authorized."); - return 0; - } - - FileTransferParam *ftp = new FileTransferParam(pccsd->hContact); - - const wchar_t *description = (wchar_t*)pccsd->wParam; - if (description && description[0]) - ftp->AppendFormatData(L"%s\r\n", (wchar_t*)pccsd->wParam); - - wchar_t **paths = (wchar_t**)pccsd->lParam; - 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(CDropbox::UploadAndReportProgress, this, ftp, nullptr); - - return ftp->GetId(); -} - -INT_PTR CDropbox::ProtoSendFileInterceptor(WPARAM wParam, LPARAM lParam) -{ - CCSDATA *pccsd = (CCSDATA*)lParam; - - const char *proto = GetContactProto(pccsd->hContact); - if (!IsAccountIntercepted(proto)) - { - auto it = interceptedContacts.find(pccsd->hContact); - if (it == interceptedContacts.end()) - return CALLSERVICE_NOTFOUND; - } - - auto it = interceptedContacts.find(pccsd->hContact); - if (it != interceptedContacts.end()) - interceptedContacts.erase(it); - - return ProtoSendFile(wParam, lParam); -} - -INT_PTR CDropbox::ProtoCancelFile(WPARAM, LPARAM lParam) -{ - CCSDATA *pccsd = (CCSDATA*)lParam; - - HANDLE hTransfer = (HANDLE)pccsd->wParam; - FileTransferParam *ftp = transfers.find((FileTransferParam*)&hTransfer); - if (ftp == nullptr) - return 0; - - ftp->Terminate(); - - return 0; -} - -INT_PTR CDropbox::ProtoSendMessage(WPARAM, LPARAM lParam) -{ - CCSDATA *pccsd = (CCSDATA*)lParam; - - if (!HasAccessToken()) { - ProtoBroadcastAck(MODULE, pccsd->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, nullptr, (LPARAM)"You cannot send messages when you are not authorized."); - return 0; - } - - char *szMessage = (char*)pccsd->lParam; - if (*szMessage == '/') { - // parse commands - char *sep = strchr(szMessage, ' '); - - struct - { - const char *szCommand; - pThreadFunc pHandler; - } - static commands[] = - { - { "help", &CDropbox::CommandHelp }, - { "list", &CDropbox::CommandList }, - { "share", &CDropbox::CommandShare }, - { "search", &CDropbox::CommandSearch }, - { "delete", &CDropbox::CommandDelete } - }; - - char command[16] = {0}; - mir_strncpy(command, szMessage + 1, sep ? sep - szMessage : mir_strlen(szMessage)); - for (int i = 0; i < _countof(commands); i++) { - if (!mir_strcmp(command, commands[i].szCommand)) { - ULONG messageId = InterlockedIncrement(&hMessageProcess); - - CommandParam *param = new CommandParam(); - param->instance = this; - param->hContact = pccsd->hContact; - param->hProcess = (HANDLE)messageId; - param->data = (sep ? sep + 1 : NULL); - - mir_forkthread(commands[i].pHandler, param); - - return messageId; - } - } - } - - ProtoBroadcastAck(MODULE, pccsd->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, nullptr, 0); - char help[1024]; - mir_snprintf(help, Translate("\"%s\" is not valid.\nUse \"/help\" for more info."), szMessage); - ProtoChainSend(GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help); - return 0; -} - -INT_PTR CDropbox::ProtoReceiveMessage(WPARAM, LPARAM lParam) -{ - CCSDATA *pccsd = (CCSDATA*)lParam; - - char *message = (char*)pccsd->lParam; - - DBEVENTINFO dbei = {}; - dbei.flags = DBEF_UTF; - dbei.szModule = MODULE; - dbei.timestamp = time(nullptr); - dbei.eventType = EVENTTYPE_MESSAGE; - dbei.cbBlob = (int)mir_strlen(message); - dbei.pBlob = (PBYTE)mir_strdup(message); - db_event_add(pccsd->hContact, &dbei); - - return 0; -} - -INT_PTR CDropbox::UploadToDropbox(WPARAM wParam, LPARAM lParam) -{ - DropboxUploadInfo *uploadInfo = (DropboxUploadInfo*)lParam; - - FileTransferParam *ftp = new FileTransferParam(GetDefaultContact()); - ftp->SetWorkingDirectory(uploadInfo->localPath); - ftp->SetServerFolder(uploadInfo->serverFolder); - - if (PathIsDirectory(uploadInfo->localPath)) - { - // temporary unsupported - - transfers.remove(ftp); - delete ftp; - - return ACKRESULT_FAILED; - } - else - ftp->AddFile(uploadInfo->localPath); - - int res = UploadToDropbox(this, ftp); - if (res == ACKRESULT_SUCCESS && wParam) { - char **data = (char**)wParam; - *data = mir_utf8encodeW(ftp->GetData()); - } - - transfers.remove(ftp); - delete ftp; - - return res; -} - -INT_PTR CDropbox::UploadToDropboxAsync(WPARAM, LPARAM lParam) -{ - DropboxUploadInfo *uploadInfo = (DropboxUploadInfo*)lParam; - - FileTransferParam *ftp = new FileTransferParam(GetDefaultContact()); - ftp->SetWorkingDirectory(uploadInfo->localPath); - ftp->SetServerFolder(uploadInfo->serverFolder); - - if (PathIsDirectory(uploadInfo->localPath)) - { - // temporary unsupported - - transfers.remove(ftp); - delete ftp; - - return NULL; - } - else - ftp->AddFile(uploadInfo->localPath); - - mir_forkthreadowner(CDropbox::UploadAndRaiseEvent, this, ftp, nullptr); - - return ftp->GetId(); -} \ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp deleted file mode 100644 index 177d5768bb..0000000000 --- a/plugins/Dropbox/src/dropbox_transfers.cpp +++ /dev/null @@ -1,217 +0,0 @@ -#include "stdafx.h" - -char* CDropbox::UploadFile(const char *data, size_t size, char *path) -{ - ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - ptrA encodedPath(mir_utf8encode(path)); - UploadFileRequest request(token, encodedPath, data, size); - NLHR_PTR response(request.Send(hNetlibConnection)); - - JSONNode root = HandleJsonResponse(response); - JSONNode node = root.at("path_lower"); - mir_strcpy(path, node.as_string().c_str()); - - return path; -} - -void CDropbox::StartUploadSession(const char *data, size_t size, char *sessionId) -{ - ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - StartUploadSessionRequest request(token, data, size); - NLHR_PTR response(request.Send(hNetlibConnection)); - - JSONNode root = HandleJsonResponse(response); - JSONNode node = root.at("session_id"); - mir_strcpy(sessionId, node.as_string().c_str()); -} - -void CDropbox::AppendToUploadSession(const char *data, size_t size, const char *sessionId, size_t offset) -{ - ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - AppendToUploadSessionRequest request(token, sessionId, offset, data, size); - NLHR_PTR response(request.Send(hNetlibConnection)); - - HandleJsonResponse(response); -} - -char* CDropbox::FinishUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, char *path) -{ - ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - FinishUploadSessionRequest request(token, sessionId, offset, path, data, size); - NLHR_PTR response(request.Send(hNetlibConnection)); - - JSONNode root = HandleJsonResponse(response); - JSONNode node = root.at("path_lower"); - mir_strcpy(path, node.as_string().c_str()); - - return path; -} - -void CDropbox::CreateFolder(const char *path) -{ - ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - CreateFolderRequest request(token, path); - NLHR_PTR response(request.Send(hNetlibConnection)); - - // forder exists on server - if (response->resultCode == HTTP_STATUS_FORBIDDEN) - return; - - HandleJsonResponse(response); -} - -void CDropbox::CreateDownloadUrl(const char *path, char *url) -{ - ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - if (db_get_b(NULL, MODULE, "UrlIsTemporary", 0)) { - GetTemporaryLinkRequest request(token, path); - NLHR_PTR response(request.Send(hNetlibConnection)); - - JSONNode root = HandleJsonResponse(response); - JSONNode link = root.at("link"); - mir_strcpy(url, link.as_string().c_str()); - return; - } - - CreateSharedLinkRequest shareRequest(token, path); - NLHR_PTR response(shareRequest.Send(hNetlibConnection)); - - HandleHttpResponse(response); - - JSONNode root = JSONNode::parse(response->pData); - if (root.isnull()) - throw DropboxException(HttpStatusToText(HTTP_STATUS_ERROR)); - - JSONNode error = root.at("error"); - if (error.isnull()) { - JSONNode link = root.at("url"); - mir_strcpy(url, link.as_string().c_str()); - return; - } - - json_string tag = error.at(".tag").as_string(); - if (tag != "shared_link_already_exists") - throw DropboxException(tag.c_str()); - - GetSharedLinkRequest getRequest(token, path); - response = getRequest.Send(hNetlibConnection); - - root = HandleJsonResponse(response); - - JSONNode links = root.at("links").as_array(); - const JSONNode &link = (*links.begin()).at("url"); - mir_strcpy(url, link.as_string().c_str()); -} - -UINT CDropbox::UploadToDropbox(void *owner, void *arg) -{ - CDropbox *instance = (CDropbox*)owner; - FileTransferParam *ftp = (FileTransferParam*)arg; - - try { - const wchar_t *folderName = ftp->GetFolderName(); - if (folderName) { - char path[MAX_PATH], url[MAX_PATH]; - PreparePath(folderName, path); - instance->CreateFolder(path); - instance->CreateDownloadUrl(path, url); - ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(url))); - } - - ftp->FirstFile(); - do - { - const wchar_t *fileName = ftp->GetCurrentRelativeFilePath(); - uint64_t fileSize = ftp->GetCurrentFileSize(); - - int chunkSize = ftp->GetCurrentFileChunkSize(); - mir_ptrdata((char*)mir_calloc(chunkSize)); - size_t size = ftp->ReadCurrentFile(data, chunkSize); - - size_t offset = 0; - char sessionId[64]; - instance->StartUploadSession(data, size, sessionId); - - offset += size; - ftp->Progress(size); - - for (size_t chunk = 0; chunk < (fileSize / chunkSize) - 1; chunk++) - { - ftp->CheckCurrentFile(); - - size = ftp->ReadCurrentFile(data, chunkSize); - instance->AppendToUploadSession(data, size, sessionId, offset); - - offset += size; - ftp->Progress(size); - } - - if (offset < fileSize) - size = ftp->ReadCurrentFile(data, fileSize - offset); - else - size = 0; - - char path[MAX_PATH]; - const wchar_t *serverFolder = ftp->GetServerFolder(); - if (serverFolder) { - wchar_t serverPath[MAX_PATH] = { 0 }; - mir_snwprintf(serverPath, L"%s\\%s", serverFolder, fileName); - PreparePath(serverPath, path); - } - else - PreparePath(fileName, path); - instance->FinishUploadSession(data, size, sessionId, offset, path); - - ftp->Progress(size); - - if (!wcschr(fileName, L'\\')) { - char url[MAX_PATH]; - instance->CreateDownloadUrl(path, url); - ftp->AppendFormatData(L"%s\r\n", ptrW(mir_utf8decodeW(url))); - } - } while (ftp->NextFile()); - } - catch (DropboxException &ex) { - Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, ex.what()); - ftp->SetStatus(ACKRESULT_FAILED); - return ACKRESULT_FAILED; - } - - ftp->SetStatus(ACKRESULT_SUCCESS); - return ACKRESULT_SUCCESS; -} - -UINT CDropbox::UploadAndReportProgress(void *owner, void *arg) -{ - CDropbox *instance = (CDropbox*)owner; - FileTransferParam *ftp = (FileTransferParam*)arg; - - int res = UploadToDropbox(owner, arg); - if (res == ACKRESULT_SUCCESS) - instance->Report(ftp->GetHContact(), ftp->GetData()); - - instance->transfers.remove(ftp); - delete ftp; - - return res; -} - -UINT CDropbox::UploadAndRaiseEvent(void *owner, void *arg) -{ - CDropbox *instance = (CDropbox*)owner; - FileTransferParam *ftp = (FileTransferParam*)arg; - - int res = UploadToDropbox(owner, arg); - - DropboxUploadResult ur = {}; - ur.hProcess = (HANDLE)ftp->GetId(); - ur.status = res; - ur.data = T2Utf(ftp->GetData()); - - NotifyEventHooks(instance->hUploadedEventHook, ftp->GetHContact(), (LPARAM)&ur); - - instance->transfers.remove(ftp); - delete ftp; - - return res; -} \ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox_utils.cpp b/plugins/Dropbox/src/dropbox_utils.cpp deleted file mode 100644 index a4e5d51747..0000000000 --- a/plugins/Dropbox/src/dropbox_utils.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include "stdafx.h" - -char* CDropbox::PreparePath(const char *oldPath, char *newPath) -{ - if (oldPath == nullptr) - mir_strcpy(newPath, ""); - else if (*oldPath != '/') - { - CMStringA result("/"); - result.Append(oldPath); - result.Replace("\\", "/"); - mir_strcpy(newPath, result); - } - else - mir_strcpy(newPath, oldPath); - return newPath; -} - -char* CDropbox::PreparePath(const wchar_t *oldPath, char *newPath) -{ - return PreparePath(ptrA(mir_utf8encodeW(oldPath)), newPath); -} - -bool CDropbox::IsAccountIntercepted(const char *module) -{ - const char *interceptedAccounts = db_get_sa(NULL, MODULE, "InterceptedAccounts"); - if (interceptedAccounts == nullptr) - interceptedAccounts = db_get_sa(NULL, MODULE, "InterceptedProtos"); - return interceptedAccounts && strstr(interceptedAccounts, module); -} - -char* CDropbox::HttpStatusToText(HTTP_STATUS status) -{ - switch (status) { - case HTTP_STATUS_ERROR: - return "Server does not respond"; - case HTTP_STATUS_OK: - return "OK"; - case HTTP_STATUS_BAD_REQUEST: - return "Bad input parameter. Error message should indicate which one and why"; - case HTTP_STATUS_UNAUTHORIZED: - return "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 HTTP_STATUS_FORBIDDEN: - return "Bad OAuth request (wrong consumer key, bad nonce, expired timestamp...). Unfortunately, re-authenticating the user won't help here"; - case HTTP_STATUS_NOT_FOUND: - return "File or folder not found at the specified path"; - case HTTP_STATUS_METHOD_NOT_ALLOWED: - return "Request method not expected (generally should be GET or POST)"; - case HTTP_STATUS_TOO_MANY_REQUESTS: - return "Your app is making too many requests and is being rate limited. 429s can trigger on a per-app or per-user basis"; - case HTTP_STATUS_SERVICE_UNAVAILABLE: - return "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 HTTP_STATUS_INSUFICIENTE_STORAGE: - return "User is over Dropbox storage quota"; - } - - return "Unknown error"; -} - -void CDropbox::HandleHttpResponse(NETLIBHTTPREQUEST *response) -{ - if (response == nullptr) - throw DropboxException(HttpStatusToText(HTTP_STATUS_ERROR)); -} - -JSONNode CDropbox::HandleJsonResponse(NETLIBHTTPREQUEST *response) -{ - HandleHttpResponse(response); - - if (response->resultCode != HTTP_STATUS_OK && - response->resultCode != HTTP_STATUS_CONFLICT) { - if (response->dataLength) - throw DropboxException(response->pData); - throw DropboxException(HttpStatusToText((HTTP_STATUS)response->resultCode)); - } - - JSONNode root = JSONNode::parse(response->pData); - if (root.isnull()) - throw DropboxException(HttpStatusToText(HTTP_STATUS_ERROR)); - - JSONNode error = root.at("error"); - if (!error.isnull()) { - json_string tag = error.at(".tag").as_string(); - throw DropboxException(tag.c_str()); - } - - return root; -} - -MEVENT CDropbox::AddEventToDb(MCONTACT hContact, WORD type, DWORD flags, DWORD cbBlob, PBYTE pBlob) -{ - DBEVENTINFO dbei = {}; - dbei.szModule = MODULE; - dbei.timestamp = time(nullptr); - dbei.eventType = type; - dbei.cbBlob = cbBlob; - dbei.pBlob = pBlob; - dbei.flags = flags; - return db_event_add(hContact, &dbei); -} - -void CDropbox::SendToContact(MCONTACT hContact, const wchar_t *data) -{ - if (hContact == GetDefaultContact()) { - char *message = mir_utf8encodeW(data); - AddEventToDb(hContact, EVENTTYPE_MESSAGE, DBEF_UTF, (DWORD)mir_strlen(message), (PBYTE)message); - return; - } - - const char *szProto = GetContactProto(hContact); - if (db_get_b(hContact, szProto, "ChatRoom", 0) == TRUE) { - ptrW tszChatRoom(db_get_wsa(hContact, szProto, "ChatRoomID")); - Chat_SendUserMessage(szProto, tszChatRoom, data); - return; - } - - char *message = mir_utf8encodeW(data); - if (ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)message) != ACKRESULT_FAILED) - AddEventToDb(hContact, EVENTTYPE_MESSAGE, DBEF_UTF | DBEF_SENT, (DWORD)mir_strlen(message), (PBYTE)message); -} - -void CDropbox::PasteToInputArea(MCONTACT hContact, const wchar_t *data) -{ - CallService(MS_MSG_SENDMESSAGEW, hContact, (LPARAM)data); -} - -void CDropbox::PasteToClipboard(const wchar_t *data) -{ - if (OpenClipboard(nullptr)) { - EmptyClipboard(); - - size_t size = sizeof(wchar_t) * (mir_wstrlen(data) + 1); - HGLOBAL hClipboardData = GlobalAlloc(NULL, size); - if (hClipboardData) { - wchar_t *pchData = (wchar_t*)GlobalLock(hClipboardData); - if (pchData) { - memcpy(pchData, (wchar_t*)data, size); - GlobalUnlock(hClipboardData); - SetClipboardData(CF_UNICODETEXT, hClipboardData); - } - } - CloseClipboard(); - } -} - -void CDropbox::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); -} diff --git a/plugins/Dropbox/src/file_transfer.h b/plugins/Dropbox/src/file_transfer.h deleted file mode 100644 index 8c50542bed..0000000000 --- a/plugins/Dropbox/src/file_transfer.h +++ /dev/null @@ -1,245 +0,0 @@ -#ifndef _FILE_TRANSFER_H_ -#define _FILE_TRANSFER_H_ - -class FileTransferParam -{ -private: - static ULONG hFileProcess; - - ULONG id; - FILE *hFile; - PROTOFILETRANSFERSTATUS pfts; - - bool isTerminated; - - const wchar_t* folderName; - int relativePathStart; - - CMStringW serverFolder; - - CMStringW data; - -public: - FileTransferParam(MCONTACT hContact) - { - hFile = NULL; - id = InterlockedIncrement(&hFileProcess); - - isTerminated = false; - - folderName = NULL; - relativePathStart = 0; - - pfts.cbSize = sizeof(this->pfts); - pfts.flags = PFTS_UNICODE | PFTS_SENDING; - pfts.hContact = hContact; - pfts.currentFileNumber = -1; - pfts.currentFileProgress = 0; - pfts.currentFileSize = 0; - pfts.currentFileTime = 0; - pfts.totalBytes = 0; - pfts.totalFiles = 0; - pfts.totalProgress = 0; - pfts.ptszFiles = (wchar_t**)mir_alloc(sizeof(wchar_t*) * (pfts.totalFiles + 1)); - pfts.ptszFiles[pfts.totalFiles] = NULL; - pfts.tszWorkingDir = NULL; - pfts.tszCurrentFile = NULL; - - ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)id, 0); - } - - ~FileTransferParam() - { - CloseCurrentFile(); - - if (pfts.tszWorkingDir) - mir_free(pfts.tszWorkingDir); - - if (pfts.pszFiles) - { - for (int i = 0; pfts.pszFiles[i]; i++) - { - if (pfts.pszFiles[i]) mir_free(pfts.pszFiles[i]); - } - mir_free(pfts.pszFiles); - } - } - - ULONG GetId() const - { - return id; - } - - MCONTACT GetHContact() const - { - return pfts.hContact; - } - - const wchar_t* GetData() const - { - if (data.IsEmpty()) - return NULL; - return data; - } - - void Terminate() - { - isTerminated = true; - } - - void SetWorkingDirectory(const wchar_t *path) - { - relativePathStart = wcsrchr(path, '\\') - path + 1; - pfts.tszWorkingDir = (wchar_t*)mir_calloc(sizeof(wchar_t) * relativePathStart); - mir_wstrncpy(pfts.tszWorkingDir, path, relativePathStart); - if (PathIsDirectory(path)) - folderName = wcsrchr(path, '\\') + 1; - } - - void SetServerFolder(const wchar_t *path) - { - if (path) - serverFolder = path; - } - - const wchar_t* GetServerFolder() const - { - if (serverFolder.IsEmpty()) - return NULL; - return serverFolder; - } - - const wchar_t* GetFolderName() const - { - return folderName; - } - - void AddFile(const wchar_t *path) - { - pfts.ptszFiles = (wchar_t**)mir_realloc(pfts.ptszFiles, sizeof(wchar_t*) * (pfts.totalFiles + 2)); - pfts.ptszFiles[pfts.totalFiles++] = mir_wstrdup(path); - pfts.ptszFiles[pfts.totalFiles] = NULL; - - FILE *file = _wfopen(path, L"rb"); - if (file != NULL) { - _fseeki64(file, 0, SEEK_END); - pfts.totalBytes += _ftelli64(file); - fclose(file); - } - } - - void AppendFormatData(const wchar_t *format, ...) - { - va_list args; - va_start(args, format); - data.AppendFormatV(format, args); - va_end(args); - } - - const wchar_t* GetCurrentFilePath() const - { - return pfts.ptszFiles[pfts.currentFileNumber]; - } - - const wchar_t* GetCurrentRelativeFilePath() const - { - return &GetCurrentFilePath()[relativePathStart]; - } - - const wchar_t* GetCurrentFileName() const - { - return wcsrchr(pfts.ptszFiles[pfts.currentFileNumber], '\\') + 1; - } - - void OpenCurrentFile() - { - hFile = _wfopen(GetCurrentFilePath(), L"rb"); - if (!hFile) - throw DropboxException("Unable to open file"); - _fseeki64(hFile, 0, SEEK_END); - pfts.currentFileSize = _ftelli64(hFile); - rewind(hFile); - } - - size_t ReadCurrentFile(void *buffer, size_t count) - { - return fread(buffer, sizeof(char), count, hFile); - } - - void CheckCurrentFile() - { - if (ferror(hFile)) - throw DropboxException("Error while file sending"); - - if (isTerminated) - throw DropboxException("Transfer was terminated"); - } - - void CloseCurrentFile() - { - if (hFile != NULL) - { - fclose(hFile); - hFile = NULL; - } - } - - const uint64_t GetCurrentFileSize() const - { - return pfts.currentFileSize; - } - - const uint64_t GetCurrentFileChunkSize() const - { - int chunkSize = 1024 * 1024; - if (pfts.currentFileSize < chunkSize) - chunkSize = min(pfts.currentFileSize, chunkSize / 4); - else if (pfts.currentFileSize > 20 * chunkSize) - chunkSize = chunkSize * 4; - return chunkSize; - } - - void Progress(size_t count) - { - pfts.currentFileProgress += count; - pfts.totalProgress += count; - ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)id, (LPARAM)&pfts); - } - - void FirstFile() - { - CloseCurrentFile(); - - pfts.currentFileNumber = 0; - pfts.currentFileProgress = 0; - pfts.tszCurrentFile = wcsrchr(pfts.ptszFiles[pfts.currentFileNumber], '\\') + 1; - ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)id, (LPARAM)&pfts); - - OpenCurrentFile(); - CheckCurrentFile(); - } - - bool NextFile() - { - CloseCurrentFile(); - - if (++pfts.currentFileNumber == pfts.totalFiles) - return false; - - pfts.currentFileProgress = 0; - pfts.tszCurrentFile = wcsrchr(pfts.ptszFiles[pfts.currentFileNumber], '\\') + 1; - ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, (HANDLE)id, 0); - - OpenCurrentFile(); - CheckCurrentFile(); - - return true; - } - - void SetStatus(int status, LPARAM param = 0) - { - ProtoBroadcastAck(MODULE, pfts.hContact, ACKTYPE_FILE, status, (HANDLE)id, param); - } -}; - -#endif //_FILE_TRANSFER_H_ \ No newline at end of file diff --git a/plugins/Dropbox/src/http_request.h b/plugins/Dropbox/src/http_request.h deleted file mode 100644 index 9d11ee4742..0000000000 --- a/plugins/Dropbox/src/http_request.h +++ /dev/null @@ -1,166 +0,0 @@ -#ifndef _HTTP_REQUEST_H_ -#define _HTTP_REQUEST_H_ - -enum HTTP_STATUS -{ - HTTP_STATUS_ERROR = 0, - 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_CONFLICT = 409, - HTTP_STATUS_TOO_MANY_REQUESTS = 429, - HTTP_STATUS_SERVICE_UNAVAILABLE = 503, - HTTP_STATUS_INSUFICIENTE_STORAGE = 507 -}; - -class HttpRequestException -{ - CMStringA message; - -public: - HttpRequestException(const char *message) : - message(message) - { - } - - const char* what() const throw() - { - return message.c_str(); - } -}; - -class HttpRequest : protected NETLIBHTTPREQUEST -{ -private: - CMStringA m_szUrl; - - void Init(int type) - { - cbSize = sizeof(NETLIBHTTPREQUEST); - requestType = type; - flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT; - szUrl = NULL; - headers = NULL; - headersCount = 0; - pData = NULL; - dataLength = 0; - resultCode = 0; - szResultDescr = NULL; - nlc = NULL; - timeout = 0; - } - -protected: - enum HttpRequestUrlFormat { FORMAT }; - - void AddHeader(LPCSTR szName, LPCSTR szValue) - { - headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER) * (headersCount + 1)); - headers[headersCount].szName = mir_strdup(szName); - headers[headersCount].szValue = mir_strdup(szValue); - headersCount++; - } - - void AddBasicAuthHeader(LPCSTR szLogin, LPCSTR szPassword) - { - char cPair[128]; - mir_snprintf( - cPair, - _countof(cPair), - "%s:%s", - szLogin, - szPassword); - - char *ePair = (char *)mir_base64_encode((BYTE*)cPair, (UINT)mir_strlen(cPair)); - - char value[128]; - mir_snprintf( - value, - _countof(value), - "Basic %s", - ePair); - - mir_free(ePair); - - headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1)); - headers[headersCount].szName = mir_strdup("Authorization"); - headers[headersCount].szValue = mir_strdup(value); - headersCount++; - } - - void AddBearerAuthHeader(LPCSTR szValue) - { - char value[128]; - mir_snprintf( - value, - _countof(value), - "Bearer %s", - szValue); - - headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1)); - headers[headersCount].szName = mir_strdup("Authorization"); - headers[headersCount].szValue = mir_strdup(value); - headersCount++; - } - - void AddUrlParameter(const char *urlFormat, ...) - { - va_list urlArgs; - va_start(urlArgs, urlFormat); - m_szUrl += m_szUrl.Find('?') == -1 ? '?' : '&'; - m_szUrl.AppendFormatV(urlFormat, urlArgs); - va_end(urlArgs); - } - - void SetData(const char *data, size_t size) - { - if (pData != NULL) - mir_free(pData); - - dataLength = (int)size; - pData = (char*)mir_alloc(size); - memcpy(pData, data, size); - } - -public: - HttpRequest(int type, LPCSTR url) - { - Init(type); - - m_szUrl = url; - } - - HttpRequest(int type, HttpRequestUrlFormat, LPCSTR urlFormat, ...) - { - Init(type); - - va_list formatArgs; - va_start(formatArgs, urlFormat); - m_szUrl.AppendFormatV(urlFormat, formatArgs); - va_end(formatArgs); - } - - ~HttpRequest() - { - for (int i = 0; i < headersCount; i++) - { - mir_free(headers[i].szName); - mir_free(headers[i].szValue); - } - mir_free(headers); - if (pData) - mir_free(pData); - } - - NETLIBHTTPREQUEST* Send(HNETLIBUSER hNetlibConnection) - { - m_szUrl.Replace('\\', '/'); - szUrl = m_szUrl.GetBuffer(); - return Netlib_HttpTransaction(hNetlibConnection, this); - } -}; - -#endif //_HTTP_REQUEST_H_ \ No newline at end of file diff --git a/plugins/Dropbox/src/main.cpp b/plugins/Dropbox/src/main.cpp deleted file mode 100644 index 033ca11032..0000000000 --- a/plugins/Dropbox/src/main.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "stdafx.h" - -void InitializeIcons(); - -int hLangpack; -CDropbox *dropbox; -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) -{ - return &pluginInfo; -} - -extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_DROPBOX, MIID_LAST }; - -extern "C" int __declspec(dllexport) Load(void) -{ - mir_getLP(&pluginInfo); - - InitializeIcons(); - - 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/resource.h b/plugins/Dropbox/src/resource.h deleted file mode 100644 index 1c8d33bf53..0000000000 --- a/plugins/Dropbox/src/resource.h +++ /dev/null @@ -1,34 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by C:\Users\unsane\Projects\c++\miranda-ng\plugins\Dropbox\res\resource.rc -// -#define IDI_DROPBOX 102 -#define IDI_UPLOAD 103 -#define IDD_OPTIONS_MAIN 109 -#define IDD_OPTIONS_INTERCEPTION 110 -#define IDC_REQUEST_CODE 1001 -#define IDC_AUTHORIZE 1002 -#define IDC_USE_SHORT_LINKS 1004 -#define IDC_URL_USE_SHORT 1004 -#define IDC_URL_ISTEMPORARY 1004 -#define IDC_AUTH_STATUS 1005 -#define IDC_GET_AUTH_LINK 1006 -#define IDC_URL_COPYTOCB 1009 -#define IDC_CHECK1 1010 -#define IDC_PROTOCOLS 1011 -#define IDC_ACCOUNTS 1011 -#define IDC_URL_COPYTOML 1029 -#define IDC_URL_COPYTOMIA 1029 -#define IDC_URL_AUTOSEND 1030 -#define IDC_GETAUTH 1200 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 105 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1013 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/plugins/Dropbox/src/stdafx.cxx b/plugins/Dropbox/src/stdafx.cxx deleted file mode 100644 index 0d27ff81bb..0000000000 --- a/plugins/Dropbox/src/stdafx.cxx +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright (C) 2012-17 Miranda NG project (https://miranda-ng.org) - -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. - -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. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "stdafx.h" - -ULONG FileTransferParam::hFileProcess = 1; \ No newline at end of file diff --git a/plugins/Dropbox/src/stdafx.h b/plugins/Dropbox/src/stdafx.h deleted file mode 100644 index 84aeb6e2a2..0000000000 --- a/plugins/Dropbox/src/stdafx.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef _COMMON_H_ -#define _COMMON_H_ - -#include -#include -#include - -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include "version.h" -#include "resource.h" - -class CDropbox; - -#define DROPBOX_API_VER "/2" -#define DROPBOX_WWW_URL "https://www.dropbox.com" -#define DROPBOX_API "https://api.dropboxapi.com" -#define DROPBOX_API_RPC DROPBOX_API DROPBOX_API_VER -#define DROPBOX_CONTENT "https://content.dropboxapi.com" -#define DROPBOX_API_CU DROPBOX_CONTENT DROPBOX_API_VER - -#define DROPBOX_APP_KEY "fa8du7gkf2q8xzg" -#include "../../../miranda-private-keys/Dropbox/secret_key.h" - -class DropboxException -{ - CMStringA message; - -public: - DropboxException(const char *message) : - message(message) - { - } - - const char* what() const throw() - { - return message.c_str(); - } -}; - -#define MODULE "Dropbox" - -#include "dropbox_options.h" -#include "http_request.h" -#include "api/account.h" -#include "api/upload.h" -#include "api/operations.h" -#include "file_transfer.h" -#include "dropbox.h" - -extern HINSTANCE g_hInstance; - -#define DROPBOX_FILE_CHUNK_SIZE 1024 * 1024 //1 MB - -#define BBB_ID_FILE_SEND 10001 - -// icons -void InitializeIcons(); -HANDLE GetIconHandleByName(const char *name); -HICON LoadIconEx(int iconId, bool big = false); - -#endif //_COMMON_H_ \ No newline at end of file diff --git a/plugins/Dropbox/src/version.h b/plugins/Dropbox/src/version.h deleted file mode 100644 index aaec775b44..0000000000 --- a/plugins/Dropbox/src/version.h +++ /dev/null @@ -1,14 +0,0 @@ -#define __MAJOR_VERSION 0 -#define __MINOR_VERSION 12 -#define __RELEASE_NUM 2 -#define __BUILD_NUM 4 - -#include - -#define __PLUGIN_NAME "Dropbox" -#define __FILENAME "Dropbox.dll" -#define __DESCRIPTION "Allows you to transfer files via Dropbox." -#define __AUTHOR "Miranda NG Team" -#define __AUTHOREMAIL "" -#define __AUTHORWEB "https://miranda-ng.org/p/Dropbox/" -#define __COPYRIGHT "© 2014-17 Miranda NG project" -- cgit v1.2.3