From 488f93815d3c247376f038377e7bc3731b074231 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 11 May 2015 20:12:46 +0000 Subject: Dropbox: work commit git-svn-id: http://svn.miranda-ng.org/main/trunk@13556 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dropbox/Dropbox.vcxproj | 5 +- plugins/Dropbox/src/dropbox.cpp | 190 +++++++++-------- plugins/Dropbox/src/dropbox.h | 24 +-- plugins/Dropbox/src/dropbox_commands.cpp | 6 +- plugins/Dropbox/src/dropbox_dialogs.cpp | 11 +- plugins/Dropbox/src/dropbox_events.cpp | 7 +- plugins/Dropbox/src/dropbox_services.cpp | 28 +-- plugins/Dropbox/src/dropbox_transfers.cpp | 334 ++++++++++++++---------------- plugins/Dropbox/src/dropbox_utils.cpp | 45 ++-- plugins/Dropbox/src/file_transfer.h | 54 +++-- plugins/Dropbox/src/http_request.h | 9 +- plugins/Dropbox/src/stdafx.h | 2 +- 12 files changed, 357 insertions(+), 358 deletions(-) diff --git a/plugins/Dropbox/Dropbox.vcxproj b/plugins/Dropbox/Dropbox.vcxproj index 437985989b..c4c8abd75b 100644 --- a/plugins/Dropbox/Dropbox.vcxproj +++ b/plugins/Dropbox/Dropbox.vcxproj @@ -29,5 +29,8 @@ comctl32.lib;shlwapi.lib;%(AdditionalDependencies) + + Sync + - \ No newline at end of file + diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp index f537148e88..27ab42cf8a 100644 --- a/plugins/Dropbox/src/dropbox.cpp +++ b/plugins/Dropbox/src/dropbox.cpp @@ -39,9 +39,11 @@ MCONTACT CDropbox::GetDefaultContact() if (!hDefaultContact) hDefaultContact = db_find_first(MODULE); - if (!hDefaultContact) { + if (!hDefaultContact) + { hDefaultContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); - if (!CallService(MS_PROTO_ADDTOCONTACT, hDefaultContact, (LPARAM)MODULE)) { + if (!CallService(MS_PROTO_ADDTOCONTACT, hDefaultContact, (LPARAM)MODULE)) + { db_set_s(NULL, MODULE, "Nick", MODULE); db_set_s(hDefaultContact, MODULE, "Nick", MODULE); db_set_ws(hDefaultContact, "CList", "MyHandle", L"Dropbox"); @@ -62,7 +64,7 @@ bool CDropbox::HasAccessToken() void CDropbox::RequestAccountInfo() { - HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_GET, DROPBOX_API_URL "/account/info"); + HttpRequest *request = new HttpRequest(hNetlibConnection, REQUEST_GET, DROPBOX_API_URL "/account/info"); request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); mir_ptr response(request->Send()); @@ -70,65 +72,71 @@ void CDropbox::RequestAccountInfo() MCONTACT hContact = CDropbox::GetDefaultContact(); - if (response && response->resultCode == HTTP_STATUS_OK) { - JSONROOT root(response->pData); - if (root) { - JSONNODE *node = json_get(root, "referral_link"); - if (node) { - ptrW referral_link = ptrW(json_as_string(node)); - db_set_ws(hContact, MODULE, "Homepage", referral_link); - } + HandleHttpResponseError(response); - node = json_get(root, "display_name"); - if (node) { - ptrW display_name = ptrW(json_as_string(node)); - wchar_t *sep = wcsrchr(display_name, L' '); - if (sep) { - db_set_ws(hContact, MODULE, "LastName", sep + 1); - display_name[wcslen(display_name) - wcslen(sep)] = '\0'; - db_set_ws(hContact, MODULE, "FirstName", display_name); - } - else { - db_set_ws(hContact, MODULE, "FirstName", display_name); - db_unset(hContact, MODULE, "LastName"); - } - } + JSONROOT root(response->pData); + if (root) + { + JSONNODE *node = json_get(root, "referral_link"); + if (node) + { + ptrW referral_link = ptrW(json_as_string(node)); + db_set_ws(hContact, MODULE, "Homepage", referral_link); + } - node = json_get(root, "country"); - if (node) { - ptrW isocodeW(json_as_string(node)); - ptrA isocode(mir_u2a(isocodeW)); - - if (!strlen(isocode)) - db_unset(hContact, MODULE, "Country"); - else { - char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode, 0); - db_set_s(hContact, MODULE, "Country", country); - } + node = json_get(root, "display_name"); + if (node) + { + ptrW display_name = ptrW(json_as_string(node)); + TCHAR *sep = wcsrchr(display_name, L' '); + if (sep) + { + db_set_ws(hContact, MODULE, "LastName", sep + 1); + display_name[wcslen(display_name) - wcslen(sep)] = '\0'; + db_set_ws(hContact, MODULE, "FirstName", display_name); + } + else + { + db_set_ws(hContact, MODULE, "FirstName", display_name); + db_unset(hContact, MODULE, "LastName"); } + } - node = json_get(root, "quota_info"); - JSONNODE *nroot = json_as_node(node); - if (nroot) { - node = json_get(nroot, "shared"); - if (node) - db_set_dw(hContact, MODULE, "SharedQuota", json_as_int(node)); - node = json_get(nroot, "normal"); - if (node) - db_set_dw(hContact, MODULE, "NormalQuota", json_as_int(node)); - node = json_get(nroot, "quota"); - if (node) - db_set_dw(hContact, MODULE, "TotalQuota", json_as_int(node)); + node = json_get(root, "country"); + if (node) + { + ptrW isocodeW(json_as_string(node)); + ptrA isocode(mir_u2a(isocodeW)); + + if (!strlen(isocode)) + db_unset(hContact, MODULE, "Country"); + else + { + char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode, 0); + db_set_s(hContact, MODULE, "Country", country); } } - } - HandleHttpResponseError(hNetlibUser, response); + node = json_get(root, "quota_info"); + JSONNODE *nroot = json_as_node(node); + if (nroot) + { + node = json_get(nroot, "shared"); + if (node) + db_set_dw(hContact, MODULE, "SharedQuota", json_as_int(node)); + node = json_get(nroot, "normal"); + if (node) + db_set_dw(hContact, MODULE, "NormalQuota", json_as_int(node)); + node = json_get(nroot, "quota"); + if (node) + db_set_dw(hContact, MODULE, "TotalQuota", json_as_int(node)); + } + } } -void CDropbox::DestroyAcceessToken() +void CDropbox::DestroyAccessToken() { - HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/disable_access_token"); + HttpRequest *request = new HttpRequest(hNetlibConnection, REQUEST_POST, DROPBOX_API_URL "/disable_access_token"); mir_ptr response(request->Send()); delete request; @@ -141,7 +149,7 @@ void CDropbox::DestroyAcceessToken() db_set_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE); } -UINT CDropbox::RequestAcceessTokenAsync(void *owner, void* param) +UINT CDropbox::RequestAccessTokenAsync(void *owner, void *param) { HWND hwndDlg = (HWND)param; CDropbox *instance = (CDropbox*)owner; @@ -150,7 +158,7 @@ UINT CDropbox::RequestAcceessTokenAsync(void *owner, void* param) SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("in process...")); if (instance->HasAccessToken()) - instance->DestroyAcceessToken(); + instance->DestroyAccessToken(); char requestToken[128]; GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, requestToken, SIZEOF(requestToken)); @@ -162,7 +170,7 @@ UINT CDropbox::RequestAcceessTokenAsync(void *owner, void* param) "grant_type=authorization_code&code=%s", requestToken); - HttpRequest *request = new HttpRequest(instance->hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/oauth2/token"); + HttpRequest *request = new HttpRequest(instance->hNetlibConnection, REQUEST_POST, DROPBOX_API_URL "/oauth2/token"); request->AddBasicAuthHeader(DROPBOX_API_KEY, DROPBOX_API_SECRET); request->AddHeader("Content-Type", "application/x-www-form-urlencoded"); request->pData = mir_strdup(data); @@ -174,42 +182,52 @@ UINT CDropbox::RequestAcceessTokenAsync(void *owner, void* param) MCONTACT hContact = instance->GetDefaultContact(); - if (response) { - JSONROOT root(response->pData); - if (root) { - if (response->resultCode == HTTP_STATUS_OK) { - JSONNODE *node = json_get(root, "access_token"); - ptrA access_token = ptrA(mir_u2a(json_as_string(node))); - db_set_s(NULL, MODULE, "TokenSecret", access_token); - - if (hContact) { - if (db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE) - db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE); - } + if (response == NULL) + { + if (hwndDlg) + SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("server does not respond")); + /*else + ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);*/ + } + JSONROOT root(response->pData); + if (root) + { + if (response->resultCode == HTTP_STATUS_OK) + { + JSONNODE *node = json_get(root, "access_token"); + ptrA access_token = ptrA(mir_u2a(json_as_string(node))); + db_set_s(NULL, MODULE, "TokenSecret", access_token); + + if (hContact) { + if (db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE) + db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE); + } + try + { instance->RequestAccountInfo(); - - if (hwndDlg) - SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you have been authorized")); - /*else - ShowNotification(TranslateT("you have been authorized"), MB_ICONINFORMATION);*/ } - else { - JSONNODE *node = json_get(root, "error_description"); - ptrW error_description(json_as_string(node)); - - if (hwndDlg) - SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, error_description); - /*else - ShowNotification((wchar_t*)error_description, MB_ICONERROR);*/ + catch (TransferException &ex) + { + Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, ex.what()); + return 0; } - } - } - else { - if (hwndDlg) - SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("server does not respond")); - HandleHttpResponseError(instance->hNetlibUser, response); + if (hwndDlg) + SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you have been authorized")); + /*else + ShowNotification(TranslateT("you have been authorized"), MB_ICONINFORMATION);*/ + } + else + { + JSONNODE *node = json_get(root, "error_description"); + ptrW error_description(json_as_string(node)); + + if (hwndDlg) + SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, error_description); + /*else + ShowNotification((TCHAR*)error_description, MB_ICONERROR);*/ + } } SetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, ""); diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h index c3e55057f7..6da80d85f4 100644 --- a/plugins/Dropbox/src/dropbox.h +++ b/plugins/Dropbox/src/dropbox.h @@ -38,7 +38,7 @@ public: virtual ~CDropbox(); private: - HANDLE hNetlibUser; + HANDLE hNetlibConnection; ULONG hFileProcess; ULONG hMessageProcess; @@ -85,23 +85,23 @@ private: // access token bool HasAccessToken(); - void RequestAcceessToken(); - void DestroyAcceessToken(); + void RequestAccessToken(); + void DestroyAccessToken(); - static UINT RequestAcceessTokenAsync(void *owner, void* param); + static UINT RequestAccessTokenAsync(void *owner, void *param); // account info void RequestAccountInfo(); // transfers - int SendFile(const char *fileName, const char *data, int length); - int SendFileChunkedFirst(const char *data, int length, char *uploadId, size_t &offset); - int SendFileChunkedNext(const char *data, int length, const char *uploadId, size_t &offset); - int SendFileChunkedLast(const char *fileName, const char *uploadId); + void SendFile(const char *fileName, const char *data, int length); + void SendFileChunkedFirst(const char *data, int length, char *uploadId, size_t &offset); + void SendFileChunkedNext(const char *data, int length, const char *uploadId, size_t &offset); + void SendFileChunkedLast(const char *fileName, const char *uploadId); - int CreateFolder(const char *folderName); + void CreateFolder(const char *folderName); - int CreateDownloadUrl(const char *path, wchar_t *url); + void CreateDownloadUrl(const char *path, char *url); static UINT SendFilesAsync(void *owner, void *arg); static UINT SendFilesAndEventAsync(void *owner, void *arg); @@ -123,8 +123,8 @@ private: static void DisableSrmmButton(MCONTACT hContact); // utils - static wchar_t *HttpStatusToText(HTTP_STATUS status); - static int HandleHttpResponseError(HANDLE hNetlibUser, NETLIBHTTPREQUEST *response); + static char* HttpStatusToText(HTTP_STATUS status); + static void HandleHttpResponseError(NETLIBHTTPREQUEST *response); }; #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 index 2e8963caa1..5b992fd45e 100644 --- a/plugins/Dropbox/src/dropbox_commands.cpp +++ b/plugins/Dropbox/src/dropbox_commands.cpp @@ -23,7 +23,7 @@ void CDropbox::CommandContent(void *arg) if (name) url.AppendFormat("/%s", ptrA(mir_utf8encode(name))); - HttpRequest *request = new HttpRequest(param->instance->hNetlibUser, REQUEST_GET, url); + HttpRequest *request = new HttpRequest(param->instance->hNetlibConnection, REQUEST_GET, url); request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); mir_ptr response(request->Send()); @@ -74,7 +74,7 @@ void CDropbox::CommandShare(void *arg) if (name) url.AppendFormat("/%s", ptrA(mir_utf8encode(name))); - HttpRequest *request = new HttpRequest(param->instance->hNetlibUser, REQUEST_POST, url); + HttpRequest *request = new HttpRequest(param->instance->hNetlibConnection, REQUEST_POST, url); request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); mir_ptr response(request->Send()); @@ -114,7 +114,7 @@ void CDropbox::CommandDelete(void *arg) if (name) { CMStringA pparam = CMStringA("root=" DROPBOX_API_ROOT "&path=") + ptrA(mir_utf8encode(name)); - HttpRequest *request = new HttpRequest(param->instance->hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/fileops/delete"); + HttpRequest *request = new HttpRequest(param->instance->hNetlibConnection, REQUEST_POST, DROPBOX_API_URL "/fileops/delete"); request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); request->AddHeader("Content-Type", "application/x-www-form-urlencoded"); request->pData = mir_strdup(pparam); diff --git a/plugins/Dropbox/src/dropbox_dialogs.cpp b/plugins/Dropbox/src/dropbox_dialogs.cpp index 0639bad285..8fe9f93f5e 100644 --- a/plugins/Dropbox/src/dropbox_dialogs.cpp +++ b/plugins/Dropbox/src/dropbox_dialogs.cpp @@ -4,7 +4,8 @@ INT_PTR CALLBACK CDropbox::MainOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam { CDropbox *instance = (CDropbox*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch (msg) { + switch (msg) + { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); instance = (CDropbox*)lParam; @@ -33,7 +34,8 @@ INT_PTR CALLBACK CDropbox::MainOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam return TRUE; case WM_COMMAND: - switch (LOWORD(wParam)) { + switch (LOWORD(wParam)) + { case IDC_GETAUTH: CallService(MS_UTILS_OPENURL, 0, (LPARAM)DROPBOX_WWW_URL DROPBOX_API_VER "/oauth2/authorize?response_type=code&client_id=" DROPBOX_API_KEY); SetFocus(GetDlgItem(hwndDlg, IDC_REQUEST_CODE)); @@ -48,7 +50,7 @@ INT_PTR CALLBACK CDropbox::MainOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam break; case IDC_AUTHORIZE: - mir_forkthreadowner(CDropbox::RequestAcceessTokenAsync, instance, hwndDlg, 0); + mir_forkthreadowner(CDropbox::RequestAccessTokenAsync, instance, hwndDlg, 0); break; case IDC_USE_SHORT_LINKS: @@ -62,7 +64,8 @@ INT_PTR CALLBACK CDropbox::MainOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam break; case WM_NOTIFY: - if (reinterpret_cast(lParam)->code == PSN_APPLY) { + if (reinterpret_cast(lParam)->code == PSN_APPLY) + { db_set_b(NULL, MODULE, "UseSortLinks", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_USE_SHORT_LINKS)); db_set_b(NULL, MODULE, "UrlAutoSend", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_URL_AUTOSEND)); db_set_b(NULL, MODULE, "UrlPasteToMessageInputArea", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_URL_COPYTOMIA)); diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp index 4c555b95d5..e66706cd06 100644 --- a/plugins/Dropbox/src/dropbox_events.cpp +++ b/plugins/Dropbox/src/dropbox_events.cpp @@ -18,7 +18,7 @@ int CDropbox::OnModulesLoaded(void *obj, WPARAM, LPARAM) CDropbox *instance = (CDropbox*)obj; - instance->hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); + instance->hNetlibConnection = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); instance->GetDefaultContact(); @@ -56,10 +56,9 @@ int CDropbox::OnContactDeleted(void *obj, WPARAM hContact, LPARAM) { CDropbox *instance = (CDropbox*)obj; - if (mir_strcmpi(GetContactProto(hContact), MODULE) == 0) { + if (mir_strcmpi(GetContactProto(hContact), MODULE) == 0) if (instance->HasAccessToken()) - instance->DestroyAcceessToken(); - } + instance->DestroyAccessToken(); return 0; } diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp index fa823c3726..46fd7fa985 100644 --- a/plugins/Dropbox/src/dropbox_services.cpp +++ b/plugins/Dropbox/src/dropbox_services.cpp @@ -77,7 +77,7 @@ INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam) ftp->hContact = (instance->hTransferContact) ? instance->hTransferContact : pccsd->hContact; instance->hTransferContact = 0; - wchar_t **paths = (wchar_t**)pccsd->lParam; + TCHAR **paths = (TCHAR**)pccsd->lParam; for (int i = 0; paths[i]; i++) { if (PathIsDirectory(paths[i])) @@ -86,17 +86,17 @@ INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam) ftp->pfts.totalFiles++; } - ftp->pwszFolders = (wchar_t**)mir_alloc(sizeof(wchar_t*) * (ftp->totalFolders + 1)); + ftp->pwszFolders = (TCHAR**)mir_alloc(sizeof(TCHAR*) * (ftp->totalFolders + 1)); ftp->pwszFolders[ftp->totalFolders] = NULL; - ftp->pfts.pwszFiles = (wchar_t**)mir_alloc(sizeof(wchar_t*) * (ftp->pfts.totalFiles + 1)); - ftp->pfts.pwszFiles[ftp->pfts.totalFiles] = NULL; + ftp->pfts.ptszFiles = (TCHAR**)mir_alloc(sizeof(TCHAR*) * (ftp->pfts.totalFiles + 1)); + ftp->pfts.ptszFiles[ftp->pfts.totalFiles] = NULL; for (int i = 0, j = 0, k = 0; paths[i]; i++) { if (PathIsDirectory(paths[i])) { if (!ftp->relativePathStart) { - wchar_t *rootFolder = paths[j]; - wchar_t *relativePath = wcsrchr(rootFolder, '\\') + 1; + TCHAR *rootFolder = paths[j]; + TCHAR *relativePath = wcsrchr(rootFolder, '\\') + 1; ftp->relativePathStart = relativePath - rootFolder; } @@ -106,15 +106,15 @@ INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam) } else { if (!ftp->pfts.wszWorkingDir) { - wchar_t *path = paths[j]; + TCHAR *path = paths[j]; int length = wcsrchr(path, '\\') - path; - ftp->pfts.wszWorkingDir = (wchar_t*)mir_alloc(sizeof(wchar_t) * (length + 1)); + ftp->pfts.wszWorkingDir = (TCHAR*)mir_alloc(sizeof(TCHAR) * (length + 1)); mir_tstrncpy(ftp->pfts.wszWorkingDir, paths[j], length + 1); ftp->pfts.wszWorkingDir[length] = '\0'; } - ftp->pfts.pwszFiles[k] = mir_wstrdup(paths[i]); + ftp->pfts.ptszFiles[k] = mir_wstrdup(paths[i]); FILE *file = _wfopen(paths[i], L"rb"); if (file != NULL) { @@ -221,7 +221,7 @@ INT_PTR CDropbox::SendFileToDropbox(void *obj, WPARAM hContact, LPARAM lParam) if (hContact == NULL) hContact = instance->GetDefaultContact(); - wchar_t *filePath = (wchar_t*)lParam; + TCHAR *filePath = (TCHAR*)lParam; FileTransferParam *ftp = new FileTransferParam(); ftp->pfts.flags |= PFTS_SENDING; @@ -231,13 +231,13 @@ INT_PTR CDropbox::SendFileToDropbox(void *obj, WPARAM hContact, LPARAM lParam) instance->hTransferContact = 0; int length = wcsrchr(filePath, '\\') - filePath; - ftp->pfts.wszWorkingDir = (wchar_t*)mir_alloc(sizeof(wchar_t) * (length + 1)); + ftp->pfts.wszWorkingDir = (TCHAR*)mir_alloc(sizeof(TCHAR) * (length + 1)); mir_tstrncpy(ftp->pfts.wszWorkingDir, filePath, length + 1); ftp->pfts.wszWorkingDir[length] = '\0'; - ftp->pfts.pwszFiles = (wchar_t**)mir_alloc(sizeof(wchar_t*) * (ftp->pfts.totalFiles + 1)); - ftp->pfts.pwszFiles[0] = mir_wstrdup(filePath); - ftp->pfts.pwszFiles[ftp->pfts.totalFiles] = NULL; + ftp->pfts.ptszFiles = (TCHAR**)mir_alloc(sizeof(TCHAR*) * (ftp->pfts.totalFiles + 1)); + ftp->pfts.ptszFiles[0] = mir_wstrdup(filePath); + ftp->pfts.ptszFiles[ftp->pfts.totalFiles] = NULL; ULONG fileId = InterlockedIncrement(&instance->hFileProcess); ftp->hProcess = (HANDLE)fileId; diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp index de361d853e..a38a806fe2 100644 --- a/plugins/Dropbox/src/dropbox_transfers.cpp +++ b/plugins/Dropbox/src/dropbox_transfers.cpp @@ -1,26 +1,26 @@ #include "stdafx.h" -int CDropbox::SendFile(const char *fileName, const char *data, int length) +/*void CDropbox::SendFile(const char *fileName, const char *data, int length) { - CMStringA url(FORMAT, DROPBOX_APICONTENT_URL "/files_put/%s/%s", DROPBOX_API_ROOT, ptrA(mir_utf8encode(fileName))); - url.Replace('\\', '/'); +CMStringA url(FORMAT, DROPBOX_APICONTENT_URL "/files_put/%s/%s", DROPBOX_API_ROOT, ptrA(mir_utf8encode(fileName))); +url.Replace('\\', '/'); - HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_PUT, DROPBOX_APICONTENT_URL "/files_put"); - request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); - request->pData = (char*)mir_alloc(sizeof(char)* length); - memcpy(request->pData, data, length); - request->dataLength = length; +HttpRequest *request = new HttpRequest(hNetlibConnection, REQUEST_PUT, DROPBOX_APICONTENT_URL "/files_put"); +request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); +request->pData = (char*)mir_alloc(sizeof(char)* length); +memcpy(request->pData, data, length); +request->dataLength = length; - mir_ptr response(request->Send()); +mir_ptr response(request->Send()); - delete request; +delete request; - return HandleHttpResponseError(hNetlibUser, response); -} +HandleHttpResponseError(hNetlibConnection, response); +}*/ -int CDropbox::SendFileChunkedFirst(const char *data, int length, char *uploadId, size_t &offset) +void CDropbox::SendFileChunkedFirst(const char *data, int length, char *uploadId, size_t &offset) { - HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_PUT, DROPBOX_APICONTENT_URL "/chunked_upload"); + HttpRequest *request = new HttpRequest(hNetlibConnection, REQUEST_PUT, DROPBOX_APICONTENT_URL "/chunked_upload"); request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); request->AddHeader("Content-Type", "application/octet-stream"); request->pData = (char*)mir_alloc(sizeof(char)* length); @@ -31,26 +31,25 @@ int CDropbox::SendFileChunkedFirst(const char *data, int length, char *uploadId, delete request; - if (response && response->resultCode == HTTP_STATUS_OK) { - JSONROOT root(response->pData); - if (root) { - JSONNODE *node = json_get(root, "upload_id"); - strcpy(uploadId, mir_u2a(json_as_string(node))); + HandleHttpResponseError(response); - node = json_get(root, "offset"); - offset = json_as_int(node); - } - } + JSONROOT root(response->pData); + if (root) + { + JSONNODE *node = json_get(root, "upload_id"); + strcpy(uploadId, mir_u2a(json_as_string(node))); - return HandleHttpResponseError(hNetlibUser, response); + node = json_get(root, "offset"); + offset = json_as_int(node); + } } -int CDropbox::SendFileChunkedNext(const char *data, int length, const char *uploadId, size_t &offset) +void CDropbox::SendFileChunkedNext(const char *data, int length, const char *uploadId, size_t &offset) { CMStringA url(DROPBOX_APICONTENT_URL "/chunked_upload"); url.AppendFormat("?upload_id=%s&offset=%i", uploadId, offset); - HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_PUT, url); + HttpRequest *request = new HttpRequest(hNetlibConnection, REQUEST_PUT, url); request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); request->AddHeader("Content-Type", "application/octet-stream"); request->pData = (char*)mir_alloc(sizeof(char)* length); @@ -61,25 +60,24 @@ int CDropbox::SendFileChunkedNext(const char *data, int length, const char *uplo delete request; - if (response && response->resultCode == HTTP_STATUS_OK) { - JSONROOT root(response->pData); - if (root) { - JSONNODE *node = json_get(root, "offset"); - offset = json_as_int(node); - } - } + HandleHttpResponseError(response); - return HandleHttpResponseError(hNetlibUser, response); + JSONROOT root(response->pData); + if (root) + { + JSONNODE *node = json_get(root, "offset"); + offset = json_as_int(node); + } } -int CDropbox::SendFileChunkedLast(const char *fileName, const char *uploadId) +void CDropbox::SendFileChunkedLast(const char *fileName, const char *uploadId) { CMStringA url(FORMAT, "%s/commit_chunked_upload/%s/%s", DROPBOX_APICONTENT_URL, DROPBOX_API_ROOT, fileName); url.Replace('\\', '/'); CMStringA param = CMStringA("upload_id=") + uploadId; - HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_POST, url); + HttpRequest *request = new HttpRequest(hNetlibConnection, REQUEST_POST, url); request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); request->AddHeader("Content-Type", "application/x-www-form-urlencoded"); request->pData = mir_strdup(param); @@ -89,17 +87,17 @@ int CDropbox::SendFileChunkedLast(const char *fileName, const char *uploadId) delete request; - return HandleHttpResponseError(hNetlibUser, response); + HandleHttpResponseError(response); } -int CDropbox::CreateFolder(const char *folderName) +void CDropbox::CreateFolder(const char *folderName) { CMStringA folder(folderName); folder.Replace('\\', '/'); CMStringA param(FORMAT, "root=%s&path=%s", DROPBOX_API_ROOT, folder); - HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/fileops/create_folder"); + HttpRequest *request = new HttpRequest(hNetlibConnection, REQUEST_POST, DROPBOX_API_URL "/fileops/create_folder"); request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); request->AddHeader("Content-Type", "application/x-www-form-urlencoded"); request->pData = mir_strdup(param); @@ -111,12 +109,12 @@ int CDropbox::CreateFolder(const char *folderName) // forder exists on server if (response->resultCode == HTTP_STATUS_FORBIDDEN) - return 0; + return; - return HandleHttpResponseError(hNetlibUser, response); + HandleHttpResponseError(response); } -int CDropbox::CreateDownloadUrl(const char *path, wchar_t *url) +void CDropbox::CreateDownloadUrl(const char *path, char *url) { CMStringA api_url(DROPBOX_API_URL); api_url.AppendFormat("/shares/%s/%s", DROPBOX_API_ROOT, path); @@ -124,151 +122,124 @@ int CDropbox::CreateDownloadUrl(const char *path, wchar_t *url) if (!db_get_b(NULL, MODULE, "UseSortLinks", 1)) api_url += "?short_url=false"; - HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_POST, api_url); + HttpRequest *request = new HttpRequest(hNetlibConnection, REQUEST_POST, api_url); request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); mir_ptr response(request->Send()); delete request; - if (response && response->resultCode == HTTP_STATUS_OK) { - JSONROOT root(response->pData); - if (root) { - JSONNODE *node = json_get(root, "url"); - wcscpy(url, json_as_string(node)); - } - } + HandleHttpResponseError(response); - return HandleHttpResponseError(hNetlibUser, response); + JSONROOT root(response->pData); + if (root) + { + JSONNODE *node = json_get(root, "url"); + mir_strcpy(url, _T2A(json_as_string(node))); + } } UINT CDropbox::SendFilesAsync(void *owner, void *arg) { - bool error = false; CDropbox *instance = (CDropbox*)owner; FileTransferParam *ftp = (FileTransferParam*)arg; ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ftp->hProcess, 0); - if (ftp->pwszFolders) { - for (int i = 0; ftp->pwszFolders[i]; i++) { - ptrA utf8_folderName(mir_utf8encodeW(ftp->pwszFolders[i])); - - if (!instance->CreateFolder(utf8_folderName)) { - if (!strchr(utf8_folderName, '\\')) { - wchar_t url[MAX_PATH]; - if (!instance->CreateDownloadUrl(utf8_folderName, url)) - ftp->AddUrl(url); - else { - error = true; - break; - } + try + { + if (ftp->pwszFolders) + { + for (int i = 0; ftp->pwszFolders[i]; i++) + { + ptrA utf8_folderName(mir_utf8encodeW(ftp->pwszFolders[i])); + + instance->CreateFolder(utf8_folderName); + if (!strchr(utf8_folderName, '\\')) + { + char url[MAX_PATH]; + instance->CreateDownloadUrl(utf8_folderName, url); + ftp->AddUrl(url); } } - else { - error = true; - break; - } } - } - if (!error) { - for (int i = 0; ftp->pfts.pwszFiles[i]; i++) { - FILE *file = _wfopen(ftp->pfts.pwszFiles[i], L"rb"); - if (file) { - const wchar_t *fileName = NULL; - if (!ftp->relativePathStart) - fileName = wcsrchr(ftp->pfts.pwszFiles[i], L'\\') + 1; + for (int i = 0; ftp->pfts.ptszFiles[i]; i++) + { + FILE *hFile = _tfopen(ftp->pfts.ptszFiles[i], _T("rb")); + if (hFile == NULL) + throw TransferException("Unable to open file"); + + const TCHAR *fileName = NULL; + if (!ftp->relativePathStart) + fileName = _tcsrchr(ftp->pfts.ptszFiles[i], L'\\') + 1; + else + fileName = &ftp->pfts.ptszFiles[i][ftp->relativePathStart]; + + _fseeki64(hFile, 0, SEEK_END); + uint64_t fileSize = _ftelli64(hFile); + rewind(hFile); + + ftp->pfts.currentFileNumber = i; + ftp->pfts.currentFileSize = fileSize; + ftp->pfts.currentFileProgress = 0; + ftp->pfts.wszCurrentFile = wcsrchr(ftp->pfts.ptszFiles[i], '\\') + 1; + + ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ftp->hProcess, (LPARAM)&ftp->pfts); + + // + size_t offset = 0; + char *uploadId = new char[32]; + + int chunkSize = DROPBOX_FILE_CHUNK_SIZE / 4; + if (fileSize < 1024 * 1024) + chunkSize = DROPBOX_FILE_CHUNK_SIZE / 20; + else if (fileSize > 20 * 1024 * 1024) + chunkSize = DROPBOX_FILE_CHUNK_SIZE; + + while (!feof(hFile) && fileSize != offset) + { + if (ferror(hFile)) + throw TransferException("Error while file sending"); + + char *data = new char[chunkSize + 1]; + int count = (int)fread(data, sizeof(char), chunkSize, hFile); + + if (offset == 0) + instance->SendFileChunkedFirst(data, count, uploadId, offset); else - fileName = &ftp->pfts.pwszFiles[i][ftp->relativePathStart]; - - fseek(file, 0, SEEK_END); - size_t fileSize = ftell(file); - fseek(file, 0, SEEK_SET); + instance->SendFileChunkedNext(data, count, uploadId, offset); - ftp->pfts.currentFileNumber = i; - ftp->pfts.currentFileSize = fileSize; - ftp->pfts.currentFileProgress = 0; - ftp->pfts.wszCurrentFile = wcsrchr(ftp->pfts.pwszFiles[i], '\\') + 1; + ftp->pfts.currentFileProgress += count; + ftp->pfts.totalProgress += count; ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ftp->hProcess, (LPARAM)&ftp->pfts); + } - // - size_t offset = 0; - char *uploadId = new char[32]; - - int chunkSize = DROPBOX_FILE_CHUNK_SIZE / 4; - if (fileSize < 1024 * 1024) - chunkSize = DROPBOX_FILE_CHUNK_SIZE / 20; - else if (fileSize > 20 * 1024 * 1024) - chunkSize = DROPBOX_FILE_CHUNK_SIZE; - - while (!feof(file) && fileSize != offset) { - if (ferror(file)) { - error = true; - break; - } - - char *data = new char[chunkSize + 1]; - int count = (int)fread(data, sizeof(char), chunkSize, file); - - if (!offset) { - if (instance->SendFileChunkedFirst(data, count, uploadId, offset)) { - error = true; - break; - } - } - else { - if (instance->SendFileChunkedNext(data, count, uploadId, offset)) { - error = true; - break; - } - } + fclose(hFile); - ftp->pfts.currentFileProgress += count; - ftp->pfts.totalProgress += count; + ptrA utf8_fileName(mir_utf8encodeW(fileName)); - ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ftp->hProcess, (LPARAM)&ftp->pfts); - } + instance->SendFileChunkedLast(utf8_fileName, uploadId); - fclose(file); + if (!_tcschr(fileName, L'\\')) + { + char url[MAX_PATH]; + instance->CreateDownloadUrl(utf8_fileName, url); + ftp->AddUrl(url); + } - if (!error) { - ptrA utf8_fileName(mir_utf8encodeW(fileName)); + ftp->pfts.currentFileProgress = ftp->pfts.currentFileSize; - if (instance->SendFileChunkedLast(utf8_fileName, uploadId)) { - error = true; - break; - } - else { - if (!wcschr(fileName, L'\\')) { - wchar_t url[MAX_PATH]; - if (!instance->CreateDownloadUrl(utf8_fileName, url)) - ftp->AddUrl(url); - else { - error = true; - break; - } - } - - ftp->pfts.currentFileProgress = ftp->pfts.currentFileSize; - - if (i < ftp->pfts.totalFiles - 1) - ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ftp->hProcess, 0); - } - } - } - else { - error = true; - break; - } + if (i < ftp->pfts.totalFiles - 1) + ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ftp->hProcess, 0); } } - - if (error) { + catch (TransferException &ex) + { + Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, ex.what()); ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ftp->hProcess, 0); - - return 1; + return 0; } ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ftp->hProcess, 0); @@ -282,53 +253,62 @@ UINT CDropbox::SendFilesAndReportAsync(void *owner, void *arg) FileTransferParam *ftp = (FileTransferParam*)arg; int res = SendFilesAsync(owner, arg); - if (!res) { - CMString urls; - for (int i = 0; ftp->pwszUrls[i]; i++) - urls.AppendFormat(L"%s\r\n", ftp->pwszUrls[i]); - wchar_t *data = urls.GetBuffer(); - - if (db_get_b(NULL, MODULE, "UrlAutoSend", 1)) { - char *message = mir_utf8encodeW(data); - if (ftp->hContact != instance->GetDefaultContact()) { - if (CallContactService(ftp->hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)message) != ACKRESULT_FAILED) { + if (!res) + { + CMStringA urls; + for (int i = 0; ftp->urlList.getCount(); i++) + urls.AppendFormat("%s\r\n", ftp->urlList[i]); + char *data = urls.GetBuffer(); + + if (db_get_b(NULL, MODULE, "UrlAutoSend", 1)) + { + char *message = mir_utf8encode(data); + if (ftp->hContact != instance->GetDefaultContact()) + { + if (CallContactService(ftp->hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)message) != ACKRESULT_FAILED) + { DBEVENTINFO dbei = { sizeof(dbei) }; dbei.flags = DBEF_UTF | DBEF_SENT/* | DBEF_READ*/; dbei.szModule = MODULE; dbei.timestamp = time(NULL); dbei.eventType = EVENTTYPE_MESSAGE; - dbei.cbBlob = (int)wcslen(data); + dbei.cbBlob = (int)mir_strlen(data); dbei.pBlob = (PBYTE)message; db_event_add(ftp->hContact, &dbei); } else CallServiceSync(MS_MSG_SENDMESSAGEW, (WPARAM)ftp->hContact, (LPARAM)data); } - else { + else + { DBEVENTINFO dbei = { sizeof(dbei) }; dbei.flags = DBEF_UTF; dbei.szModule = MODULE; dbei.timestamp = time(NULL); dbei.eventType = EVENTTYPE_MESSAGE; - dbei.cbBlob = (int)wcslen(data); + dbei.cbBlob = (int)mir_strlen(data); dbei.pBlob = (PBYTE)message; db_event_add(ftp->hContact, &dbei); } } if (db_get_b(NULL, MODULE, "UrlPasteToMessageInputArea", 0)) - CallServiceSync(MS_MSG_SENDMESSAGEW, (WPARAM)ftp->hContact, (LPARAM)data); + CallServiceSync(MS_MSG_SENDMESSAGE, (WPARAM)ftp->hContact, (LPARAM)data); - if (db_get_b(NULL, MODULE, "UrlCopyToClipboard", 0)) { - if (OpenClipboard(NULL)) { + if (db_get_b(NULL, MODULE, "UrlCopyToClipboard", 0)) + { + if (OpenClipboard(NULL)) + { EmptyClipboard(); - size_t size = sizeof(wchar_t) * (urls.GetLength() + 1); + size_t size = sizeof(TCHAR) * (urls.GetLength() + 1); HGLOBAL hClipboardData = GlobalAlloc(NULL, size); - if (hClipboardData) { - wchar_t *pchData = (wchar_t*)GlobalLock(hClipboardData); - if (pchData) { - memcpy(pchData, (wchar_t*)data, size); + if (hClipboardData) + { + TCHAR *pchData = (TCHAR*)GlobalLock(hClipboardData); + if (pchData) + { + memcpy(pchData, (TCHAR*)data, size); GlobalUnlock(hClipboardData); - SetClipboardData(CF_UNICODETEXT, hClipboardData); + SetClipboardData(CF_TEXT, hClipboardData); } } CloseClipboard(); @@ -351,7 +331,7 @@ UINT CDropbox::SendFilesAndEventAsync(void *owner, void *arg) TRANSFERINFO ti = { 0 }; ti.hProcess = ftp->hProcess; ti.status = res; - ti.data = ftp->pwszUrls; + ti.data = ftp->urlList.getArray(); NotifyEventHooks(instance->hFileSentEventHook, ftp->hContact, (LPARAM)&ti); diff --git a/plugins/Dropbox/src/dropbox_utils.cpp b/plugins/Dropbox/src/dropbox_utils.cpp index 401ba75693..28eff5049f 100644 --- a/plugins/Dropbox/src/dropbox_utils.cpp +++ b/plugins/Dropbox/src/dropbox_utils.cpp @@ -1,42 +1,41 @@ #include "stdafx.h" -wchar_t *CDropbox::HttpStatusToText(HTTP_STATUS status) +char* CDropbox::HttpStatusToText(HTTP_STATUS status) { - switch (status) { + switch (status) + { + case HTTP_STATUS_ERROR: + return "Server does not respond"; case HTTP_STATUS_OK: - return L"OK"; + return "OK"; case HTTP_STATUS_BAD_REQUEST: - return L"Bad input parameter. Error message should indicate which one and why"; + return "Bad input parameter. Error message should indicate which one and why"; case HTTP_STATUS_UNAUTHORIZED: - return L"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"; + 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 L"Bad OAuth request (wrong consumer key, bad nonce, expired timestamp...). Unfortunately, re-authenticating the user won't help here"; + 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 L"File or folder not found at the specified path"; + return "File or folder not found at the specified path"; case HTTP_STATUS_METHOD_NOT_ALLOWED: - return L"Request method not expected (generally should be GET or POST)"; + return "Request method not expected (generally should be GET or POST)"; case HTTP_STATUS_TOO_MANY_REQUESTS: - return L"Your app is making too many requests and is being rate limited. 429s can trigger on a per-app or per-user basis"; + 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 L"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."; + 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 L"User is over Dropbox storage quota"; + return "User is over Dropbox storage quota"; } - return L"Unknown"; + return "Unknown error"; } -int CDropbox::HandleHttpResponseError(HANDLE hNetlibUser, NETLIBHTTPREQUEST *response) -{ - if (!response) { - Netlib_Logf(hNetlibUser, "%s: %s", MODULE, "Server does not respond"); - return ACKRESULT_FAILED; - } - if (response->resultCode != HTTP_STATUS_OK) { - Netlib_Logf(hNetlibUser, "%s: %s", MODULE, HttpStatusToText((HTTP_STATUS)response->resultCode)); - return response->resultCode; - } - return 0; +void CDropbox::HandleHttpResponseError(NETLIBHTTPREQUEST *response) +{ + if (response == NULL) + throw TransferException(HttpStatusToText(HTTP_STATUS_ERROR)); + + if (response->resultCode != HTTP_STATUS_OK) + throw TransferException(HttpStatusToText((HTTP_STATUS)response->resultCode)); } diff --git a/plugins/Dropbox/src/file_transfer.h b/plugins/Dropbox/src/file_transfer.h index 3d887abcd5..04a0e8c8f8 100644 --- a/plugins/Dropbox/src/file_transfer.h +++ b/plugins/Dropbox/src/file_transfer.h @@ -1,6 +1,22 @@ #ifndef _FILE_TRANSFER_H_ #define _FILE_TRANSFER_H_ +class TransferException +{ + CMStringA message; + +public: + TransferException(const char *message) : + message(message) + { + } + + const char* what() const throw() + { + return message.c_str(); + } +}; + struct FileTransferParam { HANDLE hProcess; @@ -8,19 +24,19 @@ struct FileTransferParam PROTOFILETRANSFERSTATUS pfts; int totalFolders; - wchar_t **pwszFolders; + TCHAR **pwszFolders; int relativePathStart; - wchar_t **pwszUrls; + LIST urlList; - FileTransferParam() + FileTransferParam() : urlList(1) { totalFolders = 0; pwszFolders = NULL; relativePathStart = 0; pfts.cbSize = sizeof(this->pfts); - pfts.flags = PFTS_UNICODE; + pfts.flags = PFTS_TCHAR; pfts.currentFileNumber = 0; pfts.currentFileProgress = 0; pfts.currentFileSize = 0; @@ -30,8 +46,6 @@ struct FileTransferParam pfts.pszFiles = NULL; pfts.tszWorkingDir = NULL; pfts.wszCurrentFile = NULL; - - pwszUrls = NULL; } ~FileTransferParam() @@ -57,32 +71,14 @@ struct FileTransferParam mir_free(pwszFolders); } - if (pwszUrls) - { - for (int i = 0; pwszUrls[i]; i++) - { - if (pwszUrls[i]) mir_free(pwszUrls[i]); - } - mir_free(pwszUrls); - } + for (int i = 0; urlList.getCount(); i++) + mir_free(urlList[i]); + urlList.destroy(); } - void AddUrl(const wchar_t *url) + void AddUrl(const char *url) { - int count = 0; - if (pwszUrls == NULL) - pwszUrls = (wchar_t**)mir_alloc(sizeof(wchar_t*) * 2); - else - { - for (; pwszUrls[count]; count++); - pwszUrls = (wchar_t**)mir_realloc(pwszUrls, sizeof(wchar_t*) * (count + 2)); - } - - size_t length = wcslen(url); - pwszUrls[count] = (wchar_t*)mir_alloc(sizeof(wchar_t) * (length + 1)); - wcscpy(pwszUrls[count], url); - pwszUrls[count][length] = '\0'; - pwszUrls[count + 1] = NULL; + urlList.insert(mir_strdup(url)); } }; diff --git a/plugins/Dropbox/src/http_request.h b/plugins/Dropbox/src/http_request.h index 108b244c6f..3b41344776 100644 --- a/plugins/Dropbox/src/http_request.h +++ b/plugins/Dropbox/src/http_request.h @@ -3,6 +3,7 @@ enum HTTP_STATUS { + HTTP_STATUS_ERROR = 0, HTTP_STATUS_OK = 200, HTTP_STATUS_BAD_REQUEST = 400, HTTP_STATUS_UNAUTHORIZED = 401, @@ -17,13 +18,13 @@ enum HTTP_STATUS class HttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject { public: - HttpRequest(HANDLE hNetlibUser, int requestType, LPCSTR url) + HttpRequest(HANDLE hNetlibConnection, int requestType, LPCSTR url) { cbSize = sizeof(NETLIBHTTPREQUEST); flags = NLHRF_HTTP11; this->requestType = requestType; - m_hNetlibUser = hNetlibUser; + m_hNetlibConnection = hNetlibConnection; m_szUrl = mir_strdup(url); } @@ -91,12 +92,12 @@ public: NETLIBHTTPREQUEST *Send() { szUrl = m_szUrl.GetBuffer(); - return (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)this); + return (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibConnection, (LPARAM)this); } private: CMStringA m_szUrl; - HANDLE m_hNetlibUser; + HANDLE m_hNetlibConnection; }; #endif //_HTTP_REQUEST_H_ \ No newline at end of file diff --git a/plugins/Dropbox/src/stdafx.h b/plugins/Dropbox/src/stdafx.h index a575db9b9c..7e8420b896 100644 --- a/plugins/Dropbox/src/stdafx.h +++ b/plugins/Dropbox/src/stdafx.h @@ -2,7 +2,7 @@ #define _COMMON_H_ #include -#include +#include #include #include -- cgit v1.2.3