From 0b82b879821c7e73b86f189be747c5634c8b46b7 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 22 Feb 2016 21:12:25 +0000 Subject: Dropbox: - updated api to v2 - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@16326 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dropbox/src/dropbox_utils.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'plugins/Dropbox/src/dropbox_utils.cpp') diff --git a/plugins/Dropbox/src/dropbox_utils.cpp b/plugins/Dropbox/src/dropbox_utils.cpp index aee70273eb..f9e726fe92 100644 --- a/plugins/Dropbox/src/dropbox_utils.cpp +++ b/plugins/Dropbox/src/dropbox_utils.cpp @@ -1,5 +1,21 @@ #include "stdafx.h" +CMStringA CDropbox::PreparePath(const char *path) +{ + CMStringA result("/"); + result.Append(path); + result.Replace("\\", "/"); + return result; +} + +CMStringA CDropbox::PreparePath(const TCHAR *path) +{ + CMStringA result("/"); + result.Append(ptrA(mir_utf8encodeW(path))); + result.Replace("\\", "/"); + return result; +} + char* CDropbox::HttpStatusToText(HTTP_STATUS status) { switch (status) { @@ -28,13 +44,23 @@ char* CDropbox::HttpStatusToText(HTTP_STATUS status) return "Unknown error"; } -void CDropbox::HandleHttpResponseError(NETLIBHTTPREQUEST *response) +void CDropbox::HandleJsonResponseError(NETLIBHTTPREQUEST *response) { if (response == NULL) - throw TransferException(HttpStatusToText(HTTP_STATUS_ERROR)); + throw DropboxException(HttpStatusToText(HTTP_STATUS_ERROR)); + + JSONNode root = JSONNode::parse(response->pData); + if (root.empty()) { + if (response->dataLength) + throw DropboxException(response->pData); + throw DropboxException(HttpStatusToText((HTTP_STATUS)response->resultCode)); + } + + JSONNode error = root.at("error_summary"); + if (error.empty()) + return; - if (response->resultCode != HTTP_STATUS_OK) - throw TransferException(HttpStatusToText((HTTP_STATUS)response->resultCode)); + throw DropboxException(error.as_string().c_str()); } MEVENT CDropbox::AddEventToDb(MCONTACT hContact, WORD type, DWORD flags, DWORD cbBlob, PBYTE pBlob) -- cgit v1.2.3